<?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.AttendanceUserBalanceMapper">
    <insert id="batchAddBalanceDetail">
        insert into ftb_attendance_user_balance_detail
            (F_Id,F_UserId,F_ObjectId,F_Content,F_Quota)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.id},#{item.userId},#{item.objectId},#{item.content},#{item.quota})
        </foreach>
    </insert>

    <select id="getDetail" resultType="jnpf.model.attendance.vo.attendance.AttendanceUserBalanceDetailVo">
        select
            F_Id as id,
            F_ObjectId as objectId,
            F_Content as content,
            ROUND(F_Quota,2) as quota,
            F_CreatorTime as creatorTime
        from  ftb_attendance_user_balance_detail
        where F_UserId = #{userId}
        <if test="id != null and '' != id">
           and F_ObjectId = #{id}
        </if>
        <if test="id == null or  '' == id">
            and F_ObjectId is null
        </if>

        ORDER BY F_CreatorTime DESC
    </select>
    <select id="getTotalBalance" resultType="java.math.BigDecimal">
        SELECT SUM(F_Balance) as totalBalance
        FROM ftb_attendance_balance_record
        WHERE F_User_Id = #{userId} AND F_State = 0 AND F_Over = 0 AND F_DeleteMark = 0
        <if test="balanceId != null">
            AND (( F_Object_Id = #{balanceId} AND F_Type = 2)
            <if test="isRetirementLeave">
                OR(F_Type = 3 )
            </if>
            )
        </if>
        <if test="balanceId == null">
            and F_Type = 3
        </if>
    </select>
</mapper>