From e94da0876bae33361cf75a757663f687f439cd65 Mon Sep 17 00:00:00 2001 From: wxr Date: Mon, 9 Mar 2026 16:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E5=8F=89=E5=AE=A1=E6=A0=B8=EF=BC=8C?= =?UTF-8?q?=E8=B6=85=E5=B7=AE=E5=88=A4=E5=AE=9A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/SampleAnalysisAuditService.java | 9 +- .../SampleAnalysisAuditServiceImpl.java | 1084 ++++++++++++++++- 2 files changed, 1043 insertions(+), 50 deletions(-) diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditService.java index 84e056e8..03778355 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditService.java @@ -22,7 +22,14 @@ public interface SampleAnalysisAuditService { void assessmentDataReporting(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount); - void createReAnalysis(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount); + /** + * 创建复检委托 + * @param businessSubSampleId 子样id + * @param configAssayMethodId 分析方法id + * @param retestCount 复测次数 + * @param taskCount 复检任务数 + */ + void createReAnalysis(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount, Integer taskCount); JSONObject modifyParallelResultAssessment(Long businessSubSampleId, Long configAssayMethodId, Long businessSubSampleAssessmentId, List businessAssayProjectDataIds); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditServiceImpl.java index 4acd2ea5..8e08642e 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/bus/service/SampleAnalysisAuditServiceImpl.java @@ -3,8 +3,10 @@ package com.zt.plat.module.qms.business.bus.service; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,7 +29,9 @@ import com.alibaba.qlexpress4.QLOptions; import com.alibaba.qlexpress4.QLResult; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.esotericsoftware.minlog.Log; import com.zt.plat.framework.common.exception.ServiceException; +import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils; import com.zt.plat.module.qms.business.bus.controller.vo.*; @@ -86,6 +90,8 @@ import com.zt.plat.module.qms.business.config.dal.mapper.ConfigSampleReportMappe import com.zt.plat.module.qms.business.config.dal.mapper.ConfigSubSampleMapper; import com.zt.plat.module.qms.business.config.dal.mapper.ConfigSubSampleMethodMapper; import com.zt.plat.module.qms.business.config.dal.mapper.ConfigSubSampleParentMethodMapper; +import com.zt.plat.module.qms.common.dic.controller.vo.DictionaryBusinessExtendRespVO; +import com.zt.plat.module.qms.common.dic.dal.mapper.DictionaryBusinessMapper; import com.zt.plat.module.qms.core.qlexpress.cmp.AllowanceCalculatorComponent; import com.zt.plat.module.qms.core.util.number.EffectiveNumberFormatter; import com.zt.plat.module.qms.enums.QmsCommonConstant; @@ -93,6 +99,7 @@ import com.zt.plat.module.qms.enums.QmsCommonConstant; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import jakarta.annotation.Resource; +import tech.zzjc.tio.utils.cache.caffeine.DefaultRemovalListener; /** * SampleAnalysisAuditServiceImpl @@ -168,6 +175,9 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic @Resource private ConfigSubSampleMethodMapper configSubSampleMethodMapper; + + @Resource + private DictionaryBusinessMapper dictionaryBusinessMapper; @Override public JSONObject getSampleResultAssessmentList(BusinessAssayTaskDataReqVO reqVO) { @@ -267,6 +277,15 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic search.setBusinessSubSampleId(businessSubSampleId); search.setConfigAssayMethodId(configAssayMethodId); List businessAssayProjectDataList = businessAssayProjectDataMapper.selectAnalysisBy(search); + + List assessmenTypeList = dictionaryBusinessMapper.selectItemByCategoryKeys(Arrays.asList("assessmenType")); + for (BusinessAssayProjectDataExtendRespVO businessAssayProjectDataExtendRespVO : businessAssayProjectDataList) { + DictionaryBusinessExtendRespVO assessmenType = assessmenTypeList.stream().filter(f -> f.getKey().equals(businessAssayProjectDataExtendRespVO.getAssessmentType())).findFirst().orElse(null); + if (assessmenType != null) { + businessAssayProjectDataExtendRespVO.setAssessmentTypeName(assessmenType.getName()); + } + } + //已检测项目分组,取第一个 Map> businessAssayProjectDataMap = businessAssayProjectDataList.stream().collect(Collectors.groupingBy(BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodProjectId)); @@ -303,9 +322,12 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic } dataList.add(businessSubSampleAssessmentMap); } + BusinessSubSampleDO businessSubSampleDO = businessSubSampleMapper.selectById(businessSubSampleId); + ConfigSubSampleMethodExtendRespVO configSubSampleMethodExtendRespVO = configSubSampleMethodMapper.selectByConfigSubSampleIdAndConfigAssayMethodId(businessSubSampleDO.getConfigSubSampleId(), configAssayMethodId); JSONObject json = new JSONObject(); + json.put("configSubSampleMethod", configSubSampleMethodExtendRespVO); json.put("columns", columnList); json.put("datas", dataList); json.put("subDatas", businessAssayProjectDataList); @@ -662,6 +684,8 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic //自动上报的子样判定数据 List automaticBusinessSubSampleAssessmentList = new ArrayList<>(); + //分析检测项目记录 + List updateBusinessAssayProjectDataDOList = new ArrayList<>(); //判定记录 List updateBusinessSubSampleAssessmentDOList = new ArrayList<>(); List saveBusinessSubSampleAssessmentProjectDOList = new ArrayList<>(); @@ -726,13 +750,13 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic //状态设置为待上报 businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_REPORT); //查询分析项目 - List businessAssayProjectDataDOList = businessAssayProjectDataMapper.selectList(new LambdaQueryWrapperX().in(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList)); - Map> businessAssayProjectDataDOMap = businessAssayProjectDataDOList.stream().collect(Collectors.groupingBy(BusinessAssayProjectDataDO::getDictionaryProjectId)); - for (Map.Entry> businessAssayProjectDataDOEntry : businessAssayProjectDataDOMap.entrySet()) { + List businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(businessAssayTaskDataIdList); + Map> businessAssayProjectDataDOMap = businessAssayProjectDataExtendList.stream().collect(Collectors.groupingBy(BusinessAssayProjectDataExtendRespVO::getDictionaryProjectId)); + + for (Map.Entry> businessAssayProjectDataDOEntry : businessAssayProjectDataDOMap.entrySet()) { Long dictionaryProjectId = businessAssayProjectDataDOEntry.getKey(); - List val1 = businessAssayProjectDataDOEntry.getValue(); - BusinessAssayProjectDataDO businessAssayProjectDataDO = val1.get(0); - List configAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentMapper.selectByConfigBaseSampleIdAndConfigAssayMethodIdAndConfigAssayMethodProjectId(configSubSampleMethodDO.getConfigBaseSampleId(), businessAssayTaskDataDO.getConfigAssayMethodId(), businessAssayProjectDataDO.getConfigAssayMethodProjectId()); + List val1 = businessAssayProjectDataDOEntry.getValue(); + BusinessAssayProjectDataExtendRespVO businessAssayProjectDataDO = val1.get(0); //查询判定结果数据 BusinessSubSampleAssessmentProjectDO businessSubSampleAssessmentProjectDO = businessSubSampleAssessmentProjectMapper.selectByBusinessSubSampleIdAndConfigAssayMethodIdAndConfigAssayMethodProjectId(businessSubSampleId, businessAssayTaskDataDO.getConfigAssayMethodId(), businessAssayProjectDataDO.getConfigAssayMethodProjectId()); @@ -758,51 +782,1004 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic businessSubSampleAssessmentProjectDO.setSymbol(businessAssayProjectDataDO.getSymbol()); businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.NORMAL); - // 排序并处理 null - List sortedValues = val1.stream() - .map(v -> { - String val = v.getValueAfter();//补正后的值 - return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); - }) - .sorted() - .collect(Collectors.toList()); + //查查超差判定配置 + List configAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentMapper.selectByConfigBaseSampleIdAndConfigAssayMethodIdAndConfigAssayMethodProjectId(configSubSampleMethodDO.getConfigBaseSampleId(), businessAssayTaskDataDO.getConfigAssayMethodId(), businessAssayProjectDataDO.getConfigAssayMethodProjectId()); - // 获取小数精度 - int elementScale = businessAssayProjectDataDO.getDecimalPosition(); - //获取有效位数 - int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); - // 计算代表值(均值或差值) - BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + //是否复检 + boolean isRecheck = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)).anyMatch(a -> a.getRecheckCount() > 0); + + //分析人员任务数map + Map assayOperatorCountMap = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)).collect(Collectors.groupingBy(BusinessAssayProjectDataExtendRespVO::getAssayOperator, Collectors.counting())); + //分析人员数 + int assayOperatorSize = assayOperatorCountMap.size(); + + //是否多任务 + boolean isMultitask = assayOperatorCountMap.values().stream().allMatch(c -> c >= 2); + + //不是复检 + if (!isRecheck) { + if (assayOperatorSize == 1) {//单人 + if (isMultitask) {//多任务 重复性 + //过滤配置为 重复性超差 + List repetitivenessConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (repetitivenessConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); - //计算后保留有效位数 - representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); - //设置判定值 - businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); - - // 查找匹配的允差规则 - ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(configAssayMethodProjectAssessmentDOList, representativeValue); - if (matchedRule == null) { - throw new ServiceException(1_032_100_000, "未找到超差判定区间范围,元素ID: " + dictionaryProjectId + ", 值: " + representativeValue); - } + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(repetitivenessConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到重复性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } - // 计算允差值 - BigDecimal allowValue; - try { - allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); - } catch (Exception e) { - throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); - } + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } - // 判断相邻差值是否超差 - for (int i = 0; i < sortedValues.size() - 1; i++) { - BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); - if (diff.compareTo(allowValue) > 0) { - businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); - //存在超差,设置为待判定 - businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); - break; - } - } + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + int isCancelAssessment = matchedRule.getIsCancelAssessment();//查询配置,是否超差 + if (isCancelAssessment == 1) { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + } else { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + } + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + } + } else { + if (isMultitask) {//多人,多任务 单人任务先重复性,再多人任务再现性 + //查询重复性判定配置 + List repetitivenessConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (repetitivenessConfigAssayMethodProjectAssessmentDOList.size() > 0) { + //分析人员分组,先单人任务进行重复性判定 + Map> assayOperatorMap = val1.stream().collect(Collectors.groupingBy(BusinessAssayProjectDataExtendRespVO::getAssayOperator)); + for (Map.Entry> entry : assayOperatorMap.entrySet()) { + String assayOperator = entry.getKey(); + Log.debug(assayOperator + "的重复性判定"); + List assayOperatorValue = entry.getValue(); + // 排序并处理 null + List sortedValues = assayOperatorValue.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = assayOperatorValue.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(repetitivenessConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到重复性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + int isCancelAssessment = matchedRule.getIsCancelAssessment();//查询配置,是否超差 + if (isCancelAssessment == 1) { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + curBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + } else { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + } + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } else { + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + } + + } + } + + if (QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { //如果重复性超差 + businessSubSampleAssessmentProjectDO.setAssessmentValue(null);//如果重复性超差,则值标记为空 + val1.forEach(item -> { + item.setIsNotAssessment(QmsCommonConstant.YES); + }); + } + } + + //如果重复性判定不超差,再进行再现性判定 + if (QmsCommonConstant.ASMT_PENDING_REPORT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + List reproducibilityConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (reproducibilityConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(reproducibilityConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到再现性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } else { + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + } + } + } + } + } else {//多人,单任务 (内控|再现性) + //1、内控超差配置 + List internalControlConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (internalControlConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(internalControlConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + //2、再现性超差配置 + List reproducibilityConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (internalControlConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(reproducibilityConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到再现性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + + + //3、其他(不属于内控/重复性/再现性) + List otherConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> !QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL.equals(f.getAssessmentType()) && !QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType()) && !QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType()) ).collect(Collectors.toList()); + if (otherConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(otherConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(""); + curBusinessAssayProjectDataDO.setAssessmentType(""); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + + } + } + } else {//发起过复检的 + if (assayOperatorSize == 1) {//单人 + if (isMultitask) {//单人多任务 + //过滤配置为 重复性超差 + List repetitivenessConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (repetitivenessConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(repetitivenessConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到重复性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + int isCancelAssessment = matchedRule.getIsCancelAssessment();//查询配置,是否超差 + if (isCancelAssessment == 1) { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + } else { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + } + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + } + } else { + if (isMultitask) {//多人多任务 单人任务先重复性,再多人任务再现性 + //查询重复性判定配置 + List repetitivenessConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (repetitivenessConfigAssayMethodProjectAssessmentDOList.size() > 0) { + //分析人员分组,先单人任务进行重复性判定 + Integer maxRecheckCount = val1.stream().map(m -> m.getRecheckCount()).distinct().max(Comparator.naturalOrder()).get(); + //重复性,只判定最后复检的样品 + Map> assayOperatorMap = val1.stream().filter(f -> f.getRecheckCount().equals(maxRecheckCount)).collect(Collectors.groupingBy(BusinessAssayProjectDataExtendRespVO::getAssayOperator)); + for (Map.Entry> entry : assayOperatorMap.entrySet()) { + String assayOperator = entry.getKey(); + Log.debug(assayOperator + "的重复性判定"); + List assayOperatorValue = entry.getValue(); + // 排序并处理 null + List sortedValues = assayOperatorValue.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = assayOperatorValue.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(repetitivenessConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到重复性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + int isCancelAssessment = matchedRule.getIsCancelAssessment();//查询配置,是否超差 + if (isCancelAssessment == 1) { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.YES); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + curBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.YES); + } else { + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + preBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsNotAssessment(QmsCommonConstant.NO); + } + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } else { + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPETITIVENESS); + } + + } + } + + if (QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { //如果重复性超差 + businessSubSampleAssessmentProjectDO.setAssessmentValue(null);//如果重复性超差,则值标记为空 + val1.forEach(item -> { + item.setIsNotAssessment(QmsCommonConstant.YES); + }); + } + } + + //如果重复性判定不超差,再进行再现性判定 + if (QmsCommonConstant.ASMT_PENDING_REPORT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + List reproducibilityConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (reproducibilityConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(reproducibilityConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到再现性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } else { + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + } + } + } + } + + } else { //多人单任务 + //1、内控超差配置 + List internalControlConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (internalControlConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(internalControlConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + //2、再现性超差配置 + List reproducibilityConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType())).collect(Collectors.toList()); + if (internalControlConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(reproducibilityConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到再现性超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + curBusinessAssayProjectDataDO.setAssessmentType(QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + + + //3、其他(不属于内控/重复性/再现性) + List otherConfigAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentDOList.stream().filter(f -> !QmsCommonConstant.ASMT_TYPE_INTERNAL_CONTROL.equals(f.getAssessmentType()) && !QmsCommonConstant.ASMT_TYPE_REPETITIVENESS.equals(f.getAssessmentType()) && !QmsCommonConstant.ASMT_TYPE_REPRODUCIBILITY.equals(f.getAssessmentType()) ).collect(Collectors.toList()); + if (otherConfigAssayMethodProjectAssessmentDOList.size() > 0) { + // 排序并处理 null + List sortedValues = val1.stream().filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + .map(v -> { + String val = v.getValueAfter();//补正后的值 + return val == null || val.trim().isEmpty() ? BigDecimal.ZERO : new BigDecimal(val.trim()); + }) + .sorted() + .collect(Collectors.toList()); + List vBySortedValues = val1.stream() + .filter(f -> f.getIsCancelAssessment().equals(QmsCommonConstant.NO)) + // 构建 Entry: Key是原对象,Value是排序用的数字 + .map(v -> { + String valStr = v.getValueAfter(); + BigDecimal sortVal = (valStr == null || valStr.trim().isEmpty()) + ? BigDecimal.ZERO + : new BigDecimal(valStr.trim()); + return new SimpleEntry<>(v, sortVal); + }) + // 比较 Entry 的 Value 部分 + .sorted(Map.Entry.comparingByValue()) + // 提取 Key (原对象) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + + // 获取小数精度 + int elementScale = businessAssayProjectDataDO.getDecimalPosition(); + //获取有效位数 + int effectiveDigit = businessAssayProjectDataDO.getEffectiveDigit(); + // 计算代表值(均值或差值) + BigDecimal representativeValue = calculateRepresentativeValue(sortedValues, elementScale); + + //计算后保留有效位数 + representativeValue = EffectiveNumberFormatter.formatNumber2(representativeValue, elementScale, effectiveDigit); + //设置判定值 + businessSubSampleAssessmentProjectDO.setAssessmentValue(representativeValue.toPlainString()); + + // 查找匹配的允差规则 + ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule(otherConfigAssayMethodProjectAssessmentDOList, representativeValue); + if (matchedRule == null) { + throw new ServiceException(1_032_100_000, "未找到超差判定区间范围,检测项目ID: " + dictionaryProjectId + ", 值: " + representativeValue); + } + + // 计算允差值 + BigDecimal allowValue; + try { + allowValue = allowanceCalculatorComponent.calculateAllowableValue(new BigDecimal(matchedRule.getMinimumValue()), new BigDecimal(matchedRule.getMaximumValue()), new BigDecimal(matchedRule.getMinimumToleraanceValue()), new BigDecimal(matchedRule.getMaximumToleraanceValue()), new BigDecimal(matchedRule.getToleraanceAdjustmentValue()), representativeValue, matchedRule.getIsUseFormula(), matchedRule.getFormula(), elementScale); + } catch (Exception e) { + throw new ServiceException(1_032_100_000, "超差判定计算出错,检测项目ID: " + dictionaryProjectId); + } + + // 判断相邻差值是否超差 + for (int i = 0; i < sortedValues.size() - 1; i++) { + BigDecimal diff = sortedValues.get(i + 1).subtract(sortedValues.get(i)).abs(); + if (diff.compareTo(allowValue) > 0) { + businessSubSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.EXCEEDS_TOLERANCE); + BusinessAssayProjectDataExtendRespVO preBusinessAssayProjectDataDO = vBySortedValues.get(i); + BusinessAssayProjectDataExtendRespVO curBusinessAssayProjectDataDO = vBySortedValues.get(i + 1); + preBusinessAssayProjectDataDO.setAssessmentType(""); + curBusinessAssayProjectDataDO.setAssessmentType(""); + preBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + curBusinessAssayProjectDataDO.setIsCancelAssessment(QmsCommonConstant.NO); + + //存在超差,设置为待判定 + if (!QmsCommonConstant.ASMT_PENDING_ASSESSMENT.equals(businessSubSampleAssessmentDO.getReportedStatus())) { + businessSubSampleAssessmentDO.setReportedStatus(QmsCommonConstant.ASMT_PENDING_ASSESSMENT); + } + } + } + } + + + } + } + } + + + + //添加到更新列表 + updateBusinessAssayProjectDataDOList.addAll(BeanUtils.toBean(val1, BusinessAssayProjectDataDO.class)); } @@ -886,7 +1863,10 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic businessAssayTaskDO.setFlowStatus(QmsCommonConstant.RETURNED); } businessAssayTaskMapper.updateById(businessAssayTaskDO); - + + if (updateBusinessAssayProjectDataDOList.size() > 0) { + businessAssayProjectDataMapper.updateBatch(updateBusinessAssayProjectDataDOList); + } if (updateBusinessSubSampleAssessmentDOList.size() > 0) { businessSubSampleAssessmentMapper.updateBatch(updateBusinessSubSampleAssessmentDOList); } @@ -1086,7 +2066,7 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic @Override @Transactional(rollbackFor = Exception.class) - public void createReAnalysis(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount) { + public void createReAnalysis(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount, Integer taskCount) { //子样数据 BusinessSubSampleDO businessSubSampleDO = businessSubSampleMapper.selectById(businessSubSampleId); @@ -1139,8 +2119,14 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic if (CollUtil.isNotEmpty(configAssayMethodProjectParameterIdList)) { configAssayMethodProjectParameterList = configAssayMethodProjectParameterMapper.selectByIds(configAssayMethodProjectParameterIdList); } + int localTaskCount = 0; //循环检测任务 for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataDOList) { + localTaskCount++;//循环+1 + if (localTaskCount > taskCount) {//本地数据大于,则跳出循环 + break; + } + // 子样检测任务 newBusinessAssayTaskDataDO = new BusinessAssayTaskDataDO(); newBusinessAssayTaskDataDO.setId(IdWorker.getId());