<?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.pj.project.tb_pay_record.TbPayRecordMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_pay_record (id, customer_id, customer_name, out_trade_no, pay_money, pay_time, transaction_id, time_end, create_time) 
		values (#{id}, #{customerId}, #{customerName}, #{outTradeNo}, #{payMoney}, #{payTime}, #{transactionId}, #{timeEnd}, #{createTime}) 
	</insert>

	<!-- 删 -->
	<delete id="delete">
		delete from tb_pay_record 
		where id = #{id}
	</delete>

	<!-- 改 [G] -->
	<update id="update">
		update tb_pay_record set
		id = #{id}, 
		customer_id = #{customerId}, 
		customer_name = #{customerName}, 
		out_trade_no = #{outTradeNo}, 
		pay_money = #{payMoney}, 
		pay_time = #{payTime}, 
		transaction_id = #{transactionId}, 
		time_end = #{timeEnd}, 
		create_time = #{createTime}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, customer_id, customer_name, out_trade_no, pay_money, pay_time, transaction_id, time_end, create_time from tb_pay_record  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_pay_record.TbPayRecord">
		<result property="id" column="id" />
		<result property="customerId" column="customer_id" />
		<result property="customerName" column="customer_name" />
		<result property="outTradeNo" column="out_trade_no" />
		<result property="payMoney" column="pay_money" />
		<result property="payTime" column="pay_time" />
		<result property="transactionId" column="transaction_id" />
		<result property="timeEnd" column="time_end" />
		<result property="createTime" column="create_time" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_pay_record 
	</sql>
	
	<!-- 查 - 根据id -->
	<select id="getById" resultMap="model">
		<include refid="select_sql"></include>
		where id = #{id}
	</select>
	
	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>
		<where>
			<if test=' this.has("id") '> and id = #{id} </if>
			<if test=' this.has("customerId") '> and customer_id = #{customerId} </if>
			<if test=' this.has("customerName") '> and customer_name = #{customerName} </if>
			<if test=' this.has("outTradeNo") '> and out_trade_no = #{outTradeNo} </if>
			<if test=' this.has("payMoney") '> and pay_money = #{payMoney} </if>
			<if test=' this.has("payTime") '> and pay_time = #{payTime} </if>
			<if test=' this.has("transactionId") '> and transaction_id = #{transactionId} </if>
			<if test=' this.has("timeEnd") '> and time_end = #{timeEnd} </if>
			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> customer_id desc </when>
			<when test='sortType == 3'> customer_name desc </when>
			<when test='sortType == 4'> out_trade_no desc </when>
			<when test='sortType == 5'> pay_money desc </when>
			<when test='sortType == 6'> pay_time desc </when>
			<when test='sortType == 7'> transaction_id desc </when>
			<when test='sortType == 8'> time_end desc </when>
			<when test='sortType == 9'> create_time desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
