zouyu
5 天以前 e1284aa3b1b400ecebb59126d7110a3bb4a6b000
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -277,7 +277,8 @@
    }
    @Override
    public List<String> checkSubmitPlan(Integer orderId, String laboratory) {
    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory) {
        Map<String, Object> map = new HashMap<>();
        List<String> collect = new ArrayList<>();
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
        List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList());
@@ -303,7 +304,19 @@
                return insProduct.getInspectionItem() + "-" + insProduct.getInspectionItemSubclass();
            }).collect(Collectors.toList());
        }
        return collect;
        //查询ifs拆分订单是否有已下单但是未检完的单子
        long count = 0L;
        InsOrder insOrder = insOrderMapper.selectById(orderId);
        if(Objects.nonNull(insOrder.getIfsInventoryId())){
            IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
            //过滤出不合格或未提交的单子
            count = ifsInventoryQuantityMapper.selectSplitOrderList(one.getPartNo(),one.getLineNo(),one.getReleaseNo(),one.getReceiptNo(),one.getOrderNo())
                    .stream()
                    .filter(f->(Objects.nonNull(f.getInsOrderId()) && !Objects.equals(f.getInsOrderId(),orderId)) && (Objects.isNull(f.getInsResult()) || 0==f.getInsResult())).count();
        }
        map.put("errorMsg",collect);
        map.put("unInsOrderCount",count);
        return map;
    }
    @Override
@@ -756,7 +769,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode) {
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode,Boolean registerInsResults) {
        InsOrder order = insOrderMapper.selectById(orderId);
        // 1. 判断是否有重复编号, 有重复编号做提醒
        Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
@@ -926,7 +939,7 @@
            // 登记检验结果
            // 判断是否有不合格, 有不合格不能移库
            // todo: ifs移库
            insReportService.isRawMaterial(order);
            insReportService.isRawMaterial(order,registerInsResults,false);
            // 15 判断当前样品是否为原材料, 原材料需要进行数据分析, 判断之前10条数据同一个供应商, 同一个检验项的偏差是否超过10%
            // 查询ifs信息获取获取前10个供应商一样的, 检验项一样信息
@@ -966,7 +979,7 @@
            if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) {
                List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
                if (insProductAnalysisDtoList.size() < 10) {
                if (CollectionUtils.isEmpty(insProductAnalysisDtoList)) {
                    continue;
                }
@@ -975,8 +988,10 @@
                        .collect(Collectors.toList());
                double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue());
                // 判断要求值是否偏差超过10%
                double asked = isDeviationOverTenPercentByAsked(insProduct.getAsk(), insProduct.getLastValue());
                // 判断偏差是否大于10
                if (deviation > 10) {
                if (deviation > 10 || asked > 10) {
                    // 判断之前是否添加过, 添加过不需要添加
                    long count = insProductDeviationWarningService.count(Wrappers.<InsProductDeviationWarning>lambdaQuery()
                            .eq(InsProductDeviationWarning::getInsProductId, insProduct.getId()));
@@ -1004,7 +1019,8 @@
                        deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName());
                        deviationWarningDetail.setTestValue(insProduct.getLastValue());
                        deviationWarningDetail.setDetectionTime(insProduct.getCreateTime());
                        deviationWarningDetail.setIsIssue(1);
                        deviationWarningDetail.setIsIssue(deviation > 10 ? 1 : 0);
                        deviationWarningDetail.setIsIssueAsked(asked > 10 ? 1 : 0);
                        insProductAnalysisDtoList.add(deviationWarningDetail);
@@ -1057,6 +1073,24 @@
        double sum = doubleData.stream().mapToDouble(Double::doubleValue).sum();
        double average = sum / doubleData.size();
        double target = Double.parseDouble(targetStr);
        double deviationPercent = Math.abs(target - average) / average * 100;
        // 保留两位小数
        DecimalFormat df = new DecimalFormat("#.00");
        String formatted = df.format(deviationPercent);
        return Double.parseDouble(formatted);
    }
    /**
     * *****计算偏差(要求值)****
     * @param asked
     * @param targetStr
     * @return
     */
    public static double isDeviationOverTenPercentByAsked(String asked, String targetStr) {
        if(!isNumeric(asked)) return 0;
        double average = Double.parseDouble(asked);
        double target = Double.parseDouble(targetStr);
        double deviationPercent = Math.abs(target - average) / average * 100;
@@ -3710,6 +3744,18 @@
    }
    /**
     * NBSP(非间断空格) 转成 普通空格
     * @param oldStr
     * @return
     */
    private String normalizedSpaces(String oldStr){
        if(StringUtils.isBlank(oldStr)){
            return oldStr;
        }
        return oldStr.replaceAll("\u00A0", " ").trim();
    }
    /**
     * 添加报告结论中英文
     * @param sample
     * @param itemCh
@@ -3721,9 +3767,9 @@
                                       String itemCh,
                                       String itemEn) {
        // 判断是否有检验项分类map
        String classTiemName = itemCh + (StringUtils.isBlank(sample.getInspectionItemClass()) ? "" : sample.getInspectionItemClass());
        String classTiemNameEn = itemEn + (StringUtils.isBlank(sample.getInspectionItemClassEN()) ? "" : sample.getInspectionItemClassEN());
        String classTiemNameItemEN = StringUtils.isBlank(sample.getInspectionItemEn()) ? "" : sample.getInspectionItemEn();
        String classTiemName = itemCh + (StringUtils.isBlank(sample.getInspectionItemClass()) ? "" : normalizedSpaces(sample.getInspectionItemClass()));
        String classTiemNameEn = itemEn + (StringUtils.isBlank(sample.getInspectionItemClassEN()) ? "" : normalizedSpaces(sample.getInspectionItemClassEN()));
        String classTiemNameItemEN = StringUtils.isBlank(sample.getInspectionItemEn()) ? "" : normalizedSpaces(sample.getInspectionItemEn());
        if (errorClassItemMapCn.containsKey(classTiemName)) {
            // 判断是否有检验项map