| | |
| | | import com.ruoyi.production.pojo.*; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<StockInventoryDto> getByBomId(Long bomId) { |
| | | List<ProductStructureDto> structureList = productStructureMapper.listBybomId(bomId); |
| | | |
| | | if (CollectionUtils.isEmpty(structureList)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | Set<Long> allNodeIds = structureList.stream() |
| | | .map(ProductStructureDto::getId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | Set<Long> parentIds = structureList.stream() |
| | | .filter(node -> node.getParentId() != null && node.getParentId() != 0) |
| | | .map(ProductStructureDto::getParentId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | Set<Long> leafNodeIds = new HashSet<>(allNodeIds); |
| | | leafNodeIds.removeAll(parentIds); |
| | | |
| | | // 获取叶子节点的 productModelId |
| | | List<Long> productModelIds = structureList.stream() |
| | | .filter(node -> leafNodeIds.contains(node.getId())) |
| | | .map(ProductStructureDto::getProductModelId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (productModelIds.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | return stockInventoryMapper.getStockInventory(productModelIds); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int drawMaterials(ProductOrderDto productOrderDto) { |
| | | if (productOrderDto == null || productOrderDto.getId() == null) { |
| | |
| | | if (CollectionUtils.isEmpty(drawMaterialsList)) { |
| | | throw new RuntimeException("领料明细不能为空"); |
| | | } |
| | | // 如果有数据先加库存 |
| | | ProductOrder productOrder = productOrderMapper.selectById(productOrderDto.getId()); |
| | | if (productOrder != null) { |
| | | List<DrawMaterialDto> materialDtoList = JSON.parseArray(productOrder.getDrawMaterials(), DrawMaterialDto.class); |
| | | for (DrawMaterialDto drawMaterialDto : materialDtoList) { |
| | | stockUtils.addStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), null, productOrderDto.getId()); |
| | | } |
| | | } |
| | | |
| | | // 处理领料(扣减库存) |
| | | try { |