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

    <resultMap type="com.ym.mec.biz.dal.entity.StudentRecharge" id="StudentRecharge">
        <result column="id_" property="id"/>
        <result column="user_id_" property="userId"/>
        <result column="trans_no_" property="transNo"/>
        <result column="order_no_" property="orderNo"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="amount_" property="amount"/>
        <result column="fee_user_" property="feeUser"/>
        <result column="fee_platform_" property="feePlatform"/>
        <result column="pay_platform_" property="payPlatform"/>
        <result column="description_" property="description"/>
        <result column="comment_" property="comment"/>
        <result column="create_time_" property="createTime"/>
        <result column="modify_time_" property="modifyTime"/>
    </resultMap>
    
    <resultMap type="com.ym.mec.biz.dal.entity.StudentRecharge" id="StudentRechargeVO" extends="StudentRecharge">
        <result column="username_" property="user.username"/>
        <result column="trans_no_" property="transNo"/>
        <result column="trans_type_" property="transType"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="StudentRecharge">
		SELECT * FROM student_recharge WHERE id_ = #{id} 
	</select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="StudentRecharge">
		SELECT * FROM student_recharge ORDER BY id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentRecharge" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        <!--
        <selectKey resultClass="int" keyProperty="id" >
        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
        </selectKey>
        -->
        INSERT INTO student_recharge
        (id_,user_id_,trans_no_,order_no_,status_,amount_,fee_user_,fee_platform_,pay_platform_,description_,comment_,create_time_,modify_time_)
        VALUES(#{id},#{userId},#{transNo},#{orderNo},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{feeUser},#{feePlatform},#{payPlatform},#{description},#{comment},now(),now())
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentRecharge">
        UPDATE student_recharge
        <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="modifyTime != null">
                modify_time_ = #{modifyTime},
            </if>
            <if test="feePlatform != null">
                fee_platform_ = #{feePlatform},
            </if>
            <if test="comment != null">
                comment_ = #{comment},
            </if>
            <if test="amount != null">
                amount_ = #{amount},
            </if>
            <if test="feeUser != null">
                fee_user_ = #{feeUser},
            </if>
            <if test="description != null">
                description_ = #{description},
            </if>
            <if test="transNo != null">
                trans_no_ = #{transNo},
            </if>
            <if test="orderNo != null">
                order_no_ = #{orderNo},
            </if>
            <if test="payPlatform != null">
                pay_platform_ = #{payPlatform},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

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

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="StudentRechargeVO" parameterType="map">
        SELECT sr.*,u.username_,cad.trans_no_,cad.trans_type_ FROM student_recharge sr, sys_user u, sys_user_cash_account_detail cad where sr.user_id_ = u.id_ and sr.user_id_ = cad.user_id_
        <if test="status != null">
           and sr.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="transType != null">
           and cad.trans_type_ = #{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="startDate != null">
           and sr.create_time_ &gt;= #{startTime}
        </if>
        <if test="endDate != null">
           and sr.create_time_ &lt;= #{endTime}
        </if>
        <if test="organId!=null and organId!=''">
            and u.organ_id_=#{organId}
        </if>
        ORDER BY sr.id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int" parameterType="map">
		SELECT COUNT(1) FROM student_recharge sr left join sys_user u on sr.user_id_ = u.id_ left join sys_user_cash_account_detail cad on sr.user_id_ = cad.user_id_ where 1 = 1
		<if test="status != null">
           and sr.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="transType != null">
           and cad.trans_type_ = #{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="startDate != null">
           and sr.create_time_ &gt;= #{startTime}
        </if>
        <if test="endDate != null">
           and sr.create_time_ &lt;= #{endTime}
        </if>
        <if test="organId!=null and organId!=''">
            and u.organ_id_=#{organId}
        </if>
	</select>

    <select id="queryByTransNo" resultMap="StudentRecharge">
		SELECT * FROM student_recharge WHERE  trans_no_ = #{transNo}
	</select>

    <select id="queryByOrderNo" resultMap="StudentRecharge">
		SELECT * FROM student_recharge WHERE  order_no_ = #{orderNo}
	</select>
</mapper>
