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

  <sql id="Base_Column_List" >
    F_Id, F_Balance_Id, F_Quota, F_Unit, F_Use_Type, F_Object_Id ,F_Start_Time, F_End_Time, F_Lock,
    F_CreatorUserId, F_CreatorTime, F_TenantId
  </sql>
<!--  获取用户劵的使用劵详情-->
  <select id="getUserBalanceDetail" resultType="jnpf.model.doclibrary.vo.UseDetailVo">
    select F_Id id,  F_Quota quota, F_Unit unit, F_Use_Type useType, F_Object_Id objectId, DATE_FORMAT(F_Start_Time,'%Y-%m-%d') startTime, DATE_FORMAT(F_End_Time,'%Y-%m-%d') endTime, F_CreatorTime createTime
    FROM ftb_attendance_balance_use_record
    where F_Balance_Id = #{id}
  </select>

    <insert id="addOne">
        insert into ftb_attendance_balance_use_record (F_Id, F_Balance_Id, F_Quota,
          F_Unit, F_Use_Type,F_Object_Id, F_Start_Time, F_End_Time, F_Lock,F_CreatorTime)
        values (#{id}, #{balanceId}, #{quota},
          #{unit}, #{userType}, #{objectId}, #{startTime}, #{endTime}, #{lock}, now())
  </insert>
    <insert id="addBatch">
      insert into ftb_attendance_balance_use_record (F_Id, F_Balance_Id, F_Quota,
                                                     F_Unit, F_Use_Type,F_Object_Id, F_Start_Time, F_End_Time, F_Lock,F_CreatorTime)
      values
          <foreach collection="useRecordList" item="item" index="index" separator="," >
          (#{item.id}, #{item.balanceId}, #{item.quota},
            #{item.unit}, #{item.useType}, #{item.objectId}, #{item.startTime}, #{item.endTime}, #{item.lock}, now())
        </foreach>
    </insert>
    <!--  查出本次排班相关的所有消费记录-->
  <select id="getUserBalanceListByObjectId" resultType="jnpf.model.doclibrary.vo.UseDetailVo">
    select F_Id id,  F_Quota quota,F_Balance_Id balanceId
    FROM ftb_attendance_balance_use_record
    where F_Use_Type = #{userType} AND F_Object_Id = #{id}
  </select>

  <delete id="deleteByIds">
    delete  from ftb_attendance_balance_use_record
    where F_Id in
          <foreach collection="userBalanceList" item="item" index="index" separator="," open="(" close=")">
            #{item.id}
          </foreach>
  </delete>


  <!--  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >-->
<!--    delete from ftb_attendance_balance_use_record-->
<!--    where F_Id = #{fId,jdbcType=VARCHAR}-->
<!--  </delete>-->
<!--  <insert id="insert" parameterType="com.shs.cts.util.domain.po.experience.AttendanceBalanceUseRecord" >-->
<!--    insert into ftb_attendance_balance_use_record (F_Id, F_Balance_Id, F_Quota, -->
<!--      F_Unit, F_Approve_Id, F_Start_Time, -->
<!--      F_End_Time, F_Lock, F_CreatorUserId, -->
<!--      F_CreatorTime, F_TenantId)-->
<!--    values (#{fId,jdbcType=VARCHAR}, #{fBalanceId,jdbcType=VARCHAR}, #{fQuota,jdbcType=DECIMAL}, -->
<!--      #{fUnit,jdbcType=BIT}, #{fApproveId,jdbcType=VARCHAR}, #{fStartTime,jdbcType=TIMESTAMP}, -->
<!--      #{fEndTime,jdbcType=TIMESTAMP}, #{fLock,jdbcType=BIT}, #{fCreatoruserid,jdbcType=VARCHAR}, -->
<!--      #{fCreatortime,jdbcType=TIMESTAMP}, #{fTenantid,jdbcType=VARCHAR})-->
<!--  </insert>-->
<!--  -->
<!--  <update id="updateByPrimaryKey" parameterType="com.shs.cts.util.domain.po.experience.AttendanceBalanceUseRecord" >-->
<!--    update ftb_attendance_balance_use_record-->
<!--    set F_Balance_Id = #{fBalanceId,jdbcType=VARCHAR},-->
<!--      F_Quota = #{fQuota,jdbcType=DECIMAL},-->
<!--      F_Unit = #{fUnit,jdbcType=BIT},-->
<!--      F_Approve_Id = #{fApproveId,jdbcType=VARCHAR},-->
<!--      F_Start_Time = #{fStartTime,jdbcType=TIMESTAMP},-->
<!--      F_End_Time = #{fEndTime,jdbcType=TIMESTAMP},-->
<!--      F_Lock = #{fLock,jdbcType=BIT},-->
<!--      F_CreatorUserId = #{fCreatoruserid,jdbcType=VARCHAR},-->
<!--      F_CreatorTime = #{fCreatortime,jdbcType=TIMESTAMP},-->
<!--      F_TenantId = #{fTenantid,jdbcType=VARCHAR}-->
<!--    where F_Id = #{fId,jdbcType=VARCHAR}-->
<!--  </update>-->




</mapper>