opt:优化倒扣,为负数的报错问题

This commit is contained in:
zhangzq
2026-08-04 14:46:08 +08:00
parent b8355e723e
commit de960cdf17
3 changed files with 22 additions and 35 deletions

View File

@@ -64,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@@ -278,8 +279,8 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
for (WorkOrderBomItem bomItem : workOrderBomItems) { for (WorkOrderBomItem bomItem : workOrderBomItems) {
final String materialCode = bomItem.getMaterialCode(); final String materialCode = bomItem.getMaterialCode();
final BigDecimal bomQty = bomItem.getBomQty(); final BigDecimal bomQty = bomItem.getBomQty();
final BigDecimal qty = bomQty.multiply(param.getReportedQty()); final BigDecimal qty = bomQty.multiply(param.getReportedQty()).setScale(0, RoundingMode.HALF_UP);
final BigDecimal actualQty = groupInventoryMap.get(materialCode) == null?BigDecimal.ZERO:groupInventoryMap.get(materialCode); final BigDecimal actualQty = groupInventoryMap.get(materialCode) == null?BigDecimal.ZERO:groupInventoryMap.get(materialCode).setScale(0, RoundingMode.HALF_UP);
ReceiveOutRequest.Entrys entry = new ReceiveOutRequest.Entrys(); ReceiveOutRequest.Entrys entry = new ReceiveOutRequest.Entrys();
entry.setSeq(Integer.valueOf(bomItem.getItemNo())); entry.setSeq(Integer.valueOf(bomItem.getItemNo()));
entry.setMaterialno(materialCode); entry.setMaterialno(materialCode);
@@ -290,7 +291,7 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
entry.setSrcbillno(param.getSrcBillNo()); entry.setSrcbillno(param.getSrcBillNo());
entry.setSrcbillid(param.getSrcBillId()); entry.setSrcbillid(param.getSrcBillId());
entry.setSrcbillentryid(bomItem.getItemId()); entry.setSrcbillentryid(bomItem.getItemId());
if (bomQty.intValue() == 0 || qty.compareTo(actualQty) > 0) { if (bomQty.intValue() == 0 || qty.subtract(actualQty).intValue() > 0) {
status = StockReturnStatusEnum.FAIL.getCode(); status = StockReturnStatusEnum.FAIL.getCode();
if (bomQty.intValue() == 0 ){ if (bomQty.intValue() == 0 ){
entry.setRemark("bom数量为0"); entry.setRemark("bom数量为0");
@@ -301,6 +302,8 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
} }
entrys.add(entry); entrys.add(entry);
}else { }else {
final BigDecimal subtract = groupInventoryMap.get(materialCode).subtract(qty);
groupInventoryMap.put(materialCode,subtract.setScale(0, RoundingMode.HALF_UP));
final IOStorInvDtl ioStorInvDtl = new IOStorInvDtl(); final IOStorInvDtl ioStorInvDtl = new IOStorInvDtl();
ioStorInvDtl.setIostorinv_id(ioStorInv.getIostorinv_id()); ioStorInvDtl.setIostorinv_id(ioStorInv.getIostorinv_id());
ioStorInvDtl.setIostorinvdtl_id(IdUtil.getStringId()); ioStorInvDtl.setIostorinvdtl_id(IdUtil.getStringId());
@@ -345,19 +348,6 @@ public class PdaIosOutServiceImpl implements PdaIosOutService {
.structCode(struct.getStruct_code()) .structCode(struct.getStruct_code())
.materialCode(materialCode) .materialCode(materialCode)
.build()); .build());
if (actualQty.subtract(qty).intValue() > 0 ){
mdPbGroupplateMapper.update(new GroupPlate(), new LambdaUpdateWrapper<GroupPlate>()
.set(GroupPlate::getQty,actualQty.subtract(qty))
.eq(GroupPlate::getMaterial_code,materialCode)
.eq(GroupPlate::getStoragevehicle_code, param.getStorageVehicleCode())
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("入库"))
);
}else {
mdPbGroupplateMapper.delete(new LambdaUpdateWrapper<GroupPlate>()
.eq(GroupPlate::getMaterial_code,materialCode)
.eq(GroupPlate::getStoragevehicle_code, param.getStorageVehicleCode())
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("入库")));
}
entry.setRemark("等待回传EAS"); entry.setRemark("等待回传EAS");
entry.setStatus(StockReturnStatusEnum.TODO.getCode()); entry.setStatus(StockReturnStatusEnum.TODO.getCode());
entrys.add(entry); entrys.add(entry);

View File

@@ -162,6 +162,9 @@ public class StInventoryServiceImpl implements IStInventoryService {
queryWrapper.eq(GroupPlate::getPcsn, outFinishParam.getPcsn()); queryWrapper.eq(GroupPlate::getPcsn, outFinishParam.getPcsn());
} }
GroupPlate groupPlate = iMdPbGroupplateService.getOne(queryWrapper); GroupPlate groupPlate = iMdPbGroupplateService.getOne(queryWrapper);
if (groupPlate == null){
throw new BadRequestException("当前仓库无库存");
}
final BigDecimal force_qty = groupPlate.getFrozen_qty().subtract(outFinishParam.getChangeQty()); final BigDecimal force_qty = groupPlate.getFrozen_qty().subtract(outFinishParam.getChangeQty());
if (groupPlate.getQty().subtract(outFinishParam.getChangeQty()).intValue() <= 0){ if (groupPlate.getQty().subtract(outFinishParam.getChangeQty()).intValue() <= 0){
iMdPbGroupplateService.removeById(groupPlate.getGroup_id()); iMdPbGroupplateService.removeById(groupPlate.getGroup_id());
@@ -170,12 +173,19 @@ public class StInventoryServiceImpl implements IStInventoryService {
if (force_qty.intValue()< 0 ){ if (force_qty.intValue()< 0 ){
log.error("冻结数量为附属"+groupPlate.getStoragevehicle_code()+"_"+ groupPlate.getMaterial_code()); log.error("冻结数量为附属"+groupPlate.getStoragevehicle_code()+"_"+ groupPlate.getMaterial_code());
} }
groupPlate.setFrozen_qty(BigDecimal.ZERO.max(forceQty)); if (groupPlate.getQty().subtract(outFinishParam.getChangeQty()).intValue() > 0 ){
groupPlate.setQty(groupPlate.getQty().subtract(outFinishParam.getChangeQty())); groupPlate.setFrozen_qty(BigDecimal.ZERO.max(forceQty));
groupPlate.setUpdate_id(SecurityUtils.getCurrentUserId()); groupPlate.setQty(groupPlate.getQty().subtract(outFinishParam.getChangeQty()));
groupPlate.setUpdate_name(SecurityUtils.getCurrentNickName()); groupPlate.setUpdate_id(SecurityUtils.getCurrentUserId());
groupPlate.setUpdate_time(DateUtil.now()); groupPlate.setUpdate_name(SecurityUtils.getCurrentNickName());
iMdPbGroupplateService.updateById(groupPlate); groupPlate.setUpdate_time(DateUtil.now());
iMdPbGroupplateService.updateById(groupPlate);
}else {
iMdPbGroupplateService.remove(new LambdaUpdateWrapper<GroupPlate>()
.eq(GroupPlate::getMaterial_code,outFinishParam.getMaterialCode())
.eq(GroupPlate::getStoragevehicle_code, outFinishParam.getStoragevehicleCode())
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("入库")));
}
} }
StIvtStructivtflow stIvtStructivtflow = new StIvtStructivtflow(); StIvtStructivtflow stIvtStructivtflow = new StIvtStructivtflow();
stIvtStructivtflow.setId(IdUtil.getStringId()); stIvtStructivtflow.setId(IdUtil.getStringId());

View File

@@ -443,19 +443,6 @@ public class ReceiveOutReturnServiceImpl extends ServiceImpl<ReceiveOutReturnMap
.structCode("6.007.V") .structCode("6.007.V")
.materialCode(materialCode) .materialCode(materialCode)
.build()); .build());
if (actualQty.subtract(qty).intValue() > 0 ){
mdPbGroupplateMapper.update(new GroupPlate(), new LambdaUpdateWrapper<GroupPlate>()
.set(GroupPlate::getQty,actualQty.subtract(qty))
.eq(GroupPlate::getMaterial_code, materialCode)
.eq(GroupPlate::getStoragevehicle_code, "VTP0008")
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("入库"))
);
}else {
mdPbGroupplateMapper.delete(new LambdaUpdateWrapper<GroupPlate>()
.eq(GroupPlate::getMaterial_code, materialCode)
.eq(GroupPlate::getStoragevehicle_code, "VTP0008")
.eq(GroupPlate::getStatus, IOSEnum.GROUP_PLATE_STATUS.code("入库")));
}
} }
if (!CollectionUtils.isEmpty(ioStorInvDtls)){ if (!CollectionUtils.isEmpty(ioStorInvDtls)){
ioStorInvMapper.insert(ioStorInv); ioStorInvMapper.insert(ioStorInv);