<?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.KaoqinRecordMapper">
    
    <resultMap type="KaoqinRecord" id="KaoqinRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="kaYear"    column="ka_year"    />
        <result property="kaMonth"    column="ka_month"    />
        <result property="kaDay"    column="ka_day"    />
        <result property="kaWeek"    column="ka_week"    />
        <result property="kaTime"    column="ka_time"    />
        <result property="kaAddressAmIn"    column="ka_address_am_in"    />
        <result property="kaLog"    column="ka_log"    />
        <result property="kaLat"    column="ka_lat"    />
        <result property="kaSort"    column="ka_sort"    />
        <result property="kaAddressAmOut"    column="ka_address_am_out"    />
        <result property="kaAddressPmIn"    column="ka_address_pm_in"    />
        <result property="kaAddressPmOut"    column="ka_address_pm_out"    />
        <result property="kaTimeAmIn"    column="ka_time_am_in"    />
        <result property="kaTimeAmOut"    column="ka_time_am_out"    />
        <result property="kaTimePmIn"    column="ka_time_pm_in"    />
        <result property="kaTimePmOut"    column="ka_time_pm_out"    />
        <result property="kaTypeAmIn"    column="ka_type_am_in"    />
        <result property="kaTypeAmOut"    column="ka_type_am_out"    />
        <result property="kaTypePmIn"    column="ka_type_pm_in"    />
        <result property="kaTypePmOut"    column="ka_type_pm_out"    />
        <result property="kaAmInPhoto"    column="ka_am_out_photo"    />
        <result property="kaAmOutPhoto"    column="ka_type_pm_photo"    />
        <result property="kaPmInPhoto"    column="ka_pm_in_photo"    />
        <result property="kaPmOutPhoto"    column="ka_pm_out_photo"    />
        <result property="kaStatus"    column="ka_status"    />
        <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="remarkAmIn"    column="remark_am_in"    />
        <result property="remarkAmOut"    column="remark_am_out"    />
        <result property="remarkPmIn"    column="remark_pm_in"    />
        <result property="remarkPmOut"    column="remark_pm_out"    />
    </resultMap>

    <sql id="selectKaoqinRecordVo">
        select record_id, user_id, user_name, dept_id, dept_name, ancestors, ka_year, ka_month, ka_day, ka_week, ka_time, ka_address_am_in, ka_log, ka_lat, ka_sort, ka_address_am_out, ka_address_pm_in, ka_address_pm_out, ka_time_am_in, ka_time_am_out, ka_time_pm_in, ka_time_pm_out, ka_type_am_in, ka_type_am_out, ka_type_pm_in, ka_type_pm_out,ka_am_in_photo,ka_am_out_photo,ka_pm_in_photo,ka_pm_out_photo, ka_status, create_by, create_time, update_by, update_time, remark_am_in, remark_am_out, remark_pm_in, remark_pm_out from kaoqin_record
    </sql>

    <select id="selectKaoqinRecordList" parameterType="KaoqinRecord" resultMap="KaoqinRecordResult">
        <include refid="selectKaoqinRecordVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="deptId != null  and deptId != ''"> and find_in_set(#{deptId}, ancestors)</if>
            <if test="kaYear != null  and kaYear != ''"> and ka_year = #{kaYear}</if>
            <if test="kaMonth != null  and kaMonth != ''"> and ka_month = #{kaMonth}</if>
            <if test="kaDay != null  and kaDay != ''"> and ka_day = #{kaDay}</if>
            <if test="kaWeek != null  and kaWeek != ''"> and ka_week = #{kaWeek}</if>
            <if test="kaTime != null  and kaTime != ''"> and ka_time = #{kaTime}</if>
            <if test="kaAddressAmIn != null  and kaAddressAmIn != ''"> and ka_address_am_in = #{kaAddressAmIn}</if>
            <if test="kaLog != null  and kaLog != ''"> and ka_log = #{kaLog}</if>
            <if test="kaLat != null  and kaLat != ''"> and ka_lat = #{kaLat}</if>
            <if test="kaSort != null  and kaSort != ''"> and ka_sort = #{kaSort}</if>
            <if test="kaAddressAmOut != null  and kaAddressAmOut != ''"> and ka_address_am_out = #{kaAddressAmOut}</if>
            <if test="kaAddressPmIn != null  and kaAddressPmIn != ''"> and ka_address_pm_in = #{kaAddressPmIn}</if>
            <if test="kaAddressPmOut != null  and kaAddressPmOut != ''"> and ka_address_pm_out = #{kaAddressPmOut}</if>
            <if test="kaTimeAmIn != null "> and ka_time_am_in = #{kaTimeAmIn}</if>
            <if test="kaTimeAmOut != null "> and ka_time_am_out = #{kaTimeAmOut}</if>
            <if test="kaTimePmIn != null "> and ka_time_pm_in = #{kaTimePmIn}</if>
            <if test="kaTimePmOut != null "> and ka_time_pm_out = #{kaTimePmOut}</if>
            <if test="kaTypeAmIn != null  and kaTypeAmIn != ''"> and ka_type_am_in = #{kaTypeAmIn}</if>
            <if test="kaTypeAmOut != null  and kaTypeAmOut != ''"> and ka_type_am_out = #{kaTypeAmOut}</if>
            <if test="kaTypePmIn != null  and kaTypePmIn != ''"> and ka_type_pm_in = #{kaTypePmIn}</if>
            <if test="kaTypePmOut != null  and kaTypePmOut != ''"> and ka_type_pm_out = #{kaTypePmOut}</if>
            <if test="kaType != null  and kaType != ''"> and (ka_type_am_in = #{kaType} or ka_type_am_out = #{kaType} or ka_type_pm_in = #{kaType} or ka_type_pm_out = #{kaType})</if>
            <if test="kaStatus != null  and kaStatus != ''"> and ka_status = #{kaStatus}</if>
            <if test="remarkAmIn != null  and remarkAmIn != ''"> and remark_am_in = #{remarkAmIn}</if>
            <if test="remarkAmOut != null  and remarkAmOut != ''"> and remark_am_out = #{remarkAmOut}</if>
            <if test="remarkPmIn != null  and remarkPmIn != ''"> and remark_pm_in = #{remarkPmIn}</if>
            <if test="remarkPmOut != null  and remarkPmOut != ''"> and remark_pm_out = #{remarkPmOut}</if>
        </where>
    </select>
    
    <select id="selectKaoqinRecordByRecordId" parameterType="Long" resultMap="KaoqinRecordResult">
        <include refid="selectKaoqinRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertKaoqinRecord" parameterType="KaoqinRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into kaoqin_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="kaYear != null and kaYear != ''">ka_year,</if>
            <if test="kaMonth != null and kaMonth != ''">ka_month,</if>
            <if test="kaDay != null and kaDay != ''">ka_day,</if>
            <if test="kaWeek != null and kaWeek != ''">ka_week,</if>
            <if test="kaTime != null and kaTime != ''">ka_time,</if>
            <if test="kaAddressAmIn != null and kaAddressAmIn != ''">ka_address_am_in,</if>
            <if test="kaLog != null and kaLog != ''">ka_log,</if>
            <if test="kaLat != null and kaLat != ''">ka_lat,</if>
            <if test="kaSort != null and kaSort != ''">ka_sort,</if>
            <if test="kaAddressAmOut != null">ka_address_am_out,</if>
            <if test="kaAddressPmIn != null">ka_address_pm_in,</if>
            <if test="kaAddressPmOut != null">ka_address_pm_out,</if>
            <if test="kaTimeAmIn != null">ka_time_am_in,</if>
            <if test="kaTimeAmOut != null">ka_time_am_out,</if>
            <if test="kaTimePmIn != null">ka_time_pm_in,</if>
            <if test="kaTimePmOut != null">ka_time_pm_out,</if>
            <if test="kaTypeAmIn != null">ka_type_am_in,</if>
            <if test="kaTypeAmOut != null">ka_type_am_out,</if>
            <if test="kaTypePmIn != null">ka_type_pm_in,</if>
            <if test="kaTypePmOut != null">ka_type_pm_out,</if>
            <if test="kaAmInPhoto != null">ka_am_in_photo,</if>
            <if test="kaAmOutPhoto != null">ka_am_out_photo,</if>
            <if test="kaPmInPhoto != null">ka_pm_in_photo,</if>
            <if test="kaPmOutPhoto != null">ka_pm_out_photo,</if>
            <if test="kaStatus != null and kaStatus != ''">ka_status,</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="remarkAmIn != null">remark_am_in,</if>
            <if test="remarkAmOut != null">remark_am_out,</if>
            <if test="remarkPmIn != null">remark_pm_in,</if>
            <if test="remarkPmOut != null">remark_pm_out,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="kaYear != null and kaYear != ''">#{kaYear},</if>
            <if test="kaMonth != null and kaMonth != ''">#{kaMonth},</if>
            <if test="kaDay != null and kaDay != ''">#{kaDay},</if>
            <if test="kaWeek != null and kaWeek != ''">#{kaWeek},</if>
            <if test="kaTime != null and kaTime != ''">#{kaTime},</if>
            <if test="kaAddressAmIn != null and kaAddressAmIn != ''">#{kaAddressAmIn},</if>
            <if test="kaLog != null and kaLog != ''">#{kaLog},</if>
            <if test="kaLat != null and kaLat != ''">#{kaLat},</if>
            <if test="kaSort != null and kaSort != ''">#{kaSort},</if>
            <if test="kaAddressAmOut != null">#{kaAddressAmOut},</if>
            <if test="kaAddressPmIn != null">#{kaAddressPmIn},</if>
            <if test="kaAddressPmOut != null">#{kaAddressPmOut},</if>
            <if test="kaTimeAmIn != null">#{kaTimeAmIn},</if>
            <if test="kaTimeAmOut != null">#{kaTimeAmOut},</if>
            <if test="kaTimePmIn != null">#{kaTimePmIn},</if>
            <if test="kaTimePmOut != null">#{kaTimePmOut},</if>
            <if test="kaTypeAmIn != null">#{kaTypeAmIn},</if>
            <if test="kaTypeAmOut != null">#{kaTypeAmOut},</if>
            <if test="kaTypePmIn != null">#{kaTypePmIn},</if>
            <if test="kaTypePmOut != null">#{kaTypePmOut},</if>
            <if test="kaAmInPhoto != null">#{kaAmInPhoto},</if>
            <if test="kaAmOutPhoto != null">#{kaAmOutPhoto},</if>
            <if test="kaPmInPhoto != null">#{kaPmInPhoto},</if>
            <if test="kaPmOutPhoto != null">#{kaPmOutPhoto},</if>
            <if test="kaStatus != null">#{kaStatus},</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="remarkAmIn != null">#{remarkAmIn},</if>
            <if test="remarkAmOut != null">#{remarkAmOut},</if>
            <if test="remarkPmIn != null">#{remarkPmIn},</if>
            <if test="remarkPmOut != null">#{remarkPmOut},</if>
         </trim>
    </insert>

    <update id="updateKaoqinRecord" parameterType="KaoqinRecord">
        update kaoqin_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="kaYear != null and kaYear != ''">ka_year = #{kaYear},</if>
            <if test="kaMonth != null and kaMonth != ''">ka_month = #{kaMonth},</if>
            <if test="kaDay != null and kaDay != ''">ka_day = #{kaDay},</if>
            <if test="kaWeek != null and kaWeek != ''">ka_week = #{kaWeek},</if>
            <if test="kaTime != null and kaTime != ''">ka_time = #{kaTime},</if>
            <if test="kaAddressAmIn != null and kaAddressAmIn != ''">ka_address_am_in = #{kaAddressAmIn},</if>
            <if test="kaLog != null and kaLog != ''">ka_log = #{kaLog},</if>
            <if test="kaLat != null and kaLat != ''">ka_lat = #{kaLat},</if>
            <if test="kaSort != null and kaSort != ''">ka_sort = #{kaSort},</if>
            <if test="kaAddressAmOut != null">ka_address_am_out = #{kaAddressAmOut},</if>
            <if test="kaAddressPmIn != null">ka_address_pm_in = #{kaAddressPmIn},</if>
            <if test="kaAddressPmOut != null">ka_address_pm_out = #{kaAddressPmOut},</if>
            <if test="kaTimeAmIn != null">ka_time_am_in = #{kaTimeAmIn},</if>
            <if test="kaTimeAmOut != null">ka_time_am_out = #{kaTimeAmOut},</if>
            <if test="kaTimePmIn != null">ka_time_pm_in = #{kaTimePmIn},</if>
            <if test="kaTimePmOut != null">ka_time_pm_out = #{kaTimePmOut},</if>
            <if test="kaTypeAmIn != null">ka_type_am_in = #{kaTypeAmIn},</if>
            <if test="kaTypeAmOut != null">ka_type_am_out = #{kaTypeAmOut},</if>
            <if test="kaTypePmIn != null">ka_type_pm_in = #{kaTypePmIn},</if>
            <if test="kaTypePmOut != null">ka_type_pm_out = #{kaTypePmOut},</if>
            <if test="kaAmInPhoto != null">ka_am_in_photo = #{kaAmInPhoto},</if>
            <if test="kaAmOutPhoto != null">ka_am_out_photo = #{kaAmOutPhoto},</if>
            <if test="kaPmInPhoto != null">ka_pm_in_photo = #{kaPmInPhoto},</if>
            <if test="kaPmOutPhoto != null">ka_pm_out_photo = #{kaPmOutPhoto},</if>
            <if test="kaStatus != null">ka_status = #{kaStatus},</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="remarkAmIn != null">remark_am_in = #{remarkAmIn},</if>
            <if test="remarkAmOut != null">remark_am_out = #{remarkAmOut},</if>
            <if test="remarkPmIn != null">remark_pm_in = #{remarkPmIn},</if>
            <if test="remarkPmOut != null">remark_pm_out = #{remarkPmOut},</if>
        </trim>
        where record_id = #{recordId}
    </update>

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

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