| | |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.config.AliDingConfig; |
| | | import com.ruoyi.production.pojo.ProductMaterial; |
| | | import com.ruoyi.production.pojo.ProductOrder; |
| | | import com.ruoyi.production.service.ProductMaterialService; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanDto; |
| | | import com.ruoyi.productionPlan.dto.ProductionPlanImportDto; |
| | |
| | | @Autowired |
| | | private ProductOrderPlanMapper productOrderPlanMapper; |
| | | |
| | | @Autowired |
| | | private ProductMaterialService productMaterialService; |
| | | |
| | | /** |
| | | * 同步锁,确保手动和定时任务不同时执行 |
| | | */ |
| | |
| | | |
| | | // 查询主生产计划 |
| | | List<ProductionPlan> plans = productionPlanMapper.selectBatchIds(productionPlanDto.getIds()); |
| | | plans.sort(Comparator.comparingLong(ProductionPlan::getId)); |
| | | |
| | | // 校验是否存在不同的产品名称 |
| | | String firstProductName = plans.get(0).getProductName(); |
| | |
| | | } |
| | | |
| | | |
| | | // 叠加方数 |
| | | 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) { |
| | | |
| | | log.warn("操作失败,下发数量不能大于方数"); |
| | | return false; |
| | | } |
| | | |
| | | // 根据下发数量,从第一个生产计划开始分配方数 |
| | | BigDecimal assignedVolume = BigDecimal.ZERO; |
| | | for (ProductionPlan plan : plans) { |
| | | BigDecimal volume = plan.getVolume(); |
| | | if (volume == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (assignedVolume.add(volume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | plan.setAssignedQuantity(productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume)); |
| | | productionPlanMapper.updateById(plan); |
| | | break; |
| | | } |
| | | |
| | | // 分配当前计划方数 |
| | | plan.setAssignedQuantity(volume); |
| | | productionPlanMapper.updateById(plan); |
| | | assignedVolume = assignedVolume.add(volume); |
| | | // 判断下发数量是否大于等于剩余方数 |
| | | if (productionPlanDto.getTotalAssignedQuantity().compareTo(totalRemainingVolume) > 0) { |
| | | throw new BaseException("操作失败,下发数量不能大于剩余方数"); |
| | | } |
| | | |
| | | // 创建生产订单 |
| | |
| | | productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime()); |
| | | productOrderService.addProductOrder(productOrder); |
| | | |
| | | for (Long planId : productionPlanDto.getIds()) { |
| | | // 根据下发数量,从第一个生产计划开始分配方数 |
| | | BigDecimal assignedVolume = BigDecimal.ZERO; |
| | | for (ProductionPlan plan : plans) { |
| | | BigDecimal volume = plan.getVolume(); |
| | | 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(planId); |
| | | productOrderPlan.setProductionPlanId(plan.getId()); |
| | | |
| | | if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) { |
| | | // 最后一个计划,分配剩余方数 |
| | | 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(remainingVolume)); |
| | | productOrderPlan.setAssignedQuantity(remainingVolume); |
| | | // 更新生产计划 |
| | | productionPlanMapper.updateById(plan); |
| | | // 创建关联关系 |
| | | productOrderPlanMapper.insert(productOrderPlan); |
| | | assignedVolume = assignedVolume.add(remainingVolume); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | plan.setApplyNo(formData.getString("textField_l7fytfco")); |
| | | plan.setCustomerName(formData.getString("textField_lbkozohg")); |
| | | |
| | | plan.setMaterialCode(row.getString("textField_l9xo62q5")); |
| | | String materialCode = row.getString("textField_l9xo62q5"); |
| | | plan.setMaterialCode(materialCode); |
| | | |
| | | // 根据物料编码查询物料信息表,关联物料ID |
| | | if (StringUtils.isNotEmpty(materialCode)) { |
| | | LambdaQueryWrapper<ProductMaterial> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(ProductMaterial::getMaterialCode, materialCode); |
| | | ProductMaterial productMaterial = productMaterialService.getOne(queryWrapper); |
| | | if (productMaterial != null) { |
| | | plan.setProductMaterialId(productMaterial.getId()); |
| | | } |
| | | } |
| | | |
| | | plan.setProductName(row.getString("textField_l9xo62q7")); |
| | | plan.setProductSpec(row.getString("textField_l9xo62q8")); |
| | | plan.setLength(row.getInteger("numberField_lb7lgatg_value")); |