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

    <resultMap type="TRpWorktrayrealtimeinfo" id="TRpWorktrayrealtimeinfoResult">
        <result property="rfidNum"    column="RFIDNum"    />
        <result property="barCode"    column="barCode"    />
        <result property="semiBarcode"    column="SemiBarcode"    />
        <result property="currentStation"    column="CurrentStation"    />
        <result property="state"    column="State"    />
        <result property="updateTime"    column="updateTime"    />
        <result property="usedFlag"    column="UsedFlag"    />
        <result property="insertTime"    column="InsertTime"    />
        <result property="deleteTime"    column="DeleteTime"    />
        <association property="barcoderelationship" column="productBarcode" javaType="com.ruoyi.nanjing.domain.TRpBarcoderelationship" resultMap="proBarcode"/>
    </resultMap>

    <resultMap id="proBarcode" type="com.ruoyi.nanjing.domain.TRpBarcoderelationship">
        <result property="productBarcode"    column="ProductBarcode"    />
    </resultMap>
    <sql id="selectTRpWorktrayrealtimeinfoVo">
        select RFIDNum, barCode, SemiBarcode, CurrentStation, State, updateTime, UsedFlag, InsertTime, DeleteTime from T_RP_WorkTrayRealTimeInfo
    </sql>

    <select id="selectTRpWorktrayrealtimeinfoList" parameterType="TRpWorktrayrealtimeinfo" resultMap="TRpWorktrayrealtimeinfoResult">
        <include refid="selectTRpWorktrayrealtimeinfoVo"/>
        <where>
            <if test="rfidNum != '' "> and RFIDNum like ('%' + #{rfidNum} + '%')</if>
            <if test="usedFlag != null "> and UsedFlag = #{usedFlag}</if>
        </where>
    </select>

    <select id="selectTRpWorktrayrealtimeinfoById" parameterType="String" resultMap="TRpWorktrayrealtimeinfoResult">
        <include refid="selectTRpWorktrayrealtimeinfoVo"/>
        where RFIDNum = #{rfidNum}
    </select>

    <select id="selectrealtimeinfoList" resultMap="TRpWorktrayrealtimeinfoResult">
        select t1.RFIDnum,t1.barcode,t3.ProductBarcode ,t1.state,t1.UpdateTime  from  dbo.T_RP_WorkTrayRealTimeInfo  t1  left join T_BD_SubStation t2 on t1.currentStation=t2.StationID   left join dbo.T_RP_BarcodeRelationShip t3 on t1.SemiBarcode=t3.SemiBarcode_Line
        <where>
            <if test="StationCode != '' "> and t2.StationID = #{StationCode}</if>
            <if test="rfidNum != '' "> and t1.RFIDnum = #{rfidNum}</if>
            and  UsedFlag='1'
        </where>
    </select>

    <insert id="insertTRpWorktrayrealtimeinfo" parameterType="TRpWorktrayrealtimeinfo">
        insert into T_RP_WorkTrayRealTimeInfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rfidNum != null">RFIDNum,</if>
            <if test="barCode != null">barCode,</if>
            <if test="semiBarcode != null">SemiBarcode,</if>
            <if test="currentStation != null">CurrentStation,</if>
            <if test="state != null">State,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="usedFlag != null">UsedFlag,</if>
            <if test="insertTime != null">InsertTime,</if>
            <if test="deleteTime != null">DeleteTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="rfidNum != null">#{rfidNum},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="semiBarcode != null">#{semiBarcode},</if>
            <if test="currentStation != null">#{currentStation},</if>
            <if test="state != null">#{state},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="usedFlag != null">#{usedFlag},</if>
            <if test="insertTime != null">#{insertTime},</if>
            <if test="deleteTime != null">#{deleteTime},</if>
         </trim>
    </insert>

    <update id="updateTRpWorktrayrealtimeinfo" parameterType="TRpWorktrayrealtimeinfo">
        update T_RP_WorkTrayRealTimeInfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="barCode != null">barCode = #{barCode},</if>
            <if test="semiBarcode != null">SemiBarcode = #{semiBarcode},</if>
            <if test="currentStation != null">CurrentStation = #{currentStation},</if>
            <if test="state != null">State = #{state},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="usedFlag != null">UsedFlag = #{usedFlag},</if>
            <if test="insertTime != null">InsertTime = #{insertTime},</if>
            <if test="deleteTime != null">DeleteTime = #{deleteTime},</if>
        </trim>
        where RFIDNum = #{rfidNum}
    </update>

    <delete id="deleteTRpWorktrayrealtimeinfoById" parameterType="String">
        delete from T_RP_WorkTrayRealTimeInfo where RFIDNum = #{rfidNum}
    </delete>

    <delete id="deleteTRpWorktrayrealtimeinfoByIds" parameterType="String">
        delete from T_RP_WorkTrayRealTimeInfo where RFIDNum in
        <foreach item="rfidNum" collection="array" open="(" separator="," close=")">
            #{rfidNum}
        </foreach>
    </delete>

</mapper>
