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


    <sql id = "BaseSql">
    PIS.ID,
    PIS.SLAB_NO,
    PIS.SG_SIGN,
    PIS.ST_NO,
    PIS.MAT_ACT_THICK,
    PIS.MAT_ACT_WIDTH,
    PIS.MAT_ACT_LEN,
    PIS.DSTOCK_CODE,
    PIS.TENANT_ID,
    PIS.ATTRIBUTE1,
    PIS.ATTRIBUTE2,
    PIS.ATTRIBUTE3,
    PIS.ATTRIBUTE4,
    PIS.ATTRIBUTE5,
    PIS.creation_date,    PIS.created_by,    PIS.last_updated_by,    PIS.last_update_date,    PIS.object_version_number
    </sql>

    <select id = "selectList" parameterType="com.xisc.pm.api.dto.PmIrsubableSlabRequestDTO" resultType = "com.xisc.pm.domain.entity.PmIrsubableSlab">
        select
        <include refid = "BaseSql"/>
        from PM_IRSUBABLE_SLAB PIS
        <where>
            <if test="id !=null">
                and PIS.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="slabNo !=null">
                and PIS.SLAB_NO like concat(concat('%',#{slabNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="sgSign !=null">
                and PIS.SG_SIGN like concat(concat('%',#{sgSign,jdbcType = VARCHAR}), '%')
            </if>
            <if test="stNo !=null">
                and PIS.ST_NO like concat(concat('%',#{stNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="matActThickFrom !=null">
                and PIS.MAT_ACT_THICK <![CDATA[ >= ]]> #{matActThickFrom}
            </if>
            <if test="matActThickTo !=null">
                and PIS.MAT_ACT_THICK <![CDATA[ <= ]]> #{matActThickTo}
            </if>
            <if test="matActWidthFrom !=null">
                and PIS.MAT_ACT_WIDTH <![CDATA[ >= ]]> #{matActWidthFrom}
            </if>
            <if test="matActWidthTo !=null">
                and PIS.MAT_ACT_WIDTH <![CDATA[ <= ]]> #{matActWidthTo}
            </if>
            <if test="matActLenFrom !=null">
                and PIS.MAT_ACT_LEN <![CDATA[ >= ]]> #{matActLenFrom}
            </if>
            <if test="matActLenTo !=null">
                and PIS.MAT_ACT_LEN <![CDATA[ <= ]]> #{matActLenTo}
            </if>
            <if test="dstockCode !=null">
                and PIS.DSTOCK_CODE like concat(concat('%',#{dstockCode,jdbcType = VARCHAR}), '%')
            </if>
            <if test="tenantId !=null">
                and PIS.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
        </where>
    </select>

    <select id = "exportList" parameterType="com.xisc.pm.api.dto.PmIrsubableSlabRequestDTO" resultType = "com.xisc.pm.api.dto.export.PmIrsubableSlabDTO">
        select
        <include refid = "BaseSql"/>
        from PM_IRSUBABLE_SLAB PIS
        <where>
            <if test="id !=null">
                and PIS.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="slabNo !=null">
                and PIS.SLAB_NO like concat(concat('%',#{slabNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="sgSign !=null">
                and PIS.SG_SIGN like concat(concat('%',#{sgSign,jdbcType = VARCHAR}), '%')
            </if>
            <if test="stNo !=null">
                and PIS.ST_NO like concat(concat('%',#{stNo,jdbcType = VARCHAR}), '%')
            </if>
            <if test="matActThickFrom !=null">
                and PIS.MAT_ACT_THICK <![CDATA[ >= ]]> #{matActThickFrom}
            </if>
            <if test="matActThickTo !=null">
                and PIS.MAT_ACT_THICK <![CDATA[ <= ]]> #{matActThickTo}
            </if>
            <if test="matActWidthFrom !=null">
                and PIS.MAT_ACT_WIDTH <![CDATA[ >= ]]> #{matActWidthFrom}
            </if>
            <if test="matActWidthTo !=null">
                and PIS.MAT_ACT_WIDTH <![CDATA[ <= ]]> #{matActWidthTo}
            </if>
            <if test="matActLenFrom !=null">
                and PIS.MAT_ACT_LEN <![CDATA[ >= ]]> #{matActLenFrom}
            </if>
            <if test="matActLenTo !=null">
                and PIS.MAT_ACT_LEN <![CDATA[ <= ]]> #{matActLenTo}
            </if>
            <if test="dstockCode !=null">
                and PIS.DSTOCK_CODE like concat(concat('%',#{dstockCode,jdbcType = VARCHAR}), '%')
            </if>
            <if test="tenantId !=null">
                and PIS.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
        </where>
    </select>

    <select id="querySaveList" resultType="com.xisc.pm.domain.entity.PmIrsubableSlab">
        select
        MS.SLAB_NO,
        MS.SG_SIGN,
        MS.ST_NO,
        MS.SLAB_ACT_THK AS MAT_ACT_THICK,
        MS.SLAB_ACT_WID AS MAT_ACT_WIDTH,
        MS.SLAB_ACT_LEN AS MAT_ACT_LEN,
        MS.STOCK_LINE AS DSTOCK_CODE,
        MS.TENANT_ID
        from MM_SLAB MS
        left join PM_IRSUBABLE_SLAB PIS on MS.SLAB_NO = PIS.SLAB_NO
        <where>
            <if test="slabNoList != null and slabNoList.size()>0">
                and  (MS.SLAB_NO in
                <foreach collection="slabNoList" item="slabNo" open="(" close=")" separator="," index="index">
                    <if test="(index % 999) == 998"> NULL ) OR MS.SLAB_NO in (</if> #{slabNo}
                </foreach>)
            </if>
            <if test="tenantId !=null">
                and MS.TENANT_ID = #{tenantId}
            </if>
            and PIS.SLAB_NO is null
        </where>
    </select>

    <select id="checkList" resultType="com.xisc.pm.domain.entity.PmIrsubableCont">
        select
        <include refid="BaseSql"/>
        from PM_IRSUBABLE_SLAB PIS
        <where>
            <if test="slabNoList != null and slabNoList.size()>0">
                and  (PIS.SLAB_NO in
                <foreach collection="slabNoList" item="slabNo" open="(" close=")" separator="," index="index">
                    <if test="(index % 999) == 998"> NULL ) OR PIS.SLAB_NO in (</if> #{slabNo}
                </foreach>)
            </if>
        </where>
    </select>
</mapper>

