<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.RechargeRecordDAO">
	<resultMap id="RechargeRecordMap" type="com.jpsoft.shinestar.modules.base.entity.RechargeRecord">
		<id property="id" column="id_" />
		<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="delFlag" column="del_flag" />
		<result property="serialNumber" column="serial_number" />
		<result property="buyAmount" column="buy_amount" />
		<result property="buyElectricity" column="buy_electricity" />
		<result property="buyType" column="buy_type" />
		<result property="clientId" column="client_id" />
		<result property="customerNo" column="customer_no" />
		<result property="roomId" column="room_id" />
		<result property="transactionNumber" column="transaction_number" />
		<result property="productTheme" column="product_theme" />
		<result property="paymentStatus" column="payment_status" />
		<result property="chargingStatus" column="charging_status" />
		<result property="paymentTime" column="payment_time" />
		<result property="openId" column="open_id" />
		<result property="errorLog" column="error_log" />
		<result property="dumpEnergy" column="dump_energy" />
	</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.RechargeRecord">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_recharge_record
	    (id_,create_by,create_time,update_by,update_time,del_flag,serial_number,buy_amount,buy_electricity,buy_type,client_id,customer_no,
	    room_id,transaction_number,product_theme,payment_status,charging_status,payment_time,open_id,error_log,dump_energy
	    )
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
			,#{serialNumber,jdbcType=VARCHAR}
			,#{buyAmount,jdbcType= NUMERIC }
			,#{buyElectricity,jdbcType= NUMERIC }
			,#{buyType,jdbcType=VARCHAR}
			,#{clientId,jdbcType=VARCHAR}
			,#{customerNo,jdbcType=VARCHAR}
			,#{roomId,jdbcType=VARCHAR}
			,#{transactionNumber,jdbcType=VARCHAR}
			,#{productTheme,jdbcType=VARCHAR}
			,#{paymentStatus,jdbcType=VARCHAR}
			,#{chargingStatus,jdbcType=VARCHAR}
			,#{paymentTime,jdbcType=TIMESTAMP}
			,#{openId,jdbcType=VARCHAR}
			,#{errorLog,jdbcType=VARCHAR}
			,#{dumpEnergy,jdbcType= NUMERIC}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_recharge_record where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.RechargeRecord">
		update base_recharge_record
		<set>
			<if test="createBy!=null">
			create_by=#{createBy,jdbcType=VARCHAR},
			</if>
			<if test="createTime!=null">
			create_time=#{createTime,jdbcType= TIMESTAMP },
			</if>
			<if test="updateBy!=null">
			update_by=#{updateBy,jdbcType=VARCHAR},
			</if>
			<if test="updateTime!=null">
			update_time=#{updateTime,jdbcType= TIMESTAMP },
			</if>
			<if test="delFlag!=null">
			del_flag=#{delFlag,jdbcType= NUMERIC },
			</if>
			<if test="serialNumber!=null">
			serial_number=#{serialNumber,jdbcType=VARCHAR},
			</if>
			<if test="buyAmount!=null">
			buy_amount=#{buyAmount,jdbcType= NUMERIC },
			</if>
			<if test="buyElectricity!=null">
			buy_electricity=#{buyElectricity,jdbcType= NUMERIC },
			</if>
			<if test="buyType!=null">
			buy_type=#{buyType,jdbcType=VARCHAR},
			</if>
			<if test="clientId!=null">
				client_id=#{clientId,jdbcType=VARCHAR},
			</if>
			<if test="customerNo!=null">
				customer_no=#{customerNo,jdbcType=VARCHAR},
			</if>

			<if test="roomId!=null">
				room_id=#{roomId,jdbcType=VARCHAR},
			</if>
			<if test="transactionNumber!=null">
				transaction_number=#{transactionNumber,jdbcType=VARCHAR},
			</if>
			<if test="productTheme!=null">
				product_theme=#{productTheme,jdbcType=VARCHAR},
			</if>
			<if test="paymentStatus!=null">
				payment_status=#{paymentStatus,jdbcType=VARCHAR},
			</if>
			<if test="chargingStatus!=null">
				charging_status=#{chargingStatus,jdbcType=VARCHAR},
			</if>
			<if test="paymentTime!=null">
				payment_time=#{paymentTime,jdbcType=TIMESTAMP},
			</if>
			<if test="openId!=null">
				open_id=#{openId,jdbcType=VARCHAR},
			</if>
			<if test="errorLog!=null">
				error_log=#{errorLog,jdbcType=VARCHAR},
			</if>
			<if test="dumpEnergy!=null">
				dump_energy=#{dumpEnergy,jdbcType=NUMERIC},
			</if>
		</set>
		where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="RechargeRecordMap">
		select a.* from base_recharge_record a where id_=#{0} and del_flag = 0
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_recharge_record where id_=#{0} and del_flag = 0
	</select>
	<select id="list" resultMap="RechargeRecordMap">
		select * from base_recharge_record where del_flag = 0 order by create_time desc
	</select>
	<select id="search" parameterType="hashmap" resultMap="RechargeRecordMap">
		<![CDATA[
			select * from base_recharge_record
		]]>
		<where>
			del_flag = 0
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.serialNumber != null">
				and serial_number like #{searchParams.serialNumber}
			</if>
			<if test="searchParams.roomId != null">
				and room_id = #{searchParams.roomId}
			</if>
			<if test="searchParams.paymentStatus != null">
				and payment_status = #{searchParams.paymentStatus}
			</if>
			<if test="searchParams.chargingStatus != null">
				and charging_status = #{searchParams.chargingStatus}
			</if>
			<if test="searchParams.buyType != null">
				and buy_type = #{searchParams.buyType}
			</if>
			<if test="searchParams.roomsIds != null and searchParams.roomsIds.size() > 0">
				and room_id in
				<foreach item="rId" index="index" collection="searchParams.roomsIds" open="("  close=")" separator=",">
					#{rId}
				</foreach>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="getBySerialNum" resultMap="RechargeRecordMap">
		select * from base_recharge_record where serial_number=#{serialNum} and del_flag=0 limit 1
	</select>
</mapper>