| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.ProductionAccount; |
| | | import com.ruoyi.production.pojo.ProductionOperationTask; |
| | | import com.ruoyi.production.pojo.ProductionPlan; |
| | | import com.ruoyi.production.pojo.ProductionProductMain; |
| | | import com.ruoyi.production.service.ProductionOrderService; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.sales.dto.InvoiceRegistrationProductDto; |
| | | import com.ruoyi.sales.dto.SalesLedgerProductDto; |
| | | import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper; |
| | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | private final PurchaseLedgerMapper purchaseLedgerMapper; |
| | | private final ProductionPlanMapper productionPlanMapper; |
| | | private final ProductionOperationTaskMapper productionOperationTaskMapper; |
| | | private final ProductionOrderService productionOrderService; |
| | | private final TechnologyRoutingMapper technologyRoutingMapper; |
| | | private final TechnologyBomStructureMapper technologyBomStructureMapper; |
| | | private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper; |
| | |
| | | * 新增生产数据 |
| | | */ |
| | | public void addProductionData(SalesLedgerProduct salesLedgerProduct) { |
| | | if (!Integer.valueOf(1).equals(salesLedgerProduct.getType())) { |
| | | //先判断该产品是否需要生产 |
| | | if (!salesLedgerProduct.getIsProduction()) { |
| | | return; |
| | | } |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId()); |
| | | ProductionPlan productionPlan = new ProductionPlan(); |
| | | productionPlan.setApplyNo(buildSalesPlanApplyNo(salesLedgerProduct.getId())); |
| | | productionPlan.setSource("sales"); |
| | | productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | | productionPlan.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId()); |
| | | productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))); |
| | | productionPlan.setQtyRequired(salesLedgerProduct.getQuantity()); |
| | | productionPlan.setRemark("销售台账自动生成"); |
| | | productionPlan.setIssued(Boolean.FALSE); |
| | | productionPlan.setStatus(0); |
| | | if (salesLedger != null) { |
| | | productionPlan.setMpsNo(salesLedger.getSalesContractNo()); |
| | | if (salesLedger.getDeliveryDate() != null) { |
| | | productionPlan.setRequiredDate(salesLedger.getDeliveryDate().atStartOfDay()); |
| | | productionPlan.setPromisedDeliveryDate(salesLedger.getDeliveryDate().atStartOfDay()); |
| | | } |
| | | } |
| | | productionPlanMapper.insert(productionPlan); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除生产数据 |
| | | * 删除生产计划 |
| | | */ |
| | | public void deleteProductionData(List<Long> productIds) { |
| | | List<String> applyNos = productIds.stream() |
| | | .filter(Objects::nonNull) |
| | | .map(this::buildSalesPlanApplyNo) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(applyNos)) { |
| | | return; |
| | | } |
| | | List<ProductionPlan> productionPlans = productionPlanMapper.selectList( |
| | | new LambdaQueryWrapper<ProductionPlan>().in(ProductionPlan::getApplyNo, applyNos)); |
| | | if (CollectionUtils.isEmpty(productionPlans)) { |
| | | new LambdaQueryWrapper<ProductionPlan>() |
| | | .in(ProductionPlan::getSalesLedgerProductId, productIds.stream().map(Long::intValue).collect(Collectors.toList()))); |
| | | if (org.springframework.util.CollectionUtils.isEmpty(productionPlans)) { |
| | | return; |
| | | } |
| | | boolean hasIssued = productionPlans.stream().anyMatch(item -> Boolean.TRUE.equals(item.getIssued()) || (item.getStatus() != null && item.getStatus() > 0)); |
| | | if (hasIssued) { |
| | | throw new ServiceException("对应生产计划已下发生成生产订单,请先处理生产计划/生产订单后再修改销售台账"); |
| | | //如果生产计划已下发则不能删除 |
| | | if (productionPlans.stream().anyMatch(productionPlan -> productionPlan.getStatus() != 0)) { |
| | | throw new RuntimeException("生产计划已下发,不能删除该销售产品"); |
| | | } |
| | | productionPlanMapper.deleteByIds(productionPlans.stream().map(ProductionPlan::getId).collect(Collectors.toList())); |
| | | List<Long> ids = productionPlans.stream().map(ProductionPlan::getId).collect(Collectors.toList()); |
| | | productionPlanMapper.deleteByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private String buildSalesPlanApplyNo(Long salesLedgerProductId) { |
| | | return "SALE_PRODUCT_" + salesLedgerProductId; |
| | | private String generateNextPlanNo(String datePrefix) { |
| | | QueryWrapper<ProductionPlan> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.likeRight("mps_no", "JH" + datePrefix); |
| | | queryWrapper.orderByDesc("mps_no"); |
| | | queryWrapper.last("LIMIT 1"); |
| | | ProductionPlan latestPlan = productionPlanMapper.selectOne(queryWrapper); |
| | | int sequence = 1; |
| | | if (latestPlan != null && latestPlan.getMpsNo() != null && !latestPlan.getMpsNo().isEmpty()) { |
| | | String sequenceStr = latestPlan.getMpsNo().substring(("JH" + datePrefix).length()); |
| | | try { |
| | | sequence = Integer.parseInt(sequenceStr) + 1; |
| | | } catch (NumberFormatException e) { |
| | | sequence = 1; |
| | | } |
| | | } |
| | | return "JH" + datePrefix + String.format("%04d", sequence); |
| | | } |
| | | } |