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


    <sql id = "BaseSql">
    PPLCS.PROD_LINE_COARSE_ID,
    PPLCS.TM_ROLL_PL,
    PPLCS.THICK_FROM,
    PPLCS.THICK_TO,
    PPLCS.WID_FROM,
    PPLCS.WID_TO,
    PPLCS.LENGTH_FROM,
    PPLCS.LENGTH_TO,
    PPLCS.VALID_FLAG,
    PPLCS.TENANT_ID,
    PPLCS.ATTRIBUTE1,
    PPLCS.ATTRIBUTE2,
    PPLCS.ATTRIBUTE3,
    PPLCS.ATTRIBUTE4,
    PPLCS.ATTRIBUTE5,
    PPLCS.creation_date,    PPLCS.created_by,    PPLCS.last_updated_by,    PPLCS.last_update_date,    PPLCS.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmProdLineCoarseSocre">
        select
        <include refid = "BaseSql"/>
        from PM_PROD_LINE_COARSE_SOCRE PPLCS
        <where>
            <if test="prodLineCoarseId !=null">
                and PPLCS.PROD_LINE_COARSE_ID = #{prodLineCoarseId,jdbcType = INTEGER}
            </if>
            <if test="tmRollPl !=null">
                and PPLCS.TM_ROLL_PL = #{tmRollPl,jdbcType = VARCHAR}
            </if>
            <if test="thickFrom !=null">
                and PPLCS.THICK_FROM = #{thickFrom,jdbcType = INTEGER}
            </if>
            <if test="thickTo !=null">
                and PPLCS.THICK_TO = #{thickTo,jdbcType = INTEGER}
            </if>
            <if test="widFrom !=null">
                and PPLCS.WID_FROM = #{widFrom,jdbcType = INTEGER}
            </if>
            <if test="widTo !=null">
                and PPLCS.WID_TO = #{widTo,jdbcType = INTEGER}
            </if>
            <if test="lengthFrom !=null">
                and PPLCS.LENGTH_FROM = #{lengthFrom,jdbcType = INTEGER}
            </if>
            <if test="lengthTo !=null">
                and PPLCS.LENGTH_TO = #{lengthTo,jdbcType = INTEGER}
            </if>
            <if test="validFlag !=null">
                and PPLCS.VALID_FLAG = #{validFlag,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and PPLCS.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PPLCS.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PPLCS.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PPLCS.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PPLCS.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PPLCS.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectOrderWtByTmRollPl" resultType="com.xisc.pm.domain.vo.PmProdLineCoarseSocreVO">
        SELECT DISTINCT
        ppcpa.ORDER_NO,
        ppcpa.ORDER_WT,
        pplcs.TM_ROLL_PL,
        pplcs.LENGTH_FROM,
        pplcs.LENGTH_TO,
        pplcs.THICK_FROM,
        pplcs.THICK_TO,
        pplcs.WID_FROM,
        pplcs.WID_TO
        FROM
        PM_PRO_CONT ppc
        JOIN PM_PRO_CONT_PROD_ATTR ppcpa ON ppc.ORDER_NO = ppcpa.ORDER_NO
        JOIN CT_MAIN cm ON ppc.ORDER_NO = cm.ORDER_NO
        JOIN PM_CONT_MSC_TECH pcmt ON cm.ORDER_NO = pcmt.ORDER_NO
        JOIN PM_PRODUCTION_LINE ppl ON pcmt.MSC_LINE_NO = ppl.PROD_LINE_CODE
        JOIN PM_PROD_LINE_COARSE_SOCRE pplcs ON ppl.TM_ROLL_PL = pplcs.TM_ROLL_PL
        <where>
            cm.ORDER_STATUS >= '40'
            AND cm.ORDER_STATUS <![CDATA[ < ]]> '67'
            AND ppcpa.ORDER_LEN >= pplcs.LENGTH_FROM
            AND ppcpa.ORDER_LEN <![CDATA[ <= ]]> pplcs.LENGTH_TO
            AND ppcpa.ORDER_THICK >= pplcs.THICK_FROM
            AND ppcpa.ORDER_THICK <![CDATA[ <= ]]> pplcs.THICK_TO
            AND ppcpa.ORDER_WIDTH >= pplcs.WID_FROM
            AND ppcpa.ORDER_WIDTH <![CDATA[ <= ]]> pplcs.WID_TO
            <if test="tenantId !=null">
                and pplcs.TENANT_ID = #{tenantId}
            </if>
            <if test="tmRollPlList != null and tmRollPlList.size() > 0">
                and pplcs.TM_ROLL_PL in
                <foreach collection="tmRollPlList" item="tmRollPl" open="(" close=")" separator="," >
                    #{tmRollPl}
                </foreach>
            </if>
        </where>
    </select>
</mapper>

