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

import java.util.*;
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.BusinessQCCoefficientDataDO;
import com.zt.plat.module.qms.business.config.controller.vo.ConfigQCSampleMethodExtendRespVO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigQCSampleMethodDO;
import com.zt.plat.module.qms.common.dic.dal.dataobject.DictionaryBusinessDO;
import com.zt.plat.module.qms.enums.QmsCommonConstant;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 质控样检测系数任务数据,空白样、标样 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessQCCoefficientDataMapper extends BaseMapperX<BusinessQCCoefficientDataDO> {

    default PageResult<BusinessQCCoefficientDataExtendRespVO> selectPage(BusinessQCCoefficientDataPageReqVO reqVO) {
    	MPJLambdaWrapperX<BusinessQCCoefficientDataDO> queryLambdaWrapperX = new MPJLambdaWrapperX<BusinessQCCoefficientDataDO>();
    	queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.leftJoin(DictionaryBusinessDO.class, "dbd1", DictionaryBusinessDO::getId, BusinessQCCoefficientDataDO::getDictionaryBusinessId);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.leftJoin(DictionaryBusinessDO.class, "dbd2", DictionaryBusinessDO::getId, "dbd1", DictionaryBusinessDO::getParentId);
		queryLambdaWrapperX = queryLambdaWrapperX.selectAll(BusinessQCCoefficientDataDO.class);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd1", DictionaryBusinessDO::getName, ConfigQCSampleMethodExtendRespVO::getDictionaryBusinessName);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd1", DictionaryBusinessDO::getParentId, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinessId);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd2", DictionaryBusinessDO::getKey, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinesskey);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd2", DictionaryBusinessDO::getName, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinessName);
		queryLambdaWrapperX.eqIfPresent(BusinessQCCoefficientDataDO::getSampleCode, reqVO.getSampleCode())
					        .likeIfPresent(BusinessQCCoefficientDataDO::getSampleName, reqVO.getSampleName())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getBusinessAssayTaskId, reqVO.getBusinessAssayTaskId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getBusinessStandardSampleId, reqVO.getBusinessStandardSampleId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getDictionaryBusinessId, reqVO.getDictionaryBusinessId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getDictionaryBusinessKey, reqVO.getDictionaryBusinessKey())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayProject, reqVO.getAssayProject())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayDepartmentId, reqVO.getAssayDepartmentId())
					        .likeIfPresent(BusinessQCCoefficientDataDO::getAssayDepartmentName, reqVO.getAssayDepartmentName())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayOperator, reqVO.getAssayOperator())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayOperatorId, reqVO.getAssayOperatorId())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getAssignTaskTime, reqVO.getAssignTaskTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getIsAssignTasked, reqVO.getIsAssignTasked())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getIsReported, reqVO.getIsReported())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getReporter, reqVO.getReporter())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getReporterId, reqVO.getReporterId())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getReportTime, reqVO.getReportTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getUpdateCount, reqVO.getUpdateCount())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getCreateTime, reqVO.getCreateTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getRemark, reqVO.getRemark())
					        .orderByDesc(BusinessQCCoefficientDataDO::getId);
    	
        return selectJoinPage(reqVO, BusinessQCCoefficientDataExtendRespVO.class, queryLambdaWrapperX);
    }

	default List<BusinessQCCoefficientDataExtendRespVO> selectList(BusinessQCCoefficientDataReqVO reqVO) {
    	MPJLambdaWrapperX<BusinessQCCoefficientDataDO> queryLambdaWrapperX = new MPJLambdaWrapperX<BusinessQCCoefficientDataDO>();
    	queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.leftJoin(DictionaryBusinessDO.class, "dbd1", DictionaryBusinessDO::getId, BusinessQCCoefficientDataDO::getDictionaryBusinessId);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.leftJoin(DictionaryBusinessDO.class, "dbd2", DictionaryBusinessDO::getId, "dbd1", DictionaryBusinessDO::getParentId);
		queryLambdaWrapperX = queryLambdaWrapperX.selectAll(BusinessQCCoefficientDataDO.class);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd1", DictionaryBusinessDO::getName, ConfigQCSampleMethodExtendRespVO::getDictionaryBusinessName);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd1", DictionaryBusinessDO::getParentId, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinessId);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd2", DictionaryBusinessDO::getKey, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinesskey);
		queryLambdaWrapperX = (MPJLambdaWrapperX<BusinessQCCoefficientDataDO>) queryLambdaWrapperX.selectAs("dbd2", DictionaryBusinessDO::getName, ConfigQCSampleMethodExtendRespVO::getParentDictionaryBusinessName);
		queryLambdaWrapperX.eqIfPresent(BusinessQCCoefficientDataDO::getSampleCode, reqVO.getSampleCode())
					        .likeIfPresent(BusinessQCCoefficientDataDO::getSampleName, reqVO.getSampleName())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getBusinessAssayTaskId, reqVO.getBusinessAssayTaskId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getBusinessStandardSampleId, reqVO.getBusinessStandardSampleId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getDictionaryBusinessId, reqVO.getDictionaryBusinessId())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getDictionaryBusinessKey, reqVO.getDictionaryBusinessKey())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayProject, reqVO.getAssayProject())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayDepartmentId, reqVO.getAssayDepartmentId())
					        .likeIfPresent(BusinessQCCoefficientDataDO::getAssayDepartmentName, reqVO.getAssayDepartmentName())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayOperator, reqVO.getAssayOperator())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getAssayOperatorId, reqVO.getAssayOperatorId())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getAssignTaskTime, reqVO.getAssignTaskTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getIsAssignTasked, reqVO.getIsAssignTasked())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getIsReported, reqVO.getIsReported())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getReporter, reqVO.getReporter())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getReporterId, reqVO.getReporterId())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getReportTime, reqVO.getReportTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getUpdateCount, reqVO.getUpdateCount())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
					        .betweenIfPresent(BusinessQCCoefficientDataDO::getCreateTime, reqVO.getCreateTime())
					        .eqIfPresent(BusinessQCCoefficientDataDO::getRemark, reqVO.getRemark())
					        .orderByDesc(BusinessQCCoefficientDataDO::getId);
		return selectJoinList(BusinessQCCoefficientDataExtendRespVO.class, queryLambdaWrapperX);
	}

	default List<BusinessQCCoefficientDataDO> selectByBusinessAssayTaskId(Long businessAssayTaskId) {
		return selectList(new LambdaQueryWrapperX<BusinessQCCoefficientDataDO>()
				.eq(BusinessQCCoefficientDataDO::getBusinessAssayTaskId, businessAssayTaskId));
	}

	default List<BusinessQCCoefficientDataDO> selectByBusinessAssayTaskIdAndDictionaryBusinessKey(Long businessAssayTaskId, String dictionaryBusinessKey) {
		return selectList(new LambdaQueryWrapperX<BusinessQCCoefficientDataDO>()
				.eq(BusinessQCCoefficientDataDO::getBusinessAssayTaskId, businessAssayTaskId)
				.eq(BusinessQCCoefficientDataDO::getDictionaryBusinessKey, dictionaryBusinessKey));
	}

	default List<BusinessQCCoefficientDataDO> selectBySampleAssayCodesAndConfigAssayMethodDictionaryBusinessKey(List<String> sampleCodeList, String configAssayMethodDictionaryBusinessKey) {
		return selectJoinList(BusinessQCCoefficientDataDO.class, new MPJLambdaWrapperX<BusinessQCCoefficientDataDO>()
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessQCCoefficientDataDO::getConfigAssayMethodId)
				.selectAll(BusinessQCCoefficientDataDO.class)
				.in(BusinessQCCoefficientDataDO::getSampleCode, sampleCodeList)
				.eq(BusinessQCCoefficientDataDO::getIsReported, QmsCommonConstant.NO)
				.eq(ConfigAssayMethodDO::getDictionaryBusinessKey, configAssayMethodDictionaryBusinessKey));
	}

}