diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java index 6b65b6f..3441baf 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/CabinetCellController.java @@ -3,8 +3,10 @@ package com.agileboot.api.controller; import cn.hutool.json.JSONUtil; 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.error.ErrorCode; +import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService; import com.agileboot.domain.cabinet.cell.model.CabinetCellModel; import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory; 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.shop.goods.model.GoodsModel; import com.agileboot.domain.shop.goods.model.GoodsModelFactory; +import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -39,12 +42,40 @@ public class CabinetCellController { private final GoodsModelFactory goodsModelFactory; private final SmartCabinetModelFactory smartCabinetModelFactory; private final CabinetMainboardModelFactory cabinetMainboardModelFactory; + private final CabinetCellApplicationService cabinetCellApplicationService; @GetMapping("/detail") public ResponseDTO> getCabinetDetail(@RequestParam Long shopId) { return ResponseDTO.ok(smartCabinetApplicationService.getCabinetDetail(shopId)); } + + @Operation(summary = "配置格口商品库存") + @PutMapping("/configureGoodsCellsStock/{cellId}/{goodsId}/{stock}") + public ResponseDTO 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 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 clearGoodsCells(@PathVariable Long cellId) { + cabinetCellApplicationService.clearGoodsCells(cellId); + return ResponseDTO.ok(); + } + + @PostMapping("/openCabinet/{cabinetId}/{pinNo}") public ResponseDTO openCabinet(@PathVariable Long cabinetId, @PathVariable Integer pinNo, @RequestBody AddCabinetCellOperationCommand operationCommand) { diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java index 4bed918..8853371 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java @@ -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.dto.ShopCategoryDTO; 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.ShopGoodsEntity; @@ -20,6 +21,7 @@ import java.util.ArrayList; import java.util.List; 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.db.ShopEntity; import lombok.RequiredArgsConstructor; @@ -53,6 +55,19 @@ public class ShopController { return ResponseDTO.ok(shopList); } + @GetMapping("/goods/list") + public ResponseDTO> getShopGoodsList(SearchShopGoodsQuery query) { + if (StringUtils.isBlank(query.getCorpid())) { + query.setCorpid(WeixinConstants.corpid); + } + if (query.getBelongType() == null) { + query.setBelongType(0); + } + + List goodsList = goodsApplicationService.selectGoodsList(query); + return ResponseDTO.ok(goodsList); + } + @GetMapping("/goods") public ResponseDTO getShopGoodsInfo(@RequestParam(required = false) Long shopId) { /*// 获取商品列表 diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java index e1dfd06..320b4e3 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/GoodsApplicationService.java @@ -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.GoodsModelFactory; 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 java.math.BigDecimal; @@ -32,6 +33,10 @@ public class GoodsApplicationService { return new PageDTO<>(goodsDTOList, goodsPage.getTotal()); } + public List selectGoodsList(SearchShopGoodsQuery query) { + return shopGoodsService.selectGoodsList(query); + } + public void addGoods(AddGoodsCommand command) { GoodsModel model = goodsModelFactory.create(); model.loadAddGoodsCommand(command); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java index 6a9912e..7e6fa41 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java @@ -50,6 +50,19 @@ public interface ShopGoodsMapper extends BaseMapper { @Param(Constants.WRAPPER) Wrapper 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 getGoodsListQuery( + @Param(Constants.WRAPPER) Wrapper queryWrapper + ); + /** * 查询所有商品(未删除的) * @return 商品列表 diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java index 0f6656f..5bf6216 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsService.java @@ -18,6 +18,8 @@ import java.util.List; public interface ShopGoodsService extends IService { Page getGoodsList(AbstractPageQuery query); + List selectGoodsList(AbstractPageQuery query); + List selectAll(); List getGoodsWithCabinetList(Long shopId); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java index 4f118fa..a27835c 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsServiceImpl.java @@ -29,6 +29,12 @@ public class ShopGoodsServiceImpl extends ServiceImpl selectGoodsList(AbstractPageQuery query) { + QueryWrapper wrapper = query.toQueryWrapper(); + return baseMapper.getGoodsListQuery(wrapper); + } + @Override public List selectAll() { return baseMapper.selectAll();