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.controller.vo.BusinessSubSampleAssessmentPageReqVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleAssessmentDO;
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 BusinessSubSampleAssessmentMapper extends BaseMapperX<BusinessSubSampleAssessmentDO> {

    default PageResult<BusinessSubSampleAssessmentDO> selectPage(BusinessSubSampleAssessmentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessSubSampleAssessmentDO>()
                .eqIfPresent(BusinessSubSampleAssessmentDO::getBusinessSubSampleId, reqVO.getBusinessSubSampleId())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getDictionaryProjectId, reqVO.getDictionaryProjectId())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getConfigAssayMethodProjectId, reqVO.getConfigAssayMethodProjectId())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getConfigAssayMethodId, reqVO.getConfigAssayMethodId())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getTaskType, reqVO.getTaskType())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getAssayType, reqVO.getAssayType())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getDataType, reqVO.getDataType())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getDecimalPosition, reqVO.getDecimalPosition())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getAssessmentValue, reqVO.getAssessmentValue())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getAssessmentStatus, reqVO.getAssessmentStatus())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getIsReported, reqVO.getIsReported())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getReporter, reqVO.getReporter())
                .betweenIfPresent(BusinessSubSampleAssessmentDO::getReportTime, reqVO.getReportTime())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessSubSampleAssessmentDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessSubSampleAssessmentDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessSubSampleAssessmentDO::getId));
    }
    
    default List<BusinessSubSampleAssessmentExtendRespVO> selectByBusinessSubSampleIdAndConfigAssayMethodId(Long businessSubSampleId, Long configAssayMethodId) {
    	return selectJoinList(BusinessSubSampleAssessmentExtendRespVO.class, new MPJLambdaWrapperX<BusinessSubSampleAssessmentDO>()
    			.leftJoin(ConfigAssayMethodProjectDO.class, ConfigAssayMethodProjectDO::getId, BusinessSubSampleAssessmentDO::getConfigAssayMethodProjectId)
    			.leftJoin(DictionaryProjectDO.class, DictionaryProjectDO::getId, BusinessSubSampleAssessmentDO::getDictionaryProjectId)
    			.selectAll(BusinessSubSampleAssessmentDO.class)
				.selectAs(ConfigAssayMethodProjectDO::getDictionaryProjectUnit, BusinessSubSampleAssessmentExtendRespVO::getDictionaryProjectUnit)
    			.selectAs(DictionaryProjectDO::getKey, BusinessSubSampleAssessmentExtendRespVO::getDictionaryProjectKey)
				.selectAs(DictionaryProjectDO::getSimpleName, BusinessSubSampleAssessmentExtendRespVO::getSimpleName)
				.selectAs(DictionaryProjectDO::getShowName, BusinessSubSampleAssessmentExtendRespVO::getShowName)
				.eq(BusinessSubSampleAssessmentDO::getBusinessSubSampleId, businessSubSampleId)
				.eq(BusinessSubSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId));
    }
    
    default BusinessSubSampleAssessmentDO selectByBusinessSubSampleIdAndConfigAssayMethodIdAndConfigAssayMethodProjectId(Long businessSubSampleId, Long configAssayMethodId, Long configAssayMethodProjectId) {
    	return selectOne(new LambdaQueryWrapperX<BusinessSubSampleAssessmentDO>()
    			.eq(BusinessSubSampleAssessmentDO::getBusinessSubSampleId, businessSubSampleId)
    			.eq(BusinessSubSampleAssessmentDO::getConfigAssayMethodId, configAssayMethodId)
    			.eq(BusinessSubSampleAssessmentDO::getConfigAssayMethodProjectId, configAssayMethodProjectId));
    }

}