<?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="jnpf.attendance.mapper.AttendanceUserSettingMapper" >
<!--    更新配置-->
    <update id="update">
        UPDATE ftb_attendance_app_user_setting
        SET F_Status =  #{attendanceAppUserSettingDto.status},
            F_Value = #{attendanceAppUserSettingDto.value}
        WHERE F_Id = #{attendanceAppUserSettingDto.id}
    </update>
<!--    查询是否重复-->
    <select id="getDetail" resultType="java.lang.String">
        SELECT F_Id
        FROM ftb_attendance_app_user_setting
        WHERE F_Type = #{attendanceAppUserSettingDto.type}
        <if test="null != attendanceAppUserSettingDto.type and attendanceAppUserSettingDto.type != 3">
          AND F_AssociationId = #{attendanceAppUserSettingDto.associationId}
        </if>
        <if test="null != attendanceAppUserSettingDto.type and attendanceAppUserSettingDto.type != 2">
            AND F_SettingId = #{attendanceAppUserSettingDto.settingId}
        </if>
    </select>
<!--    根据父级Id查询设置列表-->
    <select id="getSettingList" resultType="jnpf.model.attendance.vo.UserSettingVo">
        SELECT F_Id  settingId,F_SettingName  settingName,F_Code code ,F_Sort  sort , F_PId pId ,F_SystemType type
        FROM ftb_attendance_app_setting
        WHERE   F_SystemType = #{type}
        <if test="null != type and type == 1">
            AND F_PId = #{pId}
        </if>
        ORDER BY F_Sort ASC
    </select>
<!--    查询用户设置/考勤组设置-->
    <select id="getUserSetting" resultType="jnpf.model.attendance.vo.UserSettingVo">
        SELECT s.F_Id  settingId,s.F_SettingName settingName ,s.F_Code code ,us.F_Status `status`,us.F_Value `value`, us.F_Id id
        FROM ftb_attendance_app_setting s
        LEFT JOIN ftb_attendance_app_user_setting  us ON s.F_Id = us.F_SettingId
        WHERE F_Type = #{appUserSettingQueryDto.type} AND s.F_SystemType = #{appUserSettingQueryDto.type}
        <if test="null != appUserSettingQueryDto.PId and '' != appUserSettingQueryDto.PId ">
          AND s.F_PId = #{appUserSettingQueryDto.PId}
        </if>
        <if test="null != appUserSettingQueryDto.associationId and '' != appUserSettingQueryDto.associationId">
          AND us.F_AssociationId = #{appUserSettingQueryDto.associationId}
        </if>
    </select>
<!--    批量获取考勤组设置-->
    <select id="getGroupSetting" resultType="jnpf.model.attendance.vo.UserSettingVo">
        SELECT F_Status `status`,F_Value `value`, F_AssociationId associationId ,F_Id  id
        FROM ftb_attendance_app_user_setting
        WHERE F_Type = #{type} AND F_AssociationId IN
        <foreach collection="groupIds" item="value" separator="," open="(" close=")">
            #{value}
        </foreach>
    </select>
<!--    根据用户编码及用户批量获取设置-->
    <select id="getUserSettingByCode" resultType="jnpf.model.attendance.vo.UserSettingVo">
        SELECT s.F_Code code ,us.F_Status `status`,us.F_Value `value` ,us.F_AssociationId associationId
        FROM ftb_attendance_app_user_setting  us
        LEFT JOIN ftb_attendance_app_setting s ON s.F_Id = us.F_SettingId
        WHERE s.F_Code IN
        <foreach collection="code" item="value" separator="," open="(" close=")">
            #{value}
        </foreach>
        <if test="null != associationId and associationId.size > 0">
             AND us.F_AssociationId IN
            <foreach collection="associationId" item="value1" separator="," open="(" close=")">
                #{value1}
            </foreach>
        </if>
        AND F_Type = #{type}
    </select>
    <!--    新增配置-->
    <insert id="add">
        INSERT INTO ftb_attendance_app_user_setting (F_Id,F_SettingId,F_Type,F_AssociationId,F_Status,F_Value)
        VALUES(#{attendanceAppUserSettingDto.id},#{attendanceAppUserSettingDto.settingId},#{attendanceAppUserSettingDto.type},#{attendanceAppUserSettingDto.associationId},#{attendanceAppUserSettingDto.status},#{attendanceAppUserSettingDto.value})
    </insert>
</mapper>