<?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.AttendanceShiftNameSettingMapper" >
<!--    新增班次名称信息-->
    <insert id="save">
        INSERT INTO ftb_attendance_shift_name
            (F_Id,F_Name,F_ShortName,F_Colour,F_Type,F_GroupId,F_SettingId,F_CreatorUserId )
        VALUES
            (#{dto.id},#{dto.name},#{dto.shortName},#{dto.colour},#{dto.shiftType},#{dto.groupId},#{dto.settingId},#{dto.userId})
    </insert>

    <!--    保存班次名称信息-->
    <update id="update">
        update ftb_attendance_shift_name
        set F_Name = #{dto.name},
            F_ShortName = #{dto.shortName},
            F_Colour = #{dto.colour},
            F_Type = #{dto.shiftType},
            F_GroupId = #{dto.groupId},
            F_SettingId = #{dto.settingId},
            F_LastModifyUserId = #{dto.userId},
            F_LastModifyTime = now()
        where F_Id = #{dto.id}
    </update>
    <!--    校验班次名称是否重复-->
    <select id="checkName" resultType="java.lang.Integer">
        SELECT COUNT(0) FROM ftb_attendance_shift_name
        WHERE F_GroupId = #{dto.groupId} AND F_DeleteMark = 0 AND F_Name = #{dto.name}
        <if test="dto.id != null and dto.id !=''">
            AND F_Id != #{dto.id}
        </if>
    </select>
<!--    获取班次名称信息详情-->
    <select id="getDetail" resultType="jnpf.model.attendance.vo.attendance.ShiftNameVo">
        select F_Id id,F_Name name,F_ShortName shortName,F_Colour colour,F_Type type,F_GroupId groupId,F_SettingId settingId, F_Enable enable
        from ftb_attendance_shift_name
        where F_Id = #{id} AND F_DeleteMark = 0
    </select>
    <!--    删除原来的关联班次信息-->
    <delete id="deletePeriodByShiftId">
        DELETE  FROM ftb_attendance_shift_setting_period
        WHERE F_ShiftId = #{id}
    </delete>
    <!--    删除班次-->
    <update id="delete">
        update ftb_attendance_shift_name
        set F_DeleteMark = 1,
            F_DeleteUserId = #{userId},
            F_LastModifyTime = now()
        where F_Id = #{shiftNameId}
    </update>
<!--    修改班次状态-->
    <update id="updateEnable">
        update ftb_attendance_shift_name
        set F_Enable = #{enable},
            F_LastModifyUserId = #{userId},
            F_LastModifyTime = now()
        where F_Id = #{shiftNameId}
    </update>
<!--    修改排班基础配置-->
    <update id="updateByGroupId">
        update ftb_attendance_shift_setting
        set F_SystemType = #{systemType},
            F_LastModifyUserId = #{userId},
            F_LastModifyTime = now()
        where F_GroupId = #{groupId}
    </update>
    <!--    获取固定排班班次详情-->
    <select id="getFixedClass" resultType="jnpf.model.attendance.vo.attendance.ShiftNameVo">
        SELECT sn.F_Id id ,sn.F_Name `name` ,sn.F_ShortName shortName ,sn.F_Colour colour ,fc.F_ShiftType fixedType ,sn.F_Type shiftType ,fc.F_Num num,fc.F_Type type , fc.F_Sort sort
        FROM ftb_attendance_fixed_class fc
        LEFT JOIN ftb_attendance_shift_name sn ON sn.F_Id = fc.F_ShiftNameId
        LEFT JOIN ftb_attendance_shift_setting ss ON ss.F_GroupId = fc.F_GroupId
        WHERE ss.F_GroupId = #{groupId}
    </select>
    <!--    新增固定排班班次详情-->
    <insert id="saveFixedClass">
        INSERT INTO ftb_attendance_fixed_class (F_Id,F_GroupId,F_Num,F_ShiftNameId,F_ShiftType,F_Sort,F_Type)
        VALUES
        <foreach collection="fixedClassDtos" item="item" separator=",">
            (#{item.id},#{item.groupId},#{item.num},#{item.shiftNameId},#{item.shiftType},#{item.sort},#{item.type})
        </foreach>
    </insert>
<!--    删除固定排班信息-->
    <select id="getListByGroupId" resultType="jnpf.model.attendance.vo.attendance.ShiftNameListVo">
        SELECT F_Id  id,F_Name  `name`,F_ShortName  shortName,F_Colour  colour,F_Type  shiftType,F_Enable `enable`
        FROM ftb_attendance_shift_name
        WHERE F_GroupId = #{queryDto.groupId} AND F_DeleteMark = 0
        <if test="queryDto.enable != null ">
            AND F_Enable = #{queryDto.enable}
        </if>
        ORDER BY F_CreatorTime DESC
    </select>
    <!--    获取考勤组班次列表-->
    <delete id="deleteFixedClass">
        DELETE  FROM ftb_attendance_fixed_class
        WHERE F_GroupId = #{settingId}
    </delete>


</mapper>