|
|
@@ -144,7 +144,9 @@ public class KxsMachineAdvanceServiceImpl extends ServiceImpl<KxsMachineAdvanceM
|
|
|
|
|
|
machineAdvanceInfo.setIsReturn(CommonConstants.SUCCESS);
|
|
|
machineAdvanceInfo.setReturnTime(LocalDateTime.now());
|
|
|
- kxsMachineAdvanceInfoMapper.updateById(machineAdvanceInfo);
|
|
|
+ //直接删除记录
|
|
|
+ kxsMachineAdvanceInfoMapper.deleteById(machineAdvanceInfo.getId());
|
|
|
+ baseMapper.deleteById(machineAdvanceInfo.getOrderId());
|
|
|
|
|
|
//修改状态为在库
|
|
|
KxsMachine machine = new KxsMachine();
|
|
|
@@ -299,77 +301,73 @@ public class KxsMachineAdvanceServiceImpl extends ServiceImpl<KxsMachineAdvanceM
|
|
|
.getData()
|
|
|
.orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
|
|
|
- KxsMachineAdvance machineAdvance = baseMapper.selectById(param.getId());
|
|
|
- if (machineAdvance == null) {
|
|
|
- return R.failed(StoreErrorTypeEnum.DATA_ERROR.getDescription());
|
|
|
- }
|
|
|
- //查询仓库
|
|
|
- KxsWarehouse warehouse = kxsWarehouseMapper.selectById(machineAdvance.getWarehouseId());
|
|
|
-
|
|
|
- //查询品牌
|
|
|
- R<KxsBrand> kxsBrandR = remoteKxsProductService.loadByBrand(warehouse.getBrandId(), SecurityConstants.FROM_IN);
|
|
|
- KxsBrand brand = RetOps.of(kxsBrandR)
|
|
|
- .getData()
|
|
|
- .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.DATA_ERROR.getDescription()));
|
|
|
-
|
|
|
- //查询用户预发额度
|
|
|
- KxsWarehouseLimit userLimit = kxsWarehouseLimitMapper.selectOne(Wrappers.<KxsWarehouseLimit>lambdaQuery()
|
|
|
- .eq(KxsWarehouseLimit::getWarehouseType, WarehouseLimitTypeEnum.XFC.getType())
|
|
|
- .eq(KxsWarehouseLimit::getUserId, userId));
|
|
|
-
|
|
|
- List<KxsMachineAdvanceInfo> machineAdvanceInfos = kxsMachineAdvanceInfoMapper.selectList(Wrappers.<KxsMachineAdvanceInfo>lambdaQuery()
|
|
|
- .in(KxsMachineAdvanceInfo::getPosSn, param.getSnList()));
|
|
|
- for (KxsMachineAdvanceInfo machineAdvanceInfo : machineAdvanceInfos) {
|
|
|
- if(machineAdvanceInfo.getIsConfirm() != 0){
|
|
|
- return R.failed(machineAdvanceInfo.getPosSn() + "该机器已确认");
|
|
|
+ for (String sn : param.getSnList()) {
|
|
|
+ KxsMachineAdvanceInfo machineAdvanceInfo = kxsMachineAdvanceInfoMapper.selectOne(Wrappers.<KxsMachineAdvanceInfo>lambdaQuery()
|
|
|
+ .eq(KxsMachineAdvanceInfo::getIsConfirm, CommonConstants.FAIL)
|
|
|
+ .eq(KxsMachineAdvanceInfo::getIsReturn, CommonConstants.FAIL)
|
|
|
+ .eq(KxsMachineAdvanceInfo::getPosSn, sn));
|
|
|
+ if(machineAdvanceInfo == null){
|
|
|
+ throw new GlobalCustomerException(sn + "已确认/已撤回");
|
|
|
}
|
|
|
- }
|
|
|
+ KxsMachineAdvance machineAdvance = baseMapper.selectById(machineAdvanceInfo.getOrderId());
|
|
|
|
|
|
- //同意
|
|
|
- if (Objects.equals(param.getConfirmType(), CommonConstants.SUCCESS)) {
|
|
|
- //扣减用户预发额度
|
|
|
- int amount;
|
|
|
- if (Objects.equals(brand.getBrandType(), BrandTypeEnum.DIANQIAN.getType())) {
|
|
|
- //电签
|
|
|
- amount = machineAdvanceInfos.size() * BrandTypeEnum.DQ_PRICE.getType();
|
|
|
- } else {
|
|
|
- amount = machineAdvanceInfos.size() * BrandTypeEnum.DJ_PRICE.getType();
|
|
|
- }
|
|
|
- //额度充足
|
|
|
- if (userLimit.getValidAmount().compareTo(BigDecimal.valueOf(amount)) >= 0) {
|
|
|
+ //查询仓库
|
|
|
+ KxsWarehouse warehouse = kxsWarehouseMapper.selectById(machineAdvance.getWarehouseId());
|
|
|
+ //查询品牌
|
|
|
+ R<KxsBrand> kxsBrandR = remoteKxsProductService.loadByBrand(machineAdvance.getBrandId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsBrand brand = RetOps.of(kxsBrandR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.DATA_ERROR.getDescription()));
|
|
|
|
|
|
- //小分仓增加已用额度 刷新可用额度
|
|
|
- userLimit.setUsedAmount(NumberUtil.add(userLimit.getUsedAmount(), amount));
|
|
|
- userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(), amount));
|
|
|
- kxsWarehouseLimitMapper.updateById(userLimit);
|
|
|
+ //查询用户预发额度
|
|
|
+ KxsWarehouseLimit userLimit = kxsWarehouseLimitMapper.selectOne(Wrappers.<KxsWarehouseLimit>lambdaQuery()
|
|
|
+ .eq(KxsWarehouseLimit::getWarehouseType, WarehouseLimitTypeEnum.XFC.getType())
|
|
|
+ .eq(KxsWarehouseLimit::getUserId, userId));
|
|
|
+
|
|
|
+ //同意
|
|
|
+ if (Objects.equals(param.getConfirmType(), CommonConstants.SUCCESS)) {
|
|
|
+ //扣减用户预发额度
|
|
|
+ int amount;
|
|
|
+ if (Objects.equals(brand.getBrandType(), BrandTypeEnum.DIANQIAN.getType())) {
|
|
|
+ //电签
|
|
|
+ amount = BrandTypeEnum.DQ_PRICE.getType();
|
|
|
+ } else {
|
|
|
+ amount = BrandTypeEnum.DJ_PRICE.getType();
|
|
|
+ }
|
|
|
+ //额度充足
|
|
|
+ if (userLimit.getValidAmount().compareTo(BigDecimal.valueOf(amount)) >= 0) {
|
|
|
|
|
|
- //减少仓库已用额度增加仓库可用额度
|
|
|
- kxsWarehouseLimitService.refreshWarehouseAmount(warehouse.getUserId(), amount, KindTypeEnum.SUB.getType());
|
|
|
- }
|
|
|
- for (KxsMachineAdvanceInfo info : machineAdvanceInfos) {
|
|
|
+ //小分仓增加已用额度 刷新可用额度
|
|
|
+ userLimit.setUsedAmount(NumberUtil.add(userLimit.getUsedAmount(), amount));
|
|
|
+ userLimit.setValidAmount(NumberUtil.sub(userLimit.getValidAmount(), amount));
|
|
|
+ kxsWarehouseLimitMapper.updateById(userLimit);
|
|
|
+
|
|
|
+ //减少仓库已用额度增加仓库可用额度
|
|
|
+ kxsWarehouseLimitService.refreshWarehouseAmount(warehouse.getUserId(), amount, KindTypeEnum.SUB.getType());
|
|
|
+ }
|
|
|
//修改为占用预发额度标签
|
|
|
if (userLimit.getValidAmount().compareTo(BigDecimal.valueOf(amount)) >= 0) {
|
|
|
- info.setIsUseAmount(CommonConstants.SUCCESS);
|
|
|
+ machineAdvanceInfo.setIsUseAmount(CommonConstants.SUCCESS);
|
|
|
}
|
|
|
- info.setIsConfirm(CommonConstants.SUCCESS);
|
|
|
- kxsMachineAdvanceInfoMapper.updateById(info);
|
|
|
- }
|
|
|
- //给预发对象发送通知
|
|
|
- KxsUserMsg toUserMsg = MsgTemplateUtil.confirmAdvanceMachineUserNote(userId.intValue(), warehouse.getWarehouseName(), machineAdvance.getBrandName(), param.getSnList());
|
|
|
- //给仓库发送通知
|
|
|
- KxsUserMsg toWarehouseMsg = MsgTemplateUtil.confirmAdvanceMachineWarehoiuseNote(warehouse.getUserId(), toUser.getUserCode(), toUser.getUsername(), warehouse.getWarehouseName(), brand.getName(), param.getSnList());
|
|
|
- remoteUserMsgService.pushUserMsg(toUserMsg, SecurityConstants.FROM_IN);
|
|
|
- remoteUserMsgService.pushUserMsg(toWarehouseMsg, SecurityConstants.FROM_IN);
|
|
|
-
|
|
|
- } else {
|
|
|
- //拒绝
|
|
|
- for (KxsMachineAdvanceInfo info : machineAdvanceInfos) {
|
|
|
- info.setIsConfirm(2);
|
|
|
- kxsMachineAdvanceInfoMapper.updateById(info);
|
|
|
+ machineAdvanceInfo.setIsConfirm(CommonConstants.SUCCESS);
|
|
|
+ kxsMachineAdvanceInfoMapper.updateById(machineAdvanceInfo);
|
|
|
+ //给预发对象发送通知
|
|
|
+ KxsUserMsg toUserMsg = MsgTemplateUtil.confirmAdvanceMachineUserNote(userId.intValue(), warehouse.getWarehouseName(), machineAdvance.getBrandName(), param.getSnList());
|
|
|
+ //给仓库发送通知
|
|
|
+ KxsUserMsg toWarehouseMsg = MsgTemplateUtil.confirmAdvanceMachineWarehoiuseNote(warehouse.getUserId(), toUser.getUserCode(), toUser.getUsername(), warehouse.getWarehouseName(), brand.getName(), param.getSnList());
|
|
|
+ remoteUserMsgService.pushUserMsg(toUserMsg, SecurityConstants.FROM_IN);
|
|
|
+ remoteUserMsgService.pushUserMsg(toWarehouseMsg, SecurityConstants.FROM_IN);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ //拒绝,直接删除记录
|
|
|
+// machineAdvanceInfo.setIsConfirm(2);
|
|
|
+ kxsMachineAdvanceInfoMapper.deleteById(machineAdvanceInfo.getId());
|
|
|
+ baseMapper.deleteById(machineAdvanceInfo.getOrderId());
|
|
|
|
|
|
//修改状态为在库
|
|
|
KxsMachine machine = new KxsMachine();
|
|
|
- machine.setId(info.getMachineId());
|
|
|
+ machine.setId(machineAdvanceInfo.getMachineId());
|
|
|
machine.setStatus(MachineTypeEnum.STATUS_IS.getType());
|
|
|
machine.setPreUserId(0);
|
|
|
R<Boolean> result = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
|
|
|
@@ -377,16 +375,17 @@ public class KxsMachineAdvanceServiceImpl extends ServiceImpl<KxsMachineAdvanceM
|
|
|
throw new GlobalCustomerException(ErrorTypeEnum.REMOTE_DATA_ERROR.getDescription());
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- //给仓库发送模版消息
|
|
|
- KxsUserMsg toWarehouseMsg = MsgTemplateUtil.advanceMachineCancelWarehouseNote(warehouse.getUserId(), toUser.getUserCode(), toUser.getUsername(), warehouse.getWarehouseName(), brand.getName(), param.getSnList());
|
|
|
- //给用户发送消息
|
|
|
- KxsUserMsg toUserMsg = MsgTemplateUtil.cancelAdvanceMachineUserNote(userId.intValue(), warehouse.getWarehouseName(), machineAdvance.getBrandName(), param.getSnList());
|
|
|
+ //给仓库发送模版消息
|
|
|
+ KxsUserMsg toWarehouseMsg = MsgTemplateUtil.advanceMachineCancelWarehouseNote(warehouse.getUserId(), toUser.getUserCode(), toUser.getUsername(), warehouse.getWarehouseName(), brand.getName(), param.getSnList());
|
|
|
+ //给用户发送消息
|
|
|
+ KxsUserMsg toUserMsg = MsgTemplateUtil.cancelAdvanceMachineUserNote(userId.intValue(), warehouse.getWarehouseName(), machineAdvance.getBrandName(), param.getSnList());
|
|
|
|
|
|
- remoteUserMsgService.pushUserMsg(toUserMsg, SecurityConstants.FROM_IN);
|
|
|
- remoteUserMsgService.pushUserMsg(toWarehouseMsg, SecurityConstants.FROM_IN);
|
|
|
+ remoteUserMsgService.pushUserMsg(toUserMsg, SecurityConstants.FROM_IN);
|
|
|
+ remoteUserMsgService.pushUserMsg(toWarehouseMsg, SecurityConstants.FROM_IN);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
return R.ok();
|
|
|
}
|
|
|
|