<?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.sys_client.SysClientMapper">

	<!-- 增 -->
	<insert id="add">
		insert into 
		sys_client (name, logo, intro, allow_url, status, is_public, create_time) 
		values (#{name}, #{logo}, #{intro}, #{allowUrl}, #{status}, #{isPublic}, now()) 
	</insert>

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

	<!-- 改 -->
	<update id="update">
		update sys_client set
		name = #{name}, 
		logo = #{logo}, 
		intro = #{intro}, 
		allow_url = #{allowUrl}, 
		status = #{status},
		is_public = #{isPublic}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, name, logo, intro, allow_url, status, is_public, create_time from sys_client  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.sys_client.SysClient">
		<result property="id" column="id" />
		<result property="name" column="name" />
		<result property="logo" column="logo" />
		<result property="intro" column="intro" />
		<result property="allowUrl" column="allow_url" />
		<result property="isPublic" column="is_public" />
		<result property="status" column="status" />
		<result property="createTime" column="create_time" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from sys_client 
	</sql>
	
	<!-- 查 - 根据id -->
	<select id="getById" resultMap="model">
		<include refid="select_sql"></include>
		where id = #{id}
	</select>
	
	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） -->
	<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 like concat('%', #{name}, '%') </if>
			<if test=' this.has("intro") '> and intro = #{intro} </if>
			<if test=' this.has("allowUrl") '> and allow_url = #{allowUrl} </if>
			<if test=' this.has("status") '> and status = #{status} </if>
			<if test=' this.has("isPublic") '> and is_public = #{isPublic} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 11'> id asc </when>
			<when test='sortType == 3'> is_public asc, id desc </when>
			<when test='sortType == 4'> status asc, id desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
