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

  <sql id="Base_Column_List" >
    F_Id, F_Name, F_User_Id, F_Balance, F_Total, F_Unit, F_Expire_Time, F_Grant_Way, 
    F_State, F_Over, F_Paid, F_CreatorUserId, F_CreatorTime, F_LastModifyUserId, F_LastModifyTime, 
    F_DeleteMark, F_DeleteTime, F_DeleteUserId, F_TenantId
  </sql>



    <!--  余额管理列表-->
<!--    <select id="getBalanceList" resultType="jnpf.model.attendance.vo.UserBalanceVo">-->
<!--      SELECT * FROM (-->
<!--        SELECT u.F_UserId userId ,(SELECT IFNULL(SUM(F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_DeleteMark = 0 AND r.F_State = 0)  balance  ,-->
<!--        (SELECT IFNULL(SUM(r.F_Balance),0)  FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 1 AND F_DeleteMark = 0 AND F_State = 0) paidBalance ,-->
<!--        (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 2 AND r.F_DeleteMark = 0 AND r.F_State = 0) unpaidBalance ,-->
<!--        (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_DeleteMark = 0 AND r.F_State = 0-->
<!--               <![CDATA[-->
<!--                 AND r.F_Expire_Time <= DATE_ADD(now(),INTERVAL 7 DAY)-->
<!--               ]]>-->
<!--        ) adventBalance-->
<!--        FROM ftb_attendance_group_user u-->
<!--        LEFT JOIN ftb_attendance_balance_record r ON u.F_UserId = r.F_User_Id-->
<!--        WHERE u.F_GroupId = #{balanceQueryDto.groupId} AND u.F_Type = 1 AND u.F_DeleteMark = 0-->
<!--        <if test="null != balanceQueryDto.userIds and balanceQueryDto.userIds.size > 0">-->
<!--          AND F_UserId in-->
<!--          <foreach collection="balanceQueryDto.userIds" index="index" item="item" open="(" separator="," close=")">-->
<!--            #{item}-->
<!--          </foreach>-->
<!--        </if>-->
<!--        GROUP BY userId-->
<!--      ) a-->
<!--      WHERE 1 = 1-->
<!--      <if test="balanceQueryDto.minBalance != null">-->
<!--        <![CDATA[-->
<!--            AND #{balanceQueryDto.minBalance} <= a.balance-->
<!--        ]]>-->
<!--      </if>-->
<!--      <if test="balanceQueryDto.maxBalance != null">-->
<!--        <![CDATA[-->
<!--             AND a.balance <= #{balanceQueryDto.maxBalance}-->
<!--        ]]>-->
<!--      </if>-->
<!--      <if test="balanceQueryDto.minAdventBalance != null">-->
<!--        <![CDATA[-->
<!--            AND #{balanceQueryDto.minAdventBalance} <= a.adventBalance-->
<!--        ]]>-->
<!--      </if>-->
<!--      <if test="balanceQueryDto.maxAdventBalance != null">-->
<!--        <![CDATA[-->
<!--             AND a.adventBalance <= #{balanceQueryDto.maxAdventBalance}-->
<!--        ]]>-->
<!--      </if>-->
<!--      ORDER BY balance <if test="null != balanceSort"> ${balanceSort} </if> ,-->
<!--      paidBalance <if test="null != paidBalanceSort"> ${paidBalanceSort} </if> ,-->
<!--      unpaidBalance  <if test="null != unpaidBalanceSort == 1"> ${unpaidBalanceSort} </if>,-->
<!--      adventBalance <if test="null != adventBalance "> ${adventBalance} </if>-->
<!--    </select>-->

    <!--  新增假期节假日劵-->
<!--  <insert id="grantBalance">-->
<!--        insert into ftb_attendance_balance_record (F_Id, F_Name, F_User_Id,-->
<!--          F_Balance, F_Total, F_Unit,-->
<!--          F_Expire_Time, F_Grant_Way, F_State,-->
<!--          F_Paid, F_CreatorUserId,F_CreatorTime,F_Type,F_Object_Id)-->
<!--        values (#{id}, #{holidayName}, #{userId},-->
<!--          #{dayNum}, #{dayNum}, #{unit},-->
<!--          #{expiresTime}, #{grantWay}, 0,-->
<!--          #{paid}, #{createUserId},now(),#{type},#{objectId})-->
<!--  </insert>-->
<!--  余额记录列表-->
<!--  <select id="getUserBalance" resultType="jnpf.model.attendance.vo.AttendanceBalanceRecordVo">-->
<!--    select F_Id id, F_Name `name`, F_User_Id userId, F_Balance balance, F_Total total, F_Unit unit, F_Expire_Time expireTime, F_Grant_Way grantWay,-->
<!--        F_State `state`, F_Over `over`, F_Paid paid, F_CreatorUserId creatoruserid, F_CreatorTime creatortime-->
<!--    from ftb_attendance_balance_record-->
<!--    where  F_User_Id IN (-->
<!--        SELECT F_UserId FROM ftb_attendance_group_user WHERE F_GroupId = #{balanceQueryDto.groupId} AND F_Type = 1-->
<!--    AND F_DeleteMark = 0-->
<!--    ) AND F_DeleteMark = 0-->
<!--      <if test="null != balanceQueryDto.iText and '' != balanceQueryDto.iText">-->
<!--        AND INSTR(F_Name ,#{balanceQueryDto.iText})> 0-->
<!--        <if test="null != balanceQueryDto.userIds and balanceQueryDto.userIds.size > 0">-->
<!--          OR F_User_Id in-->
<!--          <foreach collection="balanceQueryDto.userIds" index="index" item="item" open="(" separator="," close=")">-->
<!--            #{item}-->
<!--          </foreach>-->
<!--        </if>-->
<!--      </if>-->
<!--    <if test="null != balanceQueryDto.minGrantTime  and '' != balanceQueryDto.minGrantTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(#{balanceQueryDto.minGrantTime},'%Y-%m-%d') <= DATE_FORMAT(F_CreatorTime,'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.maxGrantTime  and '' != balanceQueryDto.maxGrantTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(F_CreatorTime,'%Y-%m-%d') <= DATE_FORMAT(#{balanceQueryDto.maxGrantTime},'%Y-%m-%d')-->
<!--     ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.minExpireTime  and '' != balanceQueryDto.minExpireTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(#{balanceQueryDto.minExpireTime},'%Y-%m-%d') <= DATE_FORMAT(F_Expire_Time,'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.maxExpireTime  and '' != balanceQueryDto.maxExpireTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(F_Expire_Time,'%Y-%m-%d') <= DATE_FORMAT(#{balanceQueryDto.maxExpireTime},'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.state">-->
<!--        AND F_State = #{balanceQueryDto.state}-->
<!--    </if>-->
<!--  </select>-->
<!--  成员余额记录列表-->
<!--  <select id="getUserBalanceDetail" resultType="jnpf.model.attendance.vo.AttendanceBalanceRecordVo">-->
<!--    select F_Id id, F_Name `name`, F_User_Id userId, F_Balance balance, F_Total total, F_Unit unit, F_Expire_Time expireTime, F_Grant_Way grantWay,-->
<!--    F_State `state`, F_Over `over`, F_Paid paid, F_CreatorUserId creatoruserid, F_CreatorTime creatortime-->
<!--    from ftb_attendance_balance_record-->
<!--    where  F_User_Id = #{balanceQueryDto.userId} AND F_DeleteMark = 0-->
<!--    <if test="null != balanceQueryDto.iText and '' != balanceQueryDto.iText">-->
<!--      AND INSTR(F_Name ,#{balanceQueryDto.iText})> 0-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.minGrantTime  and '' != balanceQueryDto.minGrantTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(#{balanceQueryDto.minGrantTime},'%Y-%m-%d') <= DATE_FORMAT(F_CreatorTime,'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.maxGrantTime  and '' != balanceQueryDto.maxGrantTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(F_CreatorTime,'%Y-%m-%d') <= DATE_FORMAT(#{balanceQueryDto.maxGrantTime},'%Y-%m-%d')-->
<!--     ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.minExpireTime  and '' != balanceQueryDto.minExpireTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(#{balanceQueryDto.minExpireTime},'%Y-%m-%d') <= DATE_FORMAT(F_Expire_Time,'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.maxExpireTime  and '' != balanceQueryDto.maxExpireTime">-->
<!--      <![CDATA[-->
<!--        AND DATE_FORMAT(F_Expire_Time,'%Y-%m-%d') <= DATE_FORMAT(#{balanceQueryDto.maxExpireTime},'%Y-%m-%d')-->
<!--        ]]>-->
<!--    </if>-->
<!--    <if test="null != balanceQueryDto.state">-->
<!--      AND F_State = #{balanceQueryDto.state}-->
<!--    </if>-->
<!--  </select>-->
  <!--  修改指定劵的状态-->
<!--  <update id="updateBalanceState">-->
<!--        update ftb_attendance_balance_record-->
<!--        set-->
<!--          F_State = #{state},-->
<!--          F_LastModifyUserId = #{userId},-->
<!--          F_LastModifyTime = now()-->
<!--        where F_Id = #{id}-->
<!--  </update>-->
<!--  获取用户余额-->
  <select id="getBalanceByUserId" resultType="jnpf.model.attendance.vo.UserBalanceVo">
    SELECT F_User_Id userId, IFNULL(SUM(F_Balance),0) balance ,
    (SELECT IFNULL(SUM(r.F_Balance),0)  FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 1 AND F_State = 0 ) paidBalance ,
    (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 2 AND F_State = 0) unpaidBalance ,
    (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND F_State = 0
    <![CDATA[
        AND r.F_Expire_Time <= DATE_ADD(now(),INTERVAL 7 DAY)
    ]]>
    ) adventBalance
    FROM ftb_attendance_balance_record
    WHERE F_User_Id  = #{userId} AND F_DeleteMark = 0 AND F_State = 0
    GROUP BY userId ,F_Unit
  </select>
  <!--  过期劵-->
  <update id="invalidationCoupons">
    UPDATE ftb_attendance_balance_record
    SET F_State = 1
    WHERE F_Id IN
    <foreach collection="ids"
             item="item" index="index" separator="," open="(" close=")">
      #{item}
    </foreach>
  </update>
  <!--  获取节日信息-->
  <select id="getFestivalSetting" resultType="jnpf.model.attendance.vo.VacationVo">
    SELECT F_Day  dayNum , F_ExpiresType expiresType ,F_ExpiresDayNumber expiresDayNumber , F_ExpiresMonth expiresMonth ,F_ExpiresDay expiresDay ,F_PaidSalaryEnable paid ,F_Name holidayName ,F_Id id
    FROM ftb_attendance_festival_setting
    WHERE F_Id = #{balanceId}
  </select>
<!--  获取假日配置信息-->
  <select id="getHolidaySetting" resultType="jnpf.model.attendance.vo.VacationVo">
    SELECT F_DayType  dayType,F_DayNumber dayNumber ,F_YoeMultiple yoeMultiple ,F_YosMultiple yosMultiple , F_ExpiresType expiresType ,F_ExpiresDayNumber expiresDayNumber , F_ExpiresMonth expiresMonth ,F_ExpiresDay expiresDay ,F_PaidSalaryEnable paid ,F_Name holidayName
    FROM ftb_attendance_holiday_setting
    WHERE  F_Id = #{balanceId}
  </select>

    <select id="getBalanceRecordByUserId" resultType="jnpf.model.attendance.vo.AttendanceBalanceRecordVo">
      SELECT t.* FROM (
        SELECT F_Id id, F_Name `name`, F_User_Id userId, F_Balance balance, F_Total total, F_Unit unit, IFNULL(F_Expire_Time,DATE_FORMAT('2999-1-1','%Y-%m-%d')) expireTime, F_Grant_Way grantWay,
               F_State `state`, F_Over `over`, F_Paid paid, F_CreatorUserId creatoruserid, F_CreatorTime creatortime
        FROM ftb_attendance_balance_record
        WHERE F_User_Id = #{userId} AND F_State = 0 AND F_Over = 0 AND F_DeleteMark = 0 AND F_Paid IN
        <foreach collection="paid"
                 item="item" index="index" separator="," open="(" close=")">
          #{item}
        </foreach>
      ) t
      ORDER BY t.expireTime ,paid ASC
    </select>
    <!--  修改劵的使用情况-->
    <update id="updateBalance">
      UPDATE ftb_attendance_balance_record
      SET F_Balance = #{balance},
          F_Over = #{over},
          F_LastModifyTime = now()
      WHERE F_Id = #{id}
    </update>
<!--  获取用户指定类型假的余额总数-->
<!--  <select id="getBalanceRecordCountByUserId" resultType="java.math.BigDecimal">-->
<!--     SELECT IFNULL(SUM(F_Balance),0)-->
<!--    FROM ftb_attendance_balance_record-->
<!--    WHERE F_User_Id = #{userId} AND F_State = 0 AND F_Over = 0 AND F_DeleteMark = 0 AND F_Paid = #{paid}-->
<!--  </select>-->
<!--  通过劵的id获取劵的详情-->
  <select id="getBalanceDetailList" resultType="jnpf.model.attendance.vo.AttendanceBalanceRecordVo">
    SELECT F_Id id, F_Balance balance
    FROM ftb_attendance_balance_record
    WHERE F_Id  IN
    <foreach collection="balanceIds" item="item" index="index" separator="," open="(" close=")">
      #{item}
    </foreach>
  </select>
<!--  验证出勤规则id有无发加班劵-->
  <select id="getBalanceByRuleId" resultType="java.lang.Integer">
    SELECT count(0)
    FROM ftb_attendance_balance_record
    WHERE F_Type = 3 and F_Object_Id = #{ruleId}
  </select>
<!--  批量获取用户余额-->
    <select id="getBalanceByUserIds" resultType="jnpf.model.attendance.vo.UserBalanceVo">
      SELECT F_User_Id userId, IFNULL(SUM(F_Balance),0) balance ,
             (SELECT IFNULL(SUM(r.F_Balance),0)  FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 1 AND F_State = 0 ) paidBalance ,
             (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND r.F_Paid = 2 AND F_State = 0) unpaidBalance ,
             (SELECT IFNULL(SUM(r.F_Balance),0) FROM ftb_attendance_balance_record r WHERE r.F_User_Id = userId AND F_State = 0
            <![CDATA[
              AND r.F_Expire_Time <= DATE_ADD(now(),INTERVAL 7 DAY)
            ]]>
    ) adventBalance
      FROM ftb_attendance_balance_record
      WHERE  F_DeleteMark = 0 AND F_State = 0
      AND F_User_Id IN
      <foreach collection="userIds"
               item="id" index="index" separator="," open="(" close=")">
        #{id}
      </foreach>
      GROUP BY userId ,F_Unit
    </select>


    <!--  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >-->
<!--    delete from ftb_attendance_balance_record-->
<!--    where F_Id = #{fId,jdbcType=VARCHAR}-->
<!--  </delete>-->
<!--  <insert id="insert" parameterType="com.shs.cts.util.domain.po.experience.AttendanceBalanceRecord" >-->
<!--    insert into ftb_attendance_balance_record (F_Id, F_Name, F_User_Id, -->
<!--      F_Balance, F_Total, F_Unit, -->
<!--      F_Expire_Time, F_Grant_Way, F_State, -->
<!--      F_Over, F_Paid, F_CreatorUserId, -->
<!--      F_CreatorTime, F_LastModifyUserId, F_LastModifyTime, -->
<!--      F_DeleteMark, F_DeleteTime, F_DeleteUserId, -->
<!--      F_TenantId)-->
<!--    values (#{fId,jdbcType=VARCHAR}, #{fName,jdbcType=VARCHAR}, #{fUserId,jdbcType=VARCHAR}, -->
<!--      #{fBalance,jdbcType=DECIMAL}, #{fTotal,jdbcType=DECIMAL}, #{fUnit,jdbcType=BIT}, -->
<!--      #{fExpireTime,jdbcType=TIMESTAMP}, #{fGrantWay,jdbcType=BIT}, #{fState,jdbcType=BIT}, -->
<!--      #{fOver,jdbcType=BIT}, #{fPaid,jdbcType=BIT}, #{fCreatoruserid,jdbcType=VARCHAR}, -->
<!--      #{fCreatortime,jdbcType=TIMESTAMP}, #{fLastmodifyuserid,jdbcType=VARCHAR}, #{fLastmodifytime,jdbcType=TIMESTAMP}, -->
<!--      #{fDeletemark,jdbcType=INTEGER}, #{fDeletetime,jdbcType=TIMESTAMP}, #{fDeleteuserid,jdbcType=VARCHAR}, -->
<!--      #{fTenantid,jdbcType=VARCHAR})-->
<!--  </insert>-->
<!-- -->
<!--  -->
<!--  <update id="updateByPrimaryKey" parameterType="com.shs.cts.util.domain.po.experience.AttendanceBalanceRecord" >-->
<!--    update ftb_attendance_balance_record-->
<!--    set F_Name = #{fName,jdbcType=VARCHAR},-->
<!--      F_User_Id = #{fUserId,jdbcType=VARCHAR},-->
<!--      F_Balance = #{fBalance,jdbcType=DECIMAL},-->
<!--      F_Total = #{fTotal,jdbcType=DECIMAL},-->
<!--      F_Unit = #{fUnit,jdbcType=BIT},-->
<!--      F_Expire_Time = #{fExpireTime,jdbcType=TIMESTAMP},-->
<!--      F_Grant_Way = #{fGrantWay,jdbcType=BIT},-->
<!--      F_State = #{fState,jdbcType=BIT},-->
<!--      F_Over = #{fOver,jdbcType=BIT},-->
<!--      F_Paid = #{fPaid,jdbcType=BIT},-->
<!--      F_CreatorUserId = #{fCreatoruserid,jdbcType=VARCHAR},-->
<!--      F_CreatorTime = #{fCreatortime,jdbcType=TIMESTAMP},-->
<!--      F_LastModifyUserId = #{fLastmodifyuserid,jdbcType=VARCHAR},-->
<!--      F_LastModifyTime = #{fLastmodifytime,jdbcType=TIMESTAMP},-->
<!--      F_DeleteMark = #{fDeletemark,jdbcType=INTEGER},-->
<!--      F_DeleteTime = #{fDeletetime,jdbcType=TIMESTAMP},-->
<!--      F_DeleteUserId = #{fDeleteuserid,jdbcType=VARCHAR},-->
<!--      F_TenantId = #{fTenantid,jdbcType=VARCHAR}-->
<!--    where F_Id = #{fId,jdbcType=VARCHAR}-->
<!--  </update>-->

  <select id="getBalanceByApplyIds" resultType="jnpf.model.attendance.model.BalanceRecord">
    SELECT
    fabur.F_Unit b_F_Unit,
    fabur.F_Quota b_F_Quota,
    fabr.F_Paid b_F_Paid,
    fabur.F_Object_Id id
    FROM ftb_attendance_balance_use_record fabur
    LEFT JOIN ftb_attendance_balance_record fabr ON fabr.F_Id = fabur.F_Balance_Id
    WHERE  F_DeleteMark = 0 AND fabur.F_Use_Type = 0
    AND fabur.F_Object_Id IN
    <foreach collection="applyIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
    GROUP BY fabr.F_User_Id ,fabur.F_Unit
  </select>
<!--  获取用户余额-->
    <select id="getStraightBalanceList" resultType="jnpf.entity.attendance.AttendanceStorageRest">
      SELECT F_User_Id userId,SUM(F_Balance) num
      FROM ftb_attendance_balance_record
      WHERE F_State = 0 AND F_Type = 3 AND F_State = 0 AND F_Over = 0 AND F_DeleteMark = 0
      GROUP BY F_User_Id
    </select>
  <select id="getOvertimeBalanceInfo" resultType="jnpf.model.attendance.model.OvertimeBalanceModel">
    SELECT
    fabr.F_User_Id userId,
    SUM(CASE WHEN fabr.F_OverTime = 1 THEN fabr.F_Total ELSE 0 END) weekdayOvertimeDays,
    SUM(CASE WHEN fabr.F_OverTime = 1 THEN fabr.F_Balance ELSE 0 END) weekdayOvertimeResidueDays,
    SUM(CASE WHEN fabr.F_OverTime = 3 THEN fabr.F_Total ELSE 0 END) holidaysOvertimeDays,
    SUM(CASE WHEN fabr.F_OverTime = 3 THEN fabr.F_Balance ELSE 0 END) holidaysOvertimeResidueDays,
    SUM(CASE WHEN fabr.F_OverTime = 2 THEN fabr.F_Total ELSE 0 END) publicHolidaysOvertimeDays,
    SUM(CASE WHEN fabr.F_OverTime = 2 THEN fabr.F_Balance ELSE 0 END) publicHolidaysOvertimeResidueDays
    FROM ftb_attendance_balance_record fabr
    WHERE fabr.F_State = 0
      AND fabr.F_Type = 3
      AND fabr.F_DeleteMark = 0
      AND fabr.F_Object_Id IS NOT NULL
      AND fabr.F_OverTimeDay between #{startDate} and #{endDate}
      AND fabr.F_User_Id IN
      <foreach collection="userIds"
               item="id" index="index" separator="," open="(" close=")">
        #{id}
      </foreach>
    GROUP BY fabr.F_User_Id
  </select>
  <select id="getSurplusDaysInfo" resultType="jnpf.model.attendance.model.SurplusDaysModel">
    SELECT
    fabr.F_User_Id userId,
    SUM(fabr.F_Balance) surplusDays
    FROM ftb_attendance_balance_record fabr
    WHERE fabr.F_State = 0
    AND fabr.F_Type = 3
    AND fabr.F_DeleteMark = 0
    AND fabr.F_User_Id IN
    <foreach collection="userIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
    GROUP BY fabr.F_User_Id
  </select>

  <select id="getOvertimeHolidaysInfo" resultType="jnpf.model.attendance.model.OvertimeHolidaysInfoModel">
    SELECT
    fabr.F_User_Id userId,
    fabr.F_FestivalStr holidayNameList,
    fabr.F_Total holidaysOvertimeDays
    FROM ftb_attendance_balance_record fabr
    WHERE fabr.F_State = 0
    AND fabr.F_Type = 3
    AND fabr.F_OverTime = 3
    AND fabr.F_FestivalStr is not null
    AND fabr.F_DeleteMark = 0
    AND fabr.F_OverTimeDay between #{startDate} and #{endDate}
    AND fabr.F_User_Id IN
    <foreach collection="userIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
  </select>
  <select id="getLeaveBalanceInfo" resultType="jnpf.model.attendance.model.LeaveBalanceInfoModel">
    SELECT
    fabr.F_User_Id userId,
    fabr.F_Object_Id leaveTypeId,
    SUM(F_Balance) value
    FROM ftb_attendance_balance_record fabr
    WHERE fabr.F_Type = 2
    AND fabr.F_DeleteMark = 0
    AND fabr.F_State = 0
    AND (fabr.F_Expire_Time >= #{startDate} or fabr.F_Expire_Time is null)
    AND fabr.F_Object_Id is not null
    AND fabr.F_User_Id IN
    <foreach collection="userIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
    GROUP BY fabr.F_User_Id,fabr.F_Object_Id
  </select>

  <select id="getLeaveApprovalInfo" resultType="jnpf.model.attendance.model.LeaveApprovalModel">
    SELECT
    F_GroupId groupId,
    F_User_Id userId,
    F_Type_Id leaveTypeId,
    F_StartTime startTime,
    F_EndTime endTime,
    F_BalanceJsonNew balanceJson,
    F_ShiftInvolved shiftInvolved
    FROM ftb_attendance_leave_approve
    WHERE
    F_DeleteMark = 0
    AND F_Status = 1
    and F_BalanceJsonNew is not null
    AND F_User_Id IN
    <foreach collection="userIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
    AND F_Id IN
    <foreach collection="leaveIds"
             item="id" index="index" separator="," open="(" close=")">
      #{id}
    </foreach>
  </select>



  <select id="selectInvalidationCoupons" resultType="jnpf.entity.attendance.AttendanceBalanceRecordEntity">
    SELECT F_Id id,
      F_Name name,
      F_Type type,
      F_Object_Id objectId,
      F_OverTime overTime,
      F_OverTimeDay overTimeDay,
      F_User_Id userId,
      F_Balance balance,
      F_Total total,
      F_Unit unit,
      F_Expire_Time expireTime,
      F_Grant_Way grantWay,
      F_State state,
      F_Over isOver,
      F_Paid paid
    FROM ftb_attendance_balance_record
    WHERE
        F_Expire_Time <![CDATA[ <= ]]> now()
      AND F_DeleteMark = 0 AND F_State = 0
  </select>

  <!--  删除当月存休-->
  <delete id="deleteByYearMonth">
    delete FROM ftb_attendance_storage_rest
    WHERE F_YearMonth = #{lastMonthDate}
  </delete>


</mapper>