<?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.zehong.system.mapper.TNfcRecordMapper">

    <resultMap type="TNfcRecord" id="TNfcRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="nfcId"    column="nfc_id"    />
        <result property="isNormal"    column="is_normal"    />
        <result property="picture"    column="picture"    />
        <result property="remarks"    column="remarks"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUser"    column="create_user"    />
        <result property="userName"    column="userName"    />
        <result property="patrolAddress"    column="patrol_address"    />
        <result property="patrolComent"    column="patrol_coment"    />
        <result property="patrolFrequency"    column="patrol_frequency"    />
    </resultMap>

    <sql id="selectTNfcRecordVo">
        select record_id, nfc_id, is_normal, picture, remarks, create_time, create_user from t_nfc_record
    </sql>

    <select id="selectTNfcRecordList" parameterType="TNfcRecord" resultMap="TNfcRecordResult">
        SELECT nr.record_id, nr.nfc_id, nr.is_normal, nr.picture, nr.remarks, nr.create_time, nr.create_user,
        u.`user_name` AS  userName,
        ns.`patrol_address` ,ns.`patrol_coment`,ns.`patrol_frequency`
        FROM t_nfc_record nr LEFT JOIN t_nfc_setting ns ON ns.`nfc_id` = nr.`nfc_id`
        LEFT JOIN sys_user u ON u.user_id = nr.create_user
        <where>
            <if test="nfcId != null "> and nr.nfc_id = #{nfcId}</if>
            <if test="isNormal != null "> and nr.is_normal = #{isNormal}</if>
            <if test="picture != null  and picture != ''"> and nr.picture = #{picture}</if>
            <if test="remarks != null  and remarks != ''"> and nr.remarks = #{remarks}</if>
            <if test="createUser != null  and createUser != ''"> and nr.create_user = #{createUser}</if>
            <if test="startTime != null  and startTime != ''"> and nr.create_time &gt; #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and nr.create_time &lt; #{endTime}</if>
        </where>
        order By nr.create_time desc
    </select>

    <select id="selectTNfcRecordById" parameterType="Long" resultMap="TNfcRecordResult">
        <include refid="selectTNfcRecordVo"/>
        where record_id = #{recordId}
    </select>

    <insert id="insertTNfcRecord" parameterType="TNfcRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into t_nfc_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nfcId != null">nfc_id,</if>
            <if test="isNormal != null">is_normal,</if>
            <if test="picture != null">picture,</if>
            <if test="remarks != null">remarks,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUser != null">create_user,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nfcId != null">#{nfcId},</if>
            <if test="isNormal != null">#{isNormal},</if>
            <if test="picture != null">#{picture},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUser != null">#{createUser},</if>
         </trim>
    </insert>

    <update id="updateTNfcRecord" parameterType="TNfcRecord">
        update t_nfc_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="nfcId != null">nfc_id = #{nfcId},</if>
            <if test="isNormal != null">is_normal = #{isNormal},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteTNfcRecordById" parameterType="Long">
        delete from t_nfc_record where record_id = #{recordId}
    </delete>

    <delete id="deleteTNfcRecordByIds" parameterType="String">
        delete from t_nfc_record where record_id in
        <foreach item="recordId" collection="array" open="(" separator="," close=")">
            #{recordId}
        </foreach>
    </delete>
</mapper>
