<?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.config.dal.mapper.MaterialAssayStandardDetailMapper">

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

        select
        dtl.ID as id,
        dtl.MTRL_ASY_STD_ID as materialAssayStandardId,
        dtl.DIC_PRJ_ID as dictionaryProjectId,
        dtl.DIC_PRJ_CD as dictionaryProjectCode,
        dtl.UNT_ID as unitId,
        dtl.UNT as unit,
        dtl.DAT_TP as dataType,
        dtl.DEC_POS as decimalPosition,
        dtl.ASY_CTGR as assayCategory,
        dtl.IS_DFT_PCK as isDefaultPick,
        dtl.SYS_DEPT_CD as systemDepartmentCode,
        dtl.RMK as remark,
        dtl.creator,
        dtl.create_time,
        dtl.updater,
        dtl.update_time,

        (SELECT d.NAME FROM T_DIC_PRJ d WHERE d.id = dtl.DIC_PRJ_ID AND d.DELETED = 0) dictionaryProjectName,
        (SELECT d.SMPL_NAME FROM T_DIC_PRJ d WHERE d.id = dtl.DIC_PRJ_ID AND d.DELETED = 0) dictionaryProjectSimpleName,
        (SELECT d.SHW_NAME FROM T_DIC_PRJ d WHERE d.id = dtl.DIC_PRJ_ID AND d.DELETED = 0) dictionaryProjectShowName,
        (SELECT tdb.NAME FROM T_DIC_BSN tdb WHERE tdb.PRN_ID = (SELECT tdb1.ID FROM T_DIC_BSN tdb1 WHERE tdb1.KY = 'dataType' AND tdb1.DELETED = 0) AND tdb.DELETED = 0 AND tdb.KY = dtl.DAT_TP) dataTypeName,
        (select name from T_DIC_BSN d where d.id = dtl.ASY_CTGR and d.DELETED = 0) assayCategoryName
        from T_MTRL_ASY_STD_DTL dtl
        <where>
            <if test="param.materialAssayStandardId != null">
                and dtl.MTRL_ASY_STD_ID = #{param.materialAssayStandardId}
            </if>
            <if test="param.standardIdList != null and param.standardIdList.size() > 0">
                and dtl.MTRL_ASY_STD_ID in
                <foreach item="item" collection="param.standardIdList" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            and dtl.DELETED = 0
        </where>
        order by dtl.create_time desc

    </select>

</mapper>