gongchunyi
3 天以前 f0bcc6b51f4a272321710650800486d7d2f019fd
src/main/java/com/ruoyi/production/service/impl/ProductionRecordServiceImpl.java
@@ -5,6 +5,7 @@
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.production.dto.*;
@@ -52,6 +53,9 @@
    @Value("${file.upload-dir}")
    private String uploadDir;
    @Autowired
    private RuoYiConfig ruoYiConfig;
    @Autowired
    private ProductionProductMainService productionProductMainService;
@@ -198,17 +202,31 @@
            throw new ServiceException("报工失败,生产订单不存在");
        }
        //  当前报工合格数量(前端已保证 = 投入数量 - 不合格数量,直接使用)
        //  当前报工合格数量
        BigDecimal qualifiedQty = dto.getQualifiedQuantity() == null ? BigDecimal.ZERO : dto.getQualifiedQuantity();
        BigDecimal unqualifiedQty = dto.getUnqualifiedQuantity() == null ? BigDecimal.ZERO : dto.getUnqualifiedQuantity();
        BigDecimal totalReportQty = dto.getQuantity() == null ? BigDecimal.ZERO : dto.getQuantity();
        if (qualifiedQty.compareTo(BigDecimal.ZERO) < 0 || unqualifiedQty.compareTo(BigDecimal.ZERO) < 0 || totalReportQty.compareTo(BigDecimal.ZERO) < 0) {
            throw new ServiceException("报工失败:合格数量、不合格数量或总数量不能为负数");
        }
        if (qualifiedQty.add(unqualifiedQty).compareTo(totalReportQty) != 0) {
            throw new ServiceException("报工失败:合格数量与不合格数量之和必须等于总报工数量");
        }
        //  订单已完成数量(历史累计)
        BigDecimal completeQty = productOrder.getCompleteQuantity() == null ? BigDecimal.ZERO : productOrder.getCompleteQuantity();
        //  需求数量
        BigDecimal totalQty = productOrder.getQuantity() == null ? BigDecimal.ZERO : productOrder.getQuantity();
        //  剩余可报工数量
        BigDecimal remainQty = totalQty.subtract(completeQty);
        //  本次报工合格数量不能超过剩余数量(校验必须在累加前执行)
        //  本次报工合格数量不能超过剩余数量
        if (qualifiedQty.compareTo(remainQty) > 0) {
            throw new ServiceException("报工失败,本次报工数量不能大于剩余可报工数量,剩余报工数量:[" + remainQty + "]");
        }
        //  本次报工不合格数量不能超过本次报工数量
        if (dto.getUnqualifiedQuantity() != null && dto.getUnqualifiedQuantity().compareTo(dto.getQuantity()) > 0) {
            throw new ServiceException("报工失败,本次报工不合格数量不能大于报工数量,报工数量:[" + dto.getQuantity() + "]");
        }
        //  历史已完成 + 本次合格数量
        BigDecimal newCompleteQty = completeQty.add(qualifiedQty);
@@ -299,6 +317,8 @@
                                paramEntity.setValueMode(orderParam.getValueMode());
                                paramEntity.setUnit(orderParam.getUnit());
                                paramEntity.setStandardValue(orderParam.getStandardValue());
                                paramEntity.setMinValue(orderParam.getMinValue());
                                paramEntity.setMaxValue(orderParam.getMaxValue());
                            }
                        }
                        productionProductRouteItemParamService.save(paramEntity);
@@ -343,6 +363,11 @@
                        fileEntity.setProductionProductRouteItemId(productRouteItemEntity.getId());
                        fileEntity.setFileName(originalFilename);
                        fileEntity.setFileUrl(formalFilePath.toString());
                        Path basePath = Paths.get(RuoYiConfig.getProfile());
                        String relativePath = basePath.relativize(formalFilePath).toString();
                        relativePath = relativePath.replace("\\", "/");
                        String url = "/profile/" + relativePath;
                        fileEntity.setUrl(url);
                        fileEntity.setFileSuffix(fileExtension);
                        fileEntity.setFileSize(Files.size(formalFilePath));
                        fileEntity.setCreateTime(LocalDateTime.now());
@@ -739,6 +764,9 @@
                                paramEntity.setParamFormat(orderParam.getParamFormat());
                                paramEntity.setValueMode(orderParam.getValueMode());
                                paramEntity.setUnit(orderParam.getUnit());
                                paramEntity.setStandardValue(orderParam.getStandardValue());
                                paramEntity.setMinValue(orderParam.getMinValue());
                                paramEntity.setMaxValue(orderParam.getMaxValue());
                            }
                        }
                        productionProductRouteItemParamService.save(paramEntity);
@@ -776,6 +804,12 @@
                        fileEntity.setProductionProductRouteItemId(routeItemId);
                        fileEntity.setFileName(originalFilename);
                        fileEntity.setFileUrl(formalFilePath.toString());
                        Path basePath = Paths.get(RuoYiConfig.getProfile());
                        String relativePath = basePath.relativize(formalFilePath).toString();
                        relativePath = relativePath.replace("\\", "/");
                        String url = "/profile/" + relativePath;
                        fileEntity.setUrl(url);
                        fileEntity.setFileSuffix(fileExtension);
                        fileEntity.setFileSize(Files.size(formalFilePath));
                        fileEntity.setCreateTime(LocalDateTime.now());