<?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.AttendanceQuickTemplateMapper" >

<!--    新增模板信息-->
    <insert id="saveTemplate">
        INSERT INTO ftb_attendance_quick_template
        (F_Id,F_Name,F_GroupId,F_CreatorTime,F_CreatorUserId )
        VALUES
            (#{dto.id},#{dto.name},#{dto.groupId},now(),#{userId})
    </insert>
    <insert id="saveClass">
        INSERT INTO ftb_attendance_quick_template_item_new (F_Id,F_TemplateId,F_Num,F_ShiftNameId,F_ShiftType,F_Sort,F_Type)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id},#{item.groupId},#{item.num},#{item.shiftNameId},#{item.shiftType},#{item.sort},#{item.type})
        </foreach>
    </insert>
    <!--    修改快速模板信息-->
    <update id="updateTemplate">
        update ftb_attendance_quick_template
        set F_Name = #{dto.name},
            F_GroupId = #{dto.groupId},
            F_LastModifyUserId = #{userId},
            F_LastModifyTime = now()
        where F_Id = #{dto.id}
    </update>
<!--    删除模板绑定的信息信息-->
    <delete id="deleteClass">
        DELETE  FROM ftb_attendance_quick_template_item_new
        WHERE F_TemplateId = #{id}
    </delete>
    <delete id="deleteTemplateItem">
        UPDATE ftb_attendance_quick_template_item_new t1
        JOIN (
        SELECT F_Num
        FROM ftb_attendance_quick_template_item_new
        WHERE F_ShiftNameId = #{shiftNameId}
        AND F_Num IN
        <foreach collection="nums" item="value" separator="," open="(" close=")">
            #{value}
        </foreach>
        ) t2 ON t1.F_Num = t2.F_Num
        SET t1.F_Type = 0,
        t1.F_ShiftNameId = NULL
        WHERE t1.F_TemplateId = #{id}
    </delete>
<!--    获取考勤组快速模板集合-->
    <select id="getTemByGroupId" resultType="jnpf.model.attendance.vo.attendance.QuickTemVo">
        SELECT F_Id  id,F_Name `name`
        FROM ftb_attendance_quick_template
        WHERE F_GroupId = #{groupId} and F_DeleteMark = 0
        ORDER BY F_CreatorTime DESC
    </select>
<!--    获取考勤组快速模板下班次集合信息-->
    <select id="getShiftByTemIds" 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 fixedSort,fc.F_TemplateId templateId
        FROM ftb_attendance_quick_template_item_new fc
        LEFT JOIN ftb_attendance_shift_name sn ON sn.F_Id = fc.F_ShiftNameId
        WHERE fc.F_TemplateId IN
        <foreach collection="temIds" item="value" separator="," open="(" close=")">
            #{value}
        </foreach>
    </select>
</mapper>