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

    <resultMap type="com.ym.mec.biz.dal.entity.SysUserCashAccount" id="SysUserCashAccount">
        <result column="user_id_" property="userId"/>
        <result column="currency_" property="currency"/>
        <result column="balance_" property="balance"/>
        <result column="frozen_amount_" property="frozenAmount"/>
        <result column="margin_balance_" property="marginBalance"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="SysUserCashAccount">
		SELECT * FROM sys_user_cash_account WHERE user_id_ = #{userId} 
	</select>
	
    <select id="getLocked" resultMap="SysUserCashAccount">
		SELECT * FROM sys_user_cash_account WHERE user_id_ = #{userId} for update
	</select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="SysUserCashAccount">
		SELECT * FROM sys_user_cash_account ORDER BY user_id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysUserCashAccount" useGeneratedKeys="true"
            keyColumn="id" keyProperty="id">
        <!--
        <selectKey resultClass="int" keyProperty="id" >
        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
        </selectKey>
        -->
        INSERT INTO sys_user_cash_account
        (user_id_,currency_,balance_,frozen_amount_,margin_balance_,status_,create_time_,update_time)
        VALUES(#{userId},#{currency},#{balance},#{frozenAmount},#{marginBalance},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},now(),now())
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.SysUserCashAccount">
        UPDATE sys_user_cash_account
        <set>
            <if test="status != null">
                status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="frozenAmount != null">
                frozen_amount_ = #{frozenAmount},
            </if>
            <if test="balance != null">
                balance_ = #{balance},
            </if>
            <if test="marginBalance != null">
                margin_balance_ = #{marginBalance},
            </if>
            <if test="currency != null">
                currency_ = #{currency},
            </if>
        </set>
        WHERE user_id_ = #{userId}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
		DELETE FROM sys_user_cash_account WHERE user_id_ = #{userId} 
	</delete>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="SysUserCashAccount" parameterType="map">
        SELECT * FROM sys_user_cash_account ORDER BY user_id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_user_cash_account
	</select>

</mapper>
