<?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.xisc.pm.infra.mapper.PmSgDetermineMapper">


    <sql id = "BaseSql">
    PSD.ID,
    PSD.ST_NO,
    PSD.LINKUP_ST_NO,
    PSD.ALTERABLE_ST_NO,
    PSD.MSC_LINE_NO,
    PSD.IS_FLAG,
    PSD.TENANT_ID,
    PSD.ATTRIBUTE1,
    PSD.ATTRIBUTE2,
    PSD.ATTRIBUTE3,
    PSD.ATTRIBUTE4,
    PSD.ATTRIBUTE5,
    PSD.creation_date,    PSD.created_by,    PSD.last_updated_by,    PSD.last_update_date,    PSD.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmSgDetermine">
        select
        <include refid = "BaseSql"/>
        from PM_SG_DETERMINE PSD
        <where>
            <if test="id !=null">
                and PSD.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="stNo !=null">
                and PSD.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="linkupStNo !=null">
                and PSD.LINKUP_ST_NO = #{linkupStNo,jdbcType = VARCHAR}
            </if>
            <if test="alterableStNo !=null">
                and PSD.ALTERABLE_ST_NO = #{alterableStNo,jdbcType = VARCHAR}
            </if>
            <if test="mscLineNo !=null">
                and PSD.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="isFlag !=null">
                and PSD.IS_FLAG = #{isFlag,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PSD.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSD.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSD.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSD.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSD.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSD.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id = "checkList" resultType = "String">
        select
        ST_NO||'-'||LINKUP_ST_NO||'-'||ALTERABLE_ST_NO||'-'||MSC_LINE_NO
        from PM_SG_DETERMINE
        <where>
            <if test="stNoList != null and stNoList.size()>0">
                and  (ST_NO||'-'||LINKUP_ST_NO||'-'||ALTERABLE_ST_NO||'-'||MSC_LINE_NO in
                <foreach collection="stNoList" item="stNo" open="(" close=")" separator="," index="index">
                    <if test="(index % 999) == 998"> NULL ) OR ST_NO||'-'||LINKUP_ST_NO||'-'||ALTERABLE_ST_NO||'-'||MSC_LINE_NO in (</if> #{stNo}
                </foreach>)
            </if>
        </where>
    </select>

    <select id = "exportList" resultType = "com.xisc.pm.api.dto.export.PmSgDetermineDTO">
        select
        <include refid = "BaseSql"/>
        from PM_SG_DETERMINE PSD
        <where>
            <if test="id !=null">
                and PSD.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="stNo !=null">
                and PSD.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="linkupStNo !=null">
                and PSD.LINKUP_ST_NO = #{linkupStNo,jdbcType = VARCHAR}
            </if>
            <if test="alterableStNo !=null">
                and PSD.ALTERABLE_ST_NO = #{alterableStNo,jdbcType = VARCHAR}
            </if>
            <if test="mscLineNo !=null">
                and PSD.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="isFlag !=null">
                and PSD.IS_FLAG = #{isFlag,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PSD.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSD.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSD.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSD.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSD.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSD.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>
</mapper>

