|
|
@ -449,51 +449,62 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService |
|
|
|
// 获取旧数据中相同物料编号的数据
|
|
|
|
List<PurchasePlanChild> oldChildren = oldDataGroupedByMaterialNo.get(materialNo); |
|
|
|
|
|
|
|
if (oldChildren != null && !oldChildren.isEmpty()) { |
|
|
|
// 按照 订单创建时间 远离当前时间排序
|
|
|
|
oldChildren.sort(Comparator.comparing(oldChild -> -Math.abs(now.getTime() - oldChild.getCreateTime().getTime()))); |
|
|
|
Integer thisPurchaseNum = purchasePlanSelectMaterialVo.getThisPurchaseNum(); |
|
|
|
|
|
|
|
int oldPurchaseNumSum = oldChildren.stream().mapToInt(PurchasePlanChild::getPurchaseNum).sum(); |
|
|
|
|
|
|
|
if (oldPurchaseNumSum < thisPurchaseNum){ |
|
|
|
throw new BusinessException("本次采购数量不能大于待采购数量"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(oldChildren)) { |
|
|
|
// 按照订单创建时间远离当前时间排序(即由远及近)
|
|
|
|
oldChildren.sort(Comparator.comparing(oldChild -> oldChild.getCreateTime().getTime())); |
|
|
|
|
|
|
|
for (PurchasePlanChild oldChild : oldChildren) { |
|
|
|
|
|
|
|
Integer thisPurchaseNum = purchasePlanSelectMaterialVo.getThisPurchaseNum(); |
|
|
|
//本次采购数也是实际采购数
|
|
|
|
oldChild.setActualPurchaseNum(thisPurchaseNum); |
|
|
|
//待采购数
|
|
|
|
Integer purchaseNum = oldChild.getPurchaseNum(); |
|
|
|
|
|
|
|
if (thisPurchaseNum <= 0) break; // 如果本次采购数已分配完毕则退出循环
|
|
|
|
|
|
|
|
if (purchaseNum >= thisPurchaseNum) { |
|
|
|
purchaseNum = purchaseNum - thisPurchaseNum; |
|
|
|
oldChild.setPurchaseNum(purchaseNum); |
|
|
|
// 当前记录的待采购数足够覆盖剩余的本次采购数
|
|
|
|
oldChild.setActualPurchaseNum(thisPurchaseNum); |
|
|
|
oldChild.setPurchaseNum(purchaseNum - thisPurchaseNum); |
|
|
|
thisPurchaseNum = 0; // 本次采购数分配完毕
|
|
|
|
} else { |
|
|
|
throw new BusinessException("本次采购数量不能大于待采购数量"); |
|
|
|
// 当前记录的待采购数不足以覆盖剩余的本次采购数
|
|
|
|
oldChild.setActualPurchaseNum(purchaseNum); |
|
|
|
thisPurchaseNum -= purchaseNum; |
|
|
|
oldChild.setPurchaseNum(0); // 该记录的待采购数清零
|
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* 部分申请:0<(实际采购数+共享库存占用数+作废数)<计划采购数;可添加采购订单 |
|
|
|
* 全部申请:0<(实际采购数+共享库存占用数+作废数)=计划采购数,作废数<计划采购数;不可添加采购订单 |
|
|
|
* */ |
|
|
|
//计划采购数
|
|
|
|
// 更新状态
|
|
|
|
Integer planPurchaseNum = oldChild.getPlanPurchaseNum(); |
|
|
|
if (thisPurchaseNum < planPurchaseNum){ |
|
|
|
oldChild.setPurchasePlanStatus("1");//部分申请
|
|
|
|
} |
|
|
|
if (thisPurchaseNum.equals(planPurchaseNum)){ |
|
|
|
if (oldChild.getActualPurchaseNum().equals(planPurchaseNum)) { |
|
|
|
oldChild.setPurchasePlanStatus("2"); // 全部申请
|
|
|
|
} else { |
|
|
|
oldChild.setPurchasePlanStatus("1"); // 部分申请
|
|
|
|
} |
|
|
|
|
|
|
|
// 更新其他字段
|
|
|
|
oldChild.setUpdateTime(new Date()); |
|
|
|
oldChild.setUpdateBy(ShiroUtils.getLoginName()); |
|
|
|
oldChild.setThisPurchaseNum(thisPurchaseNum); |
|
|
|
|
|
|
|
oldChild.setThisPurchaseNum(purchasePlanSelectMaterialVo.getThisPurchaseNum()); |
|
|
|
oldChild.setMaterialNoRmbSum(purchasePlanSelectMaterialVo.getMaterialNoRmbSum()); |
|
|
|
oldChild.setMaterialRmbSum(purchasePlanSelectMaterialVo.getMaterialRmbSum()); |
|
|
|
oldChild.setLatestQuoteRmb(purchasePlanSelectMaterialVo.getLatestQuoteRmb()); |
|
|
|
oldChild.setThisPurchaseNum(thisPurchaseNum); |
|
|
|
// 收集更新后的子表数据
|
|
|
|
purchasePlanChildren.add(oldChild); |
|
|
|
int result = purchasePlanChildMapper.updatePurchasePlanChild(oldChild); |
|
|
|
if (result <= 0){ |
|
|
|
throw new BusinessException("更新采购计划子表数据失败"); |
|
|
|
} |
|
|
|
// 更新完成后,跳出循环
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -544,14 +555,14 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService |
|
|
|
} |
|
|
|
|
|
|
|
// 累加 actualPurchaseSum
|
|
|
|
int thisPurchaseSum = children.stream() |
|
|
|
.mapToInt(PurchasePlanChild::getThisPurchaseNum) |
|
|
|
int actualPurchaseSum = children.stream() |
|
|
|
.mapToInt(PurchasePlanChild::getActualPurchaseNum) |
|
|
|
.sum(); |
|
|
|
purchasePlan.setActualPurchaseSum(purchasePlan.getActualPurchaseSum() + thisPurchaseSum); |
|
|
|
purchasePlan.setActualPurchaseSum(purchasePlan.getActualPurchaseSum() + actualPurchaseSum); |
|
|
|
|
|
|
|
// 更新 purchaseSum
|
|
|
|
int currentPurchaseSum = purchasePlan.getPurchaseSum(); |
|
|
|
purchasePlan.setPurchaseSum(currentPurchaseSum - thisPurchaseSum); |
|
|
|
purchasePlan.setPurchaseSum(currentPurchaseSum - actualPurchaseSum); |
|
|
|
|
|
|
|
// 计算合计值
|
|
|
|
double totalNoRmbSum = children.stream().mapToDouble(vo -> vo.getMaterialNoRmbSum().doubleValue()).sum(); |
|
|
|