package com.zt.plat.module.qms.business.bus.service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
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.LoginUser;
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
import com.zt.plat.module.qms.business.bus.controller.vo.BatchSampleAnalysisColumnRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayParameterDataExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayParameterDataReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayProjectAndParameterRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayProjectDataExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayProjectDataReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskAnalysisSampleAndQcProjectRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskAnalysisSampleProjectRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskBackSampleReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataExternalInfomation;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataExternalInfomation.RollbackDetail;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskParameterDataExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessQCCoefficientParameterDataReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessQCManagementParameterDataReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessQCManagementProjectDataReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessSubParentSampleAssessmentProjectExtendRespVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayParameterDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayProjectDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDetailDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskParameterDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCCoefficientDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCCoefficientParameterDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCManagementDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCManagementParameterDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCManagementProjectDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessQCManagementSampleParameterDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustDetailDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleDO;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayParameterDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayProjectDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayTaskDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayTaskDetailMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayTaskMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayTaskParameterDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCCoefficientDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCCoefficientParameterDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCManagementDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCManagementParameterDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCManagementProjectDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessQCManagementSampleParameterDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSampleEntrustDetailMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubParentSampleAssessmentProjectMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubParentSampleMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubSampleMapper;
import com.zt.plat.module.qms.business.config.controller.vo.BusinessAssayTaskAnalysisDataRespVO;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigAssayMethodProjectCoefficientRespVO;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigAssayMethodProjectRangeRespVO;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigQCSampleMethodExtendRespVO;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfInfo;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfItem;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodConfPoint;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigSubSampleMethodExtendRespVO;
import com.zt.plat.module.qms.business.config.dal.dataobject.BaseSampleDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectCoefficientDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectRangeDO;
import com.zt.plat.module.qms.business.config.dal.mapper.BaseSampleMapper;
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodMapper;
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectCoefficientMapper;
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigAssayMethodProjectRangeMapper;
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigQCSampleMethodMapper;
import com.zt.plat.module.qms.business.config.dal.mapper.ConfigSubSampleMethodMapper;
import com.zt.plat.module.qms.common.data.dal.dataobject.DataCollectionDO;
import com.zt.plat.module.qms.common.data.service.DataCollectionService;
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.util.number.EffectiveNumberFormatter;
import com.zt.plat.module.qms.enums.QmsCommonConstant;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import jakarta.annotation.Resource;

@Service
public class SampleAnalysisServiceImpl implements SampleAnalysisService {
	
	@Resource
	private DictionaryBusinessMapper dictionaryBusinessMapper;
	
	@Resource
	private ConfigAssayMethodMapper configAssayMethodMapper;
	
	@Resource
	private ConfigAssayMethodProjectRangeMapper configAssayMethodProjectRangeMapper;
	
	@Resource
	private ConfigAssayMethodProjectCoefficientMapper configAssayMethodProjectCoefficientMapper;
	
	@Resource
	private ConfigSubSampleMethodMapper configSubSampleMethodMapper;
	
	@Resource
	private BusinessSubSampleMapper businessSubSampleMapper;
	
	@Resource
	private BusinessAssayTaskMapper businessAssayTaskMapper;
	
	@Resource
	private BusinessAssayTaskDetailMapper businessAssayTaskDetailMapper;
	
	@Resource
	private BusinessAssayTaskDataMapper businessAssayTaskDataMapper;
	
	@Resource
	private BusinessAssayTaskParameterDataMapper businessAssayTaskParameterDataMapper;
	
	@Resource
	private BusinessAssayProjectDataMapper businessAssayProjectDataMapper;
	
	@Resource
	private BusinessAssayParameterDataMapper businessAssayParameterDataMapper;
	
	@Resource
	private ConfigQCSampleMethodMapper configQCSampleMethodMapper;
	
	@Resource
	private BusinessQCCoefficientDataMapper businessQCCoefficientDataMapper;
	
	@Resource
	private BusinessQCCoefficientParameterDataMapper businessQCCoefficientParameterDataMapper;
	
	@Resource
	private BusinessQCManagementDataMapper businessQCManagementDataMapper;
	
	@Resource
	private BusinessQCManagementSampleParameterDataMapper businessQCManagementSampleParameterDataMapper;
	
	@Resource
	private BusinessQCManagementProjectDataMapper businessQCManagementProjectDataMapper;
	
	@Resource
	private BusinessQCManagementParameterDataMapper businessQCManagementParameterDataMapper;
	
	@Resource
	private BusinessSampleEntrustDetailMapper businessSampleEntrustDetailMapper;
	
	@Resource
	private BaseSampleMapper baseSampleMapper;
	
	@Resource
	private BusinessSubParentSampleMapper businessSubParentSampleMapper;
	
	@Resource
	private BusinessSubParentSampleAssessmentProjectMapper businessSubParentSampleAssessmentProjectMapper;
		
    @Resource
    private DataCollectionService dataCollectionService;

	@Override
	@Deprecated
	@Transactional(rollbackFor = Exception.class)
	public BusinessAssayTaskAnalysisSampleProjectRespVO batchSampleAnalysisByTaskId(Long businessAssayTaskId) {
		BusinessAssayTaskAnalysisSampleProjectRespVO businessAssayTaskAnalysisSampleProjectRespVO = new BusinessAssayTaskAnalysisSampleProjectRespVO();
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
		if (businessAssayTaskDO == null) {
			throw new ServiceException(1_032_100_000, "未找到任务分配单");
		}
		businessAssayTaskAnalysisSampleProjectRespVO.setBusinessAssayTaskId(businessAssayTaskId);
		businessAssayTaskAnalysisSampleProjectRespVO.setBusinessAssayTasNo(businessAssayTaskDO.getTaskNo());
		businessAssayTaskAnalysisSampleProjectRespVO.setBusinessAssayTasName(businessAssayTaskDO.getTaskName());
		businessAssayTaskAnalysisSampleProjectRespVO.setAssayOperator(businessAssayTaskDO.getAssayOperator());
		businessAssayTaskAnalysisSampleProjectRespVO.setAssayTime(businessAssayTaskDO.getAssayTime());
		businessAssayTaskAnalysisSampleProjectRespVO.setConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId());
		businessAssayTaskAnalysisSampleProjectRespVO.setDataCollectionId(businessAssayTaskDO.getFormDataCollectionId());
		businessAssayTaskAnalysisSampleProjectRespVO.setFormValue(businessAssayTaskDO.getFormValue());
		businessAssayTaskAnalysisSampleProjectRespVO.setIsIngredients(businessAssayTaskDO.getIsIngredients());
		businessAssayTaskAnalysisSampleProjectRespVO.setIngredientsStatus(businessAssayTaskDO.getIngredientsStatus());
		
		ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(businessAssayTaskDO.getConfigAssayMethodId());
		businessAssayTaskAnalysisSampleProjectRespVO.setConfigAssayMethodName(configAssayMethodDO.getName());
		businessAssayTaskAnalysisSampleProjectRespVO.setDataCollectionKey(configAssayMethodDO.getDataCollectionKey());

		String minWidth = "200px";
		
		//处理列
        List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
        
        
        List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId));
        
        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        

        //子样Id列表
        List<Long> businessSubSampleIdList = businessAssayTaskDataList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样列表
        List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
        //子样配置id列表
        List<Long> configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样方法配置列表
        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
        
        
        BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
        projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);

        Map<Long, List<BusinessAssayProjectAndParameterRespVO>> projectAndParameterMap = projectAndParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
        	    Collectors.toList() // ArrayList 保持组内顺序
        	    ));
        for (Map.Entry<Long, List<BusinessAssayProjectAndParameterRespVO>> entry : projectAndParameterMap.entrySet()) {
        	BusinessAssayProjectAndParameterRespVO ep = entry.getValue().get(0);
        	String fieldIndex = "e" + ep.getDicId();
        	String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
        	boolean isEdit = StringUtils.isBlank(ep.getFormula());
        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName()));
        	
        	if (StringUtils.isNotEmpty(ep.getFormula())) {
        		BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
        		parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
                List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
                for (BusinessAssayProjectAndParameterRespVO p : plist) {
                	fieldIndex = "p" + p.getDicId();
                	title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
                	isEdit = StringUtils.isBlank(p.getFormula());
                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
				}
			}
			
		}
        businessAssayTaskAnalysisSampleProjectRespVO.setColumns(cloumns);
        

        //处理数据
        List<Map<String, Object>> datas = new ArrayList<>();
        for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) {
        	BusinessAssayTaskDetailDO businessAssayTaskDetailDO = businessAssayTaskDetailList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId())).findFirst().orElse(null);
        	

        	BusinessSubSampleDO businessSubSampleDO = businessSubSampleDOList.stream().filter(f -> f.getId().equals(businessAssayTaskDataDO.getBusinessSubSampleId())).findFirst().orElse(null);
        	ConfigSubSampleMethodExtendRespVO configSubSampleMethodDO = configSubSampleMethodDOList.stream().filter(f -> f.getConfigAssayMethodId().equals(businessAssayTaskDataDO.getConfigAssayMethodId()) && f.getConfigSubSampleId().equals(businessSubSampleDO.getConfigSubSampleId())).findFirst().orElse(null);
        	String configInfomation = configSubSampleMethodDO.getConfigInfomation();
        	if (StringUtils.isNotBlank(configInfomation)) {
				ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class);
				List<ConfigSubSampleMethodConfItem> getParamList = configSubSampleMethodConfInfo.getGetParam();
				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem: getParamList) {
					//Boolean required = configSubSampleMethodConfItem.getRequired();//是否必须
					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();//来源
					Long configMethodId = source.getMethodId();
					String sourceProject = source.getProject();
					//String sourceParameter = source.getParameter();
					
					
					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();//目标
					String targetProject = target.getProject();
					String targetParameter = target.getParameter();
					
					BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter);
					if (StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {
						//1 查询委托明细
						BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
						//2 查询样品大类
						BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId());
						//3 判断样品大类类型
						if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样
							//查询当前批次的第一个商检分析样
							BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE);
							List<BusinessSubParentSampleDO> currBusinessSubParentSampleDOList = businessSubParentSampleMapper.selectByBusinessBaseSampleId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId());
							List<Long> currBusinessSubParentSampleIdList = currBusinessSubParentSampleDOList.stream().map(m -> m.getId()).collect(Collectors.toList());
							List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(currBusinessSubParentSampleIdList, configMethodId);
							BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
							if (businessSubParentSampleAssessmentProject != null && StringUtils.isNotBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) {
								businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
							}
						} else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样
							//查询当前样品的其他分析方法的结果
							List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
							List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
							BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
							if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) {
								businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
							}
						} else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样
							//查询来样品位
							Boolean isForecastS = false;
							String forecastValue = null;
							String forecastResult = businessSampleEntrustDetailDO.getForecastResult();
							if (StringUtils.isNotBlank(forecastResult)) {
								JSONArray array = JSON.parseArray(forecastResult);
								for (int i = 0; i < array.size(); i++) {
								    JSONObject item = array.getJSONObject(i);
								    if ("S".equals(item.getString("simpleName"))) {
								    	isForecastS = true;
								    	break;
									}
								}
								for (int i = 0; i < array.size(); i++) {
								    JSONObject item = array.getJSONObject(i);
								    if (sourceProject.equals(item.getString("simpleName"))) {
								    	forecastValue = item.getString("value");
								    	break;
									}
								}
							}
							if (isForecastS) {//来样品位存在S值， 则取预报的值
								businessAssayParameterDataDO.setValue(forecastValue);
							} else {
								//查询当前样品的其他方法的结果
								List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
								List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
								BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
								if (businessSubParentSampleAssessmentProject == null || StringUtils.isBlank(businessSubParentSampleAssessmentProject.getAssessmentValue())) {
									businessAssayParameterDataDO.setValue(businessSubParentSampleAssessmentProject.getAssessmentValue());
								}
							}
							
						}
												
						businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO);
					}
				}
			}        	
        	
            Map<String, Object> map = new HashedMap<>();
            map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId());
            map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId());
            map.put("businessSubSampleId", businessAssayTaskDataDO.getBusinessSubSampleId());
            map.put("businessSubParentSampleId", businessAssayTaskDataDO.getBusinessSubParentSampleId());
            map.put("configAssayMethodId", businessAssayTaskDataDO.getConfigAssayMethodId());
            map.put("businessAssayTaskDetailId", businessAssayTaskDetailDO.getId());
            map.put("sampleCode", businessAssayTaskDetailDO.getSampleCode());
            map.put("sampleName", businessAssayTaskDetailDO.getSampleName());
            map.put("rollbackStatus", businessAssayTaskDetailDO.getRollbackStatus());

            BusinessAssayProjectDataReqVO projectDataSearch2 = new BusinessAssayProjectDataReqVO();
            projectDataSearch2.setBusinessAssayTaskDataId(businessAssayTaskDataDO.getId());
            List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch2);
            for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList2) {
				map.put("e" + ep.getDicId(), ep);
				if (StringUtils.isNotEmpty(ep.getFormula())) {
	        		BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
	        		parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
	                List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
	                for (BusinessAssayProjectAndParameterRespVO p : plist) {
	                	map.put("p" + p.getDicId(), p);
					}
				}
				
			}
            datas.add(map);
        }
        
        businessAssayTaskAnalysisSampleProjectRespVO.setDatas(datas);
        
        //查询区间范围
        List<ConfigAssayMethodProjectRangeDO> configAssayMethodProjectRangeDOList = configAssayMethodProjectRangeMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectRangeDO>().eq(ConfigAssayMethodProjectRangeDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        businessAssayTaskAnalysisSampleProjectRespVO.setConfigAssayMethodProjectRangeList(BeanUtils.toBean(configAssayMethodProjectRangeDOList, ConfigAssayMethodProjectRangeRespVO.class));
		
        //查询补正系数
        List<ConfigAssayMethodProjectCoefficientDO> configAssayMethodProjectCoefficientDOList = configAssayMethodProjectCoefficientMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectCoefficientDO>().eq(ConfigAssayMethodProjectCoefficientDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        businessAssayTaskAnalysisSampleProjectRespVO.setConfigAssayMethodProjectCoefficientList(BeanUtils.toBean(configAssayMethodProjectCoefficientDOList, ConfigAssayMethodProjectCoefficientRespVO.class));
        
		return businessAssayTaskAnalysisSampleProjectRespVO;
	}

	@Override
	@Deprecated
	@Transactional(rollbackFor = Exception.class)
	public void saveBatchSampleAnalysis(BusinessAssayTaskAnalysisSampleProjectRespVO vo) {
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(vo.getBusinessAssayTaskId());
		businessAssayTaskDO.setFormValue(vo.getFormValue());
		businessAssayTaskDO.setAssayTime(vo.getAssayTime());
		businessAssayTaskDO.setTaskAssayStatus(QmsCommonConstant.SAVED);
		//赋值数据集id
		if (vo.getDataCollectionId() == null) {
			ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(businessAssayTaskDO.getConfigAssayMethodId());
			DataCollectionDO dataCollectionDO = dataCollectionService.getLatestDataCollectionByKey(configAssayMethodDO.getDataCollectionKey());
			businessAssayTaskDO.setFormDataCollectionId(dataCollectionDO.getId());
		} else {
			businessAssayTaskDO.setFormDataCollectionId(vo.getDataCollectionId());
		}
		

//        List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, vo.getBusinessAssayTaskId()));
        
        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, vo.getBusinessAssayTaskId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        
        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        List<BusinessAssayProjectDataDO> businessAssayProjectDataList = businessAssayProjectDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayProjectDataDO>().in(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList));
        List<Long> businessAssayProjectDataIdList = businessAssayProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        List<BusinessAssayParameterDataDO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayParameterDataDO>().in(BusinessAssayParameterDataDO::getBusinessAssayProjectDataId, businessAssayProjectDataIdList));
        
		
		List<Map<String,Object>> datas = vo.getDatas();
		for (Map<String, Object> map : datas) {
//			Long businessAssayTaskDataId = (Long) map.get("businessAssayTaskDataId");
//          Long businessAssayTaskId = (Long) map.get("businessAssayTaskId");
//          Long businessSubSampleId = (Long) map.get("businessSubSampleId");
//          Long businessSubParentSampleId = (Long) map.get("businessSubParentSampleId");
//          Long configAssayMethodId = (Long) map.get("configAssayMethodId");
//          Long businessAssayTaskDetailId = (Long) map.get("businessAssayTaskDetailId");
//          String sampleCode = map.get("sampleCode");
//          String sampleName = map.get("sampleName");
            
            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
            for (Map.Entry<String, Object> entry : map.entrySet()) {
//				String key = entry.getKey();
				Object val = entry.getValue();
				if (val instanceof String || val == null) {
					continue;
				}
				BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
				listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
			}
            
            //BusinessAssayTaskDataDO businessAssayTaskDataDO = businessAssayTaskDataList.stream().filter(f -> f.getId().equals(businessAssayTaskDataId)).findFirst().orElse(null);
            
            
            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
				if ("project".equals(pap.getType())) {
					BusinessAssayProjectDataDO businessAssayProjectDataDO = businessAssayProjectDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
					if (StringUtils.isNotBlank(pap.getValue())) {
						String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
						switch (dataType) {
							case "int":
							case "date":
							case "datetime":
							case "string": 
								businessAssayProjectDataDO.setValue(pap.getValue());
								businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
								break;
							case "decimal":
								BigDecimal value = new BigDecimal(pap.getValue());
		                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
								businessAssayProjectDataDO.setValue(value.toPlainString());
								businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
								break;
							default:
								throw new IllegalArgumentException("Unexpected value: " + dataType);
						}
						
						
					} else {
						businessAssayProjectDataDO.setValue(null);
					}
					
					
				} else if ("parameter".equals(pap.getType())) {
					BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
					if (StringUtils.isNotBlank(pap.getValue())) {
						String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
						switch (dataType) {
							case "int":
							case "date":
							case "datetime":
							case "string": 
								businessAssayParameterDataDO.setValue(pap.getValue());
								businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
								break;
							case "decimal":
								BigDecimal value = new BigDecimal(pap.getValue());
		                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
		                        businessAssayParameterDataDO.setValue(value.toPlainString());
		                        businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
								break;
							default:
								throw new IllegalArgumentException("Unexpected value: " + dataType);
						}
					} else {
						businessAssayParameterDataDO.setValue(null);
					}
				}
			}
            
		}
		
		
		
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
		businessAssayProjectDataMapper.updateBatch(businessAssayProjectDataList);
		if (CollUtil.isNotEmpty(businessAssayParameterDataList)) {
			businessAssayParameterDataMapper.updateBatch(businessAssayParameterDataList);
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public BusinessAssayTaskAnalysisSampleAndQcProjectRespVO batchSampleAndQcAnalysisByTaskId(Long businessAssayTaskId) {
		BusinessAssayTaskAnalysisSampleAndQcProjectRespVO businessAssayTaskAnalysisSampleAndQcProjectRespVO = new BusinessAssayTaskAnalysisSampleAndQcProjectRespVO();
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
		if (businessAssayTaskDO == null) {
			throw new ServiceException(1_032_100_000, "未找到任务分配单");
		}
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setBusinessAssayTaskId(businessAssayTaskId);
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setBusinessAssayTasNo(businessAssayTaskDO.getTaskNo());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setBusinessAssayTasName(businessAssayTaskDO.getTaskName());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayOperator(businessAssayTaskDO.getAssayOperator());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayTime(businessAssayTaskDO.getAssayTime());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setDataCollectionId(businessAssayTaskDO.getFormDataCollectionId());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setFormValue(businessAssayTaskDO.getFormValue());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setIsIngredients(businessAssayTaskDO.getIsIngredients());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setIngredientsWay(businessAssayTaskDO.getIngredientsWay());
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setIngredientsStatus(businessAssayTaskDO.getIngredientsStatus());
		
		List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
		List<Long> configAssayMethodIdList = businessAssayTaskDataList.stream().map(m -> m.getConfigAssayMethodId()).distinct().collect(Collectors.toList());
		List<ConfigAssayMethodDO> configAssayMethodDOList = configAssayMethodMapper.selectByIds(configAssayMethodIdList);
		String configAssayMethodNames = configAssayMethodDOList.stream().map(m -> m.getName()).collect(Collectors.joining("、"));
		ConfigAssayMethodDO configAssayMethodDO = configAssayMethodDOList.get(0);
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigAssayMethodName(configAssayMethodNames);
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setDataCollectionKey(configAssayMethodDO.getDataCollectionKey());

		List<BusinessAssayTaskAnalysisDataRespVO> assayTaskAnalysisDataList = new ArrayList<>();
		
		//质控分析数据
		List<BusinessAssayTaskAnalysisDataRespVO> qcAnalysis = getQcAnalysis(businessAssayTaskDO);
		assayTaskAnalysisDataList.addAll(qcAnalysis);
		
		//样品分析数据
		BusinessAssayTaskAnalysisDataRespVO analysis = getAnalysis(businessAssayTaskDO);
		assayTaskAnalysisDataList.add(analysis);
		
		businessAssayTaskAnalysisSampleAndQcProjectRespVO.setAssayTaskAnalysisDataList(assayTaskAnalysisDataList);
		
        //查询区间范围
        List<ConfigAssayMethodProjectRangeDO> configAssayMethodProjectRangeDOList = configAssayMethodProjectRangeMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectRangeDO>().eq(ConfigAssayMethodProjectRangeDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigAssayMethodProjectRangeList(BeanUtils.toBean(configAssayMethodProjectRangeDOList, ConfigAssayMethodProjectRangeRespVO.class));

        //查询补正系数
        List<ConfigAssayMethodProjectCoefficientDO> configAssayMethodProjectCoefficientDOList = configAssayMethodProjectCoefficientMapper.selectList(new LambdaQueryWrapperX<ConfigAssayMethodProjectCoefficientDO>().eq(ConfigAssayMethodProjectCoefficientDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        businessAssayTaskAnalysisSampleAndQcProjectRespVO.setConfigAssayMethodProjectCoefficientList(BeanUtils.toBean(configAssayMethodProjectCoefficientDOList, ConfigAssayMethodProjectCoefficientRespVO.class));
        
		return businessAssayTaskAnalysisSampleAndQcProjectRespVO;
	}
	
	private BusinessAssayTaskAnalysisDataRespVO getAnalysis(BusinessAssayTaskDO businessAssayTaskDO) {
		BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO = new BusinessAssayTaskAnalysisDataRespVO();
		businessAssayTaskAnalysisDataRespVO.setAnalysisType("analysis");
		businessAssayTaskAnalysisDataRespVO.setAnalysisName("分析样");
		businessAssayTaskAnalysisDataRespVO.setSortNo(99);

    	String minWidth = "200px";

		//处理列
        List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));        
        
        List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
//        List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()));
//        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
        
        //子样Id列表
        List<Long> businessSubSampleIdList = businessAssayTaskDataList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样列表
        List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
        //子样配置id列表
        List<Long> configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样方法配置列表
//        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
        List<Long> configAssayMethodIdList = businessAssayTaskDataList.stream().map(m -> m.getConfigAssayMethodId()).distinct().collect(Collectors.toList());
        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodIds(configSubSampleIdList, configAssayMethodIdList);
        
        
        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        //任务参数查询
        List<BusinessAssayProjectAndParameterRespVO> taskParameterList = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIds(businessAssayTaskDataIdList);
        Map<String, List<BusinessAssayProjectAndParameterRespVO>> taskParameterMap = taskParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicKey,
        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
        	    Collectors.toList() // ArrayList 保持组内顺序
        	    ));
        for (Map.Entry<String, List<BusinessAssayProjectAndParameterRespVO>> entry : taskParameterMap.entrySet()) {
        	BusinessAssayProjectAndParameterRespVO taskParameter = entry.getValue().get(0);
        	String fieldIndex = "a_" + taskParameter.getDicKey();
        	String title = taskParameter.getShowName() + (StringUtils.isBlank(taskParameter.getUnit()) ? "" : "(" + taskParameter.getUnit() + ")");
        	boolean isEdit = StringUtils.isBlank(taskParameter.getFormula());
        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, taskParameter.getDataType(), taskParameter.getDecimalPosition(), null, taskParameter.getFormula(), taskParameter.getParamNo(), isEdit, taskParameter.getUnit(), "attribute", taskParameter.getFillingWay(), taskParameter.getGroupDictionaryBusinessId(), taskParameter.getGroupDictionaryBusinessKey(), taskParameter.getGroupDictionaryBusinessName()));
		}
        
        //查询检测项目
        BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
        projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
        List<Long> businessAssayProjectDataIdList = projectAndParameterList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        //检测项目参数
		BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
		parameterDataSearch.setBusinessAssayProjectDataIdList(businessAssayProjectDataIdList);
        List<BusinessAssayProjectAndParameterRespVO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
        
        Map<Long, List<BusinessAssayProjectAndParameterRespVO>> projectAndParameterMap = projectAndParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
        	    Collectors.toList() // ArrayList 保持组内顺序
        	    ));
        for (Map.Entry<Long, List<BusinessAssayProjectAndParameterRespVO>> entry : projectAndParameterMap.entrySet()) {
        	BusinessAssayProjectAndParameterRespVO ep = entry.getValue().get(0);
        	String fieldIndex = "e" + ep.getDicId();
        	String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
        	boolean isEdit = StringUtils.isBlank(ep.getFormula());
        	if (isEdit) {
				minWidth = "280px";
			}
        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName()));
        	
        	if (StringUtils.isNotEmpty(ep.getFormula())) {
        		//BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
        		//parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
                //List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
        		List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(ep.getId())).collect(Collectors.toList());
                for (BusinessAssayProjectAndParameterRespVO p : plist) {
                	fieldIndex = "p" + p.getDicId();
                	title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
                	isEdit = StringUtils.isBlank(p.getFormula());
                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
				}
			}
        }

        businessAssayTaskAnalysisDataRespVO.setColumns(cloumns);
        

        //处理数据
        List<Map<String, Object>> datas = new ArrayList<>();
        for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) {
        	BusinessAssayTaskDetailDO businessAssayTaskDetailDO = businessAssayTaskDetailList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId())).findFirst().orElse(null);

        	BusinessSubSampleDO businessSubSampleDO = businessSubSampleDOList.stream().filter(f -> f.getId().equals(businessAssayTaskDataDO.getBusinessSubSampleId())).findFirst().orElse(null);
        	ConfigSubSampleMethodExtendRespVO configSubSampleMethodDO = configSubSampleMethodDOList.stream().filter(f -> f.getConfigAssayMethodId().equals(businessAssayTaskDataDO.getConfigAssayMethodId()) && f.getConfigSubSampleId().equals(businessSubSampleDO.getConfigSubSampleId())).findFirst().orElse(null);
        	
        	if (configSubSampleMethodDO != null && StringUtils.isNotBlank(configSubSampleMethodDO.getConfigInfomation())) {
        		String configInfomation = configSubSampleMethodDO.getConfigInfomation();
				ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class);
				List<ConfigSubSampleMethodConfItem> getParamList = configSubSampleMethodConfInfo.getGetParam();
				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem: getParamList) {
					//Boolean required = configSubSampleMethodConfItem.getRequired();//是否必须
					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();//来源
					Long configMethodId = source.getMethodId();
					String sourceProject = source.getProject();
					//String sourceParameter = source.getParameter();
										
					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();//目标

					if (StringUtils.isNotBlank(target.getProject())) { //设置到检测项目参数

						List<String> projectList = Arrays.asList(target.getProject().split(","));//目标可以有多个
						for (String targetProject : projectList) {
							String targetParameter = target.getParameter();
							
							BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter);
//							if (businessAssayParameterDataDO == null) {
//								throw new ServiceException(1_032_100_000, "子样检测方法映射配置错误");
//							}
							
							if (businessAssayParameterDataDO != null && StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {
								//1 查询委托明细
								BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
								//2 查询样品大类
								BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId());
								//3 判断样品大类类型
								if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样
									//查询当前批次的第一个商检分析样
									BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE);
									List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId(), configMethodId);
									
									BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
									if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
										businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
									}
								} else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样
									//查询当前样品的其他分析方法的结果
//									List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
//									List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
//									BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
									List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(businessAssayTaskDataDO.getBusinessBaseSampleId(), configMethodId);
									
									BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
									if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
										businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
									}
								} else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样
									//查询来样品位
									Boolean isForecastS = false;
									String forecastValue = null;
									String forecastResult = businessSampleEntrustDetailDO.getForecastResult();
									if (StringUtils.isNotBlank(forecastResult)) {
										JSONArray array = JSON.parseArray(forecastResult);
										for (int i = 0; i < array.size(); i++) {
										    JSONObject item = array.getJSONObject(i);
										    if ("S".equals(item.getString("simpleName"))) {
										    	isForecastS = true;
										    	break;
											}
										}
										for (int i = 0; i < array.size(); i++) {
										    JSONObject item = array.getJSONObject(i);
										    if (sourceProject.equals(item.getString("simpleName"))) {
										    	forecastValue = item.getString("value");
										    	break;
											}
										}
									}
									if (isForecastS) {//来样品位存在S值， 则取预报的值
										businessAssayParameterDataDO.setValue(forecastValue);
									} else {
										//查询当前样品的其他方法的结果
//										List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
//										List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
//										BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
										List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(businessAssayTaskDataDO.getBusinessBaseSampleId(), configMethodId);
										BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
										if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
											businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
										}
									}
									
								}
								
								//处理已查询的数据
								BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameterRespVO = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(businessAssayParameterDataDO.getBusinessAssayProjectDataId()) && f.getDicId().equals(businessAssayParameterDataDO.getConfigAssayMethodProjectParameterId()) ).findFirst().orElse(null);
								if (businessAssayProjectAndParameterRespVO != null) {
									businessAssayProjectAndParameterRespVO.setValue(businessAssayParameterDataDO.getValue());
								}

								//更新
								businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO);
							}
						}
					} else if (StringUtils.isNotBlank(target.getAttribute())) {//设置到分析任务属性
						//TODO 在前已经设置过值，这里暂时不再设置
					}
					
				}
			}
        	
        	
            Map<String, Object> map = new HashedMap<>();
            map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId());
            map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId());
            map.put("businessSubSampleId", businessAssayTaskDataDO.getBusinessSubSampleId());
            map.put("businessSubParentSampleId", businessAssayTaskDataDO.getBusinessSubParentSampleId());
            map.put("configAssayMethodId", businessAssayTaskDataDO.getConfigAssayMethodId());
            map.put("businessAssayTaskDetailId", businessAssayTaskDetailDO.getId());
            map.put("sampleCode", businessAssayTaskDetailDO.getSampleCode());
            map.put("sampleName", businessAssayTaskDetailDO.getSampleName());
            map.put("rollbackStatus", businessAssayTaskDetailDO.getRollbackStatus());
            
            
            //List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIds(Arrays.asList(businessAssayTaskDataDO.getId()));
            List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = taskParameterList.stream().filter(f -> f.getBizId().equals(businessAssayTaskDataDO.getId())).collect(Collectors.toList());
            for (BusinessAssayProjectAndParameterRespVO taskParameter : taskParameterList2) {
				map.put("a_" + taskParameter.getDicKey(), taskParameter);
			}

            //BusinessAssayProjectDataReqVO projectDataSearch2 = new BusinessAssayProjectDataReqVO();
            //projectDataSearch2.setBusinessAssayTaskDataId(businessAssayTaskDataDO.getId());
            //List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch2);
            List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = projectAndParameterList.stream().filter(f -> f.getBizId().equals(businessAssayTaskDataDO.getId())).collect(Collectors.toList());
            for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList2) {
				map.put("e" + ep.getDicId(), ep);
				if (StringUtils.isNotEmpty(ep.getFormula())) {
	        		//BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
	        		//parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
	                //List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
					List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(ep.getId())).collect(Collectors.toList());
	                for (BusinessAssayProjectAndParameterRespVO p : plist) {
	                	map.put("p" + p.getDicId(), p);
					}
				}
				
			}
            datas.add(map);
        }
        
        businessAssayTaskAnalysisDataRespVO.setDatas(datas);
		
		
		return businessAssayTaskAnalysisDataRespVO;
	}
	
	private BusinessAssayTaskAnalysisDataRespVO getAnalysisOld(BusinessAssayTaskDO businessAssayTaskDO) {
		BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO = new BusinessAssayTaskAnalysisDataRespVO();
		businessAssayTaskAnalysisDataRespVO.setAnalysisType("analysis");
		businessAssayTaskAnalysisDataRespVO.setAnalysisName("分析样");
		businessAssayTaskAnalysisDataRespVO.setSortNo(99);

    	String minWidth = "200px";

		//处理列
        List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));        
        
        List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>().eq(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()));  
//        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskDO.getId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
        List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
        
        //子样Id列表
        List<Long> businessSubSampleIdList = businessAssayTaskDataList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样列表
        List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
        //子样配置id列表
        List<Long> configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());
        
        //子样方法配置列表
//        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
        List<Long> configAssayMethodIdList = businessAssayTaskDataList.stream().map(m -> m.getConfigAssayMethodId()).distinct().collect(Collectors.toList());
        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodIds(configSubSampleIdList, configAssayMethodIdList);
        
        
        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        //任务参数查询
        List<BusinessAssayProjectAndParameterRespVO> taskParameterList = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIds(businessAssayTaskDataIdList);
        Map<Long, List<BusinessAssayProjectAndParameterRespVO>> taskParameterMap = taskParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
        	    Collectors.toList() // ArrayList 保持组内顺序
        	    ));
        for (Map.Entry<Long, List<BusinessAssayProjectAndParameterRespVO>> entry : taskParameterMap.entrySet()) {
        	BusinessAssayProjectAndParameterRespVO taskParameter = entry.getValue().get(0);
        	String fieldIndex = "a" + taskParameter.getDicId();
        	String title = taskParameter.getShowName() + (StringUtils.isBlank(taskParameter.getUnit()) ? "" : "(" + taskParameter.getUnit() + ")");
        	boolean isEdit = StringUtils.isBlank(taskParameter.getFormula());
        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, taskParameter.getDataType(), taskParameter.getDecimalPosition(), null, taskParameter.getFormula(), taskParameter.getParamNo(), isEdit, taskParameter.getUnit(), "attribute", taskParameter.getFillingWay(), taskParameter.getGroupDictionaryBusinessId(), taskParameter.getGroupDictionaryBusinessKey(), taskParameter.getGroupDictionaryBusinessName()));
		}
        
        //查询检测项目
        BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
        projectDataSearch.setBusinessAssayTaskDataIdList(businessAssayTaskDataIdList);
        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
        List<Long> businessAssayProjectDataIdList = projectAndParameterList.stream().map(m -> m.getId()).collect(Collectors.toList());
        
        //检测项目参数
		BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
		parameterDataSearch.setBusinessAssayProjectDataIdList(businessAssayProjectDataIdList);
        List<BusinessAssayProjectAndParameterRespVO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
        
        Map<Long, List<BusinessAssayProjectAndParameterRespVO>> projectAndParameterMap = projectAndParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
        	    Collectors.toList() // ArrayList 保持组内顺序
        	    ));
        for (Map.Entry<Long, List<BusinessAssayProjectAndParameterRespVO>> entry : projectAndParameterMap.entrySet()) {
        	BusinessAssayProjectAndParameterRespVO ep = entry.getValue().get(0);
        	String fieldIndex = "e" + ep.getDicId();
        	String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
        	boolean isEdit = StringUtils.isBlank(ep.getFormula());
        	if (isEdit) {
				minWidth = "280px";
			}
        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName()));
        	
        	if (StringUtils.isNotEmpty(ep.getFormula())) {
        		//BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
        		//parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
                //List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
        		List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(ep.getId())).collect(Collectors.toList());
                for (BusinessAssayProjectAndParameterRespVO p : plist) {
                	fieldIndex = "p" + p.getDicId();
                	title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
                	isEdit = StringUtils.isBlank(p.getFormula());
                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
				}
			}
        }

        businessAssayTaskAnalysisDataRespVO.setColumns(cloumns);
        

        //处理数据
        List<Map<String, Object>> datas = new ArrayList<>();
        for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataList) {
        	BusinessAssayTaskDetailDO businessAssayTaskDetailDO = businessAssayTaskDetailList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId())).findFirst().orElse(null);

        	BusinessSubSampleDO businessSubSampleDO = businessSubSampleDOList.stream().filter(f -> f.getId().equals(businessAssayTaskDataDO.getBusinessSubSampleId())).findFirst().orElse(null);
        	ConfigSubSampleMethodExtendRespVO configSubSampleMethodDO = configSubSampleMethodDOList.stream().filter(f -> f.getConfigAssayMethodId().equals(businessAssayTaskDataDO.getConfigAssayMethodId()) && f.getConfigSubSampleId().equals(businessSubSampleDO.getConfigSubSampleId())).findFirst().orElse(null);
        	String configInfomation = configSubSampleMethodDO.getConfigInfomation();
        	if (StringUtils.isNotBlank(configInfomation)) {
				ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class);
				List<ConfigSubSampleMethodConfItem> getParamList = configSubSampleMethodConfInfo.getGetParam();
				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem: getParamList) {
					//Boolean required = configSubSampleMethodConfItem.getRequired();//是否必须
					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();//来源
					Long configMethodId = source.getMethodId();
					String sourceProject = source.getProject();
					//String sourceParameter = source.getParameter();
										
					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();//目标

					List<String> projectList = Arrays.asList(target.getProject().split(","));//目标可以有多个
					for (String targetProject : projectList) {
						String targetParameter = target.getParameter();
						
						BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayTaskDataIdAndProjectSimpleNameAndParameterKey(businessAssayTaskDataDO.getId(), targetProject, targetParameter);
//						if (businessAssayParameterDataDO == null) {
//							throw new ServiceException(1_032_100_000, "子样检测方法映射配置错误");
//						}
						
						if (businessAssayParameterDataDO != null && StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {
							//1 查询委托明细
							BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskDataDO.getBusinessBaseSampleId());
							//2 查询样品大类
							BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId());
							//3 判断样品大类类型
							if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样
								//查询当前批次的第一个商检分析样
								BusinessSampleEntrustDetailDO currBatchFirstBusinessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectCurrBatchFirstByBusinessBaseSampleIdAndBaseSampleDictionaryBusinessKey(businessAssayTaskDataDO.getBusinessBaseSampleId(), QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE);
								List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(currBatchFirstBusinessSampleEntrustDetailDO.getBusinessBaseSampleId(), configMethodId);
								
								BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
								if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
									businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
								}
							} else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样
								//查询当前样品的其他分析方法的结果
//								List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
//								List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
//								BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
								List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(businessAssayTaskDataDO.getBusinessBaseSampleId(), configMethodId);
								
								BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
								if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
									businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
								}
							} else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样
								//查询来样品位
								Boolean isForecastS = false;
								String forecastValue = null;
								String forecastResult = businessSampleEntrustDetailDO.getForecastResult();
								if (StringUtils.isNotBlank(forecastResult)) {
									JSONArray array = JSON.parseArray(forecastResult);
									for (int i = 0; i < array.size(); i++) {
									    JSONObject item = array.getJSONObject(i);
									    if ("S".equals(item.getString("simpleName"))) {
									    	isForecastS = true;
									    	break;
										}
									}
									for (int i = 0; i < array.size(); i++) {
									    JSONObject item = array.getJSONObject(i);
									    if (sourceProject.equals(item.getString("simpleName"))) {
									    	forecastValue = item.getString("value");
									    	break;
										}
									}
								}
								if (isForecastS) {//来样品位存在S值， 则取预报的值
									businessAssayParameterDataDO.setValue(forecastValue);
								} else {
									//查询当前样品的其他方法的结果
//									List<Long> businessSubParentSampleIdList = Arrays.asList(businessAssayTaskDataDO.getBusinessSubParentSampleId());
//									List<BusinessSubParentSampleAssessmentProjectExtendRespVO> businessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(businessSubParentSampleIdList, configMethodId);
//									BusinessSubParentSampleAssessmentProjectExtendRespVO businessSubParentSampleAssessmentProject = businessSubParentSampleAssessmentProjectList.stream().filter(f -> f.getSimpleName().equals(sourceProject)).findFirst().orElse(null);
									List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessBaseSampleIdAndConfigAssayMethodId(businessAssayTaskDataDO.getBusinessBaseSampleId(), configMethodId);
									BusinessAssayProjectDataExtendRespVO sourceBusinessAssayProjectDataExtendRespVO = businessAssayProjectDataExtendList.stream().filter(f -> sourceProject.equals(f.getSimpleName())).findFirst().orElse(null);
									if (sourceBusinessAssayProjectDataExtendRespVO != null && StringUtils.isNotBlank(sourceBusinessAssayProjectDataExtendRespVO.getValue())) {
										businessAssayParameterDataDO.setValue(sourceBusinessAssayProjectDataExtendRespVO.getValue());
									}
								}
								
							}
							
							//处理已查询的数据
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameterRespVO = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(businessAssayParameterDataDO.getBusinessAssayProjectDataId()) && f.getDicId().equals(businessAssayParameterDataDO.getConfigAssayMethodProjectParameterId()) ).findFirst().orElse(null);
							if (businessAssayProjectAndParameterRespVO != null) {
								businessAssayProjectAndParameterRespVO.setValue(businessAssayParameterDataDO.getValue());
							}

							//更新
							businessAssayParameterDataMapper.updateById(businessAssayParameterDataDO);
						}
					}
				}
			}
        	
        	
            Map<String, Object> map = new HashedMap<>();
            map.put("businessAssayTaskDataId", businessAssayTaskDataDO.getId());
            map.put("businessAssayTaskId", businessAssayTaskDataDO.getBusinessAssayTaskId());
            map.put("businessSubSampleId", businessAssayTaskDataDO.getBusinessSubSampleId());
            map.put("businessSubParentSampleId", businessAssayTaskDataDO.getBusinessSubParentSampleId());
            map.put("configAssayMethodId", businessAssayTaskDataDO.getConfigAssayMethodId());
            map.put("businessAssayTaskDetailId", businessAssayTaskDetailDO.getId());
            map.put("sampleCode", businessAssayTaskDetailDO.getSampleCode());
            map.put("sampleName", businessAssayTaskDetailDO.getSampleName());
            map.put("rollbackStatus", businessAssayTaskDetailDO.getRollbackStatus());
            
            
            //List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIds(Arrays.asList(businessAssayTaskDataDO.getId()));
            List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = taskParameterList.stream().filter(f -> f.getBizId().equals(businessAssayTaskDataDO.getId())).collect(Collectors.toList());
            for (BusinessAssayProjectAndParameterRespVO taskParameter : taskParameterList2) {
				map.put("a" + taskParameter.getDicId(), taskParameter);
			}

            //BusinessAssayProjectDataReqVO projectDataSearch2 = new BusinessAssayProjectDataReqVO();
            //projectDataSearch2.setBusinessAssayTaskDataId(businessAssayTaskDataDO.getId());
            //List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch2);
            List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = projectAndParameterList.stream().filter(f -> f.getBizId().equals(businessAssayTaskDataDO.getId())).collect(Collectors.toList());
            for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList2) {
				map.put("e" + ep.getDicId(), ep);
				if (StringUtils.isNotEmpty(ep.getFormula())) {
	        		//BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
	        		//parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
	                //List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
					List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataList.stream().filter(f -> f.getBizId().equals(ep.getId())).collect(Collectors.toList());
	                for (BusinessAssayProjectAndParameterRespVO p : plist) {
	                	map.put("p" + p.getDicId(), p);
					}
				}
				
			}
            datas.add(map);
        }
        
        businessAssayTaskAnalysisDataRespVO.setDatas(datas);
		
		
		return businessAssayTaskAnalysisDataRespVO;
	}
	
	private List<BusinessAssayTaskAnalysisDataRespVO> getQcAnalysis(BusinessAssayTaskDO businessAssayTaskDO) {
		List<BusinessAssayTaskAnalysisDataRespVO> list = new ArrayList<>();

    	String minWidth = "200px";
		List<ConfigQCSampleMethodExtendRespVO> configQCSampleMethodList = configQCSampleMethodMapper.selectByConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId());
		BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO = null;
		for (ConfigQCSampleMethodExtendRespVO configQCSampleMethodExtendRespVO : configQCSampleMethodList) {
			businessAssayTaskAnalysisDataRespVO = new BusinessAssayTaskAnalysisDataRespVO();
			businessAssayTaskAnalysisDataRespVO.setAnalysisType(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());
			businessAssayTaskAnalysisDataRespVO.setAnalysisName(configQCSampleMethodExtendRespVO.getDictionaryBusinessName());
			businessAssayTaskAnalysisDataRespVO.setSortNo(configQCSampleMethodExtendRespVO.getSortNo());
			businessAssayTaskAnalysisDataRespVO.setConfigQCSampleMethod(configQCSampleMethodExtendRespVO);
			
			//处理列
	        List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
	        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
	        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
	        
	        //处理数据
	        List<Map<String, Object>> datas = new ArrayList<>();
			if ("withoutProject".equals(configQCSampleMethodExtendRespVO.getParentDictionaryBusinesskey())) {//不带检测项目
				List<BusinessQCCoefficientDataDO> businessQCCoefficientDataDOList = businessQCCoefficientDataMapper.selectByBusinessAssayTaskIdAndDictionaryBusinessKey(businessAssayTaskDO.getId(), configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());			
				if (CollUtil.isEmpty(businessQCCoefficientDataDOList)) {
					continue;
				}
				BusinessQCCoefficientDataDO businessQCCoefficientDataDO = businessQCCoefficientDataDOList.get(0);
				
				BusinessQCCoefficientParameterDataReqVO parameterDataSearch = new BusinessQCCoefficientParameterDataReqVO();
				parameterDataSearch.setBusinessQCCoefficientDataId(businessQCCoefficientDataDO.getId());
				List<BusinessAssayProjectAndParameterRespVO> plist = businessQCCoefficientParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
				for (BusinessAssayProjectAndParameterRespVO p : plist) {
					String fieldIndex = "p" + p.getDicId();
					String title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
					boolean isEdit = StringUtils.isBlank(p.getFormula());
                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
				}
				
				
				for (BusinessQCCoefficientDataDO businessQCCoefficientData: businessQCCoefficientDataDOList) {
		            Map<String, Object> map = new HashedMap<>();
		            map.put("businessAssayTaskDataId", businessQCCoefficientData.getId());
		            map.put("businessAssayTaskId", businessQCCoefficientData.getBusinessAssayTaskId());
		            map.put("businessSubSampleId", "");
		            map.put("businessSubParentSampleId", "");
		            map.put("configAssayMethodId", businessQCCoefficientData.getConfigAssayMethodId());
		            map.put("businessAssayTaskDetailId", "");
		            map.put("sampleCode", businessQCCoefficientData.getSampleCode());
		            map.put("sampleName", businessQCCoefficientData.getSampleName());

		            BusinessQCCoefficientParameterDataReqVO parameterDataSearch2 = new BusinessQCCoefficientParameterDataReqVO();
		            parameterDataSearch2.setBusinessQCCoefficientDataId(businessQCCoefficientData.getId());
	                List<BusinessAssayProjectAndParameterRespVO> plist2 = businessQCCoefficientParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch2);
	                for (BusinessAssayProjectAndParameterRespVO p : plist2) {
	                	map.put("p" + p.getDicId(), p);
					}
		            datas.add(map);
				}
			} else {//带检测项目
				List<BusinessQCManagementDataDO> businessQCManagementDataDOList = businessQCManagementDataMapper.selectByBusinessAssayTaskIdAndDictionaryBusinessKey(businessAssayTaskDO.getId(), configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());
				
				if (CollUtil.isEmpty(businessQCManagementDataDOList)) {
					continue;
				}
				BusinessQCManagementDataDO businessQCManagementDataDO = businessQCManagementDataDOList.get(0);
				

		        //任务参数查询
		        List<BusinessAssayProjectAndParameterRespVO> taskParameterList = businessQCManagementSampleParameterDataMapper.selectByBusinessQCManagementDataIds(Arrays.asList(businessQCManagementDataDO.getId()));
		        Map<String, List<BusinessAssayProjectAndParameterRespVO>> taskParameterMap = taskParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicKey,
		        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
		        	    Collectors.toList() // ArrayList 保持组内顺序
		        	    ));
		        for (Map.Entry<String, List<BusinessAssayProjectAndParameterRespVO>> entry : taskParameterMap.entrySet()) {
		        	BusinessAssayProjectAndParameterRespVO taskParameter = entry.getValue().get(0);
		        	String fieldIndex = "a_" + taskParameter.getDicKey();
		        	String title = taskParameter.getShowName() + (StringUtils.isBlank(taskParameter.getUnit()) ? "" : "(" + taskParameter.getUnit() + ")");
		        	boolean isEdit = StringUtils.isBlank(taskParameter.getFormula());
		        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, taskParameter.getDataType(), taskParameter.getDecimalPosition(), null, taskParameter.getFormula(), taskParameter.getParamNo(), isEdit, taskParameter.getUnit(), "attribute", taskParameter.getFillingWay(), taskParameter.getGroupDictionaryBusinessId(), taskParameter.getGroupDictionaryBusinessKey(), taskParameter.getGroupDictionaryBusinessName()));
				}
		        

		        BusinessQCManagementProjectDataReqVO projectDataSearch = new BusinessQCManagementProjectDataReqVO();
		        projectDataSearch.setBusinessQCManagementDataId(businessQCManagementDataDO.getId());
		        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessQCManagementProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
		        for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList) {
		        	String fieldIndex = "e" + ep.getDicId();
		        	String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
		        	boolean isEdit = StringUtils.isBlank(ep.getFormula());
		        	if ("zkkby".equals(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey()) && StringUtils.isNotBlank(ep.getFormula()) && ep.getFormula().startsWith("From")) {
		        		isEdit = true;
		        		ep.setFormula(null);
					}
		        	if (isEdit) {
						minWidth = "280px";
					}
		        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName()));
		        	
		        	if (StringUtils.isNotEmpty(ep.getFormula())) {
		        		BusinessQCManagementParameterDataReqVO parameterDataSearch = new BusinessQCManagementParameterDataReqVO();
		        		parameterDataSearch.setBusinessQCManagementProjectDataId(ep.getId());
		                List<BusinessAssayProjectAndParameterRespVO> plist = businessQCManagementParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
		                for (BusinessAssayProjectAndParameterRespVO p : plist) {
		                	fieldIndex = "p" + p.getDicId();
		                	title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
		                	isEdit = StringUtils.isBlank(p.getFormula());
				        	if ("zkkby".equals(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey()) && StringUtils.isNotBlank(p.getFormula()) && p.getFormula().startsWith("From")) {
				        		isEdit = true;
				        		p.setFormula(null);
							}
		                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
						}
					}
				}

		        for (BusinessQCManagementDataDO businessQCManagementData : businessQCManagementDataDOList) {
		            Map<String, Object> map = new HashedMap<>();
		            map.put("businessAssayTaskDataId", businessQCManagementData.getId());
		            map.put("businessAssayTaskId", businessQCManagementData.getBusinessAssayTaskId());
		            map.put("businessSubSampleId", "");
		            map.put("businessSubParentSampleId", "");
		            map.put("configAssayMethodId", businessQCManagementData.getConfigAssayMethodId());
		            map.put("businessAssayTaskDetailId", "");
		            map.put("sampleCode", businessQCManagementData.getSampleCode());
		            map.put("sampleName", businessQCManagementData.getSampleName());
		            
		            List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = businessQCManagementSampleParameterDataMapper.selectByBusinessQCManagementDataIds(Arrays.asList(businessQCManagementData.getId()));
		            for (BusinessAssayProjectAndParameterRespVO taskParameter : taskParameterList2) {
						map.put("a_" + taskParameter.getDicKey(), taskParameter);
					}


		            BusinessQCManagementProjectDataReqVO projectDataSearch2 = new BusinessQCManagementProjectDataReqVO();
		            projectDataSearch2.setBusinessQCManagementDataId(businessQCManagementData.getId());
		            List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = businessQCManagementProjectDataMapper.selectProjectAndParameterBy(projectDataSearch2);
		            for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList2) {
						map.put("e" + ep.getDicId(), ep);
						if (StringUtils.isNotEmpty(ep.getFormula())) {
							BusinessQCManagementParameterDataReqVO parameterDataSearch = new BusinessQCManagementParameterDataReqVO();
			        		parameterDataSearch.setBusinessQCManagementProjectDataId(ep.getId());
			                List<BusinessAssayProjectAndParameterRespVO> plist = businessQCManagementParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
			                for (BusinessAssayProjectAndParameterRespVO p : plist) {
			                	map.put("p" + p.getDicId(), p);
							}
						}
						
					}
		            datas.add(map);
				}
				
			}
			businessAssayTaskAnalysisDataRespVO.setColumns(cloumns);
			businessAssayTaskAnalysisDataRespVO.setDatas(datas);
			list.add(businessAssayTaskAnalysisDataRespVO);
		}
		return list;
	}

	private List<BusinessAssayTaskAnalysisDataRespVO> getQcAnalysisOld(BusinessAssayTaskDO businessAssayTaskDO) {
		List<BusinessAssayTaskAnalysisDataRespVO> list = new ArrayList<>();

    	String minWidth = "200px";
		List<ConfigQCSampleMethodExtendRespVO> configQCSampleMethodList = configQCSampleMethodMapper.selectByConfigAssayMethodId(businessAssayTaskDO.getConfigAssayMethodId());
		BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO = null;
		for (ConfigQCSampleMethodExtendRespVO configQCSampleMethodExtendRespVO : configQCSampleMethodList) {
			businessAssayTaskAnalysisDataRespVO = new BusinessAssayTaskAnalysisDataRespVO();
			businessAssayTaskAnalysisDataRespVO.setAnalysisType(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());
			businessAssayTaskAnalysisDataRespVO.setAnalysisName(configQCSampleMethodExtendRespVO.getDictionaryBusinessName());
			businessAssayTaskAnalysisDataRespVO.setSortNo(configQCSampleMethodExtendRespVO.getSortNo());
			businessAssayTaskAnalysisDataRespVO.setConfigQCSampleMethod(configQCSampleMethodExtendRespVO);
			
			//处理列
	        List<BatchSampleAnalysisColumnRespVO> cloumns = new ArrayList<>();
	        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleCode", "sampleCode", "样品编号", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
	        cloumns.add(new BatchSampleAnalysisColumnRespVO("sampleName", "sampleName", "样品名称", minWidth, minWidth, "string", null, null, null, null, false, null, null, null, null, null, null));
	        
	        //处理数据
	        List<Map<String, Object>> datas = new ArrayList<>();
			if ("withoutProject".equals(configQCSampleMethodExtendRespVO.getParentDictionaryBusinesskey())) {//不带检测项目
				List<BusinessQCCoefficientDataDO> businessQCCoefficientDataDOList = businessQCCoefficientDataMapper.selectByBusinessAssayTaskIdAndDictionaryBusinessKey(businessAssayTaskDO.getId(), configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());			
				if (CollUtil.isEmpty(businessQCCoefficientDataDOList)) {
					break;
				}
				BusinessQCCoefficientDataDO businessQCCoefficientDataDO = businessQCCoefficientDataDOList.get(0);
				
				BusinessQCCoefficientParameterDataReqVO parameterDataSearch = new BusinessQCCoefficientParameterDataReqVO();
				parameterDataSearch.setBusinessQCCoefficientDataId(businessQCCoefficientDataDO.getId());
				List<BusinessAssayProjectAndParameterRespVO> plist = businessQCCoefficientParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
				for (BusinessAssayProjectAndParameterRespVO p : plist) {
					String fieldIndex = "p" + p.getDicId();
					String title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
					boolean isEdit = StringUtils.isBlank(p.getFormula());
                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
				}
				
				
				for (BusinessQCCoefficientDataDO businessQCCoefficientData: businessQCCoefficientDataDOList) {
		            Map<String, Object> map = new HashedMap<>();
		            map.put("businessAssayTaskDataId", businessQCCoefficientData.getId());
		            map.put("businessAssayTaskId", businessQCCoefficientData.getBusinessAssayTaskId());
		            map.put("businessSubSampleId", "");
		            map.put("businessSubParentSampleId", "");
		            map.put("configAssayMethodId", businessQCCoefficientData.getConfigAssayMethodId());
		            map.put("businessAssayTaskDetailId", "");
		            map.put("sampleCode", businessQCCoefficientData.getSampleCode());
		            map.put("sampleName", businessQCCoefficientData.getSampleName());

		            BusinessQCCoefficientParameterDataReqVO parameterDataSearch2 = new BusinessQCCoefficientParameterDataReqVO();
		            parameterDataSearch2.setBusinessQCCoefficientDataId(businessQCCoefficientData.getId());
	                List<BusinessAssayProjectAndParameterRespVO> plist2 = businessQCCoefficientParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch2);
	                for (BusinessAssayProjectAndParameterRespVO p : plist2) {
	                	map.put("p" + p.getDicId(), p);
					}
		            datas.add(map);
				}
			} else {//带检测项目
				List<BusinessQCManagementDataDO> businessQCManagementDataDOList = businessQCManagementDataMapper.selectByBusinessAssayTaskIdAndDictionaryBusinessKey(businessAssayTaskDO.getId(), configQCSampleMethodExtendRespVO.getDictionaryBusinessKey());
				
				if (CollUtil.isEmpty(businessQCManagementDataDOList)) {
					break;
				}
				BusinessQCManagementDataDO businessQCManagementDataDO = businessQCManagementDataDOList.get(0);
				

		        //任务参数查询
		        List<BusinessAssayProjectAndParameterRespVO> taskParameterList = businessQCManagementSampleParameterDataMapper.selectByBusinessQCManagementDataIds(Arrays.asList(businessQCManagementDataDO.getId()));
		        Map<Long, List<BusinessAssayProjectAndParameterRespVO>> taskParameterMap = taskParameterList.stream().sorted(Comparator.comparing(BusinessAssayProjectAndParameterRespVO::getParamNo)).collect(Collectors.groupingBy(BusinessAssayProjectAndParameterRespVO::getDicId,
		        	    LinkedHashMap::new, // 保持组首次出现的顺序（可选）
		        	    Collectors.toList() // ArrayList 保持组内顺序
		        	    ));
		        for (Map.Entry<Long, List<BusinessAssayProjectAndParameterRespVO>> entry : taskParameterMap.entrySet()) {
		        	BusinessAssayProjectAndParameterRespVO taskParameter = entry.getValue().get(0);
		        	String fieldIndex = "a" + taskParameter.getDicId();
		        	String title = taskParameter.getShowName() + (StringUtils.isBlank(taskParameter.getUnit()) ? "" : "(" + taskParameter.getUnit() + ")");
		        	boolean isEdit = StringUtils.isBlank(taskParameter.getFormula());
		        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, taskParameter.getDataType(), taskParameter.getDecimalPosition(), null, taskParameter.getFormula(), taskParameter.getParamNo(), isEdit, taskParameter.getUnit(), "attribute", taskParameter.getFillingWay(), taskParameter.getGroupDictionaryBusinessId(), taskParameter.getGroupDictionaryBusinessKey(), taskParameter.getGroupDictionaryBusinessName()));
				}
		        

		        BusinessQCManagementProjectDataReqVO projectDataSearch = new BusinessQCManagementProjectDataReqVO();
		        projectDataSearch.setBusinessQCManagementDataId(businessQCManagementDataDO.getId());
		        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessQCManagementProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
		        for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList) {
		        	String fieldIndex = "e" + ep.getDicId();
		        	String title = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
		        	boolean isEdit = StringUtils.isBlank(ep.getFormula());
		        	if ("zkkby".equals(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey()) && StringUtils.isNotBlank(ep.getFormula()) && ep.getFormula().startsWith("From")) {
		        		isEdit = true;
		        		ep.setFormula(null);
					}
		        	if (isEdit) {
						minWidth = "280px";
					}
		        	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, ep.getDataType(), ep.getDecimalPosition(), null, ep.getFormula(), ep.getParamNo(), isEdit, ep.getUnit(), "project", ep.getFillingWay(), ep.getGroupDictionaryBusinessId(), ep.getGroupDictionaryBusinessKey(), ep.getGroupDictionaryBusinessName()));
		        	
		        	if (StringUtils.isNotEmpty(ep.getFormula())) {
		        		BusinessQCManagementParameterDataReqVO parameterDataSearch = new BusinessQCManagementParameterDataReqVO();
		        		parameterDataSearch.setBusinessQCManagementProjectDataId(ep.getId());
		                List<BusinessAssayProjectAndParameterRespVO> plist = businessQCManagementParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
		                for (BusinessAssayProjectAndParameterRespVO p : plist) {
		                	fieldIndex = "p" + p.getDicId();
		                	title = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
		                	isEdit = StringUtils.isBlank(p.getFormula());
				        	if ("zkkby".equals(configQCSampleMethodExtendRespVO.getDictionaryBusinessKey()) && StringUtils.isNotBlank(p.getFormula()) && p.getFormula().startsWith("From")) {
				        		isEdit = true;
				        		p.setFormula(null);
							}
		                	cloumns.add(new BatchSampleAnalysisColumnRespVO(fieldIndex, fieldIndex + ".value", title,  "", minWidth, p.getDataType(), p.getDecimalPosition(), null, p.getFormula(), p.getParamNo(), isEdit, p.getUnit(), "parameter", p.getFillingWay(), p.getGroupDictionaryBusinessId(), p.getGroupDictionaryBusinessKey(), p.getGroupDictionaryBusinessName()));
						}
					}
				}

		        for (BusinessQCManagementDataDO businessQCManagementData : businessQCManagementDataDOList) {
		            Map<String, Object> map = new HashedMap<>();
		            map.put("businessAssayTaskDataId", businessQCManagementData.getId());
		            map.put("businessAssayTaskId", businessQCManagementData.getBusinessAssayTaskId());
		            map.put("businessSubSampleId", "");
		            map.put("businessSubParentSampleId", "");
		            map.put("configAssayMethodId", businessQCManagementData.getConfigAssayMethodId());
		            map.put("businessAssayTaskDetailId", "");
		            map.put("sampleCode", businessQCManagementData.getSampleCode());
		            map.put("sampleName", businessQCManagementData.getSampleName());
		            
		            List<BusinessAssayProjectAndParameterRespVO> taskParameterList2 = businessQCManagementSampleParameterDataMapper.selectByBusinessQCManagementDataIds(Arrays.asList(businessQCManagementData.getId()));
		            for (BusinessAssayProjectAndParameterRespVO taskParameter : taskParameterList2) {
						map.put("a" + taskParameter.getDicId(), taskParameter);
					}


		            BusinessQCManagementProjectDataReqVO projectDataSearch2 = new BusinessQCManagementProjectDataReqVO();
		            projectDataSearch2.setBusinessQCManagementDataId(businessQCManagementData.getId());
		            List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList2 = businessQCManagementProjectDataMapper.selectProjectAndParameterBy(projectDataSearch2);
		            for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList2) {
						map.put("e" + ep.getDicId(), ep);
						if (StringUtils.isNotEmpty(ep.getFormula())) {
							BusinessQCManagementParameterDataReqVO parameterDataSearch = new BusinessQCManagementParameterDataReqVO();
			        		parameterDataSearch.setBusinessQCManagementProjectDataId(ep.getId());
			                List<BusinessAssayProjectAndParameterRespVO> plist = businessQCManagementParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
			                for (BusinessAssayProjectAndParameterRespVO p : plist) {
			                	map.put("p" + p.getDicId(), p);
							}
						}
						
					}
		            datas.add(map);
				}
				
			}
			businessAssayTaskAnalysisDataRespVO.setColumns(cloumns);
			businessAssayTaskAnalysisDataRespVO.setDatas(datas);
			list.add(businessAssayTaskAnalysisDataRespVO);
		}
		return list;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveBatchSmpleAndQcAnalysis(BusinessAssayTaskAnalysisSampleAndQcProjectRespVO vo) {
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(vo.getBusinessAssayTaskId());
		businessAssayTaskDO.setFormValue(vo.getFormValue());
		businessAssayTaskDO.setAssayTime(vo.getAssayTime());
		businessAssayTaskDO.setTaskAssayStatus(QmsCommonConstant.SAVED);
		//赋值数据集id
		if (vo.getDataCollectionId() == null) {
			ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(businessAssayTaskDO.getConfigAssayMethodId());
			DataCollectionDO dataCollectionDO = dataCollectionService.getLatestDataCollectionByKey(configAssayMethodDO.getDataCollectionKey());
			businessAssayTaskDO.setFormDataCollectionId(dataCollectionDO.getId());
		} else {
			businessAssayTaskDO.setFormDataCollectionId(vo.getDataCollectionId());
		}
		
		List<BusinessAssayTaskAnalysisDataRespVO> assayTaskAnalysisDataList = vo.getAssayTaskAnalysisDataList();
		
		List<DictionaryBusinessExtendRespVO> dictionaryBusinessItemList = dictionaryBusinessMapper.selectItemByCategoryKeys(Arrays.asList("withProject", "withoutProject"));
		
		if (CollUtil.isNotEmpty(assayTaskAnalysisDataList)) {
			for (BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO : assayTaskAnalysisDataList) {
				DictionaryBusinessExtendRespVO dictionaryBusinessItem = dictionaryBusinessItemList.stream().filter(f -> f.getKey().equals(businessAssayTaskAnalysisDataRespVO.getAnalysisType())).findFirst().orElse(null);
				if ("analysis".equals(businessAssayTaskAnalysisDataRespVO.getAnalysisType())) {//分析样
//					List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, vo.getBusinessAssayTaskId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
					List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(vo.getBusinessAssayTaskId());
					
			        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessAssayTaskParameterDataDO> businessAssayTaskParameterDataList = businessAssayTaskParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskParameterDataDO>().in(BusinessAssayTaskParameterDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList));
			        
			        List<BusinessAssayProjectDataDO> businessAssayProjectDataList = businessAssayProjectDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayProjectDataDO>().in(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList));
			        List<Long> businessAssayProjectDataIdList = businessAssayProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessAssayParameterDataDO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayParameterDataDO>().in(BusinessAssayParameterDataDO::getBusinessAssayProjectDataId, businessAssayProjectDataIdList));
			        
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("project".equals(pap.getType())) {
								BusinessAssayProjectDataDO businessAssayProjectDataDO = businessAssayProjectDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessAssayProjectDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayProjectDataDO.setValue(pap.getValue());
											businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
											businessAssayProjectDataDO.setValue(value);
											businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + value);	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayProjectDataDO.setValue(null);
								}
							} else if ("parameter".equals(pap.getType())) {
								BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessAssayParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayParameterDataDO.setValue(pap.getValue());
											businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
					                        businessAssayParameterDataDO.setValue(value);
					                        businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + value);	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayParameterDataDO.setValue(null);
								}
							} else if ("attribute".equals(pap.getType())) {
								BusinessAssayTaskParameterDataDO businessAssayTaskParameterDataDO = businessAssayTaskParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayTaskParameterDataDO.setValue(pap.getValue());
											businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
					                        businessAssayTaskParameterDataDO.setValue(value);
					                        businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + value);
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayTaskParameterDataDO.setValue(null);
								}
							}
						}
			            
					}
					
					if (CollUtil.isNotEmpty(businessAssayTaskParameterDataList)) {
						businessAssayTaskParameterDataMapper.updateBatch(businessAssayTaskParameterDataList);
					}
					
					if (CollUtil.isNotEmpty(businessAssayProjectDataList)) {
						businessAssayProjectDataMapper.updateBatch(businessAssayProjectDataList);					
					}
					if (CollUtil.isNotEmpty(businessAssayParameterDataList)) {
						businessAssayParameterDataMapper.updateBatch(businessAssayParameterDataList);
					}
					
				} else if (dictionaryBusinessItem != null && "withProject".equals(dictionaryBusinessItem.getParentDictionaryBusinesskey())) {//带检测项目
					List<BusinessQCManagementDataDO> BusinessQCManagementDataList = businessQCManagementDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
			        
			        List<Long> businessQCManagementDataIdList = BusinessQCManagementDataList.stream().map(m -> m.getId()).collect(Collectors.toList());

			        List<BusinessQCManagementSampleParameterDataDO> businessQCManagementSampleParameterDataDOList = businessQCManagementSampleParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessQCManagementSampleParameterDataDO>().in(BusinessQCManagementSampleParameterDataDO::getBusinessQCManagementDataId, businessQCManagementDataIdList));
			        
			        List<BusinessQCManagementProjectDataDO> businessQCManagementProjectDataList = businessQCManagementProjectDataMapper.selectByBusinessQCManagementDataIds(businessQCManagementDataIdList);
			        List<Long> businessQCManagementProjectDataIdList = businessQCManagementProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessQCManagementParameterDataDO> businessQCManagementParameterDataList = businessQCManagementParameterDataMapper.selectByBusinessQCManagementProjectDataIds(businessQCManagementProjectDataIdList);
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("project".equals(pap.getType())) {
								BusinessQCManagementProjectDataDO businessQCManagementProjectDataDO = businessQCManagementProjectDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCManagementProjectDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementProjectDataDO.setValue(pap.getValue());
											businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
											businessQCManagementProjectDataDO.setValue(value);
											businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + value);	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementProjectDataDO.setValue(null);
								}
							} else if ("parameter".equals(pap.getType())) {
								BusinessQCManagementParameterDataDO businessQCManagementParameterDataDO = businessQCManagementParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCManagementParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementParameterDataDO.setValue(pap.getValue());
											businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
					                        businessQCManagementParameterDataDO.setValue(value);
					                        businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + value);
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementParameterDataDO.setValue(null);
								}
							} else if ("attribute".equals(pap.getType())) {
								BusinessQCManagementSampleParameterDataDO businessQCManagementSampleParameterDataDO = businessQCManagementSampleParameterDataDOList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementSampleParameterDataDO.setValue(pap.getValue());
											businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
					                        businessQCManagementSampleParameterDataDO.setValue(value);
					                        businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + value);	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementSampleParameterDataDO.setValue(null);
								}
							}
						}
			            
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementSampleParameterDataDOList)) {
						businessQCManagementSampleParameterDataMapper.updateBatch(businessQCManagementSampleParameterDataDOList);
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementProjectDataList)) {
						businessQCManagementProjectDataMapper.updateBatch(businessQCManagementProjectDataList);
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementParameterDataList)) {
						businessQCManagementParameterDataMapper.updateBatch(businessQCManagementParameterDataList);
					}
				} else { //不带检测项目的
					List<BusinessQCCoefficientDataDO> businessQCCoefficientDataList = businessQCCoefficientDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
			        
			        List<Long> businessQCCoefficientDataIdList = businessQCCoefficientDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessQCCoefficientParameterDataDO> businessQCCoefficientParameterDataList = businessQCCoefficientParameterDataMapper.selectByBusinessQCCoefficientDataIds(businessQCCoefficientDataIdList);
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("parameter".equals(pap.getType())) {
								BusinessQCCoefficientParameterDataDO businessQCCoefficientParameterDataDO = businessQCCoefficientParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCCoefficientParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCCoefficientParameterDataDO.setValue(pap.getValue());
											businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
//											BigDecimal value = new BigDecimal(pap.getValue());
//					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											String value = EffectiveNumberFormatter.formatNumber(pap.getValue(), pap.getDecimalPosition(), pap.getEffectiveDigit());
					                        businessQCCoefficientParameterDataDO.setValue(value);
					                        businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + value);	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCCoefficientParameterDataDO.setValue(null);
								}
							}
						}
			            
					}

					if (CollUtil.isNotEmpty(businessQCCoefficientParameterDataList)) {
						businessQCCoefficientParameterDataMapper.updateBatch(businessQCCoefficientParameterDataList);
					}
					
				}
			}
			
		}
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
	}

//	@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveBatchSmpleAndQcAnalysisOld(BusinessAssayTaskAnalysisSampleAndQcProjectRespVO vo) {
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(vo.getBusinessAssayTaskId());
		businessAssayTaskDO.setFormValue(vo.getFormValue());
		businessAssayTaskDO.setAssayTime(vo.getAssayTime());
		businessAssayTaskDO.setTaskAssayStatus(QmsCommonConstant.SAVED);
		//赋值数据集id
		if (vo.getDataCollectionId() == null) {
			ConfigAssayMethodDO configAssayMethodDO = configAssayMethodMapper.selectById(businessAssayTaskDO.getConfigAssayMethodId());
			DataCollectionDO dataCollectionDO = dataCollectionService.getLatestDataCollectionByKey(configAssayMethodDO.getDataCollectionKey());
			businessAssayTaskDO.setFormDataCollectionId(dataCollectionDO.getId());
		} else {
			businessAssayTaskDO.setFormDataCollectionId(vo.getDataCollectionId());
		}
		
		List<BusinessAssayTaskAnalysisDataRespVO> assayTaskAnalysisDataList = vo.getAssayTaskAnalysisDataList();
		
		List<DictionaryBusinessExtendRespVO> dictionaryBusinessItemList = dictionaryBusinessMapper.selectItemByCategoryKeys(Arrays.asList("withProject", "withoutProject"));
		
		if (CollUtil.isNotEmpty(assayTaskAnalysisDataList)) {
			for (BusinessAssayTaskAnalysisDataRespVO businessAssayTaskAnalysisDataRespVO : assayTaskAnalysisDataList) {
				DictionaryBusinessExtendRespVO dictionaryBusinessItem = dictionaryBusinessItemList.stream().filter(f -> f.getKey().equals(businessAssayTaskAnalysisDataRespVO.getAnalysisType())).findFirst().orElse(null);
				if ("analysis".equals(businessAssayTaskAnalysisDataRespVO.getAnalysisType())) {//分析样
//					List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>().eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, vo.getBusinessAssayTaskId()).eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, businessAssayTaskDO.getConfigAssayMethodId()));
					List<BusinessAssayTaskDataDO> businessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(vo.getBusinessAssayTaskId());
					
			        List<Long> businessAssayTaskDataIdList = businessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessAssayTaskParameterDataDO> businessAssayTaskParameterDataList = businessAssayTaskParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayTaskParameterDataDO>().in(BusinessAssayTaskParameterDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList));
			        
			        List<BusinessAssayProjectDataDO> businessAssayProjectDataList = businessAssayProjectDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayProjectDataDO>().in(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIdList));
			        List<Long> businessAssayProjectDataIdList = businessAssayProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessAssayParameterDataDO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessAssayParameterDataDO>().in(BusinessAssayParameterDataDO::getBusinessAssayProjectDataId, businessAssayProjectDataIdList));
			        
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("project".equals(pap.getType())) {
								BusinessAssayProjectDataDO businessAssayProjectDataDO = businessAssayProjectDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessAssayProjectDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayProjectDataDO.setValue(pap.getValue());
											businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											businessAssayProjectDataDO.setValue(value.toPlainString());
											businessAssayProjectDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayProjectDataDO.setValue(null);
								}
							} else if ("parameter".equals(pap.getType())) {
								BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessAssayParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayParameterDataDO.setValue(pap.getValue());
											businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
					                        businessAssayParameterDataDO.setValue(value.toPlainString());
					                        businessAssayParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayParameterDataDO.setValue(null);
								}
							} else if ("attribute".equals(pap.getType())) {
								BusinessAssayTaskParameterDataDO businessAssayTaskParameterDataDO = businessAssayTaskParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessAssayTaskParameterDataDO.setValue(pap.getValue());
											businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
					                        businessAssayTaskParameterDataDO.setValue(value.toPlainString());
					                        businessAssayTaskParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessAssayTaskParameterDataDO.setValue(null);
								}
							}
						}
			            
					}
					
					if (CollUtil.isNotEmpty(businessAssayTaskParameterDataList)) {
						businessAssayTaskParameterDataMapper.updateBatch(businessAssayTaskParameterDataList);
					}
					
					if (CollUtil.isNotEmpty(businessAssayProjectDataList)) {
						businessAssayProjectDataMapper.updateBatch(businessAssayProjectDataList);					
					}
					if (CollUtil.isNotEmpty(businessAssayParameterDataList)) {
						businessAssayParameterDataMapper.updateBatch(businessAssayParameterDataList);
					}
					
				} else if (dictionaryBusinessItem != null && "withProject".equals(dictionaryBusinessItem.getParentDictionaryBusinesskey())) {//带检测项目
					List<BusinessQCManagementDataDO> BusinessQCManagementDataList = businessQCManagementDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
			        
			        List<Long> businessQCManagementDataIdList = BusinessQCManagementDataList.stream().map(m -> m.getId()).collect(Collectors.toList());

			        List<BusinessQCManagementSampleParameterDataDO> businessQCManagementSampleParameterDataDOList = businessQCManagementSampleParameterDataMapper.selectList(new LambdaQueryWrapperX<BusinessQCManagementSampleParameterDataDO>().in(BusinessQCManagementSampleParameterDataDO::getBusinessQCManagementDataId, businessQCManagementDataIdList));
			        
			        List<BusinessQCManagementProjectDataDO> businessQCManagementProjectDataList = businessQCManagementProjectDataMapper.selectByBusinessQCManagementDataIds(businessQCManagementDataIdList);
			        List<Long> businessQCManagementProjectDataIdList = businessQCManagementProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessQCManagementParameterDataDO> businessQCManagementParameterDataList = businessQCManagementParameterDataMapper.selectByBusinessQCManagementProjectDataIds(businessQCManagementProjectDataIdList);
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("project".equals(pap.getType())) {
								BusinessQCManagementProjectDataDO businessQCManagementProjectDataDO = businessQCManagementProjectDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCManagementProjectDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementProjectDataDO.setValue(pap.getValue());
											businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
											businessQCManagementProjectDataDO.setValue(value.toPlainString());
											businessQCManagementProjectDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementProjectDataDO.setValue(null);
								}
							} else if ("parameter".equals(pap.getType())) {
								BusinessQCManagementParameterDataDO businessQCManagementParameterDataDO = businessQCManagementParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCManagementParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementParameterDataDO.setValue(pap.getValue());
											businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
					                        businessQCManagementParameterDataDO.setValue(value.toPlainString());
					                        businessQCManagementParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementParameterDataDO.setValue(null);
								}
							} else if ("attribute".equals(pap.getType())) {
								BusinessQCManagementSampleParameterDataDO businessQCManagementSampleParameterDataDO = businessQCManagementSampleParameterDataDOList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCManagementSampleParameterDataDO.setValue(pap.getValue());
											businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
					                        businessQCManagementSampleParameterDataDO.setValue(value.toPlainString());
					                        businessQCManagementSampleParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCManagementSampleParameterDataDO.setValue(null);
								}
							}
						}
			            
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementSampleParameterDataDOList)) {
						businessQCManagementSampleParameterDataMapper.updateBatch(businessQCManagementSampleParameterDataDOList);
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementProjectDataList)) {
						businessQCManagementProjectDataMapper.updateBatch(businessQCManagementProjectDataList);
					}
					
					if (CollUtil.isNotEmpty(businessQCManagementParameterDataList)) {
						businessQCManagementParameterDataMapper.updateBatch(businessQCManagementParameterDataList);
					}
				} else { //不带检测项目的
					List<BusinessQCCoefficientDataDO> businessQCCoefficientDataList = businessQCCoefficientDataMapper.selectByBusinessAssayTaskId(businessAssayTaskDO.getId());
			        
			        List<Long> businessQCCoefficientDataIdList = businessQCCoefficientDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
			        
			        List<BusinessQCCoefficientParameterDataDO> businessQCCoefficientParameterDataList = businessQCCoefficientParameterDataMapper.selectByBusinessQCCoefficientDataIds(businessQCCoefficientDataIdList);
			        
					List<Map<String,Object>> datas = businessAssayTaskAnalysisDataRespVO.getDatas();
					for (Map<String, Object> map : datas) {
			            
			            List<BusinessAssayProjectAndParameterRespVO> listBusinessAssayProjectAndParameter = new ArrayList<>();
			            for (Map.Entry<String, Object> entry : map.entrySet()) {
							Object val = entry.getValue();
							if (val instanceof String || val == null) {
								continue;
							}
							BusinessAssayProjectAndParameterRespVO businessAssayProjectAndParameter = JSON.parseObject(JSON.toJSONString(val), BusinessAssayProjectAndParameterRespVO.class);
							listBusinessAssayProjectAndParameter.add(businessAssayProjectAndParameter);
						}
			            
			            for (BusinessAssayProjectAndParameterRespVO  pap : listBusinessAssayProjectAndParameter) {
							if ("parameter".equals(pap.getType())) {
								BusinessQCCoefficientParameterDataDO businessQCCoefficientParameterDataDO = businessQCCoefficientParameterDataList.stream().filter(f -> f.getId().equals(pap.getId())).findFirst().orElse(null);
								if (StringUtils.isNotBlank(pap.getValue())) {
									businessQCCoefficientParameterDataDO.setSymbol(pap.getSymbol());
									String dataType = pap.getDataType();//string-字符串，int-整数，decimal-小数,date-日期，datetime-时间
									switch (dataType) {
										case "int":
										case "date":
										case "datetime":
										case "string": 
											businessQCCoefficientParameterDataDO.setValue(pap.getValue());
											businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + pap.getValue());
											break;
										case "decimal":
											BigDecimal value = new BigDecimal(pap.getValue());
					                        value = value.setScale(pap.getDecimalPosition(), RoundingMode.HALF_EVEN);
					                        businessQCCoefficientParameterDataDO.setValue(value.toPlainString());
					                        businessQCCoefficientParameterDataDO.setRemark(pap.getShowName() + ": " + value.toPlainString());	
											break;
										default:
											throw new IllegalArgumentException("Unexpected value: " + dataType);
									}
								} else {
									businessQCCoefficientParameterDataDO.setValue(null);
								}
							}
						}
			            
					}

					if (CollUtil.isNotEmpty(businessQCCoefficientParameterDataList)) {
						businessQCCoefficientParameterDataMapper.updateBatch(businessQCCoefficientParameterDataList);
					}
					
				}
			}
			
		}
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
	}
	

	@Override
	public void submitSampleAnalysisByTaskId(Long businessAssayTaskId) {
//		String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname();
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
		businessAssayTaskDO.setTaskAssayStatus(QmsCommonConstant.SUBMITTED);
		businessAssayTaskDO.setAssaySubmitTime(LocalDateTime.now());
		businessAssayTaskDO.setFinishStatus(QmsCommonConstant.IN_PROGRESS);
		businessAssayTaskDO.setFlowStatus(QmsCommonConstant.IN_PROGRESS);
		
		//设置分析任务属性
		List<BusinessAssayTaskParameterDataDO> updateBusinessAssayTaskParameterDataDOList = new ArrayList<>();
		//设置参数值
		List<BusinessAssayParameterDataDO> updateBusinessAssayParameterDataList = new ArrayList<>();
		
		
		List<BusinessAssayTaskDataExtendRespVO> businessAssayTaskDataExtendList = businessAssayTaskDataMapper.selectExtendByBusinessAssayTaskId(businessAssayTaskId);

		//查询检测项目
		List<Long> businessAssayTaskDataIdList = businessAssayTaskDataExtendList.stream().map(m -> m.getId()).collect(Collectors.toList());
		List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(businessAssayTaskDataIdList);
		
		//子样配置id列表
		List<Long> configSubSampleIdList = businessAssayTaskDataExtendList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());

		List<Long> configAssayMethodIdList = businessAssayTaskDataExtendList.stream().map(m -> m.getConfigAssayMethodId()).distinct().collect(Collectors.toList());
		

        //子样方法配置列表
//        List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
		List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodDOList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodIds(configSubSampleIdList, configAssayMethodIdList);
        
        //循环任务，赋值
        for (BusinessAssayTaskDataExtendRespVO businessAssayTaskData : businessAssayTaskDataExtendList) {        	
        	
        	ConfigSubSampleMethodExtendRespVO configSubSampleMethod = configSubSampleMethodDOList.stream().filter(f -> f.getConfigSubSampleId().equals(businessAssayTaskData.getConfigSubSampleId()) && f.getConfigAssayMethodId().equals(businessAssayTaskData.getConfigAssayMethodId())).findFirst().orElse(null);
        	
        	if (configSubSampleMethod != null && StringUtils.isNotBlank(configSubSampleMethod.getConfigInfomation())) {
        		String configInfomation = configSubSampleMethod.getConfigInfomation();
				ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class);
				List<ConfigSubSampleMethodConfItem> setParamList = configSubSampleMethodConfInfo.getSetParam();
				if (CollUtil.isNotEmpty(setParamList)) {//参数不为空，则设置
					//方法key
    				String methodKey = setParamList.stream().map(m -> m.getTarget().getMethodKey()).distinct().findFirst().orElse(null);
    				
					//1 查询委托明细
					BusinessSampleEntrustDetailDO businessSampleEntrustDetailDO = businessSampleEntrustDetailMapper.selectByBusinessBaseSampleId(businessAssayTaskData.getBusinessBaseSampleId());
					//2 查询样品大类
					BaseSampleDO baseSampleDO = baseSampleMapper.selectById(businessSampleEntrustDetailDO.getBaseSampleId());
					
					//3 判断样品大类类型
					if (QmsCommonConstant.ENTRUST_INSPECTION_ANALYSIS_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检分析样
						//委托登记Id
						Long businessSampleEntrustRegistrationId = businessSampleEntrustDetailDO.getBusinessSampleEntrustRegistrationId();
						//查询委托登记明细
						List<BusinessSampleEntrustDetailDO> businessSampleEntrustDetailList  = businessSampleEntrustDetailMapper.selectByBusinessSampleEntrustRegistrationId(businessSampleEntrustRegistrationId);
						//获取主样Id列表
						List<Long> businessBaseSampleIdList = businessSampleEntrustDetailList.stream().map(m -> m.getBusinessBaseSampleId()).collect(Collectors.toList());
						//查询当前分析方法下对应的任务
        				List<BusinessAssayTaskDataDO> targetBusinessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessBaseSampleIdsAndMethodKey(businessBaseSampleIdList, methodKey);
        				List<Long> targetBusinessAssayTaskDataIdList = targetBusinessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        				List<BusinessAssayProjectDataExtendRespVO> targetBusinessAssayProjectDataExtendList = new ArrayList<>();
        				if (CollUtil.isNotEmpty(targetBusinessAssayTaskDataIdList)) {//如果当前分析下存在任务
        					targetBusinessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(targetBusinessAssayTaskDataIdList);
						}
        				
        				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem : setParamList) {
        					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();
        					String project = source.getProject();
        					BusinessAssayProjectDataExtendRespVO currentBusinessAssayProjectData = businessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskData.getId()) && project.equals(f.getSimpleName())).findFirst().orElse(null);
        					if (currentBusinessAssayProjectData == null) {
								continue;
							}
        					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();
        					for (BusinessAssayTaskDataDO targetBusinessAssayTaskData : targetBusinessAssayTaskDataList) {
        						if (StringUtils.isNotBlank(target.getProject())) {//检测项目参数赋值
	        						List<String> targetProjectList = Arrays.asList(target.getProject().split(","));
	        						String targetParameter = target.getParameter();
	        						for (String targetProject : targetProjectList) {
	        							BusinessAssayProjectDataExtendRespVO targetBusinessAssayProjectData = targetBusinessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(targetBusinessAssayTaskData.getId()) && targetProject.equals(f.getSimpleName())).findFirst().orElse(null);
	        							if (targetBusinessAssayProjectData == null) {
											continue;
										}
	        							BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayProjectDataIdAndProjectSimpleNameAndParameterKey(targetBusinessAssayProjectData.getId(), targetProject, targetParameter);
	        							if (businessAssayParameterDataDO != null) {
	        								businessAssayParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
	        								updateBusinessAssayParameterDataList.add(businessAssayParameterDataDO);
	        							}
	        							
	        						}
								} else if (StringUtils.isNotBlank(target.getAttribute())) {//分析任务属性赋值
									BusinessAssayTaskParameterDataDO businessAssayTaskParameterDataDO = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIdAndKey(targetBusinessAssayTaskData.getId(), target.getAttribute());
									if (businessAssayTaskParameterDataDO != null) {
										businessAssayTaskParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
										updateBusinessAssayTaskParameterDataDOList.add(businessAssayTaskParameterDataDO);
									}
									
								}
        					}
        				}
					} else if (QmsCommonConstant.ENTRUST_COMPREHENSIVE_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是商检综合样
						//查询当前分析方法下对应的任务
        				List<BusinessAssayTaskDataDO> targetBusinessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessSubSampleIdAndMethodKey(businessAssayTaskData.getBusinessSubSampleId(), methodKey);
        				List<Long> targetBusinessAssayTaskDataIdList = targetBusinessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        				List<BusinessAssayProjectDataExtendRespVO> targetBusinessAssayProjectDataExtendList = new ArrayList<>(); 
        				if (CollUtil.isNotEmpty(targetBusinessAssayTaskDataIdList)) {
        					targetBusinessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(targetBusinessAssayTaskDataIdList);
						}
        				
        				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem : setParamList) {
        					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();
        					String project = source.getProject();
        					BusinessAssayProjectDataExtendRespVO currentBusinessAssayProjectData = businessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskData.getId()) && project.equals(f.getSimpleName())).findFirst().orElse(null);
        					if (currentBusinessAssayProjectData == null) {
								continue;
							}
        					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();
        					for (BusinessAssayTaskDataDO targetBusinessAssayTaskData : targetBusinessAssayTaskDataList) {
        						if (StringUtils.isNotBlank(target.getProject())) {//检测项目参数赋值
	        						List<String> targetProjectList = Arrays.asList(target.getProject().split(","));
	        						String targetParameter = target.getParameter();
	        						for (String targetProject : targetProjectList) {
	        							BusinessAssayProjectDataExtendRespVO targetBusinessAssayProjectData = targetBusinessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(targetBusinessAssayTaskData.getId()) && targetProject.equals(f.getSimpleName())).findFirst().orElse(null);
	        							if (targetBusinessAssayProjectData == null) {
											continue;
										}
	        							BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayProjectDataIdAndProjectSimpleNameAndParameterKey(targetBusinessAssayProjectData.getId(), targetProject, targetParameter);
	        							if (businessAssayParameterDataDO != null) {
	        								businessAssayParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
	        								updateBusinessAssayParameterDataList.add(businessAssayParameterDataDO);
	        							}
	        							
	        						}
        						} else if (StringUtils.isNotBlank(target.getAttribute())) {//分析任务属性赋值
									BusinessAssayTaskParameterDataDO businessAssayTaskParameterDataDO = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIdAndKey(targetBusinessAssayTaskData.getId(), target.getAttribute());
									if (businessAssayTaskParameterDataDO != null) {
										businessAssayTaskParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
										updateBusinessAssayTaskParameterDataDOList.add(businessAssayTaskParameterDataDO);
									}
									
								}
        					}
        				}
					} else if (QmsCommonConstant.ENTRUST_COMMISSION_INSPECTION_SAMPLE.equals(baseSampleDO.getDictionaryBusinessKey())) {//如果是委检样
						//查询当前分析方法下对应的任务
        				List<BusinessAssayTaskDataDO> targetBusinessAssayTaskDataList = businessAssayTaskDataMapper.selectByBusinessSubSampleIdAndMethodKey(businessAssayTaskData.getBusinessSubSampleId(), methodKey);
        				List<Long> targetBusinessAssayTaskDataIdList = targetBusinessAssayTaskDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
        				List<BusinessAssayProjectDataExtendRespVO> targetBusinessAssayProjectDataExtendList = new ArrayList<>();
        				if (CollUtil.isNotEmpty(targetBusinessAssayTaskDataIdList)) {
        					targetBusinessAssayProjectDataExtendList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(targetBusinessAssayTaskDataIdList);
						}
        				
        				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem : setParamList) {
        					ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();
        					String project = source.getProject();
        					BusinessAssayProjectDataExtendRespVO currentBusinessAssayProjectData = businessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskData.getId()) && project.equals(f.getSimpleName())).findFirst().orElse(null);
        					if (currentBusinessAssayProjectData == null) {
								continue;
							}
        					ConfigSubSampleMethodConfPoint target = configSubSampleMethodConfItem.getTarget();
        					for (BusinessAssayTaskDataDO targetBusinessAssayTaskData : targetBusinessAssayTaskDataList) {
        						if (StringUtils.isNotBlank(target.getProject())) {//检测项目参数赋值
	        						List<String> targetProjectList = Arrays.asList(target.getProject().split(","));
	        						String targetParameter = target.getParameter();
	        						for (String targetProject : targetProjectList) {
	        							BusinessAssayProjectDataExtendRespVO targetBusinessAssayProjectData = targetBusinessAssayProjectDataExtendList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(targetBusinessAssayTaskData.getId()) && targetProject.equals(f.getSimpleName())).findFirst().orElse(null);
	        							if (targetBusinessAssayProjectData == null) {
											continue;
										}
	        							BusinessAssayParameterDataDO businessAssayParameterDataDO = businessAssayParameterDataMapper.selectByBusinessAssayProjectDataIdAndProjectSimpleNameAndParameterKey(targetBusinessAssayProjectData.getId(), targetProject, targetParameter);
	        							if (businessAssayParameterDataDO != null && StringUtils.isBlank(businessAssayParameterDataDO.getValue())) {//值为空，才赋值
	        								businessAssayParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
	        								updateBusinessAssayParameterDataList.add(businessAssayParameterDataDO);
	        							}
	        							
	        						}
        						} else if (StringUtils.isNotBlank(target.getAttribute())) {//分析任务属性赋值
									BusinessAssayTaskParameterDataDO businessAssayTaskParameterDataDO = businessAssayTaskParameterDataMapper.selectByBusinessAssayTaskDataIdAndKey(targetBusinessAssayTaskData.getId(), target.getAttribute());
									if (businessAssayTaskParameterDataDO != null) {
										businessAssayTaskParameterDataDO.setValue(currentBusinessAssayProjectData.getValue());
										updateBusinessAssayTaskParameterDataDOList.add(businessAssayTaskParameterDataDO);
									}
									
								}
        					}
        				}
						
					}
				}
			}
		}

		//补正系数列表
		List<ConfigAssayMethodProjectCoefficientDO> configAssayMethodProjectCoefficientList = new ArrayList<>();
		if (businessAssayTaskDO.getIsIngredients().equals(QmsCommonConstant.YES) && QmsCommonConstant.MANUAL.equals(businessAssayTaskDO.getIngredientsWay())) {//如果是需要配料，并且是人工配料的
			List<Long> configBaseSampleIdList = businessAssayTaskDataExtendList.stream().map(m -> m.getConfigBaseSampleId()).distinct().collect(Collectors.toList());
			configAssayMethodProjectCoefficientList = configAssayMethodProjectCoefficientMapper.selectByConfigBaseSampleIds(configBaseSampleIdList);
		}
		
		for (BusinessAssayProjectDataExtendRespVO businessAssayProjectDataExtend : businessAssayProjectDataExtendList) {
			if (businessAssayTaskDO.getIsIngredients().equals(QmsCommonConstant.YES) && QmsCommonConstant.MANUAL.equals(businessAssayTaskDO.getIngredientsWay())) {
				ConfigAssayMethodProjectCoefficientDO configAssayMethodProjectCoefficientDO = configAssayMethodProjectCoefficientList.stream().filter(f -> 
						businessAssayProjectDataExtend.getConfigBaseSampleId().equals(f.getConfigBaseSampleId()) 
						&& businessAssayTaskDO.getConfigAssayMethodId().equals(f.getConfigAssayMethodId()) 
						&& businessAssayProjectDataExtend.getConfigAssayMethodProjectId().equals(f.getConfigAssayMethodProjectId())
						&& new BigDecimal(businessAssayProjectDataExtend.getValue()).compareTo(new BigDecimal(f.getMinimumValue())) > 0
						&& new BigDecimal(businessAssayProjectDataExtend.getValue()).compareTo(new BigDecimal(f.getMaximumValue())) <= 0
						).findFirst().orElse(null);
				if (configAssayMethodProjectCoefficientDO != null) {
					businessAssayProjectDataExtend.setConfigAssayMethodProjectCoefficientId(configAssayMethodProjectCoefficientDO.getId());//补正系数的id
					businessAssayProjectDataExtend.setCoefficient(configAssayMethodProjectCoefficientDO.getCoefficient());//补正系数
					String valueAfter = new BigDecimal(businessAssayProjectDataExtend.getValue()).multiply(configAssayMethodProjectCoefficientDO.getCoefficient()).setScale(businessAssayProjectDataExtend.getDecimalPosition(), RoundingMode.HALF_EVEN).toPlainString();
					businessAssayProjectDataExtend.setValueAfter(valueAfter);//补正后的值
				} else { //未找到补正系数，默认为1
					businessAssayProjectDataExtend.setCoefficient(new BigDecimal("1"));
					businessAssayProjectDataExtend.setValueAfter(businessAssayProjectDataExtend.getValue());
				}
			} else {
				businessAssayProjectDataExtend.setValueAfter(businessAssayProjectDataExtend.getValue());//不需要配料，补正后的值与补正前一致
			}
		}
		if (businessAssayProjectDataExtendList.size() > 0) {
			List<BusinessAssayProjectDataDO> businessAssayProjectDataList = BeanUtils.toBean(businessAssayProjectDataExtendList, BusinessAssayProjectDataDO.class);
			businessAssayProjectDataMapper.updateBatch(businessAssayProjectDataList);
		}
		
		if (updateBusinessAssayTaskParameterDataDOList.size() > 0) {
			businessAssayTaskParameterDataMapper.updateBatch(updateBusinessAssayTaskParameterDataDOList);
		}
		
		if (updateBusinessAssayParameterDataList.size() > 0) {
			businessAssayParameterDataMapper.updateBatch(updateBusinessAssayParameterDataList);
		}
		
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
	}

	@Override
	public JSONObject getSampleAnalysisDataByTaskDataId(Long businessAssayTaskDataId) {
		JSONObject resultJsonObject = new JSONObject();
		
		BusinessAssayTaskDataExtendRespVO businessAssayTaskData = businessAssayTaskDataMapper.selectExtendRespById(businessAssayTaskDataId);
		if (businessAssayTaskData == null) {
			throw new ServiceException(1_032_100_000, "未找到检测任务业务数据，请检查参数是否正确");
		}
		
		resultJsonObject = (JSONObject) JSON.toJSON(businessAssayTaskData);

        List<Map<String, Object>> columns = new ArrayList<>();
        
        BusinessAssayProjectDataReqVO projectDataSearch = new BusinessAssayProjectDataReqVO();
        projectDataSearch.setBusinessAssayTaskDataId(businessAssayTaskDataId);
        List<BusinessAssayProjectAndParameterRespVO> projectAndParameterList = businessAssayProjectDataMapper.selectProjectAndParameterBy(projectDataSearch);
        for (BusinessAssayProjectAndParameterRespVO ep : projectAndParameterList) {
        	final String eTitle = ep.getShowName() + (StringUtils.isBlank(ep.getUnit()) ? "" : "(" + ep.getUnit() + ")");
        	
        	columns.add(new HashMap<>() {
				private static final long serialVersionUID = 1L;
			{
        		put("title", eTitle);
        		put("value", ep.getValue());
        	}});
        	
        	if (StringUtils.isNotEmpty(ep.getFormula())) {
        		BusinessAssayParameterDataReqVO parameterDataSearch = new BusinessAssayParameterDataReqVO();
        		parameterDataSearch.setBusinessAssayProjectDataId(ep.getId());
                List<BusinessAssayProjectAndParameterRespVO> plist = businessAssayParameterDataMapper.selectProjectAndParameterBy(parameterDataSearch);
                for (BusinessAssayProjectAndParameterRespVO p : plist) {
                	final String pTitle = p.getShowName() + (StringUtils.isBlank(p.getUnit()) ? "" : "(" + p.getUnit() + ")");
                	columns.add(new HashMap<>() {
						private static final long serialVersionUID = 8422574140192155301L;
					{
                		put("title", pTitle);
                		put("value", p.getValue());
                	}});
				}
			}
		}
        resultJsonObject.put("columns", columns);
		return resultJsonObject;
	}

	@Override
	public void rollbackAnalysisSample(BusinessAssayTaskBackSampleReqVO req) {
		LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
		String loginUserNickname = SecurityFrameworkUtils.getLoginUserNickname();
		List<BusinessAssayTaskDetailDO> businessAssayTaskDetailList = businessAssayTaskDetailMapper.selectByIds(req.getIdList());
		for (BusinessAssayTaskDetailDO businessAssayTaskDetailDO : businessAssayTaskDetailList) {
			
			businessAssayTaskDetailDO.setRollbackStatus("returned");
			businessAssayTaskDetailDO.setRemark(req.getBackDesc());
		}
		List<Long> businessAssayTaskDataIdList = businessAssayTaskDetailList.stream().map(m -> m.getBusinessAssayTaskDataId()).collect(Collectors.toList());
		List<BusinessAssayTaskDataDO> businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByIds(businessAssayTaskDataIdList);
		for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataDOList) {
			businessAssayTaskDataDO.setBusinessAssayTaskId(null);
	    	businessAssayTaskDataDO.setAssayOperatorId(null);
	    	businessAssayTaskDataDO.setAssayOperator(null);
	    	businessAssayTaskDataDO.setAssignTaskTime(null);
	    	businessAssayTaskDataDO.setIsAssignTasked(0);
	    	
	    	BusinessAssayTaskDataExternalInfomation businessAssayTaskDataExternalInfomation = null;
	    	String externalInfomation = businessAssayTaskDataDO.getExternalInfomation();
	    	if (StringUtils.isNotBlank(externalInfomation)) {
	    		businessAssayTaskDataExternalInfomation = JSON.parseObject(externalInfomation, BusinessAssayTaskDataExternalInfomation.class);
			} else {
				businessAssayTaskDataExternalInfomation = new BusinessAssayTaskDataExternalInfomation();
			}
	    	
	    	businessAssayTaskDataExternalInfomation.setIsRollback(QmsCommonConstant.YES);
	    	
	    	List<RollbackDetail> rollbackDetailList = businessAssayTaskDataExternalInfomation.getRollbackDetailList();
	    	if (CollUtil.isEmpty(rollbackDetailList)) {
	    		rollbackDetailList = new ArrayList<>();
			}
	    	//回退详情
	    	RollbackDetail rollbackDetail = new RollbackDetail();
	    	rollbackDetail.setRollbackOperId(loginUser.getId());
	    	rollbackDetail.setRollbackOper(loginUserNickname);
	    	rollbackDetail.setRollbackReason(req.getBackDesc());
	    	rollbackDetail.setRollbackTime(DateUtil.formatLocalDateTime(LocalDateTime.now()));
	    	rollbackDetailList.add(rollbackDetail);
	    	
	    	businessAssayTaskDataExternalInfomation.setRollbackDetailList(rollbackDetailList);
	    	businessAssayTaskDataDO.setExternalInfomation(JSON.toJSONString(businessAssayTaskDataExternalInfomation));
	    	
		}
		//任务id
		Long businessAssayTaskId = businessAssayTaskDetailList.stream().map(m -> m.getBusinessAssayTaskId()).distinct().findFirst().orElse(null);
		//查询任务下的明细
		Long taskCount = businessAssayTaskDetailMapper.selectCountByBusinessAssayTaskId(businessAssayTaskId);
		if (businessAssayTaskDetailList.size() == taskCount.intValue()) {//如果回退所有样品，则作废任务
			BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
			businessAssayTaskDO.setTaskAssignStatus(QmsCommonConstant.VOID);
			
			businessAssayTaskMapper.updateById(businessAssayTaskDO);
		}
		
		//明细处理
		if (CollUtil.isNotEmpty(businessAssayTaskDetailList)) {
			businessAssayTaskDetailMapper.updateBatch(businessAssayTaskDetailList);
		}
		//任务明细处理
		if (CollUtil.isNotEmpty(businessAssayTaskDataDOList)) {
			businessAssayTaskDataMapper.updateBatch(businessAssayTaskDataDOList);
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void issuedIngredients(Long businessAssayTaskId) {
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
		List<BusinessAssayTaskDataDO> businessAssayTaskDataDOList = businessAssayTaskDataMapper.selectByBusinessAssayTaskId(businessAssayTaskId);
		List<Long> businessAssayTaskDataIdList = businessAssayTaskDataDOList.stream().map(m -> m.getId()).collect(Collectors.toList());
		//获取子样id列表
		List<Long> businessSubSampleIdList = businessAssayTaskDataDOList.stream().map(m -> m.getBusinessSubSampleId()).distinct().collect(Collectors.toList());
		List<Long> configAssayMethodIdList = businessAssayTaskDataDOList.stream().map(m -> m.getConfigAssayMethodId()).distinct().collect(Collectors.toList());
		//获取子样
		List<BusinessSubSampleDO> businessSubSampleDOList = businessSubSampleMapper.selectByIds(businessSubSampleIdList);
		//子样配置id列表
		List<Long> configSubSampleIdList = businessSubSampleDOList.stream().map(m -> m.getConfigSubSampleId()).distinct().collect(Collectors.toList());
		//子样配置方法
//		List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodId(configSubSampleIdList, businessAssayTaskDO.getConfigAssayMethodId());
		List<ConfigSubSampleMethodExtendRespVO> configSubSampleMethodList = configSubSampleMethodMapper.selectByConfigSubSampleIdsAndConfigAssayMethodIds(configSubSampleIdList, configAssayMethodIdList);

		//查询分析任务属性
		List<BusinessAssayTaskParameterDataExtendRespVO> businessAssayTaskParameterDataList = businessAssayTaskParameterDataMapper.selectExtendByBusinessAssayTaskDataIds(businessAssayTaskDataIdList);
		
		//查询检测项目
		List<BusinessAssayProjectDataExtendRespVO> businessAssayProjectDataList = businessAssayProjectDataMapper.selectByBusinessAssayTaskDataIds(businessAssayTaskDataIdList);
		List<Long> businessAssayProjectDataIdList = businessAssayProjectDataList.stream().map(m -> m.getId()).collect(Collectors.toList());
		//查询检测项目参数
		List<BusinessAssayParameterDataExtendRespVO> businessAssayParameterDataList = businessAssayParameterDataMapper.selectExtendByBusinessAssayProjectDataIds(businessAssayProjectDataIdList);

		for (BusinessAssayTaskDataDO businessAssayTaskDataDO : businessAssayTaskDataDOList) {
			//获取子样
			BusinessSubSampleDO businessSubSampleDO = businessSubSampleDOList.stream().filter(f -> f.getId().equals(businessAssayTaskDataDO.getBusinessSubSampleId())).findFirst().orElse(null);
			
			//子样配置信息
			ConfigSubSampleMethodExtendRespVO configSubSampleMethodDO = configSubSampleMethodList.stream().filter(f -> f.getConfigSubSampleId().equals(businessSubSampleDO.getConfigSubSampleId()) && f.getConfigAssayMethodId().equals(businessAssayTaskDataDO.getConfigAssayMethodId())).findFirst().orElse(null);
			String configInfomation = configSubSampleMethodDO.getConfigInfomation();
			if (StringUtils.isNotBlank(configInfomation)) {
				ConfigSubSampleMethodConfInfo configSubSampleMethodConfInfo = JSON.parseObject(configInfomation, ConfigSubSampleMethodConfInfo.class);
				//获取下发配置
				List<ConfigSubSampleMethodConfItem> downIngredients = configSubSampleMethodConfInfo.getDownIngredients();
				for (ConfigSubSampleMethodConfItem configSubSampleMethodConfItem : downIngredients) {
					if (configSubSampleMethodConfItem.getRequired()) {
						ConfigSubSampleMethodConfPoint source = configSubSampleMethodConfItem.getSource();
						if (StringUtils.isNotBlank(source.getProject())) {//来自检测项目参数
							List<String> projectList = Arrays.asList(source.getProject().split(","));//来源可以有多个
							for (String project : projectList) {
								String parameter = source.getParameter();
								BusinessAssayProjectDataExtendRespVO currentBusinessAssayProjectData = businessAssayProjectDataList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId()) &&  f.getSimpleName().equals(project)).findFirst().orElse(null);
								BusinessAssayParameterDataExtendRespVO currentBusinessAssayParameterData = businessAssayParameterDataList.stream().filter(f -> f.getBusinessAssayProjectDataId().equals(currentBusinessAssayProjectData.getId()) && f.getParameterKey().equals(parameter)).findFirst().orElse(null);
								if (currentBusinessAssayParameterData != null && StringUtils.isBlank(currentBusinessAssayParameterData.getValue())) {
									throw new ServiceException(1_032_050_000, "当前分析任务，存在下发配料必填为空情况。请检查后再下发！");
								}
							}
						} else if (StringUtils.isNotBlank(source.getAttribute())) {//来自分析任务属性
							BusinessAssayTaskParameterDataExtendRespVO currentbAssayTaskParameterData = businessAssayTaskParameterDataList.stream().filter(f -> f.getBusinessAssayTaskDataId().equals(businessAssayTaskDataDO.getId()) && f.getKey().equals(source.getAttribute())).findFirst().orElse(null);
							if (currentbAssayTaskParameterData != null && StringUtils.isBlank(currentbAssayTaskParameterData.getValue())) {
								throw new ServiceException(1_032_050_000, "当前分析任务，存在下发配料必填为空情况。请检查后再下发！");
							}
						}
					}
				}
				
			}
		}
		businessAssayTaskDO.setIngredientsWay(QmsCommonConstant.AUTOMATIC);//自动火试金配料
		businessAssayTaskDO.setIngredientsStatus(QmsCommonConstant.IN_PROGRESS);
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void manualIngredients(Long businessAssayTaskId) {
		BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
		businessAssayTaskDO.setIngredientsWay(QmsCommonConstant.MANUAL);//人工配料
		businessAssayTaskDO.setIngredientsStatus(QmsCommonConstant.ALLOW_SUBMIT);//表示为允许提交
		businessAssayTaskMapper.updateById(businessAssayTaskDO);
	}

}
