<?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.system.mapper.AccessRecordMapper">
    
    <resultMap type="AccessRecord" id="AccessRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="recordName"    column="record_name"    />
        <result property="recordPhone"    column="record_phone"    />
        <result property="recordIdCard"    column="record_id_card"    />
        <result property="recordNum"    column="record_num"    />
        <result property="recordReason"    column="record_reason"    />
        <result property="recordRemark"    column="record_remark"    />
        <result property="recordDateTime"    column="record_date_time"    />
        <result property="recordType"    column="record_type"    />
        <result property="recordSource"    column="record_source"    />
        <result property="humanFaceData"    column="human_face_data"    />
        <result property="createDept"    column="create_dept"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectAccessRecordVo">
        select record_id, record_name, record_phone, record_id_card, record_num, record_reason, record_remark, record_date_time, record_type, record_source, human_face_data, create_dept, create_by, create_time, update_by, update_time, remark from access_record
    </sql>

    <select id="selectAccessRecordList" parameterType="AccessRecord" resultMap="AccessRecordResult">
        <include refid="selectAccessRecordVo"/>
        <where>  
            <if test="recordName != null  and recordName != ''"> and record_name like concat('%', #{recordName}, '%')</if>
            <if test="recordPhone != null  and recordPhone != ''"> and record_phone = #{recordPhone}</if>
            <if test="recordIdCard != null  and recordIdCard != ''"> and record_id_card = #{recordIdCard}</if>
            <if test="recordNum != null  and recordNum != ''"> and record_num = #{recordNum}</if>
            <if test="recordReason != null  and recordReason != ''"> and record_reason = #{recordReason}</if>
            <if test="recordRemark != null  and recordRemark != ''"> and record_remark = #{recordRemark}</if>
            <if test="recordDateTime != null "> and record_date_time = #{recordDateTime}</if>
            <if test="recordType != null  and recordType != ''"> and record_type = #{recordType}</if>
            <if test="recordSource != null  and recordSource != ''"> and record_source = #{recordSource}</if>
            <if test="humanFaceData != null  and humanFaceData != ''"> and human_face_data = #{humanFaceData}</if>
            <if test="createDept != null "> and create_dept = #{createDept}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectAccessRecordByRecordId" parameterType="Long" resultMap="AccessRecordResult">
        <include refid="selectAccessRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertAccessRecord" parameterType="AccessRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into access_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordName != null">record_name,</if>
            <if test="recordPhone != null">record_phone,</if>
            <if test="recordIdCard != null">record_id_card,</if>
            <if test="recordNum != null">record_num,</if>
            <if test="recordReason != null">record_reason,</if>
            <if test="recordRemark != null">record_remark,</if>
            <if test="recordDateTime != null">record_date_time,</if>
            <if test="recordType != null">record_type,</if>
            <if test="recordSource != null">record_source,</if>
            <if test="humanFaceData != null">human_face_data,</if>
            <if test="createDept != null">create_dept,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordName != null">#{recordName},</if>
            <if test="recordPhone != null">#{recordPhone},</if>
            <if test="recordIdCard != null">#{recordIdCard},</if>
            <if test="recordNum != null">#{recordNum},</if>
            <if test="recordReason != null">#{recordReason},</if>
            <if test="recordRemark != null">#{recordRemark},</if>
            <if test="recordDateTime != null">#{recordDateTime},</if>
            <if test="recordType != null">#{recordType},</if>
            <if test="recordSource != null">#{recordSource},</if>
            <if test="humanFaceData != null">#{humanFaceData},</if>
            <if test="createDept != null">#{createDept},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAccessRecord" parameterType="AccessRecord">
        update access_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="recordName != null">record_name = #{recordName},</if>
            <if test="recordPhone != null">record_phone = #{recordPhone},</if>
            <if test="recordIdCard != null">record_id_card = #{recordIdCard},</if>
            <if test="recordNum != null">record_num = #{recordNum},</if>
            <if test="recordReason != null">record_reason = #{recordReason},</if>
            <if test="recordRemark != null">record_remark = #{recordRemark},</if>
            <if test="recordDateTime != null">record_date_time = #{recordDateTime},</if>
            <if test="recordType != null">record_type = #{recordType},</if>
            <if test="recordSource != null">record_source = #{recordSource},</if>
            <if test="humanFaceData != null">human_face_data = #{humanFaceData},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where record_id = #{recordId}
    </update>

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

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