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


    <sql id = "BaseSql">
    PCCL.LOAD_CONT_LOG_ID,
    PCCL.EVENT_ID,
    PCCL.SYSTEM_ID,
    PCCL.FUNC_ID,
    PCCL.MAT_KIND,
    PCCL.MAT_NO,
    PCCL.ORIGIN_MAT_NO,
    PCCL.ORDER_NO,
    PCCL.MAT_STATUS,
    PCCL.WHOLE_BACKLOG,
    PRCPA.MSC,
    PRCPA.MSC_LINE_NO,
    PRCPA.PSC,
    PRCPA.APN,
    PRCPA.ORDER_TYPE_CODE,
    PCCL.SG_STD,
    PCCL.SG_SIGN,
    PCCL.COMPLEX_DECIDE_CODE,
    PCCL.WT,
    PCCL.NUM,
    PCCL.OLD_ORDER_NO,
    PCCL.OLD_MAT_ACT_WT,
    PCCL.TENANT_ID,
    PCCL.ATTRIBUTE1,
    PCCL.ATTRIBUTE2,
    PCCL.ATTRIBUTE3,
    PCCL.ATTRIBUTE4,
    PCCL.ATTRIBUTE5,
    PCCL.creation_date,    PCCL.created_by,    PCCL.last_updated_by,    PCCL.last_update_date,    PCCL.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmCdContLog">
        select
        <include refid = "BaseSql"/>
        from PM_CD_CONT_LOG PCCL
            left join QD_TO_PO_ORDER PRCPA on PCCL.ORDER_NO = PRCPA.ORDER_NO
        <where>
            <if test="loadContLogId !=null">
                and PCCL.LOAD_CONT_LOG_ID = #{loadContLogId,jdbcType = INTEGER}
            </if>
            <if test="trackSeqNoTo !=null">
                and PCCL.TRACK_SEQ_NO &lt;= #{trackSeqNoTo,jdbcType = VARCHAR}
            </if>
            <if test="eventId !=null">
                and PCCL.EVENT_ID = #{eventId,jdbcType = VARCHAR}
            </if>
            <if test="systemId !=null">
                and PCCL.SYSTEM_ID = #{systemId,jdbcType = VARCHAR}
            </if>
            <if test="funcId !=null">
                and PCCL.FUNC_ID in
                    <foreach collection="funcIdList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="matKind !=null">
                and PCCL.MAT_KIND = #{matKind,jdbcType = VARCHAR}
            </if>
            <if test="matNo !=null">
                <bind name="matNo" value="matNo + '%'"/>
                and PCCL.MAT_NO like #{matNo,jdbcType=VARCHAR}
            </if>
            <if test="originMatNo !=null">
                and PCCL.ORIGIN_MAT_NO = #{originMatNo,jdbcType = VARCHAR}
            </if>
            <if test="orderNo !=null">
                and PCCL.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="matStatus !=null">
                and PCCL.MAT_STATUS = #{matStatus,jdbcType = VARCHAR}
            </if>
            <if test="wholeBacklog !=null">
                and PCCL.WHOLE_BACKLOG = #{wholeBacklog,jdbcType = VARCHAR}
            </if>
            <if test="msc !=null">
                and PCCL.MSC = #{msc,jdbcType = VARCHAR}
            </if>
            <if test="mscLineNo !=null">
                and PCCL.MSC_LINE_NO = #{mscLineNo,jdbcType = VARCHAR}
            </if>
            <if test="psc !=null">
                and PCCL.PSC = #{psc,jdbcType = VARCHAR}
            </if>
            <if test="apn !=null">
                and PCCL.APN = #{apn,jdbcType = VARCHAR}
            </if>
            <if test="sgStd !=null">
                and PCCL.SG_STD = #{sgStd,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PCCL.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="complexDecideCode !=null">
                and PCCL.COMPLEX_DECIDE_CODE = #{complexDecideCode,jdbcType = VARCHAR}
            </if>
            <if test="wt !=null">
                and PCCL.WT = #{wt,jdbcType = INTEGER}
            </if>
            <if test="num !=null">
                and PCCL.NUM = #{num,jdbcType = INTEGER}
            </if>
            <if test="oldOrderNo !=null">
                and PCCL.OLD_ORDER_NO = #{oldOrderNo,jdbcType = VARCHAR}
            </if>
            <if test="oldMatActWt !=null">
                and PCCL.OLD_MAT_ACT_WT = #{oldMatActWt,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and PCCL.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="dateRangeFrom !=null">
                and PCCL.CREATION_DATE >= #{dateRangeFrom}
            </if>
            <if test="dateRangeTo !=null">
                and PCCL.CREATION_DATE &lt;= #{dateRangeTo}
            </if>
        </where>
    </select>
</mapper>
