<?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.qnfhq.modules.user.dao.AppAssetDao">

    <resultMap type="com.qnfhq.modules.user.entity.AppAssetEntity" id="appAssetMap">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="symbol" column="symbol"/>
        <result property="total" column="total"/>
        <result property="frozen" column="frozen"/>
        <result property="available" column="available"/>
        <result property="type" column="type"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <!-- c2c卖出 冻结资产 -->
    <update id="frozeAssetByUserId" parameterType="java.util.Map">
        update t_app_asset
        <set>
            available = available - #{money},
            frozen= frozen + #{money},
            update_time = now()
        </set>
        where user_id = #{userId} and symbol =#{symbol}  and type=#{type}
    </update>

    <!-- c2c卖出取消 解冻资产 -->
    <update id="unblockAssetByUserId" parameterType="java.util.Map">
        update t_app_asset
        <set>
            available = available + #{money},
            frozen = frozen - #{money},
            update_time = now()
        </set>
        where user_id = #{userId} and symbol =#{symbol}  and type=#{type}
    </update>

    <!-- c2c买币 增加资产 -->
    <update id="addAssetByUserId" parameterType="java.util.Map">
        update t_app_asset
        <set>
            total = total + #{money},
            available=available + #{money},
            update_time = now()
        </set>
        where user_id = #{userId} and symbol =#{symbol} and type=#{type}
    </update>

    <!-- c2c放行 减少资产 -->
    <update id="releaseAssetByUserId" parameterType="java.util.Map">
        update t_app_asset
        <set>
            total = total - #{money},
            frozen=frozen - #{money},
            update_time = now()
        </set>
        where user_id = #{userId} and symbol =#{symbol} and type=#{type}
    </update>

</mapper>