<?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.emergency.avenue.admin.mapper.SysTreeDictMapper">

	<resultMap id="sysTreeDictMap" type="com.emergency.avenue.admin.api.entity.SysTreeDict">
		<id property="id" column="id"/>
		<result property="parentId" column="parent_id"/>
		<result property="name" column="name_"/>
		<result property="sort" column="sort_"/>
		<result property="delFlag" column="del_flag"/>
		<result property="type" column="type_"/>
		<result property="createBy" column="create_by"/>
		<result property="updateBy" column="update_by"/>
		<result property="createTime" column="create_time"/>
		<result property="updateTime" column="update_time"/>
		<result property="code" column="CODE_"/>
		<result property="path" column="PATH_"/>
		<result property="difference" column="DIFFERENCE_"/>
		<result property="parentCode" column="PARENT_CODE"/>
	</resultMap>

	<!--orderDict简单分页查询-->
	<select id="getOrderDictPage" resultMap="sysTreeDictMap">
		SELECT
		id,
		parent_id,
		name_,
		sort_,
		del_flag,
		content_,
		type_,
		create_by,
		update_by,
		create_time,
		update_time,
		CODE_,
		PATH_,
		DIFFERENCE_,
		PARENT_CODE
		FROM SYS_TREE_DICT
		<where>
			<if test="orderDict.id != null and orderDict.id.trim() != ''">
				AND id = #{orderDict.id}
			</if>
			<if test="orderDict.parentId != null and orderDict.parentId.trim() != ''">
				AND parent_id = #{orderDict.parentId}
			</if>
			<if test="orderDict.name != null and orderDict.name.trim() != ''">
				AND name_ = #{orderDict.name}
			</if>
			<if test="orderDict.sort != null and orderDict.sort.trim() != ''">
				AND sort_ = #{orderDict.sort}
			</if>
			<if test="orderDict.delFlag != null and orderDict.delFlag.trim() != ''">
				AND del_flag = #{orderDict.delFlag}
			</if>
			<if test="orderDict.type != null">
				AND type_ = #{orderDict.type}
			</if>
			<if test="orderDict.createBy != null and orderDict.createBy.trim() != ''">
				AND create_by = #{orderDict.createBy}
			</if>
			<if test="orderDict.updateBy != null and orderDict.updateBy.trim() != ''">
				AND update_by = #{orderDict.updateBy}
			</if>
			<if test="orderDict.createTime != null and orderDict.createTime.trim() != ''">
				AND create_time = #{orderDict.createTime}
			</if>
			<if test="orderDict.updateTime != null and orderDict.updateTime.trim() != ''">
				AND update_time = #{orderDict.updateTime}
			</if>
		</where>
	</select>

	<!--根据类型获取字典树-->
	<select id="getOrderDictList" resultType="com.emergency.avenue.admin.api.entity.SysTreeDict">
		SELECT id, parent_id, name_, sort_, content_,code_,PARENT_CODE,path_,DIFFERENCE_
		FROM SYS_TREE_DICT
		where type_ = #{type}
		  and del_flag = 0
			limit 0,5000
	</select>

	<!--根据类型获取字典树-->
	<select id="getTypesList" resultType="com.emergency.avenue.admin.api.entity.SysTreeDict">
		SELECT id,parent_id,name_,sort_,content_,type_,code_,PARENT_CODE,path_,DIFFERENCE_
		FROM SYS_TREE_DICT where type_ in
		<foreach item="item" collection="typeList" separator="," open="(" close=")" index="">
			#{item}
		</foreach>

		and del_flag=0
	</select>

	<select id="getOrderDict" resultType="com.emergency.avenue.admin.api.entity.SysTreeDict">
		select id
		from SYS_TREE_DICT
		where type_ = #{type}
		  and name_ = #{name}
	</select>
	<select id="getIds" resultType="com.emergency.avenue.admin.api.entity.SysTreeDict">
		select id,name_,code_,PARENT_CODE,path_,DIFFERENCE_ from SYS_TREE_DICT
		<where>
			id in
			<foreach item="item" collection="ids" separator="," open="(" close=")" index="">
				#{item}
			</foreach>
		</where>
	</select>

	<select id="getAllDictCode6" resultType="java.lang.String">
		SELECT CODE_  FROM SYS_TREE_DICT std WHERE STD.TYPE_ = 1 AND DIFFERENCE_ = '3' AND DEL_FLAG = 0
	</select>

</mapper>
