feat(商品): 添加获取商品列表接口及格口库存管理功能

添加获取商品列表的非分页查询接口
新增格口商品库存配置、调整和清空功能
This commit is contained in:
dzq 2025-06-14 08:09:06 +08:00
parent 4e4c4876b6
commit 460d34457e
6 changed files with 72 additions and 0 deletions

View File

@ -3,8 +3,10 @@ package com.agileboot.api.controller;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.agileboot.common.core.dto.ResponseDTO; import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.common.exception.ApiException; import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode; import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService;
import com.agileboot.domain.cabinet.cell.model.CabinetCellModel; import com.agileboot.domain.cabinet.cell.model.CabinetCellModel;
import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory; import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory;
import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModel; import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModel;
@ -19,6 +21,7 @@ import com.agileboot.domain.cabinet.smartCabinet.model.SmartCabinetModelFactory;
import com.agileboot.domain.mqtt.MqttService; import com.agileboot.domain.mqtt.MqttService;
import com.agileboot.domain.shop.goods.model.GoodsModel; import com.agileboot.domain.shop.goods.model.GoodsModel;
import com.agileboot.domain.shop.goods.model.GoodsModelFactory; import com.agileboot.domain.shop.goods.model.GoodsModelFactory;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -39,12 +42,40 @@ public class CabinetCellController {
private final GoodsModelFactory goodsModelFactory; private final GoodsModelFactory goodsModelFactory;
private final SmartCabinetModelFactory smartCabinetModelFactory; private final SmartCabinetModelFactory smartCabinetModelFactory;
private final CabinetMainboardModelFactory cabinetMainboardModelFactory; private final CabinetMainboardModelFactory cabinetMainboardModelFactory;
private final CabinetCellApplicationService cabinetCellApplicationService;
@GetMapping("/detail") @GetMapping("/detail")
public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail(@RequestParam Long shopId) { public ResponseDTO<List<CabinetDetailDTO>> getCabinetDetail(@RequestParam Long shopId) {
return ResponseDTO.ok(smartCabinetApplicationService.getCabinetDetail(shopId)); return ResponseDTO.ok(smartCabinetApplicationService.getCabinetDetail(shopId));
} }
@Operation(summary = "配置格口商品库存")
@PutMapping("/configureGoodsCellsStock/{cellId}/{goodsId}/{stock}")
public ResponseDTO<Void> configureGoodsCellsStock(@PathVariable Long cellId, @PathVariable Long goodsId, @PathVariable Integer stock) {
cabinetCellApplicationService.configureGoodsCellsStock(cellId, goodsId, stock);
return ResponseDTO.ok();
}
@Operation(summary = "调整格口商品库存")
@PutMapping("/changeGoodsCellsStock/{cellId}/{stock}")
public ResponseDTO<Void> changeGoodsCellsStock(@PathVariable Long cellId, @PathVariable Integer stock) {
if (stock < 0) {
log.error("调整格口商品库存,库存不能小于0");
return ResponseDTO.fail();
}
cabinetCellApplicationService.changeGoodsCellsStock(cellId, stock);
return ResponseDTO.ok();
}
@Operation(summary = "清空格口商品")
@PutMapping("/clearGoodsCells/{cellId}")
public ResponseDTO<Void> clearGoodsCells(@PathVariable Long cellId) {
cabinetCellApplicationService.clearGoodsCells(cellId);
return ResponseDTO.ok();
}
@PostMapping("/openCabinet/{cabinetId}/{pinNo}") @PostMapping("/openCabinet/{cabinetId}/{pinNo}")
public ResponseDTO<?> openCabinet(@PathVariable Long cabinetId, @PathVariable Integer pinNo, public ResponseDTO<?> openCabinet(@PathVariable Long cabinetId, @PathVariable Integer pinNo,
@RequestBody AddCabinetCellOperationCommand operationCommand) { @RequestBody AddCabinetCellOperationCommand operationCommand) {

View File

@ -10,6 +10,7 @@ import com.agileboot.domain.shop.category.CategoryApplicationService;
import com.agileboot.domain.shop.category.db.ShopCategoryEntity; import com.agileboot.domain.shop.category.db.ShopCategoryEntity;
import com.agileboot.domain.shop.category.dto.ShopCategoryDTO; import com.agileboot.domain.shop.category.dto.ShopCategoryDTO;
import com.agileboot.domain.shop.goods.GoodsApplicationService; import com.agileboot.domain.shop.goods.GoodsApplicationService;
import com.agileboot.domain.shop.goods.db.SearchGoodsDO;
import com.agileboot.domain.shop.goods.db.SearchGoodsWithCabinetDO; import com.agileboot.domain.shop.goods.db.SearchGoodsWithCabinetDO;
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity; import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
@ -20,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.agileboot.domain.shop.goods.query.SearchShopGoodsQuery;
import com.agileboot.domain.shop.shop.ShopApplicationService; import com.agileboot.domain.shop.shop.ShopApplicationService;
import com.agileboot.domain.shop.shop.db.ShopEntity; import com.agileboot.domain.shop.shop.db.ShopEntity;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -53,6 +55,19 @@ public class ShopController {
return ResponseDTO.ok(shopList); return ResponseDTO.ok(shopList);
} }
@GetMapping("/goods/list")
public ResponseDTO<List<SearchGoodsDO>> getShopGoodsList(SearchShopGoodsQuery<SearchGoodsDO> query) {
if (StringUtils.isBlank(query.getCorpid())) {
query.setCorpid(WeixinConstants.corpid);
}
if (query.getBelongType() == null) {
query.setBelongType(0);
}
List<SearchGoodsDO> goodsList = goodsApplicationService.selectGoodsList(query);
return ResponseDTO.ok(goodsList);
}
@GetMapping("/goods") @GetMapping("/goods")
public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo(@RequestParam(required = false) Long shopId) { public ResponseDTO<ShopGoodsResponse> getShopGoodsInfo(@RequestParam(required = false) Long shopId) {
/*// 获取商品列表 /*// 获取商品列表

View File

@ -12,6 +12,7 @@ import com.agileboot.domain.shop.goods.dto.ShopGoodsDTO;
import com.agileboot.domain.shop.goods.model.GoodsModel; import com.agileboot.domain.shop.goods.model.GoodsModel;
import com.agileboot.domain.shop.goods.model.GoodsModelFactory; import com.agileboot.domain.shop.goods.model.GoodsModelFactory;
import com.agileboot.domain.shop.goods.query.SearchShopGoodsQuery; import com.agileboot.domain.shop.goods.query.SearchShopGoodsQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -32,6 +33,10 @@ public class GoodsApplicationService {
return new PageDTO<>(goodsDTOList, goodsPage.getTotal()); return new PageDTO<>(goodsDTOList, goodsPage.getTotal());
} }
public List<SearchGoodsDO> selectGoodsList(SearchShopGoodsQuery<SearchGoodsDO> query) {
return shopGoodsService.selectGoodsList(query);
}
public void addGoods(AddGoodsCommand command) { public void addGoods(AddGoodsCommand command) {
GoodsModel model = goodsModelFactory.create(); GoodsModel model = goodsModelFactory.create();
model.loadAddGoodsCommand(command); model.loadAddGoodsCommand(command);

View File

@ -50,6 +50,19 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper @Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
); );
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
"g.stock, g.status, g.auto_approval, g.cover_img, g.usage_instruction, SUM(cc.stock) AS total_stock, " +
"GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " +
"GROUP_CONCAT(DISTINCT sc.cabinet_name) AS cabinet_name " +
"FROM shop_goods g " +
"LEFT JOIN cabinet_cell cc ON g.goods_id = cc.goods_id AND cc.deleted = 0 " +
"LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id AND sc.deleted = 0 " +
"${ew.customSqlSegment} ")
List<SearchGoodsDO> getGoodsListQuery(
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
);
/** /**
* 查询所有商品未删除的 * 查询所有商品未删除的
* @return 商品列表 * @return 商品列表

View File

@ -18,6 +18,8 @@ import java.util.List;
public interface ShopGoodsService extends IService<ShopGoodsEntity> { public interface ShopGoodsService extends IService<ShopGoodsEntity> {
Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query); Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query);
List<SearchGoodsDO> selectGoodsList(AbstractPageQuery<SearchGoodsDO> query);
List<ShopGoodsEntity> selectAll(); List<ShopGoodsEntity> selectAll();
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId); List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList(Long shopId);

View File

@ -29,6 +29,12 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
return baseMapper.getGoodsList(query.toPage(), wrapper); return baseMapper.getGoodsList(query.toPage(), wrapper);
} }
@Override
public List<SearchGoodsDO> selectGoodsList(AbstractPageQuery<SearchGoodsDO> query) {
QueryWrapper<SearchGoodsDO> wrapper = query.toQueryWrapper();
return baseMapper.getGoodsListQuery(wrapper);
}
@Override @Override
public List<ShopGoodsEntity> selectAll() { public List<ShopGoodsEntity> selectAll() {
return baseMapper.selectAll(); return baseMapper.selectAll();