buhuazhen
2 天以前 a27bcd2f9cba539ba9ffb7cfa949dc102d7446ff
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -44,6 +44,7 @@
import oshi.driver.mac.net.NetStat;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -164,15 +165,23 @@
        List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomAndProcess(productProcessRoute.getBomId(), productProcess.getId());
        List<Long> lastProcessIds = new ArrayList<>();
        List<Long> firstProcessIds = new ArrayList<>();
        if (!allProcess.isEmpty()) {
            String lastProcessName = allProcess.get(allProcess.size() - 1).getProcessName();
            String firstProcessName = allProcess.get(0).getProcessName();
            for (int i = allProcess.size() - 1; i >= 0; i--) {
                ProductStructureDto d = allProcess.get(i);
                if (lastProcessName.equals(d.getProcessName())) {
                    lastProcessIds.add(d.getId());
                } else {
                    break;
                }
            }
            for (ProductStructureDto d : allProcess) {
                if (firstProcessName.equals(d.getProcessName())) {
                    firstProcessIds.add(d.getId());
                } else {
                    break;
                }
@@ -190,13 +199,15 @@
            ProductModel productModel1 = productModelMapper.selectById(productStructureDto.getProductModelId());
            Product product = productMapper.selectById(productModel1.getProductId());
            // 判断是否为最后一道工序
            BigDecimal needQuantity = dto.getQuantity().divide(productStructureDto.getUnitQuantity(), 2, BigDecimal.ROUND_HALF_UP);
            if (lastProcessIds.contains(productStructureDto.getId())) {
            // 判断是否为最后一道工序 或者为第一道工序
            BigDecimal needQuantity = BigDecimal.ZERO;
            if(BigDecimal.ZERO.equals(productStructureDto.getUnitQuantity())){
                needQuantity = dto.getQuantity().divide(productStructureDto.getUnitQuantity(), 2, RoundingMode.HALF_UP);
            }
            if (lastProcessIds.contains(productStructureDto.getId()) || firstProcessIds.contains(productStructureDto.getId())) {
                needQuantity = dto.getQuantity().multiply(productStructureDto.getUnitQuantity());
            }
            // 查询产品库存
            BigDecimal stockQuantity = stockUtils.getStockQuantity(productModel1.getId()).get("stockQuantity");
            if (!(stockQuantity.compareTo(BigDecimal.ZERO) > 0)) {