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.BusinessQCManagementDataDO;
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.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 BusinessQCManagementDataMapper extends BaseMapperX<BusinessQCManagementDataDO> {

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

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

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

}