| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.production.dto.ProductStructureDto; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | |
| | | import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.InvoiceRegistrationProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductService; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.lang.reflect.Field; |
| | |
| | | private ProductionProductOutputMapper productionProductOutputMapper; |
| | | private ProductionProductInputMapper productionProductInputMapper; |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | private ProductBomMapper productBomMapper; |
| | | private ProductStructureMapper productStructureMapper; |
| | | |
| | | @Override |
| | | public SalesLedgerProduct selectSalesLedgerProductById(Long id) { |
| | |
| | | .orderByDesc(ProcessRoute::getCreateTime)); |
| | | if (processRoutes.size()>0){ |
| | | ProcessRoute processRoute = processRoutes.get(0); |
| | | // 获取产品bom信息 |
| | | List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomId(processRoute.getBomId()); |
| | | if (salesLedgerProduct.getQuantity() == null) { |
| | | throw new RuntimeException("最终生产数量不存在"); |
| | | } |
| | | Map<Long, BigDecimal> quantities = countWorkOrderNum(productStructureDtos, salesLedgerProduct.getQuantity()); |
| | | |
| | | //新增生产订单工艺路线主表 |
| | | ProductProcessRoute productProcessRoute = new ProductProcessRoute(); |
| | | productProcessRoute.setProductModelId(processRoute.getProductModelId()); |
| | |
| | | ProductWorkOrder productWorkOrder = new ProductWorkOrder(); |
| | | productWorkOrder.setProductProcessRouteItemId(productProcessRouteItem.getId()); |
| | | productWorkOrder.setProductOrderId(productOrder.getId()); |
| | | productWorkOrder.setPlanQuantity(salesLedgerProduct.getQuantity()); |
| | | productWorkOrder.setPlanQuantity(quantities.get(processRouteItem.getProcessId())); |
| | | productWorkOrder.setWorkOrderNo(workOrderNoStr); |
| | | productWorkOrder.setStatus(1); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 计算工单数量 |
| | | * productStructures bom信息 |
| | | * quantity 需求数量 |
| | | */ |
| | | public Map<Long, BigDecimal> countWorkOrderNum(List<ProductStructureDto> productStructures, BigDecimal quantity) { |
| | | BigDecimal originalQuantity = quantity; |
| | | Map<Long, BigDecimal> resultMap = new HashMap<>(); |
| | | resultMap.put(productStructures.get(productStructures.size() - 1).getProcessId(), quantity); |
| | | for (int i = productStructures.size() - 2; i >= 0; i--) { |
| | | ProductStructureDto productStructureDto = productStructures.get(i); |
| | | Assert.notNull(productStructureDto.getUnitQuantity(), "单位产出所需数量不存在"); |
| | | if (productStructureDto.getMaterialType().equals("0")) { |
| | | quantity = quantity.multiply(productStructureDto.getUnitQuantity()); |
| | | resultMap.put(productStructureDto.getProcessId(), quantity); |
| | | } else { |
| | | resultMap.put(productStructureDto.getProcessId(), originalQuantity.multiply(productStructureDto.getUnitQuantity())); |
| | | } |
| | | |
| | | } |
| | | return resultMap; |
| | | } |
| | | |
| | | /** |
| | | * 删除生产数据 |
| | | */ |
| | | public void deleteProductionData(List<Long> productIds) { |