| | |
| | | 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.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.mapper.*; |
| | |
| | | private StockUtils stockUtils; |
| | | @Autowired |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | @Autowired |
| | | private ProductModelMapper productModelMapper; |
| | | |
| | | @Override |
| | | public SalesLedgerProduct selectSalesLedgerProductById(Long id) { |
| | |
| | | int result; |
| | | Long salesLedgerId = salesLedgerProduct.getSalesLedgerId(); |
| | | salesLedgerProduct.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity())); |
| | | salesLedgerProduct.setTotalQuantity(normalizeTotalQuantity( |
| | | salesLedgerProduct.getTotalQuantity(), |
| | | salesLedgerProduct.getQuantity(), |
| | | salesLedgerProduct.getSingleQuantity() |
| | | )); |
| | | if (salesLedgerProduct.getId() == null) { |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | result = salesLedgerProductMapper.insert(salesLedgerProduct); |
| | |
| | | return; |
| | | } |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId()); |
| | | // 获取单位:优先使用前端传入的unit,否则从产品规格获取 |
| | | String unit = salesLedgerProduct.getUnit(); |
| | | if (unit == null || unit.isEmpty()) { |
| | | ProductModel productModel = productModelMapper.selectById(salesLedgerProduct.getProductModelId()); |
| | | unit = productModel != null ? productModel.getUnit() : null; |
| | | } |
| | | |
| | | ProductionPlan productionPlan = new ProductionPlan(); |
| | | productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId()); |
| | | productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId()); |
| | | productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")))); |
| | | productionPlan.setProductModelId(salesLedgerProduct.getProductModelId()); |
| | | // 需求数量 = 产品数量(不是总数) |
| | | productionPlan.setQtyRequired(salesLedgerProduct.getQuantity()); |
| | | // 同步单位 |
| | | productionPlan.setUnit(unit); |
| | | // 同步产品数量 |
| | | productionPlan.setQuantity(salesLedgerProduct.getQuantity()); |
| | | // 同步每件数量 |
| | | productionPlan.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity())); |
| | | // 同步总数 |
| | | productionPlan.setTotalQuantity(normalizeTotalQuantity( |
| | | salesLedgerProduct.getTotalQuantity(), |
| | | salesLedgerProduct.getQuantity(), |
| | | salesLedgerProduct.getSingleQuantity() |
| | | )); |
| | | productionPlan.setSource("销售"); |
| | | productionPlan.setStatus(0); |
| | | productionPlan.setRequiredDate(salesLedger.getDeliveryDate());//需求日期=交货日期 |
| | |
| | | return singleQuantity; |
| | | } |
| | | |
| | | private BigDecimal normalizeTotalQuantity(BigDecimal totalQuantity, BigDecimal quantity, BigDecimal singleQuantity) { |
| | | if (totalQuantity != null && totalQuantity.compareTo(BigDecimal.ZERO) > 0) { |
| | | return totalQuantity; |
| | | } |
| | | if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return quantity.multiply(normalizeSingleQuantity(singleQuantity)); |
| | | } |
| | | |
| | | private String generateNextPlanNo(String datePrefix) { |
| | | QueryWrapper<ProductionPlan> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.likeRight("mps_no", "JH" + datePrefix); |