From 9487ba863ac90aeb53e42673b767207e45b76721 Mon Sep 17 00:00:00 2001 From: dzq Date: Sat, 19 Apr 2025 09:27:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(shop-goods):=20=E6=B7=BB=E5=8A=A0=E6=A0=BC?= =?UTF-8?q?=E5=8F=A3=E5=8F=B7=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=B9=B6=E8=B0=83=E6=95=B4=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了支持格口号的字符串表示,在ShopGoodsDTO和SearchGoodsDO中添加了cellNoStr字段。同时,调整了SearchShopGoodsQuery的查询逻辑,增加了按goods_id分组的操作。此外,更新了CabinetCellMapper和ShopGoodsMapper的SQL语句,以支持新的字段和查询需求。最后,在CabinetCellController中添加了调整格口商品库存和清空格口商品的接口。 --- .../cabinet/CabinetCellController.java | 22 +++++++++++++++++++ .../cell/CabinetCellApplicationService.java | 10 +++++++++ .../cabinet/cell/db/CabinetCellMapper.java | 2 +- .../domain/shop/goods/db/SearchGoodsDO.java | 2 ++ .../domain/shop/goods/db/ShopGoodsMapper.java | 5 ++--- .../shop/goods/db/ShopGoodsServiceImpl.java | 2 +- .../domain/shop/goods/dto/ShopGoodsDTO.java | 2 ++ .../goods/query/SearchShopGoodsQuery.java | 3 ++- 8 files changed, 42 insertions(+), 6 deletions(-) diff --git a/agileboot-admin/src/main/java/com/agileboot/admin/controller/cabinet/CabinetCellController.java b/agileboot-admin/src/main/java/com/agileboot/admin/controller/cabinet/CabinetCellController.java index 0f9ea3f..da7ed3e 100644 --- a/agileboot-admin/src/main/java/com/agileboot/admin/controller/cabinet/CabinetCellController.java +++ b/agileboot-admin/src/main/java/com/agileboot/admin/controller/cabinet/CabinetCellController.java @@ -16,6 +16,7 @@ import io.swagger.v3.oas.annotations.Operation; import java.util.List; import javax.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Slf4j @RestController @RequestMapping("/cabinet/cell") @RequiredArgsConstructor @@ -81,4 +83,24 @@ public class CabinetCellController extends BaseController { cabinetCellApplicationService.configureGoodsCellsStock(cellId, goodsId, stock); return ResponseDTO.ok(); } + + @Operation(summary = "调整格口商品库存") + @AccessLog(title = "格口管理", businessType = BusinessTypeEnum.MODIFY) + @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 = "清空格口商品") + @AccessLog(title = "格口管理", businessType = BusinessTypeEnum.MODIFY) + @PutMapping("/clearGoodsCells/{cellId}") + public ResponseDTO clearGoodsCells(@PathVariable Long cellId) { + cabinetCellApplicationService.clearGoodsCells(cellId); + return ResponseDTO.ok(); + } } \ No newline at end of file diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/CabinetCellApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/CabinetCellApplicationService.java index 99626da..0805b37 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/CabinetCellApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/CabinetCellApplicationService.java @@ -91,4 +91,14 @@ public class CabinetCellApplicationService { model.setUsageStatus(2); model.updateById(); } + + public void changeGoodsCellsStock(Long cellId, Integer stock) { + CabinetCellModel model = cabinetCellModelFactory.loadById(cellId); + model.setStock(stock); + model.updateById(); + } + + public void clearGoodsCells(Long cellId) { + cabinetCellService.clearGoodsIdAndFreeCell(cellId); + } } \ No newline at end of file diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/db/CabinetCellMapper.java b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/db/CabinetCellMapper.java index 123610b..61d4c06 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/db/CabinetCellMapper.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/cabinet/cell/db/CabinetCellMapper.java @@ -47,7 +47,7 @@ public interface CabinetCellMapper extends BaseMapper { List selectByGoodsId(@Param("goodsId")Long goodsId); @Update("UPDATE cabinet_cell " + - "SET goods_id = NULL, usage_status = 1 " + + "SET stock = 0, goods_id = NULL, usage_status = 1 " + "WHERE cell_id = #{cellId}") void clearGoodsIdAndFreeCell(@Param("cellId") Long cellId); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsDO.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsDO.java index e42eaaf..57cf0d1 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsDO.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/SearchGoodsDO.java @@ -18,6 +18,8 @@ public class SearchGoodsDO extends ShopGoodsEntity { private String cabinetName; @TableField("cell_no") private Integer cellNo; + @TableField("cell_no_str") + private String cellNoStr; @TableField("total_stock") private Integer totalStock; } 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 3d4f156..7586b14 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 @@ -37,13 +37,12 @@ public interface ShopGoodsMapper extends BaseMapper { ); */ @Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " + "g.stock, g.status, g.cover_img, SUM(cc.stock) AS total_stock, " + - "GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no, " + + "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} " + - "GROUP BY g.goods_id") + "${ew.customSqlSegment} ") Page getGoodsList( Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper 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 a481b31..40c2c3b 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 @@ -20,7 +20,7 @@ public class ShopGoodsServiceImpl extends ServiceImpl getGoodsList(AbstractPageQuery query) { QueryWrapper wrapper = query.toQueryWrapper(); - wrapper.orderByAsc("sc.cabinet_id IS NULL", "sc.cabinet_id", "cc.cell_no"); +// wrapper.orderByAsc("sc.cabinet_id IS NULL", "sc.cabinet_id", "cc.cell_no"); return baseMapper.getGoodsList(query.toPage(), wrapper); } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/dto/ShopGoodsDTO.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/dto/ShopGoodsDTO.java index d4eb887..e5eda7b 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/dto/ShopGoodsDTO.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/dto/ShopGoodsDTO.java @@ -79,6 +79,8 @@ public class ShopGoodsDTO { private String cabinetName; @ExcelColumn(name = "格口号") private Integer cellNo; + @ExcelColumn(name = "格口号") + private String cellNoStr; @ExcelColumn(name = "已分配库存") private Integer totalStock; } diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/query/SearchShopGoodsQuery.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/query/SearchShopGoodsQuery.java index 026e8e0..079b751 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/query/SearchShopGoodsQuery.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/query/SearchShopGoodsQuery.java @@ -27,7 +27,8 @@ public class SearchShopGoodsQuery extends AbstractPageQuery { .eq(status != null, "g.status", status) .ge(minPrice != null, "g.price", minPrice) .le(maxPrice != null, "g.price", maxPrice) - .eq("g.deleted", 0); + .eq("g.deleted", 0) + .groupBy("g.goods_id"); this.timeRangeColumn = "create_time";