<?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.StorageRestMapper">
    <!--    批量保存数据-->
    <insert id="saveBatch">
        INSERT INTO ftb_attendance_storage_rest (F_Id,F_UserId,F_Num,F_YearMonth)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id}, #{item.userId},#{item.num}, #{item.yearMonth})
        </foreach>
    </insert>
    <!--    获取用户指定年月的存休-->
    <select id="batchGetUserStorageRest" resultType="jnpf.model.attendance.vo.attendance.AttendanceStorageRestVo">
        SELECT
            F_UserId userId,
            F_Num num,
            F_YearMonth yearMonth
        FROM ftb_attendance_storage_rest
        <where>
            AND F_YearMonth = #{yearMonth}
            <if test="userIds!= null and userIds.size()>0">
                and F_UserId in
                <foreach collection="userIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

        </where>
        group by F_UserId
    </select>

<!--    实时获取当月存休-->
    <select id="getRealTimeUserStorageRest"
            resultType="jnpf.model.attendance.vo.attendance.AttendanceStorageRestVo">
        SELECT  F_User_Id userId,IFNULL(SUM(F_Balance),0) num
        FROM ftb_attendance_balance_record
        WHERE F_User_Id IN
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
          AND F_DeleteMark = 0 AND F_State = 0  AND F_Type = 3 AND F_State = 0 AND F_Over = 0
        GROUP BY F_User_Id
    </select>
</mapper>