<?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.base.mapper.RobotOpsVisitorRecordMapper">

    <resultMap type="RobotOpsVisitorRecord" id="RobotOpsVisitorRecordResult">
        <result property="id"    column="id"    />
        <result property="visitorName"    column="visitor_name"    />
        <result property="mobile"    column="mobile"    />
        <result property="idCardNo"    column="id_card_no"    />
        <result property="visitType"    column="visit_type"    />
        <result property="visitorSource"    column="visitor_source"    />
        <result property="visitReason"    column="visit_reason"    />
        <result property="visitorPhoto"    column="visitor_photo"    />
        <result property="appointmentNo"    column="appointment_no"    />
        <result property="visitedPerson"    column="visited_person"    />
        <result property="visitTime"    column="visit_time"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="registerType"    column="register_type"    />
    </resultMap>

    <sql id="selectRobotOpsVisitorRecordVo">
        select id, visitor_name, mobile, id_card_no, visit_type, visitor_source, visit_reason, visitor_photo, appointment_no, visited_person, visit_time, remark, create_time, update_time, register_type from robot_ops_visitor_record
    </sql>

    <select id="selectRobotOpsVisitorRecordList" parameterType="RobotOpsVisitorRecord" resultMap="RobotOpsVisitorRecordResult">
        <include refid="selectRobotOpsVisitorRecordVo"/>
        <where>
            <if test="visitorName != null  and visitorName != ''"> and visitor_name like concat('%', #{visitorName}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="idCardNo != null  and idCardNo != ''"> and id_card_no = #{idCardNo}</if>
            <if test="visitType != null  and visitType != ''"> and visit_type = #{visitType}</if>
            <if test="visitorSource != null  and visitorSource != ''"> and visitor_source = #{visitorSource}</if>
            <if test="visitReason != null  and visitReason != ''"> and visit_reason = #{visitReason}</if>
            <if test="visitorPhoto != null  and visitorPhoto != ''"> and visitor_photo = #{visitorPhoto}</if>
            <if test="appointmentNo != null  and appointmentNo != ''"> and appointment_no = #{appointmentNo}</if>
            <if test="visitedPerson != null  and visitedPerson != ''"> and visited_person like concat('%', #{visitedPerson}, '%')</if>
            <if test="visitTime != null "> and visit_time = #{visitTime}</if>
            <if test="registerType != null  and registerType != ''"> and register_type = #{registerType}</if>
            <if test="params.beginTime != null and params.beginTime != ''">
                and date_format(visit_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and date_format(visit_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
            </if>
        </where>
    </select>

    <select id="selectRobotOpsVisitorRecordById" parameterType="Long" resultMap="RobotOpsVisitorRecordResult">
        <include refid="selectRobotOpsVisitorRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertRobotOpsVisitorRecord" parameterType="RobotOpsVisitorRecord" useGeneratedKeys="true" keyProperty="id">
        insert into robot_ops_visitor_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="visitorName != null">visitor_name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="idCardNo != null">id_card_no,</if>
            <if test="visitType != null and visitType != ''">visit_type,</if>
            <if test="visitorSource != null">visitor_source,</if>
            <if test="visitReason != null">visit_reason,</if>
            <if test="visitorPhoto != null">visitor_photo,</if>
            <if test="appointmentNo != null">appointment_no,</if>
            <if test="visitedPerson != null">visited_person,</if>
            <if test="visitTime != null">visit_time,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="registerType != null and registerType != ''">register_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="visitorName != null">#{visitorName},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="idCardNo != null">#{idCardNo},</if>
            <if test="visitType != null and visitType != ''">#{visitType},</if>
            <if test="visitorSource != null">#{visitorSource},</if>
            <if test="visitReason != null">#{visitReason},</if>
            <if test="visitorPhoto != null">#{visitorPhoto},</if>
            <if test="appointmentNo != null">#{appointmentNo},</if>
            <if test="visitedPerson != null">#{visitedPerson},</if>
            <if test="visitTime != null">#{visitTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="registerType != null and registerType != ''">#{registerType},</if>
        </trim>
    </insert>

    <update id="updateRobotOpsVisitorRecord" parameterType="RobotOpsVisitorRecord">
        update robot_ops_visitor_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="visitorName != null">visitor_name = #{visitorName},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="idCardNo != null">id_card_no = #{idCardNo},</if>
            <if test="visitType != null and visitType != ''">visit_type = #{visitType},</if>
            <if test="visitorSource != null">visitor_source = #{visitorSource},</if>
            <if test="visitReason != null">visit_reason = #{visitReason},</if>
            <if test="visitorPhoto != null">visitor_photo = #{visitorPhoto},</if>
            <if test="appointmentNo != null">appointment_no = #{appointmentNo},</if>
            <if test="visitedPerson != null">visited_person = #{visitedPerson},</if>
            <if test="visitTime != null">visit_time = #{visitTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="registerType != null and registerType != ''">register_type = #{registerType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRobotOpsVisitorRecordById" parameterType="Long">
        delete from robot_ops_visitor_record where id = #{id}
    </delete>

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