<?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.sundot.airport.attendance.mapper.AttendanceCheckRecordMapper">

    <resultMap type="AttendanceCheckRecord" id="AttendanceCheckRecordResult">
        <result property="tenantId" column="tenant_id"/>
        <result property="revision" column="revision"/>
        <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="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="checkInType" column="check_in_type"/>
        <result property="checkInTime" column="check_in_time"/>
        <result property="userName" column="user_name"/>
        <result property="remark" column="remark"/>
        <result property="checkInTypeDesc" column="check_in_type_desc"/>
        <result property="checkInPosition" column="check_in_position"/>
        <result property="checkInDate" column="check_in_date"/>
    </resultMap>

    <sql id="selectAttendanceCheckRecordVo">
        select tenant_id,
               revision,
               create_by,
               create_time,
               update_by,
               update_time,
               id,
               user_id,
               check_in_type,
               check_in_time,
               user_name,
               remark,
               check_in_type_desc,
               check_in_position,
               check_in_date
        from attendance_check_record
    </sql>

    <select id="selectAttendanceCheckRecordList" parameterType="AttendanceCheckRecord"
            resultMap="AttendanceCheckRecordResult">
        <include refid="selectAttendanceCheckRecordVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''">and tenant_id = #{tenantId}</if>
            <if test="revision != null ">and revision = #{revision}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="checkInType != null  and checkInType != ''">and check_in_type = #{checkInType}</if>
            <if test="checkInTime != null ">and check_in_time = #{checkInTime}</if>
            <if test="userName != null  and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
            <if test="remark != null  and remark != ''">and remark = #{remark}</if>
            <if test="checkInTypeDesc != null  and checkInTypeDesc != ''">and check_in_type_desc = #{checkInTypeDesc}
            </if>
            <if test="checkInPosition != null  and checkInPosition != ''">and check_in_position = #{checkInPosition}
            </if>
            <if test="checkInDate != null ">and check_in_date = #{checkInDate}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(check_in_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(check_in_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
            </if>
            <if test="checkInDateStart != null ">and check_in_date &gt;= concat(#{checkInDateStart}, ' 00:00:00')</if>
            <if test="checkInDateEnd != null ">and check_in_date &lt;= concat(#{checkInDateEnd}, ' 23:59:59')</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectAttendanceCheckRecordById" parameterType="Long" resultMap="AttendanceCheckRecordResult">
        <include refid="selectAttendanceCheckRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertAttendanceCheckRecord" parameterType="AttendanceCheckRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into attendance_check_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">tenant_id,</if>
            <if test="revision != null">revision,</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="userId != null">user_id,</if>
            <if test="checkInType != null and checkInType != ''">check_in_type,</if>
            <if test="checkInTime != null">check_in_time,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="remark != null">remark,</if>
            <if test="checkInTypeDesc != null and checkInTypeDesc != ''">check_in_type_desc,</if>
            <if test="checkInPosition != null">check_in_position,</if>
            <if test="checkInDate != null">check_in_date,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantId != null">#{tenantId},</if>
            <if test="revision != null">#{revision},</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="userId != null">#{userId},</if>
            <if test="checkInType != null and checkInType != ''">#{checkInType},</if>
            <if test="checkInTime != null">#{checkInTime},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="checkInTypeDesc != null and checkInTypeDesc != ''">#{checkInTypeDesc},</if>
            <if test="checkInPosition != null">#{checkInPosition},</if>
            <if test="checkInDate != null">#{checkInDate},</if>
        </trim>
    </insert>

    <update id="updateAttendanceCheckRecord" parameterType="AttendanceCheckRecord">
        update attendance_check_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="revision != null">revision = #{revision},</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="userId != null">user_id = #{userId},</if>
            <if test="checkInType != null and checkInType != ''">check_in_type = #{checkInType},</if>
            <if test="checkInTime != null">check_in_time = #{checkInTime},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="checkInTypeDesc != null and checkInTypeDesc != ''">check_in_type_desc = #{checkInTypeDesc},</if>
            <if test="checkInPosition != null">check_in_position = #{checkInPosition},</if>
            <if test="checkInDate != null">check_in_date = #{checkInDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAttendanceCheckRecordById" parameterType="Long">
        delete
        from attendance_check_record
        where id = #{id}
    </delete>

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