feat: 添加格口库存管理功能并优化商品查询

本次提交主要添加了格口库存管理功能,包括在`cabinet_cell`表中新增`stock`字段,并在相关实体类、DTO、控制器和服务中实现库存的配置和查询。同时,优化了商品查询逻辑,支持按柜机ID查询商品,并在商品DTO中添加了`total_stock`字段以显示已分配库存。此外,还在订单相关实体类中添加了`name`字段,用于存储用户姓名。
This commit is contained in:
dzq 2025-04-17 16:39:52 +08:00
parent 774dc07d1a
commit 41dc6aee69
16 changed files with 106 additions and 8 deletions

View File

@ -73,4 +73,12 @@ public class CabinetCellController extends BaseController {
cabinetCellApplicationService.configureGoodsCells(cellId, goodsId);
return ResponseDTO.ok();
}
@Operation(summary = "配置格口商品库存")
@AccessLog(title = "格口管理", businessType = BusinessTypeEnum.MODIFY)
@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();
}
}

View File

@ -71,6 +71,11 @@ public class SmartCabinetController extends BaseController {
return ResponseDTO.ok();
}
@Operation(summary = "获取所有柜机数据")
@GetMapping("/allCabinets")
public ResponseDTO<List<SmartCabinetEntity>> allCabinets() {
return ResponseDTO.ok(smartCabinetApplicationService.selectAll());
}
@Operation(summary = "获取所有柜机和格口数据")
@GetMapping("/all")

View File

@ -10,6 +10,8 @@ import com.agileboot.domain.cabinet.cell.dto.CabinetCellDTO;
import com.agileboot.domain.cabinet.cell.model.CabinetCellModel;
import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory;
import com.agileboot.domain.cabinet.cell.query.SearchCabinetCellQuery;
import com.agileboot.domain.shop.goods.db.ShopGoodsEntity;
import com.agileboot.domain.shop.goods.db.ShopGoodsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.stream.Collectors;
@ -24,11 +26,25 @@ import org.springframework.web.bind.annotation.PathVariable;
public class CabinetCellApplicationService {
private final CabinetCellService cabinetCellService;
private final CabinetCellModelFactory cabinetCellModelFactory;
private final ShopGoodsService shopGoodsService;
public PageDTO<CabinetCellDTO> getCabinetCellList(SearchCabinetCellQuery<CabinetCellEntity> query) {
Page<CabinetCellEntity> page = cabinetCellService.getCellList(query);
List<ShopGoodsEntity> goodsList = shopGoodsService.selectAll();
List<CabinetCellDTO> dtoList = page.getRecords().stream()
.map(CabinetCellDTO::new)
.map(cell -> {
CabinetCellDTO dto = new CabinetCellDTO(cell);
ShopGoodsEntity goods = goodsList.stream()
.filter(g -> g.getGoodsId().equals(cell.getGoodsId()))
.findFirst()
.orElse(null);
if (goods != null) {
dto.setGoodsName(goods.getGoodsName());
dto.setPrice(goods.getPrice());
dto.setCoverImg(goods.getCoverImg());
}
return dto;
})
.collect(Collectors.toList());
return new PageDTO<>(dtoList, page.getTotal());
}
@ -67,4 +83,12 @@ public class CabinetCellApplicationService {
model.setUsageStatus(2);
model.updateById();
}
public void configureGoodsCellsStock(Long cellId, Long goodsId, Integer stock) {
CabinetCellModel model = cabinetCellModelFactory.loadById(cellId);
model.setGoodsId(goodsId);
model.setStock(stock);
model.setUsageStatus(2);
model.updateById();
}
}

View File

@ -43,6 +43,10 @@ public class CabinetCellEntity extends BaseEntity<CabinetCellEntity> {
@TableField("pin_no")
private Integer pinNo;
@ApiModelProperty("库存数量")
@TableField("stock")
private Integer stock;
@ApiModelProperty("格口类型1小格 2中格 3大格 4超大格")
@TableField("cell_type")
private Integer cellType;

View File

@ -8,6 +8,8 @@ import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
import com.agileboot.domain.system.user.db.SysUserEntity;
import lombok.Data;
import java.math.BigDecimal;
@ExcelSheet(name = "柜机格口信息列表")
@Data
public class CabinetCellDTO {
@ -35,6 +37,9 @@ public class CabinetCellDTO {
@ExcelColumn(name = "针脚序号")
private Integer pinNo;
@ExcelColumn(name = "库存数量")
private Integer stock;
@ExcelColumn(name = "格口类型")
private Integer cellType;
@ -47,6 +52,13 @@ public class CabinetCellDTO {
@ExcelColumn(name = "关联商品ID")
private Long goodsId;
@ExcelColumn(name = "商品名称")
private String goodsName;
@ExcelColumn(name = "商品价格")
private BigDecimal price;
@ExcelColumn(name = "封面图URL")
private String coverImg;
@ExcelColumn(name = "操作人")
private String operator;

View File

@ -84,6 +84,21 @@ public class ReturnApprovalEntity extends BaseEntity<ReturnApprovalEntity> {
@TableField(exist = false)
private String coverImg;
@ApiModelProperty("手机号码")
@TableField(exist = false)
private String mobile;
@ApiModelProperty("企业微信用户ID或汇邦云用户ID")
@TableField(exist = false)
private String userid;
@ApiModelProperty("用户姓名")
@TableField(exist = false)
private String name;
@ApiModelProperty("是否内部用户0否 1汇邦云用户 2企业微信用户")
@TableField(exist = false)
private Integer isInternal;
@Override
public Serializable pkVal() {

View File

@ -18,9 +18,11 @@ import org.apache.ibatis.annotations.Select;
*/
public interface ReturnApprovalMapper extends BaseMapper<ReturnApprovalEntity> {
@Select("SELECT ra.*, sog.goods_name AS goodsName, sog.cover_img AS coverImg " +
@Select("SELECT ra.*, sog.goods_name AS goodsName, sog.cover_img AS coverImg, " +
"so.mobile, so.userid, so.name, so.is_internal AS isInternal " +
"FROM return_approval ra " +
"LEFT JOIN shop_order_goods sog ON ra.order_goods_id = sog.order_goods_id " +
"LEFT JOIN shop_order so ON ra.order_id = so.order_id AND so.deleted = 0 " +
"LEFT JOIN shop_order_goods sog ON ra.order_goods_id = sog.order_goods_id AND sog.deleted = 0 " +
"${ew.customSqlSegment}")
Page<ReturnApprovalEntity> selectApprovalWithGoodsInfo(Page<ReturnApprovalEntity> page,
@Param(Constants.WRAPPER) Wrapper<ReturnApprovalEntity> queryWrapper);

View File

@ -18,4 +18,6 @@ public class SearchGoodsDO extends ShopGoodsEntity {
private String cabinetName;
@TableField("cell_no")
private Integer cellNo;
@TableField("total_stock")
private Integer totalStock;
}

View File

@ -23,7 +23,7 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
* @param queryWrapper 查询条件
* @return 商品分页列表
*/
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
/* @Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
"g.stock, g.status, g.cover_img, c.category_name, " +
"sc.cabinet_id, sc.cabinet_name, cc.cell_no " +
"FROM shop_goods g " +
@ -34,6 +34,19 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
Page<SearchGoodsDO> getGoodsList(
Page<SearchGoodsDO> page,
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
); */
@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 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")
Page<SearchGoodsDO> getGoodsList(
Page<SearchGoodsDO> page,
@Param(Constants.WRAPPER) Wrapper<SearchGoodsDO> queryWrapper
);
/**

View File

@ -18,7 +18,9 @@ public class ShopGoodsDTO {
public ShopGoodsDTO(ShopGoodsEntity entity) {
if (entity != null) {
BeanUtil.copyProperties(entity, this);
if (this.getTotalStock() == null) {
this.setTotalStock(0);
}
/* ShopCategoryEntity category = CacheCenter.categoryCache.get(entity.getCategoryId() + "");
if (category != null) {
this.categoryName = category.getCategoryName();
@ -77,4 +79,6 @@ public class ShopGoodsDTO {
private String cabinetName;
@ExcelColumn(name = "格口号")
private Integer cellNo;
@ExcelColumn(name = "已分配库存")
private Integer totalStock;
}

View File

@ -23,7 +23,7 @@ public class SearchShopGoodsQuery<T> extends AbstractPageQuery<T> {
queryWrapper
.like(StrUtil.isNotEmpty(goodsName), "g.goods_name", goodsName)
.eq(categoryId != null, "g.category_id", categoryId)
.eq(categoryId != null, "cc.cabinet_id", categoryId)
.eq(status != null, "g.status", status)
.ge(minPrice != null, "g.price", minPrice)
.le(maxPrice != null, "g.price", maxPrice)

View File

@ -124,6 +124,7 @@ public class OrderApplicationService {
orderModel.setMobile(command.getMobile());
orderModel.setIsInternal(command.getIsInternal());
orderModel.setUserid(command.getQyUserid());
orderModel.setName(command.getName());
orderModel.insert();
processOrderGoods(orderModel, goodsList);

View File

@ -31,6 +31,9 @@ public class SubmitOrderCommand {
@ApiModelProperty("企业微信用户ID或汇邦云用户ID")
private String qyUserid;
@ApiModelProperty("用户姓名")
private String name;
@ApiModelProperty("是否内部订单 0否 1汇邦云用户 2企业微信用户")
private Integer isInternal;
}

View File

@ -53,6 +53,10 @@ public class ShopOrderEntity extends BaseEntity<ShopOrderEntity> {
@TableField("userid")
private String userid;
@ApiModelProperty("用户姓名")
@TableField("name")
private String name;
@ApiModelProperty("是否内部用户0否 1汇邦云用户 2企业微信用户")
@TableField("is_internal")
private Integer isInternal;

View File

@ -25,6 +25,7 @@ CREATE TABLE `cabinet_cell` (
`goods_id` BIGINT DEFAULT NULL COMMENT '关联商品ID',
`cell_no` INT NOT NULL COMMENT '格口号',
`pin_no` INT NOT NULL COMMENT '针脚序号',
`stock` INT NOT NULL DEFAULT 0 COMMENT '库存数量',
`cell_type` TINYINT NOT NULL DEFAULT 1 COMMENT '格口类型1小格 2中格 3大格 4超大格',
`usage_status` TINYINT NOT NULL DEFAULT 1 COMMENT '使用状态1空闲 2已占用',
`available_status` TINYINT NOT NULL DEFAULT 1 COMMENT '可用状态1正常 2故障',

View File

@ -67,5 +67,5 @@ ADD COLUMN `is_internal` TINYINT(1) DEFAULT 0 COMMENT '是否内部用户0否
ALTER TABLE `shop_order`
ADD COLUMN `userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '企业微信用户ID或汇邦云用户ID' AFTER `mobile`;
ALTER TABLE `cabinet_cell`
ADD COLUMN `stock` INT NOT NULL DEFAULT 0 COMMENT '库存数量' AFTER `pin_no`;
ALTER TABLE `shop_order`
ADD COLUMN `name` varchar(30) DEFAULT NULL COMMENT '成员名称' AFTER `mobile`;