<?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.ruoyi.nanjing.mapper.TRpWorktrayhistoryinfoMapper">

    <resultMap type="TRpWorktrayhistoryinfo" id="TRpWorktrayhistoryinfoResult">
        <result property="currentStation"    column="CurrentStation"    />
        <result property="barCode"    column="barCode"    />
        <result property="rfidNum"    column="RFIDNum"    />
        <result property="state"    column="State"    />
        <result property="updateTime"    column="updateTime"    />
        <association property="barcoderelationship" column="productBarcode" javaType="com.ruoyi.nanjing.domain.TRpBarcoderelationship" resultMap="proBarcode"/>
        <association property="substation" column="stationCode" javaType="com.ruoyi.nanjing.domain.TBdSubstation" resultMap="staCode"/>
        <association property="stationpara" column="parameter" javaType="com.ruoyi.nanjing.domain.TRpStationpara" resultMap="stationPara"/>
    </resultMap>
    <resultMap id="stationPara" type="com.ruoyi.nanjing.domain.TRpStationpara">
        <result property="id"    column="ID"    />
        <result property="barcode"    column="Barcode"    />
        <result property="semiBarcode"    column="SemiBarcode"    />
        <result property="scanBarcode"    column="ScanBarcode"    />
        <result property="rfidNO"    column="RFIDNO"    />
        <result property="shiftNo"    column="ShiftNo"    />
        <result property="stationID"    column="StationID"    />
        <result property="machineID"    column="MachineID"    />
        <result property="maskID"    column="MaskID"    />
        <result property="insertTime"    column="InsertTime"    />
        <result property="uploadFlag"    column="UploadFlag"    />
        <result property="finalFlag"    column="FinalFlag"    />
        <result property="state"    column="State"    />
    </resultMap>

    <resultMap id="staCode" type="com.ruoyi.nanjing.domain.TBdSubstation">
        <result property="StationCode" column="StationCode"/>
    </resultMap>
    <resultMap id="proBarcode" type="com.ruoyi.nanjing.domain.TRpBarcoderelationship">
        <result property="productBarcode"    column="ProductBarcode"    />
    </resultMap>
    <sql id="selectTRpWorktrayhistoryinfoVo">
        select * from T_RP_WorkTrayHistoryInfo
    </sql>

    <select id="selectTRpWorktrayhistoryinfoList"  parameterType="TRpWorktrayhistoryinfo" resultMap="TRpWorktrayhistoryinfoResult" statementType="STATEMENT">
        select t3.StationCode ,t1.RFIDNO, t1.Barcode,t2.ProductBarcode,
        t1.State,t1.InsertTime from ${substation.TableName} t1
        left join  T_RP_BarcodeRelationShip t2 on  t1.SemiBarcode=t2.SemiBarcode_Line
        left join T_BD_SubStation  t3 on t1.StationID=t3.StationID
        <where>
            <if test="rfidNO != '' and rfidNO != null "> t1.RFIDNO = ${rfidNO}</if>
            <if test="productBarcode != '' and productBarcode != null "> t2.ProductBarcode = ${productBarcode}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND t1.InsertTime >= '${beginTime}'
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND '${endTime}' >= t1.InsertTime
            </if>
        </where>
    </select>

    <select id="selectTRpWorktrayhistoryinfoById" parameterType="String" resultMap="TRpWorktrayhistoryinfoResult">
        <include refid="selectTRpWorktrayhistoryinfoVo"/>
        where CurrentStation = #{currentStation}
    </select>

    <insert id="insertTRpWorktrayhistoryinfo" parameterType="TRpWorktrayhistoryinfo">
        insert into T_RP_WorkTrayHistoryInfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="currentStation != null">CurrentStation,</if>
            <if test="barCode != null">barCode,</if>
            <if test="rfidNum != null">RFIDNum,</if>
            <if test="state != null">State,</if>
            <if test="updateTime != null">updateTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="currentStation != null">#{currentStation},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="rfidNum != null">#{rfidNum},</if>
            <if test="state != null">#{state},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTRpWorktrayhistoryinfo" parameterType="TRpWorktrayhistoryinfo">
        update T_RP_WorkTrayHistoryInfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="barCode != null">barCode = #{barCode},</if>
            <if test="rfidNum != null">RFIDNum = #{rfidNum},</if>
            <if test="state != null">State = #{state},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where CurrentStation = #{currentStation}
    </update>

    <delete id="deleteTRpWorktrayhistoryinfoById" parameterType="String">
        delete from T_RP_WorkTrayHistoryInfo where CurrentStation = #{currentStation}
    </delete>

    <delete id="deleteTRpWorktrayhistoryinfoByIds" parameterType="String">
        delete from T_RP_WorkTrayHistoryInfo where CurrentStation in
        <foreach item="currentStation" collection="array" open="(" separator="," close=")">
            #{currentStation}
        </foreach>
    </delete>

</mapper>
