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

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.BusinessSubSampleAssessmentDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleAssessmentProjectDO;
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.framework.mybatis.core.mapper.BaseMapperX;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

/**
 * 子样判定检测项目数据业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessSubSampleAssessmentProjectMapper extends BaseMapperX<BusinessSubSampleAssessmentProjectDO> {

    default PageResult<BusinessSubSampleAssessmentProjectDO> selectPage(BusinessSubSampleAssessmentProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessSubSampleAssessmentProjectDO>()
        		.eqIfPresent(BusinessSubSampleAssessmentProjectDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId, reqVO.getBusinessSubSampleAssessmentId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getUsage, reqVO.getUsage())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getSymbol, reqVO.getSymbol())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getAssayType, reqVO.getAssayType())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getEffectiveDigit, reqVO.getEffectiveDigit())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getAssessmentValue, reqVO.getAssessmentValue())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getAssessmentStatus, reqVO.getAssessmentStatus())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubSampleAssessmentProjectDO::getReportTime, reqVO.getReportTime())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubSampleAssessmentProjectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubSampleAssessmentProjectDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessSubSampleAssessmentProjectDO::getId));
    }
    
    default List<BusinessSubSampleAssessmentProjectExtendRespVO> selectByBusinessSubParentSampleIdAndBusinessSubParentSampleAssessmentId(Long businessSubParentSampleId, Long businessSubParentSampleAssessmentId) {
    	return selectJoinList(BusinessSubSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentProjectDO>()
				.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId)
    			.selectAll(BusinessSubSampleAssessmentProjectDO.class)
				.selectAs(BusinessSubSampleAssessmentDO::getRetestCount, BusinessSubSampleAssessmentProjectExtendRespVO::getRetestCount)
				.selectAs(ConfigAssayMethodDO::getName, BusinessSubSampleAssessmentProjectExtendRespVO::getConfigAssayMethodName)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.eq(BusinessSubSampleAssessmentProjectDO::getBusinessSubParentSampleId, businessSubParentSampleId)
				.eq(BusinessSubSampleAssessmentDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentId));
    }
    
    default List<BusinessSubSampleAssessmentProjectExtendRespVO> selectByBusinessSubParentSampleIdAndConfigAssayMethodId(Long businessSubParentSampleId, Long configAssayMethodId) {
    	return selectJoinList(BusinessSubSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentProjectDO>()
				.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId)
    			.selectAll(BusinessSubSampleAssessmentProjectDO.class)
				.selectAs(BusinessSubSampleAssessmentDO::getRetestCount, BusinessSubSampleAssessmentProjectExtendRespVO::getRetestCount)
				.selectAs(ConfigAssayMethodDO::getName, BusinessSubSampleAssessmentProjectExtendRespVO::getConfigAssayMethodName)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.eq(BusinessSubSampleAssessmentProjectDO::getBusinessSubParentSampleId, businessSubParentSampleId)
				.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId));
    }

	default List<BusinessSubSampleAssessmentProjectExtendRespVO> selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(List<Long> businessSubParentSampleIds, Long configAssayMethodId) {
		return selectJoinList(BusinessSubSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentProjectDO>()
				.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId)
				.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
				.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId)
				.selectAll(BusinessSubSampleAssessmentProjectDO.class)
				.selectAs(BusinessSubSampleAssessmentDO::getRetestCount, BusinessSubSampleAssessmentProjectExtendRespVO::getRetestCount)
				.selectAs(ConfigAssayMethodDO::getName, BusinessSubSampleAssessmentProjectExtendRespVO::getConfigAssayMethodName)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
				.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.in(BusinessSubSampleAssessmentProjectDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
				.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId));
	}
    
	@Deprecated
	default List<BusinessSubSampleAssessmentProjectExtendRespVO> selectByBusinessSubSampleIdAndConfigAssayMethodId(Long businessSubSampleId, Long configAssayMethodId) {
    	return selectJoinList(BusinessSubSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentProjectDO>()
				.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId)
    			.selectAll(BusinessSubSampleAssessmentProjectDO.class)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.eq(BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId));
    }
    
    default List<BusinessSubSampleAssessmentProjectExtendRespVO> selectByBusinessSubSampleIdAndConfigAssayMethodIdAndRetestCount(Long businessSubSampleId, Long configAssayMethodId, Integer retestCount) {
    	return selectJoinList(BusinessSubSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentProjectDO>()
				.leftJoin(BusinessSubSampleAssessmentDO.class, BusinessSubSampleAssessmentDO::getId, BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleAssessmentId)
				.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentProjectDO::getDictionaryProjectId)
    			.selectAll(BusinessSubSampleAssessmentProjectDO.class)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.eq(BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId)
				.eq(BusinessSubSampleAssessmentDO::getRetestCount, retestCount));
    }
    
    default BusinessSubSampleAssessmentProjectDO selectByBusinessSubSampleIdAndConfigAssayMethodIdAndConfigAssayMethodProjectId(Long businessSubSampleId, Long configAssayMethodId, Long configAssayMethodProjectId) {
    	return selectOne(new LambdaQueryWrapperX<BusinessSubSampleAssessmentProjectDO>()
    			.eq(BusinessSubSampleAssessmentProjectDO::getBusinessSubSampleId, businessSubSampleId)
    			.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId)
    			.eq(BusinessSubSampleAssessmentProjectDO::getConfigAssayMethodProjectId, configAssayMethodProjectId));
    }


}