feat:手动更新智能柜库存

This commit is contained in:
dzc committed 2025-04-07 18:33:43 +08:00
1 parent b28045e29d
commit b36618e138
4 files changed
+37 -14

No files matched your search

+13 -12
View File
@@ -329,17 +329,18 @@ CREATE TABLE hard_spu_category
DROP TABLE IF EXISTS hard_spu_repertory;
CREATE TABLE hard_spu_repertory
(
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
user_id bigint NOT NULL COMMENT '用户id',
hard_id bigint NOT NULL COMMENT '设备id',
spu_id bigint NOT NULL COMMENT '商品id',
count bigint DEFAULT 0 COMMENT '更新库存数量',
biz_type tinytext NOT NULL COMMENT '上架类型',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
user_id bigint NOT NULL COMMENT '用户id',
hard_id bigint NOT NULL COMMENT '设备id',
spu_id bigint NOT NULL COMMENT '商品id',
before_count int NOT NULL COMMENT '更新前的库存数量',
count int DEFAULT 0 COMMENT '更新库存数量',
biz_type tinytext NOT NULL COMMENT '上架类型',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB COMMENT ='硬件商品库存更新记录';
@@ -48,6 +48,12 @@ public class HardSpuRepertoryEntity extends Model<HardSpuRepertoryEntity> {
@Schema(description = "商品id")
private Long spuId;
/**
* 更新前的库存数量
*/
@Schema(description = "更新前的库存数量")
private Integer beforeCount;
/**
* 更新库存数量
*/
@@ -55,7 +61,7 @@ public class HardSpuRepertoryEntity extends Model<HardSpuRepertoryEntity> {
@Min(value = 1, message = "更新库存数量不能小于1")
@Max(value = 100, message = "更新库存数量不能大于100")
@Schema(description = "更新库存数量")
private Long count;
private Integer count;
/**
* 上架类型
@@ -1,6 +1,7 @@
package com.bsd.pjcloud.hard.service.impl.spu;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.entity.SysUser;
@@ -28,6 +29,7 @@ import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
@@ -60,16 +62,27 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
* 新增
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long create(HardSpuRepertoryEntity entity, PjcloudUser user) {
// 查询商品
HardSpuEntity spuDetail = hardSpuService.getById(entity.getSpuId());
if (ObjectUtil.isEmpty(spuDetail)) {
throw new RuntimeException("商品不存在");
}
Integer beforeCount = 0;
if (ObjectUtil.isNotEmpty(spuDetail.getRepertoryCount())) {
beforeCount = spuDetail.getRepertoryCount();
}
entity.setBeforeCount(beforeCount);
entity.setUserId(user.getId());
entity.setHardId(spuDetail.getHardId());
entity.setBizType(SpuRepertoryTypeEnum.HANDLER.getType());
baseMapper.insert(entity);
// 更新商品库存
HardSpuEntity spu = new HardSpuEntity();
spu.setId(spuDetail.getId());
spu.setRepertoryCount(entity.getCount() + beforeCount);
hardSpuService.updateById(spu);
return entity.getId();
}
@@ -77,6 +90,7 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
if (ObjectUtil.isEmpty(list)) return;
// 商户
List<Long> mchIds = list.stream().map(HardSpuRepertoryVo::getSpuMchId).filter(ObjectUtil::isNotEmpty).distinct().toList();
list.forEach(v -> v.setMerchantId(v.getSpuMchId()));
if (ObjectUtil.isNotEmpty(mchIds)) {
List<MchManageVo> mchList = remoteMchService.getByIds(mchIds).getData();
if (ObjectUtil.isNotEmpty(mchList)) {
@@ -7,6 +7,7 @@
<result property="userId" column="user_id"/>
<result property="hardId" column="hard_id"/>
<result property="spuId" column="spu_id"/>
<result property="beforeCount" column="before_count"/>
<result property="count" column="count"/>
<result property="bizType" column="biz_type"/>
<result property="createBy" column="create_by"/>
@@ -22,6 +23,7 @@
a.user_id,
a.hard_id,
a.spu_id,
a.before_count,
a.count,
a.biz_type,
a.create_by,
@@ -55,7 +57,7 @@
<select id="scopePageJoin" resultType="com.bsd.pjcloud.hard.api.vo.spu.HardSpuRepertoryVo">
<include refid="selectA"/>
s.name,
s.name as spuName,
s.spu_category_id,
s.hard_door_number,
s.mch_id as spuMchId,