<?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.aucma.report.mapper.BoxLastShotRecordMapper">

    <resultMap type="BoxLastShotRecord" id="BoxLastShotRecordResult">
        <result property="objId" column="obj_id"/>
        <result property="system" column="system"/>
        <result property="gunCode" column="gun_code"/>
        <result property="productLineCode" column="product_line_code"/>
        <result property="stationNumber" column="stationnumber"/>
        <result property="polTemp" column="pol_temp"/>
        <result property="polHp" column="pol_hp"/>
        <result property="polVol" column="pol_vol"/>
        <result property="polUsage" column="pol_usage"/>
        <result property="isoTemp" column="iso_temp"/>
        <result property="isoHp" column="iso_hp"/>
        <result property="isoVol" column="iso_vol"/>
        <result property="isoUsage" column="iso_usage"/>
        <result property="pourNu" column="pour_nu"/>
        <result property="setTime" column="set_time"/>
        <result property="setWeight" column="set_weight"/>
        <result property="setRatio" column="set_ratio"/>
        <result property="pourWeight" column="pour_weight"/>
        <result property="pourRatio" column="pour_ratio"/>
        <result property="mpTime" column="mp_time"/>
        <result property="hpTime" column="hp_time"/>
        <result property="hydrPress" column="hydr_press"/>
        <result property="hydrTemp" column="hydr_temp"/>
        <result property="mixpistOn" column="mixpist_on"/>
        <result property="mixpistOff" column="mixpist_off"/>
        <result property="totalYield" column="total_yield"/>
        <result property="pourEnd" column="pour_end"/>
        <result property="createTime" column="create_time"/>
        <result property="systemStatus" column="systemstatus"/>
        <result property="productLineName" column="productLineName"/>
        <result property="stationName" column="stationName"/>
    </resultMap>

    <sql id="selectBoxLastShotRecordVo">
        select VBL.OBJ_ID,
               VBL.SYSTEM,
               VBL.GUN_CODE,
               VBL.PRODUCT_LINE_CODE,
               VBL.POL_TEMP,
               VBL.POL_HP,
               VBL.POL_VOL,
               VBL.POL_USAGE,
               VBL.ISO_TEMP,
               VBL.ISO_HP,
               VBL.ISO_VOL,
               VBL.ISO_USAGE,
               VBL.POUR_NU,
               VBL.SET_TIME,
               VBL.SET_WEIGHT,
               VBL.SET_RATIO,
               VBL.POUR_WEIGHT,
               VBL.POUR_RATIO,
               VBL.MP_TIME,
               VBL.HP_TIME,
               VBL.HYDR_PRESS,
               VBL.HYDR_TEMP,
               VBL.MIXPIST_ON,
               VBL.MIXPIST_OFF,
               VBL.TOTAL_YIELD,
               VBL.POUR_END,
               VBL.CREATE_TIME,
               VBL.STATIONNUMBER,
               VBL.SYSTEMSTATUS,
               BP.PRODUCT_LINE_NAME  stationName,
               BPP.PRODUCT_LINE_NAME productLineName
        from VIEW_BOX_LASTSHOTRECORD VBL
                 LEFT JOIN BASE_PRODUCTLINE BP ON BP.PRODUCT_LINE_CODE = VBL.STATIONNUMBER
                 LEFT JOIN BASE_PRODUCTLINE BPP ON BPP.PRODUCT_LINE_CODE = BP.PARENT_ID
    </sql>

    <select id="selectBoxLastShotRecordList" parameterType="BoxLastShotRecord" resultMap="BoxLastShotRecordResult">
        <include refid="selectBoxLastShotRecordVo"/>
        <where>
            <if test="system != null  and system != ''">and VBL.system = #{system}</if>
            <if test="gunCode != null  and gunCode != ''">and VBL.gun_code = #{gunCode}</if>
            <if test="productLineCode != null  and productLineCode != ''">and VBL.product_line_code = #{productLineCode}
            </if>
            <if test="stationNumber != null  and stationNumber != ''">and VBL.stationnumber = #{stationNumber}</if>
            <if test="beginBeginTime != null  and beginBeginTime != '' and endBeginTime != null  and endBeginTime != ''">
                AND TO_CHAR(VBL.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') BETWEEN #{beginBeginTime} AND #{endBeginTime}
            </if>
        </where>
        ORDER BY VBL.CREATE_TIME DESC
    </select>

    <select id="selectBoxLastShotRecordByObjId" parameterType="Long" resultMap="BoxLastShotRecordResult">
        <include refid="selectBoxLastShotRecordVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBoxLastShotRecord" parameterType="BoxLastShotRecord">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_box_lastshotrecord.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into box_lastshotrecord
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="system != null">system,</if>
            <if test="gunCode != null">gun_code,</if>
            <if test="productLineCode != null">product_line_code,</if>
            <if test="stationNumber != null">stationnumber,</if>
            <if test="polTemp != null">pol_temp,</if>
            <if test="polHp != null">pol_hp,</if>
            <if test="polVol != null">pol_vol,</if>
            <if test="polUsage != null">pol_usage,</if>
            <if test="isoTemp != null">iso_temp,</if>
            <if test="isoHp != null">iso_hp,</if>
            <if test="isoVol != null">iso_vol,</if>
            <if test="isoUsage != null">iso_usage,</if>
            <if test="pourNu != null">pour_nu,</if>
            <if test="setTime != null">set_time,</if>
            <if test="setWeight != null">set_weight,</if>
            <if test="setRatio != null">set_ratio,</if>
            <if test="pourWeight != null">pour_weight,</if>
            <if test="pourRatio != null">pour_ratio,</if>
            <if test="mpTime != null">mp_time,</if>
            <if test="hpTime != null">hp_time,</if>
            <if test="hydrPress != null">hydr_press,</if>
            <if test="hydrTemp != null">hydr_temp,</if>
            <if test="mixpistOn != null">mixpist_on,</if>
            <if test="mixpistOff != null">mixpist_off,</if>
            <if test="totalYield != null">total_yield,</if>
            <if test="pourEnd != null">pour_end,</if>
            <if test="createTime != null">create_time,</if>
            <if test="systemStatus != null">systemstatus,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="system != null">#{system},</if>
            <if test="gunCode != null">#{gunCode},</if>
            <if test="productLineCode != null">#{productLineCode},</if>
            <if test="stationNumber != null">#{stationNumber},</if>
            <if test="polTemp != null">#{polTemp},</if>
            <if test="polHp != null">#{polHp},</if>
            <if test="polVol != null">#{polVol},</if>
            <if test="polUsage != null">#{polUsage},</if>
            <if test="isoTemp != null">#{isoTemp},</if>
            <if test="isoHp != null">#{isoHp},</if>
            <if test="isoVol != null">#{isoVol},</if>
            <if test="isoUsage != null">#{isoUsage},</if>
            <if test="pourNu != null">#{pourNu},</if>
            <if test="setTime != null">#{setTime},</if>
            <if test="setWeight != null">#{setWeight},</if>
            <if test="setRatio != null">#{setRatio},</if>
            <if test="pourWeight != null">#{pourWeight},</if>
            <if test="pourRatio != null">#{pourRatio},</if>
            <if test="mpTime != null">#{mpTime},</if>
            <if test="hpTime != null">#{hpTime},</if>
            <if test="hydrPress != null">#{hydrPress},</if>
            <if test="hydrTemp != null">#{hydrTemp},</if>
            <if test="mixpistOn != null">#{mixpistOn},</if>
            <if test="mixpistOff != null">#{mixpistOff},</if>
            <if test="totalYield != null">#{totalYield},</if>
            <if test="pourEnd != null">#{pourEnd},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="systemStatus != null">#{systemStatus},</if>
        </trim>
    </insert>

    <update id="updateBoxLastShotRecord" parameterType="BoxLastShotRecord">
        update box_lastshotrecord
        <trim prefix="SET" suffixOverrides=",">
            <if test="system != null">system = #{system},</if>
            <if test="gunCode != null">gun_code = #{gunCode},</if>
            <if test="productLineCode != null">product_line_code = #{productLineCode},</if>
            <if test="stationNumber != null">stationnumber = #{stationNumber},</if>
            <if test="polTemp != null">pol_temp = #{polTemp},</if>
            <if test="polHp != null">pol_hp = #{polHp},</if>
            <if test="polVol != null">pol_vol = #{polVol},</if>
            <if test="polUsage != null">pol_usage = #{polUsage},</if>
            <if test="isoTemp != null">iso_temp = #{isoTemp},</if>
            <if test="isoHp != null">iso_hp = #{isoHp},</if>
            <if test="isoVol != null">iso_vol = #{isoVol},</if>
            <if test="isoUsage != null">iso_usage = #{isoUsage},</if>
            <if test="pourNu != null">pour_nu = #{pourNu},</if>
            <if test="setTime != null">set_time = #{setTime},</if>
            <if test="setWeight != null">set_weight = #{setWeight},</if>
            <if test="setRatio != null">set_ratio = #{setRatio},</if>
            <if test="pourWeight != null">pour_weight = #{pourWeight},</if>
            <if test="pourRatio != null">pour_ratio = #{pourRatio},</if>
            <if test="mpTime != null">mp_time = #{mpTime},</if>
            <if test="hpTime != null">hp_time = #{hpTime},</if>
            <if test="hydrPress != null">hydr_press = #{hydrPress},</if>
            <if test="hydrTemp != null">hydr_temp = #{hydrTemp},</if>
            <if test="mixpistOn != null">mixpist_on = #{mixpistOn},</if>
            <if test="mixpistOff != null">mixpist_off = #{mixpistOff},</if>
            <if test="totalYield != null">total_yield = #{totalYield},</if>
            <if test="pourEnd != null">pour_end = #{pourEnd},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="systemStatus != null">systemstatus = #{systemStatus},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBoxLastShotRecordByObjId" parameterType="Long">
        delete
        from box_lastshotrecord
        where obj_id = #{objId}
    </delete>

    <delete id="deleteBoxLastShotRecordByObjIds" parameterType="String">
        delete from box_lastshotrecord where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>