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


    <sql id = "BaseSql">
    PSCH.STEEL_CAST_HEAT_ID,
    PSCH.ARCHIVE_FLAG,
    PSCH.MAIN_BACKLOG_CODE,
    PSCH.PONO,
    PSCH.PONO_STATUS,
    PSCH.CC_SEQ,
    PSCH.ST_NO,
    PSCH.SG_SIGN,
    PSCH.MOLD_THICK,
    PSCH.MOLD_WIDTH,
    PSCH.CAST_LOT_NO,
    PSCH.YEAR_ID,
    PSCH.CAST_LOT_DIV_NO,
    PSCH.CAST_LOT_SUM,
    PSCH.CC_MACH_NO,
    PSCH.CC_TYPE,
    PSCH.RESTRAND_FLG,
    PSCH.BACKLOG_EA,
    PSCH.REFINE_ROUTE_CODE,
    PSCH.SMELT_MODE,
    PSCH.PLAN_TAP_WT,
    PSCH.APN,
    PSCH.DEST,
    PSCH.NEW_TEST_NO,
    PSCH.STEEL_PLAN_DATE,
    PSCH.STEEL_APP_DATE,
    PSCH.PLAN_DATE,
    PSCH.CC_REQ_TIME,
    PSCH.CC_REQ_TIME_FLAG,
    PSCH.HEAT_CONFM_TIME,
    PSCH.HOT_REQ_TIME,
    PSCH.HOT_SEND_FLAG,
    PSCH.HOT_CHARGE_FLAG,
    PSCH.TD_CHG_FLG,
    PSCH.PREV_PONO,
    PSCH.SLAB_REQ,
    PSCH.FLAME_CLEAN_DIV,
    PSCH.SHIFT_POINT,
    PSCH.SHIFT_NO,
    PSCH.SHIFT_GROUP,
    PSCH.HOLD_PLANNER,
    PSCH.HOLD_TIME,
    PSCH.PLAN_RELEASER,
    PSCH.REL_TIME,
    PSCH.SEND_PLANNER,
    PSCH.SEND_TIME,
    PSCH.CC_BASE,
    PSCH.POUR_TIME,
    PSCH.ADJUST_FLAG,
    PSCH.TENANT_ID,
    PSCH.ATTRIBUTE1,
    PSCH.ATTRIBUTE2,
    PSCH.ATTRIBUTE3,
    PSCH.ATTRIBUTE4,
    PSCH.ATTRIBUTE5,
    PSCH.IS_BLOOM,
    PSCH.WITNESS_POINT_STATUS,
    PSCH.creation_date,    PSCH.created_by,    PSCH.last_updated_by,    PSCH.last_update_date,    PSCH.object_version_number
    </sql>

    <select id = "selectList" resultType = "com.xisc.pm.domain.entity.PmSteelCastHeat">
        select
        <include refid = "BaseSql"/>
        from PM_STEEL_CAST_HEAT PSCH
        <where>
            <if test="steelCastHeatId !=null">
                and PSCH.STEEL_CAST_HEAT_ID = #{steelCastHeatId,jdbcType = INTEGER}
            </if>
            <if test="archiveFlag !=null">
                and PSCH.ARCHIVE_FLAG = #{archiveFlag,jdbcType = VARCHAR}
            </if>
            <if test="mainBacklogCode !=null">
                and PSCH.MAIN_BACKLOG_CODE = #{mainBacklogCode,jdbcType = VARCHAR}
            </if>
            <if test="pono !=null">
                and PSCH.PONO = #{pono,jdbcType = VARCHAR}
            </if>
            <if test="ponoStatus !=null">
                and PSCH.PONO_STATUS = #{ponoStatus,jdbcType = VARCHAR}
            </if>
            <if test="ccSeq !=null">
                and PSCH.CC_SEQ = #{ccSeq,jdbcType = INTEGER}
            </if>
            <if test="stNo !=null">
                and PSCH.ST_NO = #{stNo,jdbcType = VARCHAR}
            </if>
            <if test="sgSign !=null">
                and PSCH.SG_SIGN = #{sgSign,jdbcType = VARCHAR}
            </if>
            <if test="moldThick !=null">
                and PSCH.MOLD_THICK = #{moldThick,jdbcType = INTEGER}
            </if>
            <if test="moldWidth !=null">
                and PSCH.MOLD_WIDTH = #{moldWidth,jdbcType = INTEGER}
            </if>
            <if test="castLotNo !=null">
                and PSCH.CAST_LOT_NO = #{castLotNo,jdbcType = VARCHAR}
            </if>
            <if test="yearId !=null">
                and PSCH.YEAR_ID = #{yearId,jdbcType = INTEGER}
            </if>
            <if test="castLotDivNo !=null">
                and PSCH.CAST_LOT_DIV_NO = #{castLotDivNo,jdbcType = INTEGER}
            </if>
            <if test="castLotSum !=null">
                and PSCH.CAST_LOT_SUM = #{castLotSum,jdbcType = INTEGER}
            </if>
            <if test="ccMachNo !=null">
                and PSCH.CC_MACH_NO = #{ccMachNo,jdbcType = VARCHAR}
            </if>
            <if test="ccType !=null">
                and PSCH.CC_TYPE = #{ccType,jdbcType = VARCHAR}
            </if>
            <if test="restrandFlg !=null">
                and PSCH.RESTRAND_FLG = #{restrandFlg,jdbcType = VARCHAR}
            </if>
            <if test="backlogEa !=null">
                and PSCH.BACKLOG_EA = #{backlogEa,jdbcType = VARCHAR}
            </if>
            <if test="refineRouteCode !=null">
                and PSCH.REFINE_ROUTE_CODE = #{refineRouteCode,jdbcType = VARCHAR}
            </if>
            <if test="smeltMode !=null">
                and PSCH.SMELT_MODE = #{smeltMode,jdbcType = INTEGER}
            </if>
            <if test="planTapWt !=null">
                and PSCH.PLAN_TAP_WT = #{planTapWt,jdbcType = INTEGER}
            </if>
            <if test="apn !=null">
                and PSCH.APN = #{apn,jdbcType = VARCHAR}
            </if>
            <if test="dest !=null">
                and PSCH.DEST = #{dest,jdbcType = VARCHAR}
            </if>
            <if test="newTestNo !=null">
                and PSCH.NEW_TEST_NO = #{newTestNo,jdbcType = VARCHAR}
            </if>
            <if test="steelPlanDate !=null">
                and PSCH.STEEL_PLAN_DATE = #{steelPlanDate,jdbcType = OTHER}
            </if>
            <if test="steelAppDate !=null">
                and PSCH.STEEL_APP_DATE = #{steelAppDate,jdbcType = OTHER}
            </if>
            <if test="planDate !=null">
                and PSCH.PLAN_DATE = #{planDate,jdbcType = OTHER}
            </if>
            <if test="ccReqTime !=null">
                and PSCH.CC_REQ_TIME = #{ccReqTime,jdbcType = OTHER}
            </if>
            <if test="ccReqTimeFlag !=null">
                and PSCH.CC_REQ_TIME_FLAG = #{ccReqTimeFlag,jdbcType = VARCHAR}
            </if>
            <if test="heatConfmTime !=null">
                and PSCH.HEAT_CONFM_TIME = #{heatConfmTime,jdbcType = OTHER}
            </if>
            <if test="hotReqTime !=null">
                and PSCH.HOT_REQ_TIME = #{hotReqTime,jdbcType = OTHER}
            </if>
            <if test="hotSendFlag !=null">
                and PSCH.HOT_SEND_FLAG = #{hotSendFlag,jdbcType = VARCHAR}
            </if>
            <if test="hotChargeFlag !=null">
                and PSCH.HOT_CHARGE_FLAG = #{hotChargeFlag,jdbcType = VARCHAR}
            </if>
            <if test="tdChgFlg !=null">
                and PSCH.TD_CHG_FLG = #{tdChgFlg,jdbcType = INTEGER}
            </if>
            <if test="prevPono !=null">
                and PSCH.PREV_PONO = #{prevPono,jdbcType = VARCHAR}
            </if>
            <if test="slabReq !=null">
                and PSCH.SLAB_REQ = #{slabReq,jdbcType = VARCHAR}
            </if>
            <if test="flameCleanDiv !=null">
                and PSCH.FLAME_CLEAN_DIV = #{flameCleanDiv,jdbcType = VARCHAR}
            </if>
            <if test="shiftPoint !=null">
                and PSCH.SHIFT_POINT = #{shiftPoint,jdbcType = VARCHAR}
            </if>
            <if test="shiftNo !=null">
                and PSCH.SHIFT_NO = #{shiftNo,jdbcType = VARCHAR}
            </if>
            <if test="shiftGroup !=null">
                and PSCH.SHIFT_GROUP = #{shiftGroup,jdbcType = VARCHAR}
            </if>
            <if test="holdPlanner !=null">
                and PSCH.HOLD_PLANNER = #{holdPlanner,jdbcType = VARCHAR}
            </if>
            <if test="holdTime !=null">
                and PSCH.HOLD_TIME = #{holdTime,jdbcType = VARCHAR}
            </if>
            <if test="planReleaser !=null">
                and PSCH.PLAN_RELEASER = #{planReleaser,jdbcType = VARCHAR}
            </if>
            <if test="relTime !=null">
                and PSCH.REL_TIME = #{relTime,jdbcType = VARCHAR}
            </if>
            <if test="sendPlanner !=null">
                and PSCH.SEND_PLANNER = #{sendPlanner,jdbcType = VARCHAR}
            </if>
            <if test="sendTime !=null">
                and PSCH.SEND_TIME = #{sendTime,jdbcType = VARCHAR}
            </if>
            <if test="ccBase !=null">
                and PSCH.CC_BASE = #{ccBase,jdbcType = VARCHAR}
            </if>
            <if test="pourTime !=null">
                and PSCH.POUR_TIME = #{pourTime,jdbcType = INTEGER}
            </if>
            <if test="adjustFlag !=null">
                and PSCH.ADJUST_FLAG = #{adjustFlag,jdbcType = VARCHAR}
            </if>
            <if test="tenantId !=null">
                and PSCH.TENANT_ID = #{tenantId,jdbcType = INTEGER}
            </if>
            <if test="attribute1 !=null">
                and PSCH.ATTRIBUTE1 = #{attribute1,jdbcType = VARCHAR}
            </if>
            <if test="attribute2 !=null">
                and PSCH.ATTRIBUTE2 = #{attribute2,jdbcType = VARCHAR}
            </if>
            <if test="attribute3 !=null">
                and PSCH.ATTRIBUTE3 = #{attribute3,jdbcType = VARCHAR}
            </if>
            <if test="attribute4 !=null">
                and PSCH.ATTRIBUTE4 = #{attribute4,jdbcType = VARCHAR}
            </if>
            <if test="attribute5 !=null">
                and PSCH.ATTRIBUTE5 = #{attribute5,jdbcType = VARCHAR}
            </if>
            <if test="isBloom !=null">
                and PSCH.IS_BLOOM = #{isBloom,jdbcType = INTEGER}
            </if>
            <if test="witnessPointStatus !=null">
                and PSCH.WITNESS_POINT_STATUS = #{witnessPointStatus,jdbcType = VARCHAR}
            </if>
        </where>
    </select>

    <select id="queryList" resultType="com.xisc.pm.domain.entity.PmSteelCastHeat">
        SELECT
        <include refid = "BaseSql"/>
        FROM
        PM_STEEL_CAST_HEAT PSCH
        <where>
            PSCH.PONO_STATUS  <![CDATA[ <= ]]> '15'
            <if test="tenantId !=null">
                and PSCH.TENANT_ID = #{tenantId}
            </if>
            <if test="dto.status !=null">
                and PSCH.PONO_STATUS = #{dto.status}
            </if>
            <if test="dto.ccType !=null">
                and PSCH.CC_TYPE = #{dto.ccType}
            </if>
            <if test="dto.mainBacklogCode !=null">
                AND PSCH.MAIN_BACKLOG_CODE = #{dto.mainBacklogCode}
            </if>
            <if test="dto.planDate !=null and dto.status != '11'">
                  AND trunc(PSCH.PLAN_DATE) = trunc(#{dto.planDate})
            </if>
            <if test="dto.stNo !=null">
                AND PSCH.ST_NO = #{dto.stNo}
            </if>
            <if test="dto.userId !=null">
                AND PSCH.created_by = #{dto.userId}
            </if>
        </where>
        order by PSCH.CAST_LOT_NO asc, PSCH.CAST_LOT_DIV_NO asc
    </select>

    <select id="queryPonoIsAdjust" resultType="string">
        SELECT
          PSCH.PONO
        FROM
        PM_STEEL_CAST_HEAT PSCH
        join SM_PREPLAN sp on PSCH.PONO = sp.PONO
        <where>
            sp.ADJUST_FLAG = 1
            <if test="tenantId !=null">
                and PSCH.TENANT_ID = #{tenantId}
            </if>
        </where>
    </select>
</mapper>

