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

	<resultMap type="com.ym.mec.biz.dal.entity.SysTenantAccountDetail"
		id="SysTenantAccountDetail">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId" />
		<result column="order_no_" property="orderNo" />
		<result column="trans_type_" property="transType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="trans_status_" property="transStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="trans_no_" property="transNo" />
		<result column="trans_cash_amount_" property="transCashAmount" />
		<result column="total_available_minutes_" property="totalAvailableMinutes" />
		<result column="trans_minutes_" property="transMinutes" />
		<result column="memo_" property="memo" />
		<result column="operator_id_" property="operatorId" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>

	<sql id="queryCondition">
		<where>
			<if test="transType != null">
				and trans_type_ = #{transType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="transStatus != null">
				and trans_status_ = #{transStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="userId != null">
				and user_id_ = #{userId}
			</if>
			<if test="startTime != null">
				and create_time_ >= #{startTime}
			</if>
			<if test="endTime != null">
				<![CDATA[and create_time_ <= #{endTime}]]>
			</if>
		</where>
	</sql>

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

	<select id="queryByOrderNo" resultMap="SysTenantAccountDetail">
		SELECT * FROM sys_tenant_account_detail WHERE order_no_ = #{orderNo}
	</select>

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

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysTenantAccountDetail"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO sys_tenant_account_detail
		(id_,user_id_,order_no_,trans_type_,trans_status_,trans_no_,trans_cash_amount_,total_available_minutes_,trans_minutes_,memo_,operator_id_,create_time_,update_time_)
		VALUES(#{id},#{userId},#{orderNo},#{transType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{transStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{transNo},#{transCashAmount},#{totalAvailableMinutes},#{transMinutes},#{memo},#{operatorId},#{createTime},#{updateTime})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.SysTenantAccountDetail">
		UPDATE sys_tenant_account_detail
		<set>
			<if test="transCashAmount != null">
				trans_cash_amount_ = #{transCashAmount},
			</if>
			<if test="userId != null">
				user_id_ = #{userId},
			</if>
			<if test="orderNo != null">
				order_no_ = #{orderNo},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="totalAvailableMinutes != null">
				total_available_minutes_ = #{totalAvailableMinutes},
			</if>
			<if test="transType != null">
				trans_type_ = #{transType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="updateTime != null">
				update_time_ = #{updateTime},
			</if>
			<if test="memo != null">
				memo_ = #{memo},
			</if>
			<if test="transStatus != null">
				trans_status_ = #{transStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="transNo != null">
				trans_no_ = #{transNo},
			</if>
			<if test="transMinutes != null">
				trans_minutes_ = #{transMinutes},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
		</set>
		WHERE id_ = #{id}
	</update>

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

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="SysTenantAccountDetail" parameterType="map">
		SELECT * FROM sys_tenant_account_detail
		<include refid="queryCondition" />
		order by id_ desc
		<include refid="global.limit" />
	</select>

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

	<!-- 查询当前表的总记录数 -->
	<select id="sumTransMinutes" resultType="int">
		SELECT SUM(trans_minutes_) FROM sys_tenant_account_detail
		<include refid="queryCondition" />
	</select>
</mapper>
