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

    <resultMap type="RobotOpsAppointmentRecord" id="RobotOpsAppointmentRecordResult">
        <result property="id"    column="id"    />
        <result property="appointmentNo"    column="appointment_no"    />
        <result property="visitorName"    column="visitor_name"    />
        <result property="mobile"    column="mobile"    />
        <result property="visitedPerson"    column="visited_person"    />
        <result property="appointmentTime"    column="appointment_time"    />
        <result property="status"    column="status"    />
        <result property="syncTime"    column="sync_time"    />
        <result property="sourcePlatform"    column="source_platform"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectRobotOpsAppointmentRecordVo">
        select id, appointment_no, visitor_name, mobile, visited_person, appointment_time, status, sync_time, source_platform, remark, create_time, update_time from robot_ops_appointment_record
    </sql>

    <select id="selectRobotOpsAppointmentRecordList" parameterType="RobotOpsAppointmentRecord" resultMap="RobotOpsAppointmentRecordResult">
        <include refid="selectRobotOpsAppointmentRecordVo"/>
        <where>
            <if test="appointmentNo != null  and appointmentNo != ''"> and appointment_no = #{appointmentNo}</if>
            <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="visitedPerson != null  and visitedPerson != ''"> and visited_person like concat('%', #{visitedPerson}, '%')</if>
            <if test="appointmentTime != null "> and appointment_time = #{appointmentTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="syncTime != null "> and sync_time = #{syncTime}</if>
            <if test="sourcePlatform != null  and sourcePlatform != ''"> and source_platform = #{sourcePlatform}</if>
            <if test="params.beginTime != null and params.beginTime != ''">
                and date_format(appointment_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and date_format(appointment_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
            </if>
        </where>
    </select>

    <select id="selectRobotOpsAppointmentRecordById" parameterType="Long" resultMap="RobotOpsAppointmentRecordResult">
        <include refid="selectRobotOpsAppointmentRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertRobotOpsAppointmentRecord" parameterType="RobotOpsAppointmentRecord" useGeneratedKeys="true" keyProperty="id">
        insert into robot_ops_appointment_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appointmentNo != null and appointmentNo != ''">appointment_no,</if>
            <if test="visitorName != null">visitor_name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="visitedPerson != null">visited_person,</if>
            <if test="appointmentTime != null">appointment_time,</if>
            <if test="status != null">status,</if>
            <if test="syncTime != null">sync_time,</if>
            <if test="sourcePlatform != null">source_platform,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appointmentNo != null and appointmentNo != ''">#{appointmentNo},</if>
            <if test="visitorName != null">#{visitorName},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="visitedPerson != null">#{visitedPerson},</if>
            <if test="appointmentTime != null">#{appointmentTime},</if>
            <if test="status != null">#{status},</if>
            <if test="syncTime != null">#{syncTime},</if>
            <if test="sourcePlatform != null">#{sourcePlatform},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateRobotOpsAppointmentRecord" parameterType="RobotOpsAppointmentRecord">
        update robot_ops_appointment_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="appointmentNo != null and appointmentNo != ''">appointment_no = #{appointmentNo},</if>
            <if test="visitorName != null">visitor_name = #{visitorName},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="visitedPerson != null">visited_person = #{visitedPerson},</if>
            <if test="appointmentTime != null">appointment_time = #{appointmentTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="syncTime != null">sync_time = #{syncTime},</if>
            <if test="sourcePlatform != null">source_platform = #{sourcePlatform},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRobotOpsAppointmentRecordById" parameterType="Long">
        delete from robot_ops_appointment_record where id = #{id}
    </delete>

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