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


    <sql id = "BaseSql">
    PSTC.ORDER_STRUCTURE_ID,
    PSTC.HEADER_COLUMN_NUM,
    PSTC.THICK_FROM,
    PSTC.THICK_TO,
    PSTC.WID_FROM,
    PSTC.WID_TO,
    PSTC.LENGTH_FROM,
    PSTC.LENGTH_TO,
    PSTC.TENANT_ID,
    PSTC.ATTRIBUTE1,
    PSTC.ATTRIBUTE2,
    PSTC.ATTRIBUTE3,
    PSTC.ATTRIBUTE4,
    PSTC.ATTRIBUTE5,
    PSTC.creation_date,    PSTC.created_by,    PSTC.last_updated_by,    PSTC.last_update_date,    PSTC.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmSpecTableColumn">
        select
        <include refid = "BaseSql"/>
        from PM_SPEC_TABLE_COLUMN PSTC
        <where>
            <if test="orderStructureId !=null">
                and PSTC.ORDER_STRUCTURE_ID = #{orderStructureId,jdbcType = INTEGER}
            </if>
            <if test="headerColumnNum !=null">
                and PSTC.HEADER_COLUMN_NUM = #{headerColumnNum,jdbcType = INTEGER}
            </if>
            <if test="thickFrom !=null">
                and PSTC.THICK_FROM = #{thickFrom,jdbcType = INTEGER}
            </if>
            <if test="thickTo !=null">
                and PSTC.THICK_TO = #{thickTo,jdbcType = INTEGER}
            </if>
            <if test="widFrom !=null">
                and PSTC.WID_FROM = #{widFrom,jdbcType = INTEGER}
            </if>
            <if test="widTo !=null">
                and PSTC.WID_TO = #{widTo,jdbcType = INTEGER}
            </if>
            <if test="lengthFrom !=null">
                and PSTC.LENGTH_FROM = #{lengthFrom,jdbcType = INTEGER}
            </if>
            <if test="lengthTo !=null">
                and PSTC.LENGTH_TO = #{lengthTo,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and PSTC.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSTC.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSTC.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSTC.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSTC.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSTC.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectOrderNoList" resultType="string">
        SELECT DISTINCT
          ppc.ORDER_NO
        FROM
        PM_PRO_CONT ppc
        JOIN PM_PRO_CONT_PROD_ATTR ppcpa ON ppc.ORDER_NO = ppcpa.ORDER_NO
        JOIN PM_CONT_MSC_TECH pcmt ON ppc.ORDER_NO = pcmt.ORDER_NO
        JOIN CT_MAIN cm ON ppc.ORDER_NO = cm.ORDER_NO
        <where>
            cm.ORDER_STATUS >= '40'
            AND cm.ORDER_STATUS  <![CDATA[ < ]]>  '67'
            <if test="dto.stNoList != null and dto.stNoList.size() > 0">
                AND pcmt.ST_NO in
                <foreach collection="dto.stNoList" item="stNo" open="(" close=")" separator="," >
                    #{stNo}
                </foreach>
            </if>
            <if test="dto.designProdLineCodeList != null and dto.designProdLineCodeList.size() > 0">
                AND pcmt.MSC_LINE_NO  in
                <foreach collection="dto.designProdLineCodeList" item="mscLineNo" open="(" close=")" separator="," >
                    #{mscLineNo}
                </foreach>
            </if>
            <if test="dto.delivyDateFrom !=null">
                AND ppcpa.DELIVY_DATE  <![CDATA[ >= ]]> #{dto.delivyDateFrom}
            </if>
            <if test="dto.delivyDateTo !=null">
                AND ppcpa.DELIVY_DATE  <![CDATA[ <= ]]> #{dto.delivyDateTo}
            </if>
            <if test="dto.orderCustCname !=null">
                <bind name="orderCustCnameLike" value="'%' + dto.orderCustCname + '%'"/>
                AND ppcpa.ORDER_CUST_CNAME like #{orderCustCnameLike}
            </if>
            <if test="dto.consignCustCname !=null">
                <bind name="consignCustCnameLike" value="'%' + dto.consignCustCname + '%'"/>
                AND ppcpa.CONSIGN_CUST_CNAME like #{consignCustCnameLike}
            </if>
            <if test="dto.sgSign !=null">
                <bind name="sgSignLike" value="'%' + dto.sgSign + '%'"/>
                AND ppcpa.SG_SIGN like #{sgSignLike}
            </if>
            <if test="dto.orderNoErp !=null">
                <bind name="orderNoErpLike" value="'%' + dto.orderNoErp + '%'"/>
                AND ppcpa.ORDER_NO_ERP like #{orderNoErpLike}
            </if>
            <if test="tenantId !=null">
                and ppc.TENANT_ID = #{tenantId}
            </if>
        </where>
    </select>

    <select id="selectLineList" resultType="string">
        SELECT DISTINCT
        ppcpa.ORDER_NO
        FROM
        PM_PRO_CONT_PROD_ATTR ppcpa
        JOIN PM_CONT_MSC_TECH pcmt ON ppcpa.ORDER_NO = pcmt.ORDER_NO
        JOIN PM_PRO_CONT ppc ON ppc.ORDER_NO = ppcpa.ORDER_NO
        JOIN CT_MAIN cm ON ppcpa.ORDER_NO = cm.ORDER_NO
        <where>
            cm.ORDER_STATUS >= '40'
            AND cm.ORDER_STATUS  <![CDATA[ < ]]>  '67'
            <if test="dto.stNo !=null">
                AND pcmt.ST_NO = #{dto.stNo}
            </if>
            <if test="dto.designProdLineCodeList != null and dto.designProdLineCodeList.size() > 0">
                AND pcmt.MSC_LINE_NO  in
                <foreach collection="dto.designProdLineCodeList" item="mscLineNo" open="(" close=")" separator="," >
                    #{mscLineNo}
                </foreach>
            </if>
            <if test="dto.delivyDateFrom !=null">
                AND ppcpa.DELIVY_DATE  <![CDATA[ >= ]]> #{dto.delivyDateFrom}
            </if>
            <if test="dto.delivyDateTo !=null">
                AND ppcpa.DELIVY_DATE  <![CDATA[ <= ]]> #{dto.delivyDateTo}
            </if>
            <if test="dto.orderCustCname !=null">
                AND ppcpa.ORDER_CUST_CNAME = #{dto.orderCustCname}
            </if>
            <if test="dto.consignCustCname !=null">
                AND ppcpa.CONSIGN_CUST_CNAME = #{dto.consignCustCname}
            </if>
            <if test="dto.sgSign !=null">
                AND ppcpa.SG_SIGN = #{dto.sgSign}
            </if>
            <if test="dto.orderNoErp !=null">
                AND ppcpa.ORDER_NO_ERP = #{dto.orderNoErp}
            </if>
            <if test="tenantId !=null">
                and ppcpa.TENANT_ID = #{tenantId}
            </if>
            <if test="dto.thickFrom !=null">
                and ppcpa.ORDER_THICK >= #{dto.thickFrom}
            </if>
            <if test="dto.thickTo !=null">
                and ppcpa.ORDER_THICK <![CDATA[ <= ]]>  #{dto.thickTo}
            </if>
            <if test="dto.widthFrom !=null">
                and ppcpa.ORDER_WIDTH >= #{dto.widthFrom}
            </if>
            <if test="dto.widthTo !=null">
                and ppcpa.ORDER_WIDTH <![CDATA[ <= ]]>  #{dto.widthTo}
            </if>
            <if test="dto.lenFrom !=null">
                and ppcpa.ORDER_LEN >= #{dto.lenFrom}
            </if>
            <if test="dto.lenTo !=null">
                and ppcpa.ORDER_LEN <![CDATA[ <= ]]>  #{dto.lenTo}
            </if>
        </where>
    </select>
</mapper>

