<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zt.plat.module.qms.business.bus.dal.mapper.BusinessAssayReportDataMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="queryWaitingDataForReport" resultType="com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayReportDataDO">
--         SELECT d.*,
        select
        d.ID as id,
        d.CFG_RPT_TP_ID as configReportTypeId,
        d.CFG_SMP_RPT_ID as configSampleReportId,
        d.BSN_BSE_SMP_ID as businessBaseSampleId,
        d.SMP_CD as sampleCode,
        d.ASY_DAT as assayData,
        d.RPT_FLW_CD as reportFlowCode,
        d.DOC_DAT_ID as documentDataId,
        d.SYS_DEPT_CD as systemDepartmentCode,
        d.UPD_CNT as updateCount,
        d.RMK as remark,
        d.CREATE_TIME as createTime,
        d.CREATOR as creator,
        d.UPDATER as updater,
        d.UPDATE_TIME as updateTime,
        d.CREATOR_NAME as creatorName,
        d.DELETED as deleted,
        s.CREATE_TIME as baseSampleCreateTime,
        s.SMP_NAME as sampleName
        FROM T_BSN_ASY_RPT_DAT d
        inner join T_BSN_BSE_SMP s on d.BSN_BSE_SMP_ID = s.id
        <where>
            and d.CFG_RPT_TP_ID = #{param.configReportTypeId}
            and NOT EXISTS (
            SELECT 1
            FROM T_RPT_DOC_DAT rd
            LEFT JOIN T_RPT_DOC_MAIN m on rd.MAIN_ID = m.ID
            WHERE rd.SRC_ID = d.id
            and m.RPT_DOC_TP = #{param.configReportTypeId}
            );
            <if test="param.sampleCode != null and param.sampleCode != ''">
                and d.SMP_CD like '%' || #{param.sampleCode} || '%'
            </if>
            <if test="param.sampleName != null and param.sampleName != ''">
                and s.SMP_NAME like '%' || #{param.sampleName} || '%'
            </if>
            <if test="param.baseSampleCreateTime != null and param.baseSampleCreateTime.size > 0">
                and s.CREATE_TIME between #{param.baseSampleCreateTime[0]} and #{param.baseSampleCreateTime[1]}
            </if>
            and d.deleted = 0
        </where>
    </select>

</mapper>


