<?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_people.TbBusinessPeopleMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		tb_business_people (id, name, phone, business_id, create_time) 
		values (#{id}, #{name}, #{phone}, #{businessId}, #{createTime}) 
	</insert>


	<!-- 改 [G] -->
	<update id="update">
		update tb_business_people set
		id = #{id}, 
		name = #{name}, 
		phone = #{phone}, 
		business_id = #{businessId}, 
		create_time = #{createTime}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, name, phone, business_id, create_time from tb_business_people  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_business_people.TbBusinessPeople">
		<result property="id" column="id" />
		<result property="name" column="name" />
		<result property="phone" column="phone" />
		<result property="businessId" column="business_id" />
		<result property="createTime" column="create_time" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_business_people 
	</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("name") '> and name = #{name} </if>
			<if test=' this.has("phone") '> and phone = #{phone} </if>
			<if test=' this.has("businessId") '> and business_id = #{businessId} </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'> name desc </when>
			<when test='sortType == 3'> phone desc </when>
			<when test='sortType == 4'> business_id desc </when>
			<when test='sortType == 5'> create_time desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
