<?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.BusinessAssayProjectDataMapper">

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

    <select id="selectAssayMethodProjectByBusinessSubSampleIdListAndConfigAssayMethodId" resultType="com.zt.plat.module.qms.business.bus.controller.vo.AssayMethodProjectRespVO">
        SELECT
            tbapd.DIC_PRJ_ID dictionaryProjectId,
            tdp.NAME AS dictionaryProjectName,
            tdp.SMPL_NAME AS dictionaryProjectSimpleName,
            tdp.SHW_NAME AS dictionaryProjectShowName,
            tbatd.ASY_TP AS assayType,
            tbatd.CFG_ASY_MTHD_ID AS configAssayMethodId,
            tcam.NAME AS configAssayMethodName,
            tcam.MTHD_NAME_CTGR AS configAssayMethodNameAndCategory,
            tcamp.SRT_NO
        FROM
            T_BSN_ASY_PRJ_DAT tbapd
        LEFT JOIN T_BSN_ASY_TSK_DAT tbatd ON
            tbapd.BSN_ASY_TSK_DAT_ID = tbatd.ID
        LEFT JOIN T_CFG_ASY_MTHD tcam ON
            tbatd.CFG_ASY_MTHD_ID = tcam.ID
        LEFT JOIN T_CFG_ASY_MTHD_PRJ tcamp ON
            tbapd.CFG_ASY_MTHD_PRJ_ID = tcamp.ID
        LEFT JOIN T_DIC_PRJ tdp ON
            tbapd.DIC_PRJ_ID = tdp.ID
        WHERE
            tbapd.DELETED = 0
            AND tbapd.IS_ENBD = 1
            AND tbatd.DELETED = 0
            AND tbatd.IS_ASN_TSKD = 0
            AND tbatd.BSN_SB_SMP_ID IN 
            <foreach collection="businessSubSampleIdList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach> 
            AND tbatd.CFG_ASY_MTHD_ID = #{configAssayMethodId}
        GROUP BY 
            tbapd.DIC_PRJ_ID,
            tdp.NAME,
            tdp.SMPL_NAME,
            tdp.SHW_NAME,
            tbatd.ASY_TP,
            tbatd.CFG_ASY_MTHD_ID,
            tcam.NAME,
            tcam.MTHD_NAME_CTGR,
            tcamp.SRT_NO
        ORDER BY tcamp.SRT_NO ASC        
    </select>
</mapper>