@@ -109,43 +109,12 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
public JSONObject getSampleResultAssessmentList ( Long configAssayMethodId , String assessmentStatus ) {
List < ConfigAssayMethodProjectExtendRespVO > configAssayMethodProjectDOList = configAssayMethodProjectMapper . selectByConfigAssayMethodId ( configAssayMethodId ) ;
List < Map < String , Object > > columnList = new ArrayList < > ( ) ;
// columnList.add(new HashMap<String, Object>() {{
// put("title", "样品名称");
// put("field", "sampleName");
// put("dataType", "string");
// put("decimalPosition", null);
// put("isEdit", false);
// }});
// columnList.add(new HashMap<String, Object>() {{
// put("title", "样品编号");
// put("field", "sampleAssayCode");
// put("dataType", "string");
// put("decimalPosition", null);
// put("isEdit", false);
// }});
// columnList.add(new HashMap<String, Object>() {{
// put("title", "收样时间");
// put("field", "sampleReceiveTime");
// put("dataType", "string");
// put("decimalPosition", null);
// put("isEdit", false);
// }});
// columnList.add(new HashMap<String, Object>() {{
// put("title", "分析人");
// put("field", "assayOperator");
// put("dataType", "string");
// put("decimalPosition", null);
// put("isEdit", false);
// }});
// columnList.add(new HashMap<String, Object>() {{
// put("title", "上报时间");
// put("field", "reportTime");
// put("dataType", "string");
// put("decimalPosition", null);
// put("isEdit", false);
// }});
for ( ConfigAssayMethodProjectExtendRespVO configAssayMethodProject : configAssayMethodProjectDOList ) {
columnList . add ( new HashMap < String , Object > ( ) { {
columnList . add ( new HashMap < String , Object > ( ) {
private static final long serialVersionUID = 2100402322138923549L ;
{
put ( " title " , configAssayMethodProject . getShowName ( ) + " ( " + configAssayMethodProject . getDictionaryProjectUnit ( ) + " ) " ) ;
put ( " field " , configAssayMethodProject . getSimpleName ( ) ) ;
put ( " dataType " , configAssayMethodProject . getDataType ( ) ) ;
@@ -178,6 +147,7 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
for ( BusinessSubSampleAssessmentExtendRespVO businessSubSampleAssessment : businessSubSampleAssessmentList ) {
businessAssayTaskDataAssessmentMap . put ( " id " , businessSubSampleAssessment . getId ( ) ) ;
businessAssayTaskDataAssessmentMap . put ( " assessmentStatus " , businessSubSampleAssessment . getAssessmentStatus ( ) ) ;
businessAssayTaskDataAssessmentMap . put ( " assessmentStatus_ " + businessSubSampleAssessment . getSimpleName ( ) , businessSubSampleAssessment . getAssessmentStatus ( ) ) ;
businessAssayTaskDataAssessmentMap . put ( businessSubSampleAssessment . getSimpleName ( ) , businessSubSampleAssessment . getAssessmentValue ( ) ) ;
businessAssayTaskDataAssessmentMap . put ( " assessmentValue " , businessSubSampleAssessment . getAssessmentValue ( ) ) ;
}
@@ -193,8 +163,10 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
List < BusinessAssayProjectDataExtendRespVO > businessAssayProjectDataList = businessAssayProjectDataMapper . selectByBusinessAssayTaskDataId ( businessAssayTaskDataExtendRespVO . getId ( ) ) ;
for ( BusinessAssayProjectDataExtendRespVO businessAssayProjectData : businessAssayProjectDataList ) {
businessAssayTaskDataMap . put ( businessAssayProjectData . getSimpleName ( ) , businessAssayProjectData . getValue ( ) ) ;
businessAssayTaskDataMap . put ( " isNotAssessment_ " + businessAssayProjectData . getSimpleName ( ) , businessAssayProjectData . getIsNotAssessment ( ) ) ;
//添加判定状态
businessAssayTaskDataMap . put ( " assessmentStatus " , assessmentMap . get ( " assessmentStatus " ) ) ;
}
dataList . add ( businessAssayTaskDataMap ) ;
@@ -210,7 +182,6 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
json . put ( " datas " , dataList ) ;
return json ;
}
@Override
public JSONObject getParallelResultAssessment ( Long businessSubSampleId , Long configAssayMethodId ) {
@@ -229,12 +200,12 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
//单个检测项目的分析结果
List < BusinessAssayProjectDataExtendRespVO > businessAssayProjectDataSingleList = businessAssayProjectDataEntry . getValue ( ) ;
for ( BusinessAssayProjectDataExtendRespVO businessAssayProjectDataExtendRespVO : businessAssayProjectDataSingleList ) { //每个检测结果作为一个动态列
columnList . add ( new HashMap < String , Object > ( ) { {
columnList . add ( new HashMap < String , Object > ( ) {
private static final long serialVersionUID = - 1844858000003248901L ;
{
put ( " title " , businessAssayProjectDataExtendRespVO . getSampleAssayCode ( ) + " ( " + businessAssayProjectDataExtendRespVO . getAssayOperator ( ) + " ) " ) ;
put ( " field " , businessAssayProjectDataExtendRespVO . getId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getConfigAssayMethodProject Id ( ) + " ; " + businessAssayProjectDataExtendRespVO . getBusinessSubSampleId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getAnalysisCount ( ) ) ;
// put("dataType", configAssayMethodProject.getDataType());
// put("decimalPosition", configAssayMethodProject.getDecimalPosition());
// put("isEdit", true);
put ( " field " , businessAssayProjectDataExtendRespVO . getBusinessAssayTaskData Id ( ) + " ; " + businessAssayProjectDataExtendRespVO . getBusinessSubSampleId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getAnalysisCount ( ) ) ;
} } ) ;
}
@@ -249,7 +220,7 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
Map < String , Object > businessSubSampleAssessmentMap = BeanUtil . beanToMap ( businessSubSampleAssessment ) ;
List < BusinessAssayProjectDataExtendRespVO > businessAssayProjectDataSingleList = businessAssayProjectDataList . stream ( ) . filter ( f - > f . getDictionaryProjectId ( ) . equals ( businessSubSampleAssessment . getDictionaryProjectId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
for ( BusinessAssayProjectDataExtendRespVO businessAssayProjectDataExtendRespVO : businessAssayProjectDataSingleList ) {
businessSubSampleAssessmentMap . put ( businessAssayProjectDataExtendRespVO . getId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getConfigAssayMethodProject Id ( ) + " ; " + businessAssayProjectDataExtendRespVO . getBusinessSubSampleId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getAnalysisCount ( ) , businessAssayProjectDataExtendRespVO . getValue ( ) ) ;
businessSubSampleAssessmentMap . put ( businessAssayProjectDataExtendRespVO . getBusinessAssayTaskData Id ( ) + " ; " + businessAssayProjectDataExtendRespVO . getBusinessSubSampleId ( ) + " ; " + businessAssayProjectDataExtendRespVO . getAnalysisCount ( ) , businessAssayProjectDataExtendRespVO . getValue ( ) ) ;
}
dataList . add ( businessSubSampleAssessmentMap ) ;
}
@@ -698,6 +669,78 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
}
@Override
@Transactional ( rollbackFor = Exception . class )
public JSONObject modifyParallelResultAssessment ( Long businessSubSampleId , Long configAssayMethodId , Long businessSubSampleAssessmentId , List < Long > businessAssayProjectDataIds ) {
BusinessSubSampleAssessmentDO businessSubSampleAssessmentDO = businessSubSampleAssessmentMapper . selectById ( businessSubSampleAssessmentId ) ;
BusinessAssayProjectDataReqVO businessAssayProjectDataSearch = new BusinessAssayProjectDataReqVO ( ) ;
businessAssayProjectDataSearch . setBusinessSubSampleId ( businessSubSampleId ) ;
businessAssayProjectDataSearch . setConfigAssayMethodId ( configAssayMethodId ) ;
businessAssayProjectDataSearch . setConfigAssayMethodProjectId ( businessSubSampleAssessmentDO . getConfigAssayMethodProjectId ( ) ) ;
List < BusinessAssayProjectDataExtendRespVO > businessAssayProjectDataList = businessAssayProjectDataMapper . selectAnalysisBy ( businessAssayProjectDataSearch ) ;
List < BusinessAssayProjectDataDO > businessAssayProjectDataDOList = BeanUtil . copyToList ( businessAssayProjectDataList , BusinessAssayProjectDataDO . class ) ;
for ( BusinessAssayProjectDataDO businessAssayProjectDataDO : businessAssayProjectDataDOList ) {
if ( businessAssayProjectDataIds . contains ( businessAssayProjectDataDO . getId ( ) ) ) {
businessAssayProjectDataDO . setIsNotAssessment ( QmsCommonConstant . NO ) ;
} else {
businessAssayProjectDataDO . setIsNotAssessment ( QmsCommonConstant . YES ) ;
}
}
// 排序并处理 null
List < BigDecimal > sortedValues = businessAssayProjectDataDOList . stream ( )
. filter ( f - > f . getIsNotAssessment ( ) . equals ( QmsCommonConstant . NO ) )
. map ( v - > {
String val = v . getValue ( ) ;
return val = = null | | val . trim ( ) . isEmpty ( ) ? BigDecimal . ZERO : new BigDecimal ( val . trim ( ) ) ;
} )
. sorted ( )
. collect ( Collectors . toList ( ) ) ;
// 获取小数精度
int elementScale = businessSubSampleAssessmentDO . getDecimalPosition ( ) ;
// 计算代表值(均值或差值)
BigDecimal representativeValue = calculateRepresentativeValue ( sortedValues , elementScale ) ;
//设置判定值
businessSubSampleAssessmentDO . setAssessmentValue ( representativeValue . toPlainString ( ) ) ;
List < ConfigAssayMethodProjectAssessmentDO > configAssayMethodProjectAssessmentDOList = configAssayMethodProjectAssessmentMapper . selectList ( new LambdaQueryWrapperX < ConfigAssayMethodProjectAssessmentDO > ( )
. eq ( ConfigAssayMethodProjectAssessmentDO : : getConfigAssayMethodId , businessSubSampleAssessmentDO . getConfigAssayMethodId ( ) )
. eq ( ConfigAssayMethodProjectAssessmentDO : : getConfigAssayMethodProjectId , businessSubSampleAssessmentDO . getConfigAssayMethodProjectId ( ) ) ) ;
// 查找匹配的允差规则
ConfigAssayMethodProjectAssessmentDO matchedRule = findMatchingRule ( configAssayMethodProjectAssessmentDOList , representativeValue ) ;
if ( matchedRule = = null ) {
throw new ServiceException ( 500 , " 未找到超差判定区间范围, 元素ID: " + businessSubSampleAssessmentDO . getDictionaryProjectId ( ) + " , 值: " + 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 ( 500 , " 超差判定计算出错, 检测项目ID: " + businessSubSampleAssessmentDO . getDictionaryProjectId ( ) ) ;
}
// 判断相邻差值是否超差
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 ) {
businessSubSampleAssessmentDO . setAssessmentStatus ( QmsCommonConstant . EXCEEDS_TOLERANCE ) ;
break ;
}
}
//更新判定值
businessSubSampleAssessmentMapper . updateById ( businessSubSampleAssessmentDO ) ;
//更新检测项目
businessAssayProjectDataMapper . updateBatch ( businessAssayProjectDataDOList ) ;
return getParallelResultAssessment ( businessSubSampleId , configAssayMethodId ) ;
}
}