feat(shop-goods): 添加格口号字符串字段并调整查询逻辑

为了支持格口号的字符串表示,在ShopGoodsDTO和SearchGoodsDO中添加了cellNoStr字段。同时,调整了SearchShopGoodsQuery的查询逻辑,增加了按goods_id分组的操作。此外,更新了CabinetCellMapper和ShopGoodsMapper的SQL语句,以支持新的字段和查询需求。最后,在CabinetCellController中添加了调整格口商品库存和清空格口商品的接口。
This commit is contained in:
dzq 2025-04-19 09:27:42 +08:00
parent 65b6dbd1d9
commit 9487ba863a
8 changed files with 42 additions and 6 deletions

View File

@ -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<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 = "清空格口商品")
@AccessLog(title = "格口管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping("/clearGoodsCells/{cellId}")
public ResponseDTO<Void> clearGoodsCells(@PathVariable Long cellId) {
cabinetCellApplicationService.clearGoodsCells(cellId);
return ResponseDTO.ok();
}
}

View File

@ -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);
}
}

View File

@ -47,7 +47,7 @@ public interface CabinetCellMapper extends BaseMapper<CabinetCellEntity> {
List<CabinetCellEntity> 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);

View File

@ -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;
}

View File

@ -37,13 +37,12 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
); */
@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<SearchGoodsDO> getGoodsList(
Page<SearchGoodsDO> page,
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper

View File

@ -20,7 +20,7 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
@Override
public Page<SearchGoodsDO> getGoodsList(AbstractPageQuery<SearchGoodsDO> query) {
QueryWrapper<SearchGoodsDO> 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);
}

View File

@ -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;
}

View File

@ -27,7 +27,8 @@ public class SearchShopGoodsQuery<T> extends AbstractPageQuery<T> {
.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";