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


    <sql id = "BaseSql">
    PIC.ID,
    PIC.ORDER_NO,
    PIC.SG_SIGN,
    PIC.SG_STD,
    PIC.ORDER_THICK,
    PIC.ORDER_WIDTH,
    PIC.ORDER_LEN,
    PIC.DELIVY_DATE,
    PIC.TENANT_ID,
    PIC.ATTRIBUTE1,
    PIC.ATTRIBUTE2,
    PIC.ATTRIBUTE3,
    PIC.ATTRIBUTE4,
    PIC.ATTRIBUTE5,
    PIC.creation_date,    PIC.created_by,    PIC.last_updated_by,    PIC.last_update_date,    PIC.object_version_number
    </sql>

    <select id = "selectList" parameterType="com.xisc.pm.api.dto.PmIrsubableContRequestDTO" resultType = "com.xisc.pm.domain.entity.PmIrsubableCont">
        select
        <include refid="BaseSql"/>
        from PM_IRSUBABLE_CONT PIC
        <where>
            <if test="id !=null">
                and PIC.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="orderNoFrom !=null">
                and PIC.ORDER_NO <![CDATA[ >= ]]> #{orderNoFrom}
            </if>
            <if test="orderNoTo !=null">
                and PIC.ORDER_NO <![CDATA[ <= ]]> #{orderNoTo}
            </if>
            <if test="sgSign !=null">
                and PIC.SG_SIGN like concat(concat('%',#{sgSign,jdbcType = VARCHAR}), '%')
            </if>
            <if test="sgStd !=null">
                and PIC.SG_STD like concat(concat('%',#{sgStd,jdbcType = VARCHAR}), '%')
            </if>
            <if test="orderThickFrom !=null">
                and PIC.ORDER_THICK  <![CDATA[ >= ]]> #{orderThickFrom}
            </if>
            <if test="orderThickTo !=null">
                and PIC.ORDER_THICK  <![CDATA[ <= ]]> #{orderThickTo}
            </if>
            <if test="orderWidthFrom !=null">
                and PIC.ORDER_WIDTH <![CDATA[ >= ]]> #{orderWidthFrom}
            </if>
            <if test="orderWidthTo !=null">
                and PIC.ORDER_WIDTH <![CDATA[ <= ]]> #{orderWidthTo}
            </if>
            <if test="orderLenFrom !=null">
                and PIC.ORDER_LEN <![CDATA[ >= ]]> #{orderLenFrom}
            </if>
            <if test="orderLenTo !=null">
                and PIC.ORDER_LEN <![CDATA[ <= ]]> #{orderLenTo}
            </if>
            <if test="delivyDateFrom !=null">
                and PIC.DELIVY_DATE <![CDATA[ >= ]]> #{delivyDateFrom}
            </if>
            <if test="delivyDateTo !=null">
                and PIC.DELIVY_DATE <![CDATA[ <= ]]> #{delivyDateTo}
            </if>
            <if test="tenantId !=null">
                and PIC.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
        </where>
    </select>


    <select id = "exportList" parameterType="com.xisc.pm.api.dto.PmIrsubableContRequestDTO" resultType = "com.xisc.pm.api.dto.export.PmIrsubableContDTO">
        select
        <include refid="BaseSql"/>
        from PM_IRSUBABLE_CONT PIC
        <where>
            <if test="id !=null">
                and PIC.ID = #{id,jdbcType = INTEGER}
            </if>
            <if test="orderNoFrom !=null">
                and PIC.ORDER_NO <![CDATA[ >= ]]> #{orderNoFrom}
            </if>
            <if test="orderNoTo !=null">
                and PIC.ORDER_NO <![CDATA[ <= ]]> #{orderNoTo}
            </if>
            <if test="sgSign !=null">
                and PIC.SG_SIGN like concat(concat('%',#{sgSign,jdbcType = VARCHAR}), '%')
            </if>
            <if test="sgStd !=null">
                and PIC.SG_STD like concat(concat('%',#{sgStd,jdbcType = VARCHAR}), '%')
            </if>
            <if test="orderThickFrom !=null">
                and PIC.ORDER_THICK  <![CDATA[ >= ]]> #{orderThickFrom}
            </if>
            <if test="orderThickTo !=null">
                and PIC.ORDER_THICK  <![CDATA[ <= ]]> #{orderThickTo}
            </if>
            <if test="orderWidthFrom !=null">
                and PIC.ORDER_WIDTH <![CDATA[ >= ]]> #{orderWidthFrom}
            </if>
            <if test="orderWidthTo !=null">
                and PIC.ORDER_WIDTH <![CDATA[ <= ]]> #{orderWidthTo}
            </if>
            <if test="orderLenFrom !=null">
                and PIC.ORDER_LEN <![CDATA[ >= ]]> #{orderLenFrom}
            </if>
            <if test="orderLenTo !=null">
                and PIC.ORDER_LEN <![CDATA[ <= ]]> #{orderLenTo}
            </if>
            <if test="delivyDateFrom !=null">
                and PIC.DELIVY_DATE <![CDATA[ >= ]]> #{delivyDateFrom}
            </if>
            <if test="delivyDateTo !=null">
                and PIC.DELIVY_DATE <![CDATA[ <= ]]> #{delivyDateTo}
            </if>
            <if test="tenantId !=null">
                and PIC.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
        </where>
    </select>

    <select id="querySaveList" resultType="com.xisc.pm.domain.entity.PmIrsubableCont">
        select
        PPCPA.ORDER_NO,
        PPCPA.SG_SIGN,
        PPCPA.SG_STD,
        PPCPA.ORDER_THICK,
        PPCPA.ORDER_WIDTH,
        PPCPA.ORDER_LEN,
        PPCPA.DELIVY_DATE,
        PPCPA.TENANT_ID
        from PM_PRO_CONT_PROD_ATTR PPCPA
        left join PM_IRSUBABLE_CONT PIC on PPCPA.ORDER_NO = PIC.ORDER_NO
        <where>
            <if test="orderNoList != null and orderNoList.size()>0">
                and  (PPCPA.ORDER_NO in
                <foreach collection="orderNoList" item="orderNo" open="(" close=")" separator="," index="index">
                    <if test="(index % 999) == 998"> NULL ) OR PPCPA.ORDER_NO in (</if> #{orderNo}
                </foreach>)
            </if>
            <if test="tenantId !=null">
                and PPCPA.TENANT_ID = #{tenantId}
            </if>
            and PIC.ORDER_NO is null
        </where>
    </select>

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

