package com.zt.plat.module.qms.business.bus.dal.mapper;

import java.util.*;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.business.bus.controller.vo.*;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayProjectDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessBaseSampleDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleAnalysisGroupDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodProjectDO;
import com.zt.plat.module.qms.business.dic.dal.dataobject.DictionaryProjectDO;
import com.zt.plat.module.qms.common.dic.dal.dataobject.DictionaryBusinessDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;

import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 检测项目数据业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessAssayProjectDataMapper extends BaseMapperX<BusinessAssayProjectDataDO> {
	
	default List<BusinessAssayProjectAndParameterRespVO> selectProjectAndParameterBy(BusinessAssayProjectDataReqVO reqVO) {
		return selectJoinList(BusinessAssayProjectAndParameterRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
				.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessAssayProjectDataDO::getConfigAssayMethodProjectId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, ConfigAssayMethodProjectDO::getDictionaryBusinessId)
				.selectAs(BusinessAssayProjectDataDO::getId, BusinessAssayProjectAndParameterRespVO::getId)
				.selectAs(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, BusinessAssayProjectAndParameterRespVO::getBizId)
				.selectAs(BusinessAssayProjectDataDO::getDictionaryProjectId, BusinessAssayProjectAndParameterRespVO::getDicId)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectAndParameterRespVO::getDicKey)
				//.selectAs(DictionaryProjectDO::getName, BusinessAssayProjectAndParameterRespVO::getName)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectAndParameterRespVO::getName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectAndParameterRespVO::getShowName)
				.selectAs(BusinessAssayProjectDataDO::getDataType, BusinessAssayProjectAndParameterRespVO::getDataType)
				.selectAs(BusinessAssayProjectDataDO::getDecimalPosition, BusinessAssayProjectAndParameterRespVO::getDecimalPosition)
				.selectAs(BusinessAssayProjectDataDO::getEffectiveDigit, BusinessAssayProjectAndParameterRespVO::getEffectiveDigit)
				.selectAs(BusinessAssayProjectDataDO::getValue, BusinessAssayProjectAndParameterRespVO::getValue)
				.selectAs(BusinessAssayProjectDataDO::getSymbol, BusinessAssayProjectAndParameterRespVO::getSymbol)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessAssayProjectAndParameterRespVO::getUnit)
				.selectAs(ConfigAssayMethodProjectDO::getIsNull, BusinessAssayProjectAndParameterRespVO::getIsNull)
				.selectAs(ConfigAssayMethodProjectDO::getFormula, BusinessAssayProjectAndParameterRespVO::getFormula)
				.selectAs(ConfigAssayMethodProjectDO::getSortNo, BusinessAssayProjectAndParameterRespVO::getParamNo)
				.selectAs("'project'", BusinessAssayProjectAndParameterRespVO::getType)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryBusinessId, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessId)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryBusinessKey, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessKey)
				.selectAs(DictionaryBusinessDO::getName, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessName)
                .eqIfPresent(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, reqVO.getBusinessAssayTaskDataId())
                .inIfPresent(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, reqVO.getBusinessAssayTaskDataIdList())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getUsage, reqVO.getUsage())
                .eqIfPresent(BusinessAssayProjectDataDO::getSymbol, reqVO.getSymbol())
                .eqIfPresent(BusinessAssayProjectDataDO::getValue, reqVO.getValue())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectCoefficientId, reqVO.getConfigAssayMethodProjectCoefficientId())
                .eqIfPresent(BusinessAssayProjectDataDO::getCoefficient, reqVO.getCoefficient())
                .eqIfPresent(BusinessAssayProjectDataDO::getValueAfter, reqVO.getValueAfter())
                .eqIfPresent(BusinessAssayProjectDataDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessAssayProjectDataDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessAssayProjectDataDO::getEffectiveDigit, reqVO.getEffectiveDigit())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsNotAssessment, reqVO.getIsNotAssessment())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsEnabled, reqVO.getIsEnabled())
                .eqIfPresent(BusinessAssayProjectDataDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessAssayProjectDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessAssayProjectDataDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessAssayProjectDataDO::getRemark, reqVO.getRemark())
                .orderByAsc(ConfigAssayMethodProjectDO::getSortNo));
	}

	default List<BusinessAssayProjectAndParameterRespVO> selectProjectAndParameterByOld(BusinessAssayProjectDataReqVO reqVO) {
		return selectJoinList(BusinessAssayProjectAndParameterRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
				.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessAssayProjectDataDO::getConfigAssayMethodProjectId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.leftJoin(DictionaryBusinessDO.class, DictionaryBusinessDO::getId, ConfigAssayMethodProjectDO::getDictionaryBusinessId)
				.selectAs(BusinessAssayProjectDataDO::getId, BusinessAssayProjectAndParameterRespVO::getId)
				.selectAs(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, BusinessAssayProjectAndParameterRespVO::getBizId)
				.selectAs(BusinessAssayProjectDataDO::getConfigAssayMethodProjectId, BusinessAssayProjectAndParameterRespVO::getDicId)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectAndParameterRespVO::getDicKey)
				//.selectAs(DictionaryProjectDO::getName, BusinessAssayProjectAndParameterRespVO::getName)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectAndParameterRespVO::getName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectAndParameterRespVO::getShowName)
				.selectAs(BusinessAssayProjectDataDO::getDataType, BusinessAssayProjectAndParameterRespVO::getDataType)
				.selectAs(BusinessAssayProjectDataDO::getDecimalPosition, BusinessAssayProjectAndParameterRespVO::getDecimalPosition)
				.selectAs(BusinessAssayProjectDataDO::getEffectiveDigit, BusinessAssayProjectAndParameterRespVO::getEffectiveDigit)
				.selectAs(BusinessAssayProjectDataDO::getValue, BusinessAssayProjectAndParameterRespVO::getValue)
				.selectAs(BusinessAssayProjectDataDO::getSymbol, BusinessAssayProjectAndParameterRespVO::getSymbol)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessAssayProjectAndParameterRespVO::getUnit)
				.selectAs(ConfigAssayMethodProjectDO::getIsNull, BusinessAssayProjectAndParameterRespVO::getIsNull)
				.selectAs(ConfigAssayMethodProjectDO::getFormula, BusinessAssayProjectAndParameterRespVO::getFormula)
				.selectAs(ConfigAssayMethodProjectDO::getSortNo, BusinessAssayProjectAndParameterRespVO::getParamNo)
				.selectAs("'project'", BusinessAssayProjectAndParameterRespVO::getType)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryBusinessId, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessId)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryBusinessKey, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessKey)
				.selectAs(DictionaryBusinessDO::getName, BusinessAssayProjectAndParameterRespVO::getGroupDictionaryBusinessName)
                .eqIfPresent(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, reqVO.getBusinessAssayTaskDataId())
                .inIfPresent(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, reqVO.getBusinessAssayTaskDataIdList())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getUsage, reqVO.getUsage())
                .eqIfPresent(BusinessAssayProjectDataDO::getSymbol, reqVO.getSymbol())
                .eqIfPresent(BusinessAssayProjectDataDO::getValue, reqVO.getValue())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectCoefficientId, reqVO.getConfigAssayMethodProjectCoefficientId())
                .eqIfPresent(BusinessAssayProjectDataDO::getCoefficient, reqVO.getCoefficient())
                .eqIfPresent(BusinessAssayProjectDataDO::getValueAfter, reqVO.getValueAfter())
                .eqIfPresent(BusinessAssayProjectDataDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessAssayProjectDataDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessAssayProjectDataDO::getEffectiveDigit, reqVO.getEffectiveDigit())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsNotAssessment, reqVO.getIsNotAssessment())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsEnabled, reqVO.getIsEnabled())
                .eqIfPresent(BusinessAssayProjectDataDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessAssayProjectDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessAssayProjectDataDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessAssayProjectDataDO::getRemark, reqVO.getRemark())
                .orderByAsc(ConfigAssayMethodProjectDO::getSortNo));
	}

    default PageResult<BusinessAssayProjectDataDO> selectPage(BusinessAssayProjectDataPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessAssayProjectDataDO>()
                .eqIfPresent(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, reqVO.getBusinessAssayTaskDataId())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessAssayProjectDataDO::getUsage, reqVO.getUsage())
                .eqIfPresent(BusinessAssayProjectDataDO::getSymbol, reqVO.getSymbol())
                .eqIfPresent(BusinessAssayProjectDataDO::getValue, reqVO.getValue())
                .eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectCoefficientId, reqVO.getConfigAssayMethodProjectCoefficientId())
                .eqIfPresent(BusinessAssayProjectDataDO::getCoefficient, reqVO.getCoefficient())
                .eqIfPresent(BusinessAssayProjectDataDO::getValueAfter, reqVO.getValueAfter())
                .eqIfPresent(BusinessAssayProjectDataDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessAssayProjectDataDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessAssayProjectDataDO::getEffectiveDigit, reqVO.getEffectiveDigit())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsNotAssessment, reqVO.getIsNotAssessment())
                .eqIfPresent(BusinessAssayProjectDataDO::getAssessmentType, reqVO.getAssessmentType())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsCancelAssessment, reqVO.getIsCancelAssessment())
                .eqIfPresent(BusinessAssayProjectDataDO::getIsEnabled, reqVO.getIsEnabled())
                .eqIfPresent(BusinessAssayProjectDataDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessAssayProjectDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessAssayProjectDataDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessAssayProjectDataDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessAssayProjectDataDO::getId));
    }
    
	default List<BusinessAssayProjectDataExtendRespVO> selectList(BusinessAssayProjectDataReqVO reqVO) {
		MPJLambdaWrapper<BusinessAssayProjectDataDO> mpjLambdaWrapper = new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
		.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
		.leftJoin(BusinessSubSampleAnalysisGroupDO.class, on -> on
				.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, BusinessAssayTaskDataDO::getAssayDepartmentId))
		.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessAssayProjectDataDO::getConfigAssayMethodProjectId)
		.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessAssayTaskDataDO::getConfigAssayMethodId)
		.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
		.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
		.selectAll(BusinessAssayProjectDataDO.class)
		.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectUnit)
		.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
		.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
		.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
		.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
		.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
		.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
		.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
		.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
		.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
		.selectAs(BusinessAssayTaskDataDO::getSampleFlowNodeKey, BusinessAssayProjectDataExtendRespVO::getSampleFlowNodeKey)
		.selectAs(BusinessAssayTaskDataDO::getSampleFlowNodeTime, BusinessAssayProjectDataExtendRespVO::getSampleFlowNodeTime)
		.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
		.selectAs(ConfigAssayMethodDO::getName, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodName)
		.selectAs(ConfigAssayMethodDO::getMethodNameCategory, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodNameAndCategory)
		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayProjectDataExtendRespVO::getSampleName)
		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayProjectDataExtendRespVO::getSampleCode)
		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayProjectDataExtendRespVO::getSampleAssayCode)
		.selectAs(BusinessSubSampleDO::getSampleReturnCode, BusinessAssayProjectDataExtendRespVO::getSampleReturnCode);

	    if (ObjectUtil.isNotEmpty(reqVO.getAssayDepartmentId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, reqVO.getAssayDepartmentId());
		}
	    
	    if (ObjectUtil.isNotEmpty(reqVO.getIsAssignTasked())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsAssignTasked, reqVO.getIsAssignTasked());
		}

	    if (ObjectUtil.isNotEmpty(reqVO.getSampleName())) {
	    	mpjLambdaWrapper.like(BusinessSubSampleDO::getSampleName, reqVO.getSampleName());
		}
	    
	    if (ObjectUtil.isNotEmpty(reqVO.getSampleAssayCode())) {
	    	mpjLambdaWrapper.like(BusinessSubSampleDO::getSampleAssayCode, reqVO.getSampleAssayCode());
		}
	    
    	if (ObjectUtil.isNotEmpty(reqVO.getSampleFlowNodeKey())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getSampleFlowNodeKey, reqVO.getSampleFlowNodeKey());
		}
    	
    	if (ObjectUtil.isNotEmpty(reqVO.getSampleFlowNodeTime()) && ObjectUtil.isNotEmpty(reqVO.getSampleFlowNodeTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getSampleFlowNodeTime()[1])) {
    		mpjLambdaWrapper.between(BusinessSubSampleDO::getSampleFlowNodeTime, reqVO.getSampleFlowNodeTime()[0], reqVO.getSampleFlowNodeTime()[1]);
		}
	    
	    if (ObjectUtil.isAllNotEmpty(reqVO.getDictionaryProjectIdList()) && !ArrayUtil.isEmpty(reqVO.getDictionaryProjectIdList())) {
	    	mpjLambdaWrapper.in(BusinessAssayProjectDataDO::getDictionaryProjectId, reqVO.getDictionaryProjectIdList());
        }
	    
	    if (ObjectUtil.isNotEmpty(reqVO.getSampleStatus())) {
    		mpjLambdaWrapper.eq(BusinessSubSampleAnalysisGroupDO::getSampleStatus, reqVO.getSampleStatus());
		}
		
		mpjLambdaWrapper.orderByAsc(BusinessAssayTaskDataDO::getSampleFlowNodeTime)
        .orderByAsc("NVL(REGEXP_SUBSTR(SMP_ASY_CD, '^(.*-)'), SMP_ASY_CD)")
        .orderByAsc("CASE WHEN INSTR(SMP_ASY_CD, '-') = 0 THEN 0 WHEN REGEXP_LIKE(REGEXP_SUBSTR(SMP_ASY_CD, '[^-]+$'), '[^0-9]') THEN 9999999 ELSE CAST(REGEXP_SUBSTR(SMP_ASY_CD, '[^-]+$') AS BIGINT) END");
		
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, mpjLambdaWrapper);
	}
    
    default List<BusinessAssayProjectDataExtendRespVO> selectByBusinessAssayTaskId(Long businessAssayTaskId) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
    			.eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId)
    			.eq(BusinessAssayProjectDataDO::getIsEnabled, QmsCommonConstant.YES));
    }
    
    default List<BusinessAssayProjectDataExtendRespVO> selectByBusinessAssayTaskDataId(Long businessAssayTaskDataId) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
				.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
				.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
				.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
				.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
    			.eq(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataId));
    }
    
    default List<BusinessAssayProjectDataExtendRespVO> selectByBusinessBaseSampleIdAndConfigAssayMethodId(Long businessBaseSampleId, Long configAssayMethodId) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
				.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
				.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
				.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
				.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
    			.eq(BusinessAssayTaskDataDO::getBusinessBaseSampleId, businessBaseSampleId)
    			.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId));
    }
    
    default List<BusinessAssayProjectDataExtendRespVO> selectByBusinessAssayTaskDataIds(List<Long> businessAssayTaskDataIds) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
    			.leftJoin(BusinessBaseSampleDO.class, BusinessBaseSampleDO::getId, BusinessAssayTaskDataDO::getBusinessBaseSampleId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
				.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
				.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
				.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
				.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
				.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
				.selectAs(BusinessBaseSampleDO::getConfigBaseSampleId, BusinessAssayProjectDataExtendRespVO::getConfigBaseSampleId)
    			.in(BusinessAssayProjectDataDO::getBusinessAssayTaskDataId, businessAssayTaskDataIds));
    }
    
    default List<BusinessAssayProjectDataExtendRespVO> selectAnalysisBy(BusinessAssayProjectDataReqVO reqVO) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessAssayProjectDataDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
    			.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectUnit)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
				.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
				.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
				.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
				.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
				.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
				.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayProjectDataExtendRespVO::getSampleName)
				.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayProjectDataExtendRespVO::getSampleCode)
				.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayProjectDataExtendRespVO::getSampleAssayCode)
				.selectAs(BusinessSubSampleDO::getSampleReturnCode, BusinessAssayProjectDataExtendRespVO::getSampleReturnCode)
				.eqIfPresent(BusinessAssayTaskDataDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId())
				.eqIfPresent(BusinessAssayTaskDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
				.eqIfPresent(BusinessAssayProjectDataDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
				.orderByAsc(BusinessAssayTaskDataDO::getRecheckCount)
				.orderByAsc(BusinessAssayTaskDataDO::getAssayOperator));
    }
    
    default List<BusinessAssayProjectDataExtendRespVO> selectExtendByIds(List<Long> idList) {
    	return selectJoinList(BusinessAssayProjectDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayProjectDataDO>()
    			.leftJoin(BusinessAssayTaskDataDO.class, BusinessAssayTaskDataDO::getId, BusinessAssayProjectDataDO::getBusinessAssayTaskDataId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessAssayProjectDataDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessAssayProjectDataDO::getDictionaryProjectId)
    			.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.selectAll(BusinessAssayProjectDataDO.class)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectUnit)
				.selectAs(DictionaryProjectDO::getKey, BusinessAssayProjectDataExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessAssayProjectDataExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessAssayProjectDataExtendRespVO::getShowName)
				.selectAs(BusinessAssayTaskDataDO::getAssayOperator, BusinessAssayProjectDataExtendRespVO::getAssayOperator)
				.selectAs(BusinessAssayTaskDataDO::getRecheckCount, BusinessAssayProjectDataExtendRespVO::getRecheckCount)
				.selectAs(BusinessAssayTaskDataDO::getRetestCount, BusinessAssayProjectDataExtendRespVO::getRetestCount)
				.selectAs(BusinessAssayTaskDataDO::getBusinessBaseSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessBaseSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubParentSampleId)
				.selectAs(BusinessAssayTaskDataDO::getBusinessSubSampleId, BusinessAssayProjectDataExtendRespVO::getBusinessSubSampleId)
				.selectAs(BusinessAssayTaskDataDO::getConfigAssayMethodId, BusinessAssayProjectDataExtendRespVO::getConfigAssayMethodId)
				.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayProjectDataExtendRespVO::getSampleName)
				.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayProjectDataExtendRespVO::getSampleCode)
				.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayProjectDataExtendRespVO::getSampleAssayCode)
				.selectAs(BusinessSubSampleDO::getSampleReturnCode, BusinessAssayProjectDataExtendRespVO::getSampleReturnCode)
				.in(BusinessAssayProjectDataDO::getId, idList));
    	
    }

	List<AssayMethodProjectRespVO> selectAssayMethodProjectByBusinessSubSampleIdListAndConfigAssayMethodId(@Param("businessSubSampleIdList")List<Long> businessSubSampleIdList, @Param("configAssayMethodId") Long configAssayMethodId);



}