<?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="SysDictMapper">
	<resultMap id="BaseResultMap"
		type="com.wechat.model.dbEntity.SysDict">
		<id column="id" property="id" jdbcType="VARCHAR" />
		<result column="value" property="value" jdbcType="VARCHAR" />
		<result column="label" property="label" jdbcType="VARCHAR" />
		<result column="type" property="type" jdbcType="VARCHAR" />
		<result column="description" property="description" jdbcType="VARCHAR" />
		<result column="sort" property="sort" jdbcType="DECIMAL" />
		<result column="parent_id" property="parentId" jdbcType="VARCHAR" />
		<result column="create_by" property="createBy" jdbcType="VARCHAR" />
		<result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
		<result column="update_by" property="updateBy" jdbcType="VARCHAR" />
		<result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
		<result column="remarks" property="remarks" jdbcType="VARCHAR" />
		<result column="del_flag" property="delFlag" jdbcType="CHAR" />
	</resultMap>
	<sql id="Base_Column_List">
		id, value, label, type, description, sort, parent_id,
		create_by,
		create_date, update_by,
		update_date, remarks, del_flag
	</sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="java.lang.String">
		select
		<include refid="Base_Column_List" />
		from sys_dict
		where id = #{id,jdbcType=VARCHAR}
	</select>
	<select id="getLabel" resultType="java.lang.String"
		parameterType="java.util.HashMap">
		select
		label AS label
		from sys_dict
		where del_flag = 0 and
		type = #{type} and value= #{value}
	</select>
	<select id="getRemarks" resultType="java.lang.String"
		parameterType="java.util.HashMap">
		select
		remarks AS remarks
		from sys_dict
		where del_flag = 0
		and type = #{type} and value= #{value}
	</select>
	<select id="getSysArea" resultType="java.lang.String"
		parameterType="java.lang.String">
		select
		name AS name
		from sys_area
		where del_flag = 0 and
		code = #{code}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
		delete from
		sys_dict
		where id = #{id,jdbcType=VARCHAR}
	</delete>
	<insert id="insert"
		parameterType="com.wechat.model.dbEntity.SysDict">
		insert into sys_dict (id, value, label,
		type,
		description, sort,
		parent_id, create_by, create_date,
		update_by,
		update_date, remarks,
		del_flag)
		values (#{id,jdbcType=VARCHAR},
		#{value,jdbcType=VARCHAR},
		#{label,jdbcType=VARCHAR},
		#{type,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
		#{sort,jdbcType=DECIMAL},
		#{parentId,jdbcType=VARCHAR},
		#{createBy,jdbcType=VARCHAR},
		#{createDate,jdbcType=TIMESTAMP},
		#{updateBy,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP},
		#{remarks,jdbcType=VARCHAR},
		#{delFlag,jdbcType=CHAR})
	</insert>
	<insert id="insertSelective"
		parameterType="com.wechat.model.dbEntity.SysDict">
		insert into sys_dict
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="value != null">
				value,
			</if>
			<if test="label != null">
				label,
			</if>
			<if test="type != null">
				type,
			</if>
			<if test="description != null">
				description,
			</if>
			<if test="sort != null">
				sort,
			</if>
			<if test="parentId != null">
				parent_id,
			</if>
			<if test="createBy != null">
				create_by,
			</if>
			<if test="createDate != null">
				create_date,
			</if>
			<if test="updateBy != null">
				update_by,
			</if>
			<if test="updateDate != null">
				update_date,
			</if>
			<if test="remarks != null">
				remarks,
			</if>
			<if test="delFlag != null">
				del_flag,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="id != null">
				#{id,jdbcType=VARCHAR},
			</if>
			<if test="value != null">
				#{value,jdbcType=VARCHAR},
			</if>
			<if test="label != null">
				#{label,jdbcType=VARCHAR},
			</if>
			<if test="type != null">
				#{type,jdbcType=VARCHAR},
			</if>
			<if test="description != null">
				#{description,jdbcType=VARCHAR},
			</if>
			<if test="sort != null">
				#{sort,jdbcType=DECIMAL},
			</if>
			<if test="parentId != null">
				#{parentId,jdbcType=VARCHAR},
			</if>
			<if test="createBy != null">
				#{createBy,jdbcType=VARCHAR},
			</if>
			<if test="createDate != null">
				#{createDate,jdbcType=TIMESTAMP},
			</if>
			<if test="updateBy != null">
				#{updateBy,jdbcType=VARCHAR},
			</if>
			<if test="updateDate != null">
				#{updateDate,jdbcType=TIMESTAMP},
			</if>
			<if test="remarks != null">
				#{remarks,jdbcType=VARCHAR},
			</if>
			<if test="delFlag != null">
				#{delFlag,jdbcType=CHAR},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective"
		parameterType="com.wechat.model.dbEntity.SysDict">
		update sys_dict
		<set>
			<if test="value != null">
				value = #{value,jdbcType=VARCHAR},
			</if>
			<if test="label != null">
				label = #{label,jdbcType=VARCHAR},
			</if>
			<if test="type != null">
				type = #{type,jdbcType=VARCHAR},
			</if>
			<if test="description != null">
				description = #{description,jdbcType=VARCHAR},
			</if>
			<if test="sort != null">
				sort = #{sort,jdbcType=DECIMAL},
			</if>
			<if test="parentId != null">
				parent_id = #{parentId,jdbcType=VARCHAR},
			</if>
			<if test="createBy != null">
				create_by = #{createBy,jdbcType=VARCHAR},
			</if>
			<if test="createDate != null">
				create_date = #{createDate,jdbcType=TIMESTAMP},
			</if>
			<if test="updateBy != null">
				update_by = #{updateBy,jdbcType=VARCHAR},
			</if>
			<if test="updateDate != null">
				update_date = #{updateDate,jdbcType=TIMESTAMP},
			</if>
			<if test="remarks != null">
				remarks = #{remarks,jdbcType=VARCHAR},
			</if>
			<if test="delFlag != null">
				del_flag = #{delFlag,jdbcType=CHAR},
			</if>
		</set>
		where id = #{id,jdbcType=VARCHAR}
	</update>
	<update id="updateByPrimaryKey"
		parameterType="com.wechat.model.dbEntity.SysDict">
		update sys_dict
		set value = #{value,jdbcType=VARCHAR},
		label = #{label,jdbcType=VARCHAR},
		type = #{type,jdbcType=VARCHAR},
		description = #{description,jdbcType=VARCHAR},
		sort =
		#{sort,jdbcType=DECIMAL},
		parent_id = #{parentId,jdbcType=VARCHAR},
		create_by = #{createBy,jdbcType=VARCHAR},
		create_date =
		#{createDate,jdbcType=TIMESTAMP},
		update_by =
		#{updateBy,jdbcType=VARCHAR},
		update_date =
		#{updateDate,jdbcType=TIMESTAMP},
		remarks =
		#{remarks,jdbcType=VARCHAR},
		del_flag = #{delFlag,jdbcType=CHAR}
		where
		id = #{id,jdbcType=VARCHAR}
	</update>

	<!-- <select id="getByAllProvice" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from sys_dict where parent_id= 1 and del_flag =0
	</select>
	<select id="getAllCities" parameterType="java.util.Map"
		resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from sys_dict where del_flag=0
		<if test="list != null">
			and parent_id in
			<foreach collection="list" item="items" open="("
				separator="," close=")">
				#{items}
			</foreach>

		</if>
	</select>
	<select id="getAllArea" parameterType="java.util.List"
		resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from sys_dict where del_flag=0
		<if test="list != null">
			and parent_id in
			<foreach collection="list" item="item" separator="," open="("
				close=")">
				#{item}
			</foreach>
		</if>
	</select> -->
	
	
	<resultMap type="com.wechat.model.responseDto.DPResp" id="DPRespList">
		<result column="label" property="label"/>
		<result column="value" property="value"/>
		<collection property="children" ofType="com.wechat.model.responseDto.DPResp">  
			<result column="school.label" property="label"/>
			<result column="school.value" property="value"/>
	    </collection> 
	</resultMap>
	<!-- 获取学校列表 -->
	<select id="getSchoolList" resultMap="DPRespList">
		SELECT
			s1.label as 'label',
			s1.value as 'value',
			s.label as 'school.label',
			s.value as 'school.value'
		FROM
			sys_dict s
			left join sys_dict s1 on s1.value=s.description and s1.type='diqu' and s1.del_flag=0
		WHERE
			s.type = 'school' and s.del_flag=0
		order by s1.value, s.value
	</select>
	
	<select id="getDictByType" resultType="com.wechat.model.responseDto.DPResp">
		SELECT
			<choose>
				<when test="lang == 'en'.toString()">
					s.en as 'label',
				</when>
				<otherwise>
					s.label as 'label',
				</otherwise>
			</choose>
			s.value as 'value'
		FROM
			sys_dict s
		WHERE
			s.type = #{type} and s.del_flag=0
		order by s.sort
	</select>
	<select id="getDictLVByType" resultType="com.wechat.model.responseDto.LVResp">
		SELECT
			<choose>
				<when test="lang == 'en'.toString()">
					s.en as 'label',
				</when>
				<otherwise>
					s.label as 'label',
				</otherwise>
			</choose>
			s.value as 'value'
		FROM
			sys_dict s
		WHERE
			s.type = #{type} and s.del_flag=0
		order by s.sort
	</select>
	<!-- 国家区号码 -->
	<select id="getPhoneCode" resultType="com.wechat.model.responseDto.PhoneCodeResp">
		SELECT
			<choose>
				<when test="lang == 'en'.toString()">
					s.en as 'label',
				</when>
				<otherwise>
					s.label as 'label',
				</otherwise>
			</choose>
			s.value as 'value'
		FROM
			sys_dict s
		WHERE
			s.type = #{type} and s.del_flag=0
		order by s.sort
	</select>
</mapper>