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

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.BusinessSubParentSampleAssessmentDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleAssessmentProjectDO;
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.module.qms.enums.QmsCommonConstant;
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 BusinessSubParentSampleAssessmentProjectMapper extends BaseMapperX<BusinessSubParentSampleAssessmentProjectDO> {

    List<BusinessSubParentSampleAssessmentGroupRespVO> selectUnReportMethodGroupList(@Param("reqVO") BusinessSubParentSampleAssessmentGroupReqVO reqVO);
    
    default PageResult<BusinessSubParentSampleAssessmentProjectDO> selectPage(BusinessSubParentSampleAssessmentProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessSubParentSampleAssessmentProjectDO>()
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, reqVO.getBusinessSubParentSampleAssessmentId())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getUsage, reqVO.getUsage())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getSymbol, reqVO.getSymbol())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getAssayType, reqVO.getAssayType())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getEffectiveDigit, reqVO.getEffectiveDigit())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getAssessmentValue, reqVO.getAssessmentValue())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getAssessmentStatus, reqVO.getAssessmentStatus())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubParentSampleAssessmentProjectDO::getReportTime, reqVO.getReportTime())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubParentSampleAssessmentProjectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubParentSampleAssessmentProjectDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessSubParentSampleAssessmentProjectDO::getId));
    }
    
    default List<BusinessSubParentSampleAssessmentProjectExtendRespVO> selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(List<Long> businessSubParentSampleIds, Long configAssayMethodId) {
    	return selectJoinList(BusinessSubParentSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentProjectDO>()
    			.leftJoin(BusinessSubParentSampleAssessmentDO.class, BusinessSubParentSampleAssessmentDO::getId, BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId)
    		    .leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubParentSampleAssessmentProjectDO::getDictionaryProjectId)
    			.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.selectAll(BusinessSubParentSampleAssessmentProjectDO.class)
    			.selectAs(BusinessSubParentSampleAssessmentDO::getRetestCount, BusinessSubParentSampleAssessmentProjectExtendRespVO::getRetestCount)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.selectAs(ConfigAssayMethodDO::getName, BusinessSubSampleAssessmentProjectExtendRespVO::getConfigAssayMethodName)
    			.in(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
    			.eq(BusinessSubParentSampleAssessmentProjectDO::getAssessmentStatus, QmsCommonConstant.NORMAL)
    			.eq(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId));
    }
    
    default List<BusinessSubParentSampleAssessmentProjectDO> selectByConfigAssayMethodId(Long configAssayMethodId) {
    	return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
    			.eq(BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId));
    }
    
    

    default List<BusinessSubParentSampleAssessmentProjectDO> selectByBusinessSubParentSampleAssessmentIdAndDictionaryProjectIds(Long businessSubParentSampleAssessmentId, List<Long> recheckDictionaryProjectIdList) {
		return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
				.eq(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentId)
				.in(BusinessSubParentSampleAssessmentProjectDO::getDictionaryProjectId, recheckDictionaryProjectIdList));
	}
    
    default List<BusinessSubParentSampleAssessmentProjectDO> selectByBusinessSubParentSampleAssessmentId(Long businessSubParentSampleAssessmentId) {
		return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
				.eq(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentId));
	}
    
    default List<BusinessSubParentSampleAssessmentProjectExtendRespVO> selectByBusinessSubParentSampleAssessmentIds(List<Long> businessSubParentSampleAssessmentIdList) {
    	return selectJoinList(BusinessSubParentSampleAssessmentProjectExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentProjectDO>()
    			.leftJoin(BusinessSubParentSampleAssessmentDO.class, BusinessSubParentSampleAssessmentDO::getId, BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId)
    		    .leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubParentSampleAssessmentProjectDO::getDictionaryProjectId)
    			.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodId)
    			.selectAll(BusinessSubParentSampleAssessmentProjectDO.class)
    			.selectAs(BusinessSubParentSampleAssessmentDO::getRetestCount, BusinessSubParentSampleAssessmentProjectExtendRespVO::getRetestCount)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentProjectExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentProjectExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentProjectExtendRespVO::getShowName)
				.selectAs(ConfigAssayMethodDO::getName, BusinessSubSampleAssessmentProjectExtendRespVO::getConfigAssayMethodName)
				.in(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentIdList));
	}

	List<NoReportSubParentSampleAssessmentRespVO> selectNoReportSubParentSampleAssessment(@Param("reqVO") BusinessSubParentSampleAssessmentGroupReqVO reqVO);
	
	List<RecheckSubSampleParentMethodRespVO> getRecheckAssayMethodList(@Param("baseSampleId") Long baseSampleId, @Param("businessSubParentSampleId") Long businessSubParentSampleId, @Param("configAssayMethodId") Long configAssayMethodId, @Param("assayDepartmentId") Long assayDepartmentId);

    

}