<?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.traceability.mapper.ProReadrecordMapper">
    
    <resultMap type="ProReadrecord" id="ProReadrecordResult">
        <result property="id"    column="id"    />
        <result property="machineId"    column="machineId"    />
        <result property="resource"    column="resource"    />
        <result property="equipId"    column="equipId"    />
        <result property="positionId"    column="positionId"    />
        <result property="ant"    column="ant"    />
        <result property="rfidStr"    column="rfidStr"    />
        <result property="isSuccess"    column="is_success"    />
        <result property="readTime"    column="readTime"    />
    </resultMap>

    <sql id="selectProReadrecordVo">
        select id, machineId, resource, equipId, positionId, ant, rfidStr, is_success, readTime from pro_readrecord
    </sql>

    <select id="selectProReadrecordList" parameterType="ProReadrecord" resultMap="ProReadrecordResult">
        <include refid="selectProReadrecordVo"/>
        <where>  
            <if test="resource != null  and resource != ''"> and resource = #{resource}</if>
            <if test="positionId != null "> and positionId = #{positionId}</if>
            <if test="rfidStr != null  and rfidStr != ''"> and rfidStr = #{rfidStr}</if>
            <if test="isSuccess != null "> and is_success = #{isSuccess}</if>
            <if test="params.beginReadTime != null and params.beginReadTime != '' and params.endReadTime != null and params.endReadTime != ''"> and readTime between #{params.beginReadTime} and #{params.endReadTime}</if>
        </where>
    </select>
    
    <select id="selectProReadrecordById" parameterType="Long" resultMap="ProReadrecordResult">
        <include refid="selectProReadrecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProReadrecord" parameterType="ProReadrecord" useGeneratedKeys="true" keyProperty="id">
        insert into pro_readrecord
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="machineId != null">machineId,</if>
            <if test="resource != null">resource,</if>
            <if test="equipId != null">equipId,</if>
            <if test="positionId != null">positionId,</if>
            <if test="ant != null">ant,</if>
            <if test="rfidStr != null">rfidStr,</if>
            <if test="isSuccess != null">is_success,</if>
            <if test="readTime != null">readTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="machineId != null">#{machineId},</if>
            <if test="resource != null">#{resource},</if>
            <if test="equipId != null">#{equipId},</if>
            <if test="positionId != null">#{positionId},</if>
            <if test="ant != null">#{ant},</if>
            <if test="rfidStr != null">#{rfidStr},</if>
            <if test="isSuccess != null">#{isSuccess},</if>
            <if test="readTime != null">#{readTime},</if>
         </trim>
    </insert>

    <update id="updateProReadrecord" parameterType="ProReadrecord">
        update pro_readrecord
        <trim prefix="SET" suffixOverrides=",">
            <if test="machineId != null">machineId = #{machineId},</if>
            <if test="resource != null">resource = #{resource},</if>
            <if test="equipId != null">equipId = #{equipId},</if>
            <if test="positionId != null">positionId = #{positionId},</if>
            <if test="ant != null">ant = #{ant},</if>
            <if test="rfidStr != null">rfidStr = #{rfidStr},</if>
            <if test="isSuccess != null">is_success = #{isSuccess},</if>
            <if test="readTime != null">readTime = #{readTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProReadrecordById" parameterType="Long">
        delete from pro_readrecord where id = #{id}
    </delete>

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

</mapper>