<?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_fee_details.TbFeeDetailsMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_fee_details (id, business_id, business_no, car_no, fee_type, item_type_id, item_type_name, item_id, item_name, item_price, pay_day, pay_type, create_time)
		values (#{id}, #{businessId}, #{businessNo}, #{carNo}, #{feeType}, #{itemTypeId}, #{itemTypeName}, #{itemId}, #{itemName}, #{itemPrice}, #{payDay}, #{payType}, #{createTime})
	</insert>

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

	<!-- 改 [G] -->
	<update id="update">
		update tb_fee_details set
		id = #{id},
		business_id = #{businessId},
		business_no = #{businessNo}, 
		car_no = #{carNo},
		fee_type = #{feeType},
		item_type_id = #{itemTypeId}, 
		item_type_name = #{itemTypeName}, 
		item_id = #{itemId}, 
		item_name = #{itemName}, 
		item_price = #{itemPrice}, 
		pay_day = #{payDay}, 
		pay_type = #{payType}, 
		create_time = #{createTime}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, business_no, car_no, item_type_id, item_type_name, item_id, item_name, item_price, pay_day, pay_type, create_time from tb_fee_details  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_fee_details.TbFeeDetails">
		<result property="id" column="id" />
        <result property="businessId" column="business_id" />
		<result property="businessNo" column="business_no" />
		<result property="carNo" column="car_no" />
        <result property="feeType" column="fee_type" />
		<result property="itemTypeId" column="item_type_id" />
		<result property="itemTypeName" column="item_type_name" />
		<result property="itemId" column="item_id" />
		<result property="itemName" column="item_name" />
		<result property="itemPrice" column="item_price" />
		<result property="payDay" column="pay_day" />
		<result property="payType" column="pay_type" />
		<result property="createTime" column="create_time" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_fee_details 
	</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("businessId") '> and business_id = #{businessId} </if>
			<if test=' this.has("businessNo") '> and business_no = #{businessNo} </if>
			<if test=' this.has("carNo") '> and car_no = #{carNo} </if>
            <if test=' this.has("feeType") '> and fee_type = #{feeType} </if>
			<if test=' this.has("itemTypeId") '> and item_type_id = #{itemTypeId} </if>
			<if test=' this.has("itemTypeName") '> and item_type_name = #{itemTypeName} </if>
			<if test=' this.has("itemId") '> and item_id = #{itemId} </if>
			<if test=' this.has("itemName") '> and item_name = #{itemName} </if>
			<if test=' this.has("itemPrice") '> and item_price = #{itemPrice} </if>
			<if test=' this.has("payDay") '> and pay_day = #{payDay} </if>
			<if test=' this.has("payType") '> and pay_type = #{payType} </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'> business_no desc </when>
			<when test='sortType == 3'> car_no desc </when>
			<when test='sortType == 4'> item_type_id desc </when>
			<when test='sortType == 5'> item_type_name desc </when>
			<when test='sortType == 6'> item_id desc </when>
			<when test='sortType == 7'> item_name desc </when>
			<when test='sortType == 8'> item_price desc </when>
			<when test='sortType == 9'> pay_day desc </when>
			<when test='sortType == 10'> pay_type desc </when>
			<when test='sortType == 11'> create_time desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
