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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.BusinessAssayReportDataPageReqVO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayReportDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessBaseSampleDO;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 检测报表数据业务 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface BusinessAssayReportDataMapper extends BaseMapperX<BusinessAssayReportDataDO> {

    default PageResult<BusinessAssayReportDataDO> selectPage(BusinessAssayReportDataPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BusinessAssayReportDataDO>()
                .eqIfPresent(BusinessAssayReportDataDO::getConfigReportTypeId, reqVO.getConfigReportTypeId())
                .eqIfPresent(BusinessAssayReportDataDO::getConfigSampleReportId, reqVO.getConfigSampleReportId())
                .eqIfPresent(BusinessAssayReportDataDO::getBusinessBaseSampleId, reqVO.getBusinessBaseSampleId())
                .eqIfPresent(BusinessAssayReportDataDO::getSampleCode, reqVO.getSampleCode())
                .eqIfPresent(BusinessAssayReportDataDO::getDataSource, reqVO.getDataSource())
                .eqIfPresent(BusinessAssayReportDataDO::getAssayData, reqVO.getAssayData())
                .eqIfPresent(BusinessAssayReportDataDO::getIsAllReported, reqVO.getIsAllReported())
                .eqIfPresent(BusinessAssayReportDataDO::getReportedSource, reqVO.getReportedSource())
                .eqIfPresent(BusinessAssayReportDataDO::getReportFlowCode, reqVO.getReportFlowCode())
                .eqIfPresent(BusinessAssayReportDataDO::getDocumentDataId, reqVO.getDocumentDataId())
                .eqIfPresent(BusinessAssayReportDataDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .betweenIfPresent(BusinessAssayReportDataDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BusinessAssayReportDataDO::getUpdateCount, reqVO.getUpdateCount())
                .eqIfPresent(BusinessAssayReportDataDO::getRemark, reqVO.getRemark())
                .orderByDesc(BusinessAssayReportDataDO::getId));
    }

	default List<BusinessAssayReportDataDO> selectBytBusinessBaseSampleId(Long businessBaseSampleId) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayReportDataDO>()
				.eqIfPresent(BusinessAssayReportDataDO::getBusinessBaseSampleId, businessBaseSampleId));
	}

	default List<BusinessAssayReportDataDO> selectBytBusinessBaseSampleIds(List<Long> businessBaseSampleIds) {
		return selectList(new LambdaQueryWrapperX<BusinessAssayReportDataDO>()
				.inIfPresent(BusinessAssayReportDataDO::getBusinessBaseSampleId, businessBaseSampleIds));
	}
	
	default List<BusinessAssayReportDataExtendRespVO> selectExtendByBusinessBaseSampleIds(List<Long> businessBaseSampleIds) {
		return selectJoinList(BusinessAssayReportDataExtendRespVO.class, new MPJLambdaWrapperX<BusinessAssayReportDataDO>()
				.leftJoin(BusinessBaseSampleDO.class, BusinessBaseSampleDO::getId, BusinessAssayReportDataDO::getBusinessBaseSampleId)
				.selectAll(BusinessAssayReportDataDO.class)
				.selectAs(BusinessBaseSampleDO::getSampleName, BusinessAssayReportDataExtendRespVO::getSampleName)
				.selectAs(BusinessBaseSampleDO::getBaseSampleName, BusinessAssayReportDataExtendRespVO::getBaseSampleName)
				.inIfPresent(BusinessAssayReportDataDO::getBusinessBaseSampleId, businessBaseSampleIds));
		
	}

	//查询报告待编制数据
	Page<BusinessAssayReportDataDO> queryWaitingDataForReport(IPage<?> page, @Param("param") BusinessAssayReportDataPageReqVO param);

}