<?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.KaoqinConfigMapper">
    
    <resultMap type="KaoqinConfig" id="KaoqinConfigResult">
        <result property="kaoqinId"    column="kaoqin_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="kaAddress"    column="ka_address"    />
        <result property="kaLog"    column="ka_log"    />
        <result property="kaLat"    column="ka_lat"    />
        <result property="kaNum"    column="ka_num"    />
        <result property="kaRadius"    column="ka_radius"    />
        <result property="kaSort"    column="ka_sort"    />
        <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="isPhoto"    column="is_photo"    />
        <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="selectKaoqinConfigVo">
        select kaoqin_id, dept_id,dept_name, ka_address, ka_log, ka_lat, ka_num, ka_radius, ka_sort, ka_time_am_in, ka_time_am_out, ka_time_pm_in, ka_time_pm_out,is_photo, create_by, create_time, update_by, update_time, remark from kaoqin_config
    </sql>

    <select id="selectKaoqinConfigList" parameterType="KaoqinConfig" resultMap="KaoqinConfigResult">
        <include refid="selectKaoqinConfigVo"/>
        <where>  
            <if test="ancestors != null and ancestors != ''"> and FIND_IN_SET(dept_id,#{ancestors})</if>
            <if test="kaAddress != null  and kaAddress != ''"> and ka_address = #{kaAddress}</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="kaNum != null  and kaNum != ''"> and ka_num = #{kaNum}</if>
            <if test="kaRadius != null  and kaRadius != ''"> and ka_radius = #{kaRadius}</if>
            <if test="kaSort != null  and kaSort != ''"> and ka_sort = #{kaSort}</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="isPhoto != null and isPhoto!= ''"> and is_photo = #{isPhoto}</if>
        </where>
    </select>
    
    <select id="selectKaoqinConfigByKaoqinId" parameterType="Long" resultMap="KaoqinConfigResult">
        <include refid="selectKaoqinConfigVo"/>
        where kaoqin_id = #{kaoqinId}
    </select>
    <select id="selectKaoqinConfigByDeptId" parameterType="Long" resultMap="KaoqinConfigResult">
        <include refid="selectKaoqinConfigVo"/>
        <where>
            <if test="deptId != null and deptId != ''"> and dept_id = #{deptId}</if>
        </where>
    </select>

    <insert id="insertKaoqinConfig" parameterType="KaoqinConfig" useGeneratedKeys="true" keyProperty="kaoqinId">
        insert into kaoqin_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="kaAddress != null and kaAddress != ''">ka_address,</if>
            <if test="kaLog != null and kaLog != ''">ka_log,</if>
            <if test="kaLat != null and kaLat != ''">ka_lat,</if>
            <if test="kaNum != null and kaNum != ''">ka_num,</if>
            <if test="kaRadius != null and kaRadius != ''">ka_radius,</if>
            <if test="kaSort != null and kaSort != ''">ka_sort,</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="isPhoto != null and isPhoto != ''">is_photo,</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="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="kaAddress != null and kaAddress != ''">#{kaAddress},</if>
            <if test="kaLog != null and kaLog != ''">#{kaLog},</if>
            <if test="kaLat != null and kaLat != ''">#{kaLat},</if>
            <if test="kaNum != null and kaNum != ''">#{kaNum},</if>
            <if test="kaRadius != null and kaRadius != ''">#{kaRadius},</if>
            <if test="kaSort != null and kaSort != ''">#{kaSort},</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="isPhoto != null and isPhoto != ''">#{isPhoto},</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="updateKaoqinConfig" parameterType="KaoqinConfig">
        update kaoqin_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="kaAddress != null and kaAddress != ''">ka_address = #{kaAddress},</if>
            <if test="kaLog != null and kaLog != ''">ka_log = #{kaLog},</if>
            <if test="kaLat != null and kaLat != ''">ka_lat = #{kaLat},</if>
            <if test="kaNum != null and kaNum != ''">ka_num = #{kaNum},</if>
            <if test="kaRadius != null and kaRadius != ''">ka_radius = #{kaRadius},</if>
            <if test="kaSort != null and kaSort != ''">ka_sort = #{kaSort},</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="isPhoto != null and isPhoto !=''">is_photo = #{isPhoto},</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 kaoqin_id = #{kaoqinId}
    </update>

    <delete id="deleteKaoqinConfigByKaoqinId" parameterType="Long">
        delete from kaoqin_config where kaoqin_id = #{kaoqinId}
    </delete>

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