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

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.controller.vo.BusinessAssayTaskDataExtendRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataGroupRespVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataPageReqVO;
import com.zt.plat.module.qms.business.bus.controller.vo.BusinessAssayTaskDataReqVO;
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.BusinessSubSampleAssessmentDO;
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.enums.QmsCommonConstant;

import cn.hutool.core.collection.CollUtil;
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 BusinessAssayTaskDataMapper extends BaseMapperX<BusinessAssayTaskDataDO> {
	
	default List<BusinessAssayTaskDataExtendRespVO> selectList(BusinessAssayTaskDataReqVO reqVO) {
		MPJLambdaWrapper<BusinessAssayTaskDataDO> mpjLambdaWrapper = new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
		.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessAssayTaskDataDO::getConfigAssayMethodId)
		.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
		.leftJoin(BusinessSubSampleAnalysisGroupDO.class, on -> on
				.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, BusinessAssayTaskDataDO::getAssayDepartmentId))
		.selectAll(BusinessAssayTaskDataDO.class)
		.selectAs(ConfigAssayMethodDO::getName, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodName)
		.selectAs(ConfigAssayMethodDO::getMethodNameCategory, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodNameAndCategory)
		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
		.selectAs(BusinessSubSampleDO::getConfigSubSampleId, BusinessAssayTaskDataExtendRespVO::getConfigSubSampleId);
    	if (ObjectUtil.isNotEmpty(reqVO.getBusinessBaseSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubParentSampleId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId());			
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessAssayTaskId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, reqVO.getBusinessAssayTaskId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubSampleAssessmentId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubSampleAssessmentId, reqVO.getBusinessSubSampleAssessmentId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getTaskType())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getTaskType, reqVO.getTaskType());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getAssayType())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayType, reqVO.getAssayType());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayProject())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayProject, reqVO.getAssayProject());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayDepartmentId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, reqVO.getAssayDepartmentId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayDepartmentName())) {
    		mpjLambdaWrapper.like(BusinessAssayTaskDataDO::getAssayDepartmentName, reqVO.getAssayDepartmentName());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayOperator())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayOperator, reqVO.getAssayOperator());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayOperatorId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayOperatorId, reqVO.getAssayOperatorId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()) && ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()[1])) {
    		mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getAssignTaskTime, reqVO.getAssignTaskTime()[0], reqVO.getAssignTaskTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getIsAssignTasked())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsAssignTasked, reqVO.getIsAssignTasked());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getIsReported())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsReported, reqVO.getIsReported());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReporter())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getReporter, reqVO.getReporter());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReporterId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getReporterId, reqVO.getReporterId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReportTime()) && ObjectUtil.isNotEmpty(reqVO.getReportTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getReportTime()[1])) {
    		mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getReportTime, reqVO.getReportTime()[0], reqVO.getReportTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getConfigSampleFlowId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getConfigSampleFlowId, reqVO.getConfigSampleFlowId());
		}
    	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(BusinessAssayTaskDataDO::getSampleFlowNodeTime, reqVO.getSampleFlowNodeTime()[0], reqVO.getSampleFlowNodeTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getRecheckCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRecheckCount, reqVO.getRecheckCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getRetestCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRetestCount, reqVO.getRetestCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getUpdateCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getUpdateCount, reqVO.getUpdateCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getSystemDepartmentCode())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getCreateTime()) && ObjectUtil.isNotEmpty(reqVO.getCreateTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getCreateTime()[1])) {
        	mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getCreateTime, reqVO.getCreateTime()[0], reqVO.getCreateTime()[1]);
		}
        if (ObjectUtil.isNotEmpty(reqVO.getRemark())) {
        	mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRemark, reqVO.getRemark());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodDictionaryBusinessId())) {
        	mpjLambdaWrapper.eq(ConfigAssayMethodDO::getDictionaryBusinessId, reqVO.getConfigAssayMethodDictionaryBusinessId());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodDictionaryBusinessKey())) {
        	mpjLambdaWrapper.eq(ConfigAssayMethodDO::getDictionaryBusinessKey, reqVO.getConfigAssayMethodDictionaryBusinessKey());
		}
        
        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");
//        .orderByAsc(BusinessSubSampleDO::getSampleAssayCode);
		return selectJoinList(BusinessAssayTaskDataExtendRespVO.class, mpjLambdaWrapper);
    }

    default PageResult<BusinessAssayTaskDataExtendRespVO> selectPage(BusinessAssayTaskDataPageReqVO reqVO) {
    	MPJLambdaWrapper<BusinessAssayTaskDataDO> mpjLambdaWrapper = new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
		.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessAssayTaskDataDO::getConfigAssayMethodId)
		.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
		.leftJoin(BusinessSubSampleAnalysisGroupDO.class, on -> on
				.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, BusinessAssayTaskDataDO::getAssayDepartmentId))
		.selectAll(BusinessAssayTaskDataDO.class)
		.selectAs(ConfigAssayMethodDO::getName, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodName)
		.selectAs(ConfigAssayMethodDO::getMethodNameCategory, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodNameAndCategory)
		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
		.selectAs(BusinessSubSampleDO::getConfigSubSampleId, BusinessAssayTaskDataExtendRespVO::getConfigSubSampleId);
    	if (ObjectUtil.isNotEmpty(reqVO.getBusinessBaseSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubParentSampleId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId());			
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessAssayTaskId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, reqVO.getBusinessAssayTaskId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubSampleAssessmentId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubSampleAssessmentId, reqVO.getBusinessSubSampleAssessmentId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getTaskType())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getTaskType, reqVO.getTaskType());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getAssayType())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayType, reqVO.getAssayType());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayProject())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayProject, reqVO.getAssayProject());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayDepartmentId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, reqVO.getAssayDepartmentId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayDepartmentName())) {
    		mpjLambdaWrapper.like(BusinessAssayTaskDataDO::getAssayDepartmentName, reqVO.getAssayDepartmentName());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayOperator())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayOperator, reqVO.getAssayOperator());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssayOperatorId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getAssayOperatorId, reqVO.getAssayOperatorId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()) && ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getAssignTaskTime()[1])) {
    		mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getAssignTaskTime, reqVO.getAssignTaskTime()[0], reqVO.getAssignTaskTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getIsAssignTasked())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsAssignTasked, reqVO.getIsAssignTasked());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getIsReported())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsReported, reqVO.getIsReported());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReporter())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getReporter, reqVO.getReporter());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReporterId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getReporterId, reqVO.getReporterId());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getReportTime()) && ObjectUtil.isNotEmpty(reqVO.getReportTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getReportTime()[1])) {
    		mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getReportTime, reqVO.getReportTime()[0], reqVO.getReportTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getConfigSampleFlowId())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getConfigSampleFlowId, reqVO.getConfigSampleFlowId());
		}
    	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(BusinessAssayTaskDataDO::getSampleFlowNodeTime, reqVO.getSampleFlowNodeTime()[0], reqVO.getSampleFlowNodeTime()[1]);
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getRecheckCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRecheckCount, reqVO.getRecheckCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getRetestCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRetestCount, reqVO.getRetestCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getUpdateCount())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getUpdateCount, reqVO.getUpdateCount());
		}
    	if (ObjectUtil.isNotEmpty(reqVO.getSystemDepartmentCode())) {
    		mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getCreateTime()) && ObjectUtil.isNotEmpty(reqVO.getCreateTime()[0]) && ObjectUtil.isNotEmpty(reqVO.getCreateTime()[1])) {
        	mpjLambdaWrapper.between(BusinessAssayTaskDataDO::getCreateTime, reqVO.getCreateTime()[0], reqVO.getCreateTime()[1]);
		}
        if (ObjectUtil.isNotEmpty(reqVO.getRemark())) {
        	mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getRemark, reqVO.getRemark());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodDictionaryBusinessId())) {
        	mpjLambdaWrapper.eq(ConfigAssayMethodDO::getDictionaryBusinessId, reqVO.getConfigAssayMethodDictionaryBusinessId());
		}
        if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodDictionaryBusinessKey())) {
        	mpjLambdaWrapper.eq(ConfigAssayMethodDO::getDictionaryBusinessKey, reqVO.getConfigAssayMethodDictionaryBusinessKey());
		}
        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");
//        .orderByAsc(BusinessSubSampleDO::getSampleAssayCode);
        return selectJoinPage(reqVO, BusinessAssayTaskDataExtendRespVO.class, mpjLambdaWrapper);
    }
    

	default BusinessAssayTaskDataExtendRespVO selectExtendRespById(Long businessAssayTaskDataId) {
		return selectJoinOne(BusinessAssayTaskDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
        		.selectAll(BusinessAssayTaskDataDO.class)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
        		.eq(BusinessAssayTaskDataDO::getId, businessAssayTaskDataId));
	}
	
	default BusinessAssayTaskDataExtendRespVO selectBySampleCode(String sampleCode) {
		return selectJoinOne(BusinessAssayTaskDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
        		.selectAll(BusinessAssayTaskDataDO.class)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
        		.eq(BusinessSubSampleDO::getSampleAssayCode, sampleCode)
        		.eq(BusinessAssayTaskDataDO::getIsReported, QmsCommonConstant.NO));		
	}
	
	default List<BusinessAssayTaskDataExtendRespVO> selectBySampleAssayCodesAndConfigAssayMethodId(List<String> sampleAssayCodes, Long configAssayMethodId) {
		return selectJoinList(BusinessAssayTaskDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
        		.selectAll(BusinessAssayTaskDataDO.class)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
        		.in(BusinessSubSampleDO::getSampleAssayCode, sampleAssayCodes)
        		.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId)
        		.eq(BusinessAssayTaskDataDO::getIsReported, QmsCommonConstant.NO));		
	}
	
	default List<BusinessAssayTaskDataExtendRespVO> selectBySampleAssayCodesAndConfigAssayMethodDictionaryBusinessKey(List<String> sampleAssayCodes, String configAssayMethodDictionaryBusinessKey) {
		return selectJoinList(BusinessAssayTaskDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessAssayTaskDataDO::getConfigAssayMethodId)
        		.selectAll(BusinessAssayTaskDataDO.class)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
        		.selectAs(BusinessSubSampleDO::getConfigSubSampleId, BusinessAssayTaskDataExtendRespVO::getConfigSubSampleId)
        		.in(BusinessSubSampleDO::getSampleAssayCode, sampleAssayCodes)
        		.eq(ConfigAssayMethodDO::getDictionaryBusinessKey, configAssayMethodDictionaryBusinessKey)
        		.eq(BusinessAssayTaskDataDO::getIsReported, QmsCommonConstant.NO));		
	}
	
	default List<BusinessAssayTaskDataExtendRespVO> selectResultAssessmentList(BusinessAssayTaskDataReqVO reqVO) {
		MPJLambdaWrapper<BusinessAssayTaskDataDO> mpjLambdaWrapper = new MPJLambdaWrapper<BusinessAssayTaskDataDO>()
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessAssayTaskDataDO::getConfigAssayMethodId)
        		.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
        		.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleAssessmentId)
        		.leftJoin(BusinessSubSampleAnalysisGroupDO.class, on -> on
        				.eq(BusinessSubSampleAnalysisGroupDO::getBusinessSubSampleId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
        				.eq(BusinessSubSampleAnalysisGroupDO::getAssayDepartmentId, BusinessAssayTaskDataDO::getAssayDepartmentId))
        		.selectAll(BusinessAssayTaskDataDO.class)
        		.selectAs(ConfigAssayMethodDO::getName, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodName)
        		.selectAs(ConfigAssayMethodDO::getMethodNameCategory, BusinessAssayTaskDataExtendRespVO::getConfigAssayMethodNameAndCategory)
        		.selectAs(ConfigAssayMethodDO::getConfigReportTemplateKey, BusinessAssayTaskDataExtendRespVO::getConfigReportTemplateKey)
        		.selectAs(BusinessSubSampleDO::getSampleName, BusinessAssayTaskDataExtendRespVO::getSampleName)
        		.selectAs(BusinessSubSampleDO::getSampleCode, BusinessAssayTaskDataExtendRespVO::getSampleCode)
        		.selectAs(BusinessSubSampleDO::getSampleAssayCode, BusinessAssayTaskDataExtendRespVO::getSampleAssayCode)
        		.selectAs(BusinessSubSampleAssessmentDO::getIsRecheck, BusinessAssayTaskDataExtendRespVO::getAsmtIsRecheck)
        		.selectAs(BusinessSubSampleAssessmentDO::getIsReported, BusinessAssayTaskDataExtendRespVO::getAsmtIsReported)
        		.selectAs(BusinessSubSampleAssessmentDO::getReportedStatus, BusinessAssayTaskDataExtendRespVO::getAsmtReportedStatus)
        		.selectAs(BusinessSubSampleAnalysisGroupDO::getSampleReceiver, BusinessAssayTaskDataExtendRespVO::getSampleReceiver)
        		.selectAs(BusinessSubSampleAnalysisGroupDO::getSampleReceiveTime, BusinessAssayTaskDataExtendRespVO::getSampleReceiveTime);
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessBaseSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getBusinessSubParentSampleId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getConfigAssayMethodId())) {
			mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId());
		}
		if (ObjectUtil.isNotEmpty(reqVO.getAsmtReportedStatus())) {
			mpjLambdaWrapper.eq(BusinessSubSampleAssessmentDO::getReportedStatus, reqVO.getAsmtReportedStatus());
			switch(reqVO.getAsmtReportedStatus()) {
				case QmsCommonConstant.ASMT_INITIAL:
				case QmsCommonConstant.ASMT_PENDING_REPORT:
				case QmsCommonConstant.ASMT_PENDING_ASSESSMENT:
					mpjLambdaWrapper.eq(BusinessAssayTaskDataDO::getIsAssignTasked, QmsCommonConstant.YES);//已任务指派
					break;
			}
		}
		if (ObjectUtil.isNotEmpty(reqVO.getSampleReceiveTime()) && reqVO.getSampleReceiveTime().length == 2) {
			mpjLambdaWrapper.between(BusinessSubSampleAnalysisGroupDO::getSampleReceiveTime, reqVO.getSampleReceiveTime()[0], reqVO.getSampleReceiveTime()[1]);
		}
		mpjLambdaWrapper.eq(BusinessSubSampleAnalysisGroupDO::getSampleStatus, "已收样");//已收样
		mpjLambdaWrapper.orderByAsc(BusinessAssayTaskDataDO::getBusinessSubSampleId).orderByAsc(BusinessAssayTaskDataDO::getReportTime);
		
		return selectJoinList(BusinessAssayTaskDataExtendRespVO.class, mpjLambdaWrapper);
    }
	
	/**
	 * 查询未指派的分析任务分组
	 * @param reqVO
	 * @return
	 */
	List<BusinessAssayTaskDataGroupRespVO> selectUnAssayTaskGroupList(@Param("reqVO") BusinessAssayTaskDataReqVO reqVO);
	
	
	List<BusinessAssayTaskDataGroupRespVO> selectUnAssayTaskGroupTypeList(@Param("reqVO") BusinessAssayTaskDataReqVO reqVO);

	/**
	 * 查询未审核的分析任务分组
	 * @param reqVO
	 * @return
	 */
	List<BusinessAssayTaskDataGroupRespVO> selectUnAuditTaskGroupList(@Param("reqVO") BusinessAssayTaskDataReqVO reqVO);

    /**
     * 根据任务分配单id查询分析任务
     * @param businessAssayTaskId 任务分配单id
     * @return
     */
	default List<BusinessAssayTaskDataDO> selectByBusinessAssayTaskId(Long businessAssayTaskId) {
		return selectJoinList(BusinessAssayTaskDataDO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId)
		        .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")
				);
	}

    /**
     * 根据任务分配单id查询分析任务
     * @param businessAssayTaskId 任务分配单id
     * @return
     */
	default List<BusinessAssayTaskDataExtendRespVO> selectExtendByBusinessAssayTaskId(Long businessAssayTaskId) {
		return selectJoinList(BusinessAssayTaskDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayTaskDataDO>()
				.leftJoin(BusinessSubSampleDO.class, BusinessSubSampleDO::getId, BusinessAssayTaskDataDO::getBusinessSubSampleId)
				.leftJoin(BusinessBaseSampleDO.class, BusinessBaseSampleDO::getId, BusinessAssayTaskDataDO::getBusinessBaseSampleId)
				.selectAll(BusinessAssayTaskDataDO.class)
				.selectAs(BusinessBaseSampleDO::getConfigBaseSampleId, BusinessAssayTaskDataExtendRespVO::getConfigBaseSampleId)
				.selectAs(BusinessSubSampleDO::getConfigSubSampleId, BusinessAssayTaskDataExtendRespVO::getConfigSubSampleId)
				.eq(BusinessAssayTaskDataDO::getBusinessAssayTaskId, businessAssayTaskId));
	}
	
	/**
	 * 根据子样查询分析任务
	 * @param businessSubSampleId 子样id
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubSampleId(Long businessSubSampleId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId));
	}

	/**
	 * 根据子样及分析方法Key查询分析任务
	 * @param businessSubSampleId 子样id
	 * @param methodKey 分析方法key
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubSampleIdAndMethodKey(Long businessSubSampleId, String methodKey) {
		String inSql = "SELECT tcam.ID FROM T_CFG_ASY_MTHD tcam WHERE tcam.DELETED = 0 AND tcam.DIC_BSN_KY = '" + methodKey + "'";
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
				.inSql(BusinessAssayTaskDataDO::getConfigAssayMethodId, inSql));
	}

	/**
	 * 根据正样样Id列表及分析方法Key查询分析任务
	 * @param businessBaseSampleIdList 正样id列表
	 * @param methodKey 分析方法key
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessBaseSampleIdsAndMethodKey(List<Long> businessBaseSampleIdList, String methodKey) {
		String inSql = "SELECT tcam.ID FROM T_CFG_ASY_MTHD tcam WHERE tcam.DELETED = 0 AND tcam.DIC_BSN_KY = '" + methodKey + "'";
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.in(BusinessAssayTaskDataDO::getBusinessBaseSampleId, businessBaseSampleIdList)
				.inSql(BusinessAssayTaskDataDO::getConfigAssayMethodId, inSql));
	}
	
	/**
	 * 根据主样及分析部门查询分析任务
	 * @param businessBaseSampleIdList 主样id
	 * @param assayDepartmentId 分析部门id
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessBaseSampleIdsAndAssayDepartmentId(List<Long> businessBaseSampleIdList, Long assayDepartmentId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.in(BusinessAssayTaskDataDO::getBusinessBaseSampleId, businessBaseSampleIdList)
				.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, assayDepartmentId));
	}
	
	/**
	 * 根据主样查询分析任务
	 * @param businessBaseSampleIdList 主样id
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessBaseSampleIds(List<Long> businessBaseSampleIdList) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.in(BusinessAssayTaskDataDO::getBusinessBaseSampleId, businessBaseSampleIdList));
	}

	
	/**
	 * 根据主样及分析部门查询分析任务
	 * @param businessBaseSampleId 主样id
	 * @param assayDepartmentId 分析部门id
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessBaseSampleIdAndAssayDepartmentId(Long businessBaseSampleId, Long assayDepartmentId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessBaseSampleId, businessBaseSampleId)
				.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, assayDepartmentId));
	}
	
	/**
	 * 根据子样及分析部门查询分析任务
	 * @param businessSubSampleId 子样id
	 * @param assayDepartmentId 分析部门id
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubSampleIdAndAssayDepartmentId(Long businessSubSampleId, Long assayDepartmentId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessAssayTaskDataDO::getAssayDepartmentId, assayDepartmentId));
	}
	
	
	/**
	 * 根据子样查询分析任务
	 * @param businessSubSampleId 子样id
	 * @param configAssayMethodId 分析方法
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubSampleIdAndConfigAssayMethodId(Long businessSubSampleId, Long configAssayMethodId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId));
	}
	
	/**
	 * 根据分样主样id列表查询分析任务
	 * @param businessSubParentSampleIds
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubParentSampleIds(List<Long> businessSubParentSampleIds) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.in(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, businessSubParentSampleIds));
	}
	
	/**
	 * 根据分样查询分析任务
	 * @param businessSubParentSampleId 分样样id
	 * @param configAssayMethodId 分析方法
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubParentSampleIdAndConfigAssayMethodId(Long businessSubParentSampleId, Long configAssayMethodId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, businessSubParentSampleId)
				.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId));
	}
	
	/**
	 * 根据分样查询分析任务
	 * @param businessSubParentSampleIds 分样样id列表
	 * @param configAssayMethodId 分析方法
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(List<Long> businessSubParentSampleIds, Long configAssayMethodId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.in(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
				.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId));
	}

	/**
	 * 查询是否上报的分析任务
	 * @param excludeIds 排除的id列表
	 * @param businessSubSampleId 子样id
	 * @param configAssayMethodId 分析方法id
	 * @param retestCount 复测次数
	 * @param isReported 是否上报
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectIsReportedList(List<Long> excludeIds, Long businessSubSampleId, Long configAssayMethodId, Integer retestCount, Integer isReported) {
		LambdaQueryWrapper<BusinessAssayTaskDataDO> queryWrapper = new LambdaQueryWrapperX<BusinessAssayTaskDataDO>();
		if (CollUtil.isNotEmpty(excludeIds)) {
			queryWrapper.notIn(BusinessAssayTaskDataDO::getId, excludeIds);
		}
		queryWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
		.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId)
		.eq(BusinessAssayTaskDataDO::getRetestCount, retestCount)
		.eq(BusinessAssayTaskDataDO::getIsReported, isReported);
		return selectList(queryWrapper);
	}
	
	/**
	 * 查询双杯样是否上报的分析任务
	 * @param excludeIds 排除的id列表
	 * @param businessSubParentSampleId 分样id
	 * @param configAssayMethodId 分析方法id
	 * @param isReported 是否上报
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectDoubleCupIsReportedList(List<Long> excludeIds, Long businessSubParentSampleId, Long configAssayMethodId, Integer isReported) {
		LambdaQueryWrapper<BusinessAssayTaskDataDO> queryWrapper = new LambdaQueryWrapperX<BusinessAssayTaskDataDO>();
		if (CollUtil.isNotEmpty(excludeIds)) {
			queryWrapper.notIn(BusinessAssayTaskDataDO::getId, excludeIds);
		}
		queryWrapper.eq(BusinessAssayTaskDataDO::getBusinessSubParentSampleId, businessSubParentSampleId)
		.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId)
		.eq(BusinessAssayTaskDataDO::getIsReported, isReported);
		return selectList(queryWrapper);
	}

	/**
	 * 查询最大复检次数的检测任务数据
	 * @param businessSubSampleId 子样id
	 * @param configAssayMethodId 分析方法
	 * @return
	 */
	default List<BusinessAssayTaskDataDO> selectMaxRecheckCountByBusinessSubSampleIdAndConfigAssayMethodId(Long businessSubSampleId, Long configAssayMethodId) {
		BusinessAssayTaskDataDO maxRecheckCountBusinessAssayTaskData = selectOne(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId)
				.orderByDesc(BusinessAssayTaskDataDO::getRecheckCount)
				.last("LIMIT 1"));
		
		return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDataDO>()
				.eq(BusinessAssayTaskDataDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessAssayTaskDataDO::getConfigAssayMethodId, configAssayMethodId)
				.eq(BusinessAssayTaskDataDO::getRecheckCount, maxRecheckCountBusinessAssayTaskData.getRecheckCount()));
		
		
	}

	/**
	 * 查询未指派的子样
	 * @return
	 */
	List<UnAssignTaskedSubSampleRespVO> selectUnAssignTaskedSubSample(@Param("reqVO") BusinessAssayTaskDataReqVO reqVO);



}