<?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_dict_item.SysDictItemMapper">

	<!-- 增 [G] -->
	<insert id="add">
		insert into 
		sys_dict_item (id, dict_id, item_value, item_text, des, sort, status)
		values (#{id}, #{dictId}, #{itemValue}, #{itemText}, #{des}, #{sort}, #{status})
	</insert>

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

	<!-- 改 [G] -->
	<update id="update">
		update sys_dict_item set
		id = #{id}, 
		dict_id = #{dictId}, 
		item_value = #{itemValue}, 
		item_text = #{itemText}, 
		des = #{des},
		sort = #{sort}, 
		status = #{status}
		where id = #{id}
	</update>


	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, dict_id, item_value, item_text, desc, sort, status from sys_dict_item  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.sys_dict_item.SysDictItem">
		<result property="id" column="id" />
		<result property="dictId" column="dict_id" />
		<result property="itemValue" column="item_value" />
		<result property="itemText" column="item_text" />
		<result property="des" column="des" />
		<result property="sort" column="sort" />
		<result property="status" column="status" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from sys_dict_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.isNotNull("id") '> and id = #{id} </if>
			<if test=' this.isNotNull("dictId") '> and dict_id = #{dictId} </if>
			<if test=' this.isNotNull("itemValue") '> and item_value = #{itemValue} </if>
			<if test=' this.isNotNull("itemText") '> and item_text = #{itemText} </if>
			<if test=' this.isNotNull("des") '> and desc= #{des} </if>
			<if test=' this.isNotNull("sort") '> and sort = #{sort} </if>
			<if test=' this.isNotNull("status") '> and status = #{status} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> dict_id desc </when>
			<when test='sortType == 3'> item_value desc </when>
			<when test='sortType == 4'> item_text desc </when>
			<when test='sortType == 5'> des desc </when>
			<when test='sortType == 6'> sort desc </when>
			<when test='sortType == 7'> status desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
