| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.AmountUtils; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | |
| | | result = salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | addProductionData(salesLedgerProduct); |
| | | } else { |
| | | //查询原本的产品型号id |
| | | result = salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | /*删除对应的生产数据并重新新增*/ |
| | | deleteProductionData(Arrays.asList(salesLedgerProduct.getId())); |
| | | |
| | | addProductionData(salesLedgerProduct); |
| | | /*同步对应的生产数据:计划未下发时原地更新需求数量,保留生产计划号*/ |
| | | syncProductionData(salesLedgerProduct); |
| | | } |
| | | |
| | | // 如果插入或更新成功,并且有 salesLedgerId,才继续更新主表金额 |
| | |
| | | */ |
| | | public void addProductionData(SalesLedgerProduct salesLedgerProduct) { |
| | | //先判断该产品是否需要生产 |
| | | if (salesLedgerProduct.getIsProduction()) { |
| | | if (Boolean.TRUE.equals(salesLedgerProduct.getIsProduction())) { |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId()); |
| | | ProductionPlan productionPlan = new ProductionPlan(); |
| | | productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 同步生产数据 |
| | | * 需要生产:生产计划已下发时禁止修改;未下发时原地更新需求数量,保留生产计划号; |
| | | * 改为走库存:删除未下发的生产计划。 |
| | | */ |
| | | public void syncProductionData(SalesLedgerProduct salesLedgerProduct) { |
| | | if (salesLedgerProduct.getId() == null) { |
| | | return; |
| | | } |
| | | List<ProductionPlan> productionPlans = listProductionData(salesLedgerProduct.getId()); |
| | | if (CollectionUtils.isEmpty(productionPlans)) { |
| | | //原来不需要生产,现在改为需要生产,补建生产计划 |
| | | if (Boolean.TRUE.equals(salesLedgerProduct.getIsProduction())) { |
| | | addProductionData(salesLedgerProduct); |
| | | } |
| | | return; |
| | | } |
| | | //改为走库存,删除未下发的生产计划 |
| | | if (!Boolean.TRUE.equals(salesLedgerProduct.getIsProduction())) { |
| | | deleteProductionData(Collections.singletonList(salesLedgerProduct.getId())); |
| | | return; |
| | | } |
| | | if (productionPlans.stream().anyMatch(plan -> plan.getStatus() != null && plan.getStatus() != 0)) { |
| | | throw new ServiceException("生产计划已下发,不能修改该销售产品"); |
| | | } |
| | | for (ProductionPlan productionPlan : productionPlans) { |
| | | productionPlan.setQtyRequired(salesLedgerProduct.getQuantity()); |
| | | productionPlan.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | productionPlanMapper.updateById(productionPlan); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除生产计划 |
| | | */ |
| | | public void deleteProductionData(List<Long> productIds) { |
| | |
| | | } |
| | | List<ProductionPlan> productionPlans = productionPlanMapper.selectList( |
| | | new LambdaQueryWrapper<ProductionPlan>() |
| | | .in(ProductionPlan::getSalesLedgerProductId, productIds.stream().map(Long::intValue).collect(Collectors.toList()))); |
| | | .in(ProductionPlan::getSalesLedgerProductId, productIds)); |
| | | if (CollectionUtils.isEmpty(productionPlans)) { |
| | | return; |
| | | } |
| | | //如果生产计划已下发则不能删除 |
| | | if (productionPlans.stream().anyMatch(productionPlan -> productionPlan.getStatus() != 0)) { |
| | | if (productionPlans.stream().anyMatch(productionPlan -> productionPlan.getStatus() != null && productionPlan.getStatus() != 0)) { |
| | | throw new RuntimeException("生产计划已下发,不能删除该销售产品"); |
| | | } |
| | | List<Long> ids = productionPlans.stream().map(ProductionPlan::getId).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询销售产品对应的生产计划 |
| | | */ |
| | | private List<ProductionPlan> listProductionData(Long productId) { |
| | | return productionPlanMapper.selectList(new LambdaQueryWrapper<ProductionPlan>() |
| | | .eq(ProductionPlan::getSalesLedgerProductId, productId)); |
| | | } |
| | | |
| | | /** |
| | | * 通用方法:根据主表ID和子表列表,更新主表的合同金额 |
| | | */ |
| | | public <T, S> void updateMainContractAmount( |