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


    <sql id = "BaseSql">
    CD.DET_ID,
    CD.CONTRACT_NUM,
    CD.ORDER_NO,
    CD.WHOLE_BACKLOG_CODE,
    CD.SUB_BACKLOG_CODE,
    CD.INS_WGT,
    CD.INS_NUM,
    CD.STOCK_WGT,
    CD.STOCK_NUM,
    CD.PLAN_WGT,
    CD.PLAN_NUM,
    CD.PASS_WGT,
    CD.PASS_NUM,
    CD.LACK_WGT,
    CD.LACK_NUM,
    CD.SCHE_PROD_WGT,
    CD.SCHE_PROD_NUM,
    CD.HOLD_WGT,
    CD.HOLD_NUM,
    CD.MOVE_IN_WGT,
    CD.MOVE_IN_NUM,
    CD.MOVE_OUT_WGT,
    CD.MOVE_OUT_NUM,
    CD.OVER_DEVO_WGT,
    CD.OVER_DEVO_NUM,
    CD.SUP_DEVO_WGT,
    CD.SUP_DEVO_NUM,
    CD.REWORK_WGT,
    CD.REWORK_NUM,
    CD.WASTE_WGT,
    CD.WASTE_NUM,
    CD.END_WGT,
    CD.END_NUM,
    CD.TENANT_ID,
    CD.creation_date,    CD.created_by,    CD.last_updated_by,    CD.last_update_date,    CD.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.vo.CtDetVO">
        select
        <include refid = "BaseSql"/>
        from XISC.CT_DET CD
        <where>
        	<if test="orderNoList != null and orderNoList.size() > 0">
				and cd.ORDER_NO in 
				<foreach collection="orderNoList" item="orderNoItem" open="(" close=")" separator="," >
					#{orderNoItem}
				</foreach>
			</if>
        	<if test="wholeBacklogCodeList != null and wholeBacklogCodeList.size() > 0">
				and cd.WHOLE_BACKLOG_CODE in 
				<foreach collection="wholeBacklogCodeList" item="wholeBacklogCodeItem" open="(" close=")" separator="," >
					#{wholeBacklogCodeItem}
				</foreach>
			</if>
            <if test="detId !=null">
                and CD.DET_ID = #{detId,jdbcType = INTEGER}
            </if>
            <if test="contractNum !=null">
                and CD.CONTRACT_NUM = #{contractNum,jdbcType = VARCHAR}
            </if>
            <if test="orderNo !=null">
                and CD.ORDER_NO = #{orderNo,jdbcType = VARCHAR}
            </if>
            <if test="wholeBacklogCode !=null">
                and CD.WHOLE_BACKLOG_CODE = #{wholeBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="subBacklogCode !=null">
                and CD.SUB_BACKLOG_CODE = #{subBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="insWgt !=null">
                and CD.INS_WGT = #{insWgt,jdbcType = INTEGER}
            </if>
            <if test="insNum !=null">
                and CD.INS_NUM = #{insNum,jdbcType = INTEGER}
            </if>
            <if test="stockWgt !=null">
                and CD.STOCK_WGT = #{stockWgt,jdbcType = INTEGER}
            </if>
            <if test="stockNum !=null">
                and CD.STOCK_NUM = #{stockNum,jdbcType = INTEGER}
            </if>
            <if test="planWgt !=null">
                and CD.PLAN_WGT = #{planWgt,jdbcType = INTEGER}
            </if>
            <if test="planNum !=null">
                and CD.PLAN_NUM = #{planNum,jdbcType = INTEGER}
            </if>
            <if test="passWgt !=null">
                and CD.PASS_WGT = #{passWgt,jdbcType = INTEGER}
            </if>
            <if test="passNum !=null">
                and CD.PASS_NUM = #{passNum,jdbcType = INTEGER}
            </if>
            <if test="lackWgt !=null">
                and CD.LACK_WGT = #{lackWgt,jdbcType = INTEGER}
            </if>
            <if test="lackNum !=null">
                and CD.LACK_NUM = #{lackNum,jdbcType = INTEGER}
            </if>
            <if test="scheProdWgt !=null">
                and CD.SCHE_PROD_WGT = #{scheProdWgt,jdbcType = INTEGER}
            </if>
            <if test="scheProdNum !=null">
                and CD.SCHE_PROD_NUM = #{scheProdNum,jdbcType = INTEGER}
            </if>
            <if test="holdWgt !=null">
                and CD.HOLD_WGT = #{holdWgt,jdbcType = INTEGER}
            </if>
            <if test="holdNum !=null">
                and CD.HOLD_NUM = #{holdNum,jdbcType = INTEGER}
            </if>
            <if test="moveInWgt !=null">
                and CD.MOVE_IN_WGT = #{moveInWgt,jdbcType = INTEGER}
            </if>
            <if test="moveInNum !=null">
                and CD.MOVE_IN_NUM = #{moveInNum,jdbcType = INTEGER}
            </if>
            <if test="moveOutWgt !=null">
                and CD.MOVE_OUT_WGT = #{moveOutWgt,jdbcType = INTEGER}
            </if>
            <if test="moveOutNum !=null">
                and CD.MOVE_OUT_NUM = #{moveOutNum,jdbcType = INTEGER}
            </if>
            <if test="overDevoWgt !=null">
                and CD.OVER_DEVO_WGT = #{overDevoWgt,jdbcType = INTEGER}
            </if>
            <if test="overDevoNum !=null">
                and CD.OVER_DEVO_NUM = #{overDevoNum,jdbcType = INTEGER}
            </if>
            <if test="supDevoWgt !=null">
                and CD.SUP_DEVO_WGT = #{supDevoWgt,jdbcType = INTEGER}
            </if>
            <if test="supDevoNum !=null">
                and CD.SUP_DEVO_NUM = #{supDevoNum,jdbcType = INTEGER}
            </if>
            <if test="reworkWgt !=null">
                and CD.REWORK_WGT = #{reworkWgt,jdbcType = INTEGER}
            </if>
            <if test="reworkNum !=null">
                and CD.REWORK_NUM = #{reworkNum,jdbcType = INTEGER}
            </if>
            <if test="wasteWgt !=null">
                and CD.WASTE_WGT = #{wasteWgt,jdbcType = INTEGER}
            </if>
            <if test="wasteNum !=null">
                and CD.WASTE_NUM = #{wasteNum,jdbcType = INTEGER}
            </if>
            <if test="endWgt !=null">
                and CD.END_WGT = #{endWgt,jdbcType = INTEGER}
            </if>
            <if test="endNum !=null">
                and CD.END_NUM = #{endNum,jdbcType = INTEGER}
            </if>
            <if test="tenantId !=null">
                and CD.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
        </where>
    </select>
    
    <select id="selectCtPrcPredPlanTime" resultType="com.xisc.pm.domain.vo.CtPrcPredPlanTimeVO">
      select 
      			  cpppt.ORDER_NO,
                  cpppt.WHOLE_BACKLOG_CODE,
                  cpppt.PLAN_END_DATE,
                  cpppt.LATEST_END_DATE
       from CT_PRC_PRED_PLAN_TIME cpppt
      where cpppt.TENANT_ID = #{tenantId}
      		<if test="orderNoList != null and orderNoList.size() > 0">
				and cpppt.ORDER_NO in 
				<foreach collection="orderNoList" item="orderNoItem" open="(" close=")" separator="," >
					#{orderNoItem}
				</foreach>
			</if>
        	<if test="wholeBacklogCodeList != null and wholeBacklogCodeList.size() > 0">
				and cpppt.WHOLE_BACKLOG_CODE in 
				<foreach collection="wholeBacklogCodeList" item="wholeBacklogCodeItem" open="(" close=")" separator="," >
					#{wholeBacklogCodeItem}
				</foreach>
			</if>
    </select>
</mapper>
