整车绑定:库存逻辑优化

This commit is contained in:
attiya 2025-11-28 09:53:30 +08:00
parent 34fdf8cffc
commit 9ff710aaec

View File

@ -105,6 +105,10 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
throw new EbikeException("该中控不存在");
}
if (ecuInfo.getIsClaim()) {
throw new EbikeException("该中控暂时不在库中");
}
//判断中控与电池关系
if (ecuInfo.getBindBattery() && StringUtil.hasText(bindVo.getBatteryCode())) {
throw new EbikeException("该中控与电池一体无需额外绑定电池");
@ -162,54 +166,55 @@ public class EbikeBikeInfoServiceImpl extends ServiceImpl<EbikeBikeInfoMapper, E
List<EbikeInventoryRecord> list = new ArrayList<>();
//TODO优化封装
for (int i = 1; i < 4; i++) {
if (i != 2) {
if (i == 1 && !ecuInfo.getBindBattery()) {
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(i)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
} else if (i == 3) {
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(i)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
}
} else if (bindVo.getHasHelme()) {
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(i)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
}
if (!ecuInfo.getBindBattery()){
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(1)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
}else {
ecuInfo.setIsClaim(Boolean.TRUE);
ebikeEcuInfoService.updateById(ecuInfo);
}
if (bindVo.getHasHelme()){
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(2)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
}
EbikeInventoryVo inventoryVo = EbikeInventoryVo.builder()
.operatorId(operatorId)
.inventoryType(3)
.inventoryNum(-1)
.build();
EbikeInventoryRecord inventoryRecord = EbikeInventoryRecord.builder()
.operatorId(inventoryVo.getOperatorId())
.inventoryType(inventoryVo.getInventoryType())
.inventoryRecordNum(Long.valueOf(inventoryVo.getInventoryNum()))
.createdBy(StpUtil.getLoginIdAsLong())
.build();
list.add(inventoryRecord);
inventoryService.reduceInventory(inventoryVo);
recordService.saveBatch(list);
//录入最终数据