| | |
| | | } |
| | | |
| | | |
| | | // 叠加方数 |
| | | BigDecimal totalVolume = plans.stream() |
| | | .map(ProductionPlan::getVolume) |
| | | // 叠加剩余方数 |
| | | BigDecimal totalRemainingVolume = plans.stream() |
| | | .map(ProductionPlan::getRemainingVolume) |
| | | .filter(v -> v != null) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 判断下发数量是否大于等于方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalVolume) > 0) { |
| | | throw new BaseException("操作失败,下发数量不能大于方数"); |
| | | // 判断下发数量是否大于等于剩余方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) { |
| | | throw new BaseException("操作失败,下发数量不能大于剩余方数"); |
| | | } |
| | | |
| | | // 创建生产订单 |
| | |
| | | if (volume == null) { |
| | | continue; |
| | | } |
| | | // 计算剩余方数 |
| | | BigDecimal remainingVolume = plan.getRemainingVolume(); |
| | | if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | |
| | | ProductOrderPlan productOrderPlan = new ProductOrderPlan(); |
| | | productOrderPlan.setProductOrderId(productOrder.getId()); |
| | | productOrderPlan.setProductionPlanId(plan.getId()); |
| | | |
| | | if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | BigDecimal remainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(lastRemainingVolume); |
| | | productionPlanMapper.updateById(plan); |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | break; |
| | | } |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(volume)); |
| | | productOrderPlan.setAssignedQuantity(volume); |
| | | plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | // 更新生产计划 |
| | | productionPlanMapper.updateById(plan); |
| | | // 创建关联关系 |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | assignedVolume = assignedVolume.add(volume); |
| | | assignedVolume = assignedVolume.add(remainingVolume); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | searchParam.put("appType", aliDingConfig.getAppType()); |
| | | searchParam.put("systemToken", aliDingConfig.getSystemToken()); |
| | | searchParam.put("userId", aliDingConfig.getUserId()); |
| | | searchParam.put("formUuid", aliDingConfig.getFormUuid()); |
| | | searchParam.put("formUuid", aliDingConfig.getProducePlanFormUuid()); |
| | | searchParam.put("currentPage", pageNumber); |
| | | searchParam.put("pageSize", pageSize); |
| | | searchParam.put("pageNumber", pageNumber); |
| | | |
| | | JSONArray searchConditions = new JSONArray(); |
| | | JSONObject condition = new JSONObject(); |
| | | condition.put("key", "processApprovedResult"); |
| | | JSONArray valueArray = new JSONArray(); |
| | | valueArray.add("agree"); |
| | | |
| | | condition.put("value", valueArray); |
| | | condition.put("type", "ARRAY"); |
| | | condition.put("operator", "in"); |
| | | condition.put("componentName", "SelectField"); |
| | | searchConditions.add(condition); |
| | | |
| | | searchParam.put("searchFieldJson", searchConditions.toJSONString()); |
| | | |
| | | // 默认按修改时间升序排序,确保分页拉取数据的连续性 |
| | | // "+" 表示升序,"gmt_modified" 是官方内置字段 |