<?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_business_item.TbBusinessItemMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_business_item (id, business_id, item_code, item_price, item_name, status, operate_time, operaror) 
		values (#{id}, #{businessId}, #{itemCode}, #{itemPrice}, #{itemName}, #{status}, #{operateTime}, #{operaror}) 
	</insert>



	<!-- 改 [G] -->
	<update id="update">
		update tb_business_item set
		id = #{id}, 
		business_id = #{businessId}, 
		item_code = #{itemCode}, 
		item_price = #{itemPrice}, 
		item_name = #{itemName}, 
		status = #{status}, 
		operate_time = #{operateTime}, 
		operaror = #{operaror}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->

	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_business_item.TbBusinessItem">
		<result property="id" column="id" />
		<result property="businessId" column="business_id" />
		<result property="itemCode" column="item_code" />
		<result property="itemPrice" column="item_price" />
		<result property="itemName" column="item_name" />
		<result property="status" column="status" />
		<result property="operateTime" column="operate_time" />
		<result property="operaror" column="operaror" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select *
		from tb_business_item 
	</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("itemCode") '> and item_code = #{itemCode} </if>
			<if test=' this.has("itemPrice") '> and item_price = #{itemPrice} </if>
			<if test=' this.has("itemName") '> and item_name = #{itemName} </if>
			<if test=' this.has("status") '> and status = #{status} </if>
			<if test=' this.has("operateTime") '> and operate_time = #{operateTime} </if>
			<if test=' this.has("operaror") '> and operaror = #{operaror} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> business_id desc </when>
			<when test='sortType == 3'> item_code desc </when>
			<when test='sortType == 4'> item_price desc </when>
			<when test='sortType == 5'> item_name desc </when>
			<when test='sortType == 6'> status desc </when>
			<when test='sortType == 7'> operate_time desc </when>
			<when test='sortType == 8'> operaror desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
