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.BusinessSubParentSampleAssessmentDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigAssayMethodDO;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 班组判定数据业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessSubParentSampleAssessmentMapper extends BaseMapperX<BusinessSubParentSampleAssessmentDO> {

    default PageResult<BusinessSubParentSampleAssessmentDO> selectPage(BusinessSubParentSampleAssessmentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessSubParentSampleAssessmentDO>()
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, reqVO.getBusinessSubParentSampleId())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getAssayType, reqVO.getAssayType())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getAssessmentStatus, reqVO.getAssessmentStatus())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getRetestCount, reqVO.getRetestCount())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubParentSampleAssessmentDO::getReportTime, reqVO.getReportTime())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getResultTreatmentWay, reqVO.getResultTreatmentWay())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubParentSampleAssessmentDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubParentSampleAssessmentDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessSubParentSampleAssessmentDO::getId));
    }

    default List<BusinessSubParentSampleAssessmentDO> selectByBusinessSubParentSampleIds(List<Long> businessSubParentSampleIds) {
    	return selectJoinList(BusinessSubParentSampleAssessmentDO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentDO>()
    			.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId)
    			.in(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleIds));
    }
    
    default BusinessSubParentSampleAssessmentDO selectByBusinessSubParentSampleIdAndConfigAssayMethodIdAndRetestCount(Long businessSubParentSampleId, Long configAssayMethodId, Integer retestCount) {
    	return selectOne(new LambdaQueryWrapperX<BusinessSubParentSampleAssessmentDO>()
    			.eq(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleId)
    			.eq(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId)
    			.eq(BusinessSubParentSampleAssessmentDO::getRetestCount, retestCount));
    }

    default List<BusinessSubParentSampleAssessmentExtendRespVO> selectByBusinessSubParentSampleIdsAndConfigAssayMethodId(List<Long> businessSubParentSampleIds, Long configAssayMethodId) {
    	return selectJoinList(BusinessSubParentSampleAssessmentExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentDO>()
    			.leftJoin(BusinessSubParentSampleDO.class, BusinessSubParentSampleDO::getId, BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId)
    			.selectAll(BusinessSubParentSampleAssessmentDO.class)
    			.selectAs(BusinessSubParentSampleDO::getConfigSubSampleParentId, BusinessSubParentSampleAssessmentExtendRespVO::getConfigSubSampleParentId)
    			.selectAs(BusinessSubParentSampleDO::getBusinessBaseSampleId, BusinessSubParentSampleAssessmentExtendRespVO::getBusinessBaseSampleId)
    			.in(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
    			.eq(BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId));
    }

    default List<BusinessSubParentSampleAssessmentDO> selectByBusinessSubParentSampleIdsAndAssayDepartmentId(List<Long> businessSubParentSampleIds,
			Long assayDepartmentId) {
    	return selectJoinList(BusinessSubParentSampleAssessmentDO.class, new MPJLambdaWrapperX<BusinessSubParentSampleAssessmentDO>()
    			.leftJoin(ConfigAssayMethodDO.class, ConfigAssayMethodDO::getId, BusinessSubParentSampleAssessmentDO::getConfigAssayMethodId)
    			.in(BusinessSubParentSampleAssessmentDO::getBusinessSubParentSampleId, businessSubParentSampleIds)
    			.eq(ConfigAssayMethodDO::getAssayDepartmentId, assayDepartmentId));
    }

}