<?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="com.ym.mec.biz.dal.dao.TenantAssetsInfoDao">
    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantAssetsInfo">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
        <result column="balance_" jdbcType="VARCHAR" property="balance"/>
        <result column="frozen_amount_" jdbcType="VARCHAR" property="frozenAmount"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , tenant_id_, balance_, frozen_amount_, created_time_, updated_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.TenantAssetsInfo">
        insert into tenant_assets_info(tenant_id_, balance_, frozen_amount_, created_time_, updated_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.tenantId}, #{entity.balance}, #{entity.frozenAmount}, #{entity.createdTime},
            #{entity.updatedTime})
        </foreach>
    </insert>

    <update id="deductAmount" parameterType="object">
        update tenant_assets_info
        set balance_ = balance_ - #{deductAmount}
        where tenant_id_ = #{tenantId}
    </update>

    <update id="checkDeductAmount" parameterType="object">
        update tenant_assets_info
        set balance_ = balance_ - #{deductAmount}
        where tenant_id_ = #{tenantId}
          and balance_  <![CDATA[ >= ]]> #{deductAmount}
    </update>
    
    <update id="updateAmount">
        update tenant_assets_info set balance_ = balance_ + #{amount} where tenant_id_ = #{tenantId}
    </update>

    <select id="queryPeopleNum" parameterType="integer" resultType="integer">
        select c.student_num_ +1
        from course_schedule as a
                 left join vip_group as b
                           on a.music_group_id_ = b.id_
                 left join vip_group_category as c on b.vip_group_category_id_ = c.id_
        where a.id_ =#{courseId}
    </select>

</mapper>
