feat:每个货柜独立库存
This commit is contained in:
1 parent
4b2afa8800
commit
30e61bac2f
22 files changed
+293
-39
No files matched your search
@@ -444,6 +444,9 @@ CREATE TABLE hard_spu_join
|
||||
cabinet_no varchar(32) DEFAULT NULL COMMENT '货柜编号',
|
||||
spu_id bigint DEFAULT NULL COMMENT '商品id',
|
||||
hard_door_number int DEFAULT NULL COMMENT '商品放置层数',
|
||||
version bigint DEFAULT 0 COMMENT '乐观锁',
|
||||
sales_count bigint DEFAULT 0 COMMENT '销量',
|
||||
repertory_count bigint NOT NULL DEFAULT 0 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 '修改人',
|
||||
@@ -481,6 +484,8 @@ CREATE TABLE hard_spu_repertory
|
||||
(
|
||||
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||
user_id bigint NOT NULL COMMENT '用户id',
|
||||
hard_door_id bigint NOT NULL COMMENT '智能柜编号',
|
||||
cabinet_no int NOT NULL COMMENT '货柜编号(1,2)',
|
||||
spu_id bigint NOT NULL COMMENT '商品id',
|
||||
before_count int NOT NULL COMMENT '更新前的库存数量',
|
||||
count int DEFAULT 0 COMMENT '更新库存数量',
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.manager;
|
||||
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardDoorCabinetDto extends HardDoorCabinetEntity {
|
||||
}
|
||||
+2
@@ -13,4 +13,6 @@ public class HardSpuRepertoryDto extends HardSpuRepertoryEntity {
|
||||
|
||||
private List<Long> userIds;
|
||||
|
||||
private Long cabinetId;
|
||||
|
||||
}
|
||||
+19
@@ -51,6 +51,25 @@ public class HardSpuJoinEntity extends Model<HardSpuJoinEntity> {
|
||||
@Schema(description = "放置层数")
|
||||
private Integer hardDoorNumber;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
@Version
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
@Schema(description = "销量")
|
||||
private Integer salesCount;
|
||||
|
||||
/**
|
||||
* 库存
|
||||
*/
|
||||
@Schema(description = "库存")
|
||||
private Integer repertoryCount;
|
||||
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
+13
@@ -36,6 +36,19 @@ public class HardSpuRepertoryEntity extends Model<HardSpuRepertoryEntity> {
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 硬件柜子id
|
||||
*/
|
||||
@Schema(description = "硬件柜子id")
|
||||
private Long hardDoorId;
|
||||
|
||||
/**
|
||||
* 柜门编号
|
||||
*/
|
||||
@Schema(description = "柜门编号")
|
||||
private Integer cabinetNo;
|
||||
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.manager;
|
||||
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.base.BaseHardInterface;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class HardDoorCabinetVo extends HardDoorCabinetEntity implements BaseHardInterface {
|
||||
|
||||
/**
|
||||
* 设备相关
|
||||
*/
|
||||
private Long hardId;
|
||||
|
||||
private String hardName;
|
||||
|
||||
private String hardType;
|
||||
|
||||
private String deviceCode;
|
||||
|
||||
}
|
||||
+12
-1
@@ -2,11 +2,12 @@ package com.bsd.pjcloud.hard.api.vo.spu;
|
||||
|
||||
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuRepertoryEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.base.BaseHardInterface;
|
||||
import com.bsd.pjcloud.wallet.api.vo.base.BaseMchInterface;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HardSpuRepertoryVo extends HardSpuRepertoryEntity implements BaseMchInterface, BaseUserInterface {
|
||||
public class HardSpuRepertoryVo extends HardSpuRepertoryEntity implements BaseMchInterface, BaseUserInterface, BaseHardInterface {
|
||||
|
||||
/**
|
||||
* 商品相关
|
||||
@@ -42,5 +43,15 @@ public class HardSpuRepertoryVo extends HardSpuRepertoryEntity implements BaseMc
|
||||
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 设备相关
|
||||
*/
|
||||
private Long hardId;
|
||||
|
||||
private String hardName;
|
||||
|
||||
private String hardType;
|
||||
|
||||
private String deviceCode;
|
||||
|
||||
}
|
||||
+9
@@ -9,9 +9,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
|
||||
import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
|
||||
import com.bsd.pjcloud.hard.service.HardDoorManagerService;
|
||||
@@ -79,6 +82,12 @@ public class HardDoorManagerController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "柜门下拉查询", description = "柜门下拉查询")
|
||||
@GetMapping("/select-cabinet")
|
||||
public R<Page<HardDoorCabinetVo>> selectCabinet(@ParameterObject Page page, @ParameterObject HardDoorCabinetDto dto) {
|
||||
return R.ok(hardDoorManagerService.selectCabinet(page, dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('hard_hardDoorManager_view')")
|
||||
|
||||
+3
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardPutawayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuDto;
|
||||
@@ -45,6 +46,7 @@ public class HardSpuController {
|
||||
|
||||
@Operation(summary = "app上架", description = "上架")
|
||||
@PostMapping("/app/putaway")
|
||||
@Idempotent(expireTime = 5, info = "正在上架中,请勿重复操作")
|
||||
public R appPutaway(@Valid @RequestBody HardPutawayDto dto) {
|
||||
hardSpuService.putaway(dto);
|
||||
return R.ok();
|
||||
@@ -52,6 +54,7 @@ public class HardSpuController {
|
||||
|
||||
@Operation(summary = "app下架", description = "下架")
|
||||
@PostMapping("/app/un-putaway")
|
||||
@Idempotent(expireTime = 5, info = "正在下架中,请勿重复操作")
|
||||
public R appUnPutaway(@Valid @RequestBody HardPutawayDto dto) {
|
||||
hardSpuService.unPutaway(dto);
|
||||
return R.ok();
|
||||
|
||||
+9
-2
@@ -2,11 +2,13 @@ package com.bsd.pjcloud.hard.controller.spu;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
@@ -44,6 +46,7 @@ public class HardSpuRepertoryController {
|
||||
|
||||
@Operation(summary = "app上架完成", description = "app上架完成")
|
||||
@PostMapping("/app/repertory-done")
|
||||
@Idempotent(expireTime = 5, info = "正在操作中,请勿重复操作")
|
||||
public R<Boolean> appRepertoryDone(@Valid @RequestBody DeductionSpuRepertoryDto body) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
return R.ok(hardSpuRepertoryService.appRepertoryDone(body, user.getId()));
|
||||
@@ -78,9 +81,13 @@ public class HardSpuRepertoryController {
|
||||
@SysLog("新增硬件商品库存更新记录")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('hard_hardSpuRepertory_add')")
|
||||
public R save(@Validated @RequestBody HardSpuRepertoryEntity hardSpuRepertory) {
|
||||
@Idempotent(expireTime = 5, info = "正在上架中,请勿重复操作")
|
||||
public R save(@Validated @RequestBody HardSpuRepertoryDto dto) {
|
||||
if (ObjectUtil.isEmpty(dto.getCabinetId())) {
|
||||
return R.failed("请选择所属柜门");
|
||||
}
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
return R.ok(hardSpuRepertoryService.create(hardSpuRepertory, user));
|
||||
return R.ok(hardSpuRepertoryService.create(dto, user));
|
||||
}
|
||||
|
||||
@Operation(summary = "修改硬件商品库存更新记录", description = "修改硬件商品库存更新记录")
|
||||
|
||||
+6
@@ -1,11 +1,17 @@
|
||||
package com.bsd.pjcloud.hard.mapper.manager;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface HardDoorCabinetMapper extends PjcloudBaseMapper<HardDoorCabinetEntity> {
|
||||
|
||||
Page<HardDoorCabinetVo> scopePageJoin(Page page, @Param("dto") HardDoorCabinetDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+6
@@ -1,13 +1,19 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HardDoorCabinetService extends IService<HardDoorCabinetEntity> {
|
||||
|
||||
Page<HardDoorCabinetVo> scopePageJoin(Page page, HardDoorCabinetDto dto, DataScope dataScope);
|
||||
|
||||
void saveOrUpdate(Long hardDoorId, List<DoorStatusVo.Cabinet> list);
|
||||
|
||||
List<HardDoorCabinetEntity> getListByHardDoorId(Long hardDoorId);
|
||||
|
||||
+7
@@ -3,15 +3,22 @@ package com.bsd.pjcloud.hard.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
|
||||
|
||||
public interface HardDoorManagerService extends IService<HardDoorManagerEntity> {
|
||||
|
||||
Page<HardDoorManagerVo> scopePageJoin(Page page, HardDoorManagerDto dto, DataScope dataScope);
|
||||
|
||||
/**
|
||||
* 柜门下拉查询
|
||||
*/
|
||||
Page<HardDoorCabinetVo> selectCabinet(Page page, HardDoorCabinetDto dto);
|
||||
|
||||
/**
|
||||
* 根据硬件id查询详情
|
||||
*/
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public interface HardSpuRepertoryService extends IService<HardSpuRepertoryEntity
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
Long create(HardSpuRepertoryEntity entity, PjcloudUser user);
|
||||
Long create(HardSpuRepertoryDto dto, PjcloudUser user);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.DeductionSpuStockDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardPutawayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuJoinVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuVo;
|
||||
@@ -73,5 +74,5 @@ public interface HardSpuService extends IService<HardSpuEntity> {
|
||||
/**
|
||||
* 扣减库存
|
||||
*/
|
||||
Boolean deductionSpuStock(List<DeductionSpuStockDto> list);
|
||||
Boolean deductionSpuStock(HardDoorFlowEntity hardDoorFlow, List<DeductionSpuStockDto> list);
|
||||
}
|
||||
+9
@@ -4,12 +4,16 @@ import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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.feign.RemoteFileService;
|
||||
import com.bsd.pjcloud.common.core.util.QRCodeImageGenerator;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetCodeVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardDoorCabinetMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
|
||||
@@ -36,6 +40,11 @@ public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMappe
|
||||
|
||||
private final RemoteFileService remoteFileService;
|
||||
|
||||
@Override
|
||||
public Page<HardDoorCabinetVo> scopePageJoin(Page page, HardDoorCabinetDto dto, DataScope dataScope) {
|
||||
return baseMapper.scopePageJoin(page, dto, dataScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrUpdate(Long hardDoorId, List<DoorStatusVo.Cabinet> list) {
|
||||
List<HardDoorCabinetEntity> cabinetList = baseMapper.selectList(new LambdaQueryWrapper<HardDoorCabinetEntity>()
|
||||
|
||||
+11
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorCabinetDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardDoorManagerDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.manager.HardManagerDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardChangeVolume;
|
||||
@@ -14,6 +15,7 @@ import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardManagerEntity;
|
||||
import com.bsd.pjcloud.hard.api.utils.HardUtil;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardDoorManagerMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
|
||||
@@ -55,6 +57,15 @@ public class HardDoorManagerServiceImpl extends ServiceImpl<HardDoorManagerMappe
|
||||
return pageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 柜门下拉查询
|
||||
*/
|
||||
@Override
|
||||
public Page<HardDoorCabinetVo> selectCabinet(Page page, HardDoorCabinetDto dto) {
|
||||
DataScope dataScope = new DataScope();
|
||||
return hardDoorCabinetService.scopePageJoin(page, dto, dataScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据硬件id查询详情
|
||||
*/
|
||||
|
||||
+10
-1
@@ -38,6 +38,7 @@ import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardParentCarEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
|
||||
import com.bsd.pjcloud.hard.api.utils.HardUtil;
|
||||
import com.bsd.pjcloud.hard.api.vo.HardDoorFlowVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardManagerVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
@@ -93,6 +94,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
private final HardParentCarServiceImpl hardParentCarServiceImpl;
|
||||
@Lazy
|
||||
private final HardInvoiceService hardInvoiceService;
|
||||
@Lazy
|
||||
private final HardDoorFlowService hardDoorFlowService;
|
||||
private final HardBroadcastService hardBroadcastService;
|
||||
private final HardSpuService hardSpuService;
|
||||
|
||||
@@ -698,7 +701,13 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
entity.setIncrCount(v.getProductCount());
|
||||
return entity;
|
||||
}).toList();
|
||||
Boolean isDeduction = hardSpuService.deductionSpuStock(list);
|
||||
// 查询订单流程
|
||||
HardDoorFlowVo doorFlow = hardDoorFlowService.getByOrderId(order.getId());
|
||||
if (ObjectUtil.isEmpty(doorFlow)) {
|
||||
log.info("|{}|{},失败,order不存在:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(list));
|
||||
return;
|
||||
}
|
||||
Boolean isDeduction = hardSpuService.deductionSpuStock(doorFlow, list);
|
||||
if (!isDeduction) {
|
||||
log.info("|{}|{},失败,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(list));
|
||||
throw new RuntimeException("扣减智能柜库存" + CarErrorMsg + "错误");
|
||||
|
||||
+58
-23
@@ -15,14 +15,14 @@ import com.bsd.pjcloud.hard.api.constant.spu.HardSpuRepertoryTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.DeductionSpuRepertoryDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuRepertoryDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuJoinEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuRepertoryEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.spu.HardSpuRepertoryVo;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.spu.HardSpuRepertoryMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardDoorFlowService;
|
||||
import com.bsd.pjcloud.hard.service.HardSpuRepertoryService;
|
||||
import com.bsd.pjcloud.hard.service.HardSpuService;
|
||||
import com.bsd.pjcloud.hard.service.*;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
|
||||
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
@@ -46,6 +46,8 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
|
||||
|
||||
private final HardSpuService hardSpuService;
|
||||
private final HardDoorFlowService hardDoorFlowService;
|
||||
private final HardDoorCabinetService hardDoorCabinetService;
|
||||
private final HardSpuJoinService hardSpuJoinService;
|
||||
|
||||
private final RemoteMchService remoteMchService;
|
||||
private final RemoteUserService remoteUserService;
|
||||
@@ -62,9 +64,9 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long create(HardSpuRepertoryEntity entity, PjcloudUser user) {
|
||||
public Long create(HardSpuRepertoryDto dto, PjcloudUser user) {
|
||||
// 查询商品
|
||||
HardSpuEntity spuDetail = hardSpuService.getById(entity.getSpuId());
|
||||
HardSpuEntity spuDetail = hardSpuService.getById(dto.getSpuId());
|
||||
if (ObjectUtil.isEmpty(spuDetail)) {
|
||||
throw new RuntimeException("商品不存在");
|
||||
}
|
||||
@@ -74,20 +76,42 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
|
||||
if (ObjectUtil.equals(spuDetail.getPrice(), 0)) {
|
||||
throw new RuntimeException("商品价格不能为0");
|
||||
}
|
||||
// 查询货柜
|
||||
HardDoorCabinetEntity doorCabinet = hardDoorCabinetService.getById(dto.getCabinetId());
|
||||
if (ObjectUtil.isEmpty(doorCabinet)) {
|
||||
throw new RuntimeException("货柜不存在");
|
||||
}
|
||||
dto.setHardDoorId(doorCabinet.getHardDoorId());
|
||||
dto.setCabinetNo(doorCabinet.getCabinetNo());
|
||||
HardSpuJoinEntity cabinetSpu = hardSpuJoinService.getOne(new LambdaQueryWrapper<HardSpuJoinEntity>()
|
||||
.eq(HardSpuJoinEntity::getHardDoorId, dto.getHardDoorId())
|
||||
.eq(HardSpuJoinEntity::getCabinetNo, dto.getCabinetNo())
|
||||
.eq(HardSpuJoinEntity::getSpuId, dto.getSpuId())
|
||||
);
|
||||
if (ObjectUtil.isEmpty(cabinetSpu)) {
|
||||
throw new RuntimeException("货柜中没有这个商品");
|
||||
}
|
||||
Integer beforeCount = 0;
|
||||
if (ObjectUtil.isNotEmpty(spuDetail.getRepertoryCount())) {
|
||||
beforeCount = spuDetail.getRepertoryCount();
|
||||
}
|
||||
entity.setBeforeCount(beforeCount);
|
||||
entity.setUserId(user.getId());
|
||||
entity.setBizType(HardSpuRepertoryTypeEnum.HANDLER.getType());
|
||||
baseMapper.insert(entity);
|
||||
// 更新商品库存
|
||||
dto.setBeforeCount(beforeCount);
|
||||
dto.setUserId(user.getId());
|
||||
dto.setBizType(HardSpuRepertoryTypeEnum.HANDLER.getType());
|
||||
baseMapper.insert(dto);
|
||||
// 更新商品总库存
|
||||
HardSpuEntity spu = new HardSpuEntity();
|
||||
spu.setId(spuDetail.getId());
|
||||
spu.setRepertoryCount(entity.getCount() + beforeCount);
|
||||
spu.setRepertoryCount(dto.getCount() + beforeCount);
|
||||
spu.setVersion(spuDetail.getVersion());
|
||||
hardSpuService.updateById(spu);
|
||||
return entity.getId();
|
||||
// 更新柜门商品库存
|
||||
HardSpuJoinEntity cabinetSpuJoin = new HardSpuJoinEntity();
|
||||
cabinetSpuJoin.setId(cabinetSpu.getId());
|
||||
cabinetSpuJoin.setVersion(cabinetSpu.getVersion());
|
||||
cabinetSpuJoin.setRepertoryCount(dto.getCount() + cabinetSpu.getRepertoryCount());
|
||||
hardSpuJoinService.updateById(cabinetSpuJoin);
|
||||
return dto.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,9 +193,13 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
|
||||
// 查询商品列表
|
||||
List<Long> spuIds = list.stream().map(DeductionSpuRepertoryDto.Item::getHardSpuId).toList();
|
||||
List<HardSpuEntity> spuList = hardSpuService.listByIds(spuIds);
|
||||
// 查询货柜商品列表
|
||||
List<HardSpuJoinEntity> spuJoinList = hardSpuJoinService.list(new LambdaQueryWrapper<HardSpuJoinEntity>()
|
||||
.in(HardSpuJoinEntity::getSpuId, spuIds)
|
||||
.eq(HardSpuJoinEntity::getHardDoorId, hardDoorFlow.getHardDoorId())
|
||||
.eq(HardSpuJoinEntity::getCabinetNo, hardDoorFlow.getCabinetNo())
|
||||
);
|
||||
// 更新上架记录
|
||||
List<HardSpuRepertoryEntity> spuRepertoryList = new ArrayList<>();
|
||||
List<HardSpuEntity> spuUpdateList = new ArrayList<>();
|
||||
for (DeductionSpuRepertoryDto.Item i : list) {
|
||||
spuList.stream().filter(v -> v.getId().equals(i.getHardSpuId())).findFirst().ifPresent(spu -> {
|
||||
HardSpuRepertoryEntity entity = new HardSpuRepertoryEntity();
|
||||
@@ -179,24 +207,31 @@ public class HardSpuRepertoryServiceImpl extends ServiceImpl<HardSpuRepertoryMap
|
||||
if (ObjectUtil.isNotEmpty(spu.getRepertoryCount())) {
|
||||
beforeCount = spu.getRepertoryCount();
|
||||
}
|
||||
entity.setHardDoorId(hardDoorFlow.getHardDoorId());
|
||||
entity.setCabinetNo(hardDoorFlow.getCabinetNo());
|
||||
entity.setSpuId(spu.getId());
|
||||
entity.setUserId(userId);
|
||||
entity.setBeforeCount(beforeCount);
|
||||
entity.setCount(i.getPlusCount() + beforeCount);
|
||||
entity.setCount(i.getPlusCount());
|
||||
entity.setBizId(body.getFlowId());
|
||||
entity.setBizType(HardSpuRepertoryTypeEnum.PERSION.getType());
|
||||
spuRepertoryList.add(entity);
|
||||
|
||||
baseMapper.insert(entity);
|
||||
// 更新总商品库存
|
||||
HardSpuEntity spuEntity = new HardSpuEntity();
|
||||
spuEntity.setId(spu.getId());
|
||||
spuEntity.setRepertoryCount(entity.getCount());
|
||||
spuUpdateList.add(spuEntity);
|
||||
spuEntity.setVersion(spu.getVersion());
|
||||
spuEntity.setRepertoryCount(entity.getCount() + beforeCount);
|
||||
hardSpuService.updateById(spuEntity);
|
||||
// 更新货柜商品库存
|
||||
spuJoinList.stream().filter(v -> ObjectUtil.equals(v.getSpuId(), spu.getId())).findFirst().ifPresent(spuJoin -> {
|
||||
HardSpuJoinEntity spuJoinEntity = new HardSpuJoinEntity();
|
||||
spuJoinEntity.setId(spuJoin.getId());
|
||||
spuJoinEntity.setVersion(spuJoin.getVersion());
|
||||
spuJoinEntity.setRepertoryCount(entity.getCount() + spuJoin.getRepertoryCount());
|
||||
hardSpuJoinService.updateById(spuJoinEntity);
|
||||
});
|
||||
});
|
||||
}
|
||||
// 添加上架记录
|
||||
baseMapper.insert(spuRepertoryList);
|
||||
// 更新商品库存
|
||||
hardSpuService.updateBatchById(spuUpdateList);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+25
-6
@@ -15,6 +15,7 @@ import com.bsd.pjcloud.hard.api.dto.spu.DeductionSpuStockDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardPutawayDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.HardSpuJoinDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardDoorFlowEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.spu.HardSpuJoinEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorManagerVo;
|
||||
@@ -183,11 +184,8 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
|
||||
// 校验商品
|
||||
HardSpuEntity spuDetail = validateSpu(dto.getHardSpuId());
|
||||
// 判断这一层是否重复
|
||||
long doorCount = hardSpuJoinService.count(new LambdaUpdateWrapper<HardSpuJoinEntity>()
|
||||
.eq(HardSpuJoinEntity::getHardDoorNumber, spuJoinDetail.getHardDoorNumber())
|
||||
.eq(HardSpuJoinEntity::getSpuId, spuDetail.getId())
|
||||
);
|
||||
if (doorCount > 0) throw new RuntimeException("该层已有相同商品");
|
||||
long doorCount = hardSpuJoinService.count(new LambdaUpdateWrapper<HardSpuJoinEntity>().eq(HardSpuJoinEntity::getSpuId, spuDetail.getId()));
|
||||
if (doorCount > 0) throw new RuntimeException("该货柜已有相同商品");
|
||||
LambdaUpdateWrapper<HardSpuJoinEntity> updateObj = new LambdaUpdateWrapper<HardSpuJoinEntity>()
|
||||
.set(HardSpuJoinEntity::getSpuId, spuDetail.getId())
|
||||
.eq(HardSpuJoinEntity::getId, dto.getId());
|
||||
@@ -251,7 +249,11 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deductionSpuStock(List<DeductionSpuStockDto> list) {
|
||||
public Boolean deductionSpuStock(HardDoorFlowEntity hardDoorFlow, List<DeductionSpuStockDto> list) {
|
||||
if (ObjectUtil.isEmpty(hardDoorFlow)) {
|
||||
log.error("|{}|扣减商品库存失败flow为空dto|{}|", TAG, JSONUtil.toJsonStr(list));
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtil.isEmpty(list)) {
|
||||
log.error("|{}|扣减商品库存失败list为空", TAG);
|
||||
return false;
|
||||
@@ -262,6 +264,12 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
|
||||
log.error("|{}|扣减商品库存失败查询到的智能柜商品为空dto|{}|", TAG, JSONUtil.toJsonStr(list));
|
||||
return false;
|
||||
}
|
||||
// 查询货柜商品
|
||||
List<HardSpuJoinEntity> hardSpuJoinList = hardSpuJoinService.list(new LambdaQueryWrapper<HardSpuJoinEntity>()
|
||||
.in(HardSpuJoinEntity::getSpuId, hardSpuIdes)
|
||||
.eq(HardSpuJoinEntity::getHardDoorId, hardDoorFlow.getHardDoorId())
|
||||
.eq(HardSpuJoinEntity::getCabinetNo, hardDoorFlow.getCabinetNo())
|
||||
);
|
||||
for (HardSpuEntity i : hardSpuList) {
|
||||
list.stream().filter(j -> ObjectUtil.equals(i.getId(), j.getHardSpuId())).findFirst().ifPresent(hardSpu -> {
|
||||
if (ObjectUtil.isNotEmpty(hardSpu.getIncrCount())) {
|
||||
@@ -269,11 +277,22 @@ public class HardSpuServiceImpl extends ServiceImpl<HardSpuMapper, HardSpuEntity
|
||||
entity.setId(hardSpu.getHardSpuId());
|
||||
entity.setSalesCount(i.getSalesCount() + hardSpu.getIncrCount());
|
||||
entity.setRepertoryCount(i.getRepertoryCount() - hardSpu.getIncrCount());
|
||||
entity.setVersion(i.getVersion());
|
||||
// 乐观锁循环扣减库存
|
||||
baseMapper.updateById(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (HardSpuJoinEntity i : hardSpuJoinList) {
|
||||
// 更新货柜商品库存
|
||||
list.stream().filter(v -> ObjectUtil.equals(v.getHardSpuId(), i.getSpuId())).findFirst().ifPresent(spu -> {
|
||||
HardSpuJoinEntity spuJoinEntity = new HardSpuJoinEntity();
|
||||
spuJoinEntity.setId(i.getId());
|
||||
spuJoinEntity.setVersion(i.getVersion());
|
||||
spuJoinEntity.setRepertoryCount(i.getRepertoryCount() - spu.getIncrCount());
|
||||
hardSpuJoinService.updateById(spuJoinEntity);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+44
-3
@@ -2,8 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.hard.mapper.manager.HardDoorCabinetMapper">
|
||||
|
||||
<resultMap id="hardDoorCabinetMap" type="com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity">
|
||||
<resultMap id="hardDoorCabinetMap" type="com.bsd.pjcloud.hard.api.entity.manager.HardDoorCabinetEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="hardDoorId" column="hard_door_id"/>
|
||||
<result property="cabinetNo" column="cabinet_no"/>
|
||||
@@ -18,5 +17,47 @@
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="tenantId" column="tenant_id"/>
|
||||
</resultMap>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.hard_door_id,
|
||||
a.cabinet_no,
|
||||
a.is_lock_online,
|
||||
a.lock_status,
|
||||
a.door_status,
|
||||
a.sale_status,
|
||||
a.qr_code,
|
||||
a.create_by,
|
||||
a.create_time,
|
||||
a.update_by,
|
||||
a.update_time,
|
||||
a.del_flag,
|
||||
a.tenant_id,
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.hardDoorId != null">
|
||||
and a.hard_door_id = #{dto.hardDoorId}
|
||||
</if>
|
||||
<if test="dto.cabinetNo != null">
|
||||
and a.cabinet_no like concat('%', #{dto.cabinetNo}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="scopePageJoin" resultType="com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo">
|
||||
<include refid="selectA"/>
|
||||
hardDoor.device_code,
|
||||
h.id as hardId,
|
||||
h.name as hardName,
|
||||
h.type as hardType
|
||||
from hard_door_cabinet a
|
||||
inner join hard_door_manager hardDoor on hardDoor.id = a.hard_door_id
|
||||
inner join hard_manager h on h.id = hardDoor.hard_id
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
order by a.hard_door_id asc , a.cabinet_no asc
|
||||
</select>
|
||||
</mapper>
|
||||
+11
-1
@@ -5,6 +5,8 @@
|
||||
<resultMap id="hardSpuRepertoryMap" type="com.bsd.pjcloud.hard.api.entity.spu.HardSpuRepertoryEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="hardDoorId" column="hard_door_id"/>
|
||||
<result property="cabinetNo" column="cabinet_no"/>
|
||||
<result property="spuId" column="spu_id"/>
|
||||
<result property="beforeCount" column="before_count"/>
|
||||
<result property="count" column="count"/>
|
||||
@@ -19,6 +21,8 @@
|
||||
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.hard_door_id,
|
||||
a.cabinet_no,
|
||||
a.user_id,
|
||||
a.spu_id,
|
||||
a.before_count,
|
||||
@@ -55,10 +59,16 @@
|
||||
<include refid="selectA"/>
|
||||
s.name as spuName,
|
||||
s.spu_category_id,
|
||||
c.name as spuCategoryName
|
||||
c.name as spuCategoryName,
|
||||
hardD.device_code,
|
||||
m.id as hardId,
|
||||
m.name as hardName,
|
||||
m.type as hardType
|
||||
from hard_spu_repertory a
|
||||
left join hard_spu s on s.id = a.spu_id
|
||||
left join hard_spu_category c on c.id = s.spu_category_id
|
||||
left join hard_door_manager hardD on hardD.id = a.hard_door_id
|
||||
left join hard_manager m on m.id = hardD.hard_id
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
|
||||
Reference in new issue
Block a user