<?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="SysDictionaryMapper">

	<!-- 列表 -->
	<select id="listPage" resultType="SysDictionary">
		select a.id,a.type,a.key,a.value,a.order_by,a.description
		from sys_dictionary a
		where 1 = 1 and id in (select value from sys_dictionary where type=#{pd.cmsEditType})
		<if test="pd.type != null and pd.type != ''">
			and a.type = #{pd.type}
		</if>
		order by a.type,a.key
	</select>

	<!-- 查询总数 -->
	<select id="findCount" resultType="Long">
		select count(a.id) as sum
		from sys_dictionary a
		where 1 = 1 and id in (select value from sys_dictionary where type=#{cmsEditType})
		<if test="type != null and type != ''">
			and a.type = #{type}
		</if>
	</select>

	<!-- 获取详情 -->
	<select id="findOneById" resultType="PageData">
		select a.id,a.type,a.key,a.value,a.description
		from sys_dictionary a
		where 1=1
		<if test="id != null and id != ''">
			and a.id = #{id}
		</if>
	</select>

	<update id="edit">
		update sys_dictionary 
		set value = #{value},description = #{description}
		where id = #{id}
	</update>

	<!-- 获取详情 -->
	<select id="findListByType" resultType="SysDictionary">
		select a.id,a.type,a.key,a.value,a.description
		from sys_dictionary a
		where a.type = #{type}
		order by order_by asc
	</select>
	
	<!-- 获取详情 -->
	<select id="findOneByTypeAndKey" resultType="SysDictionary">
		select a.id,a.type,a.key,a.value,a.description
		from sys_dictionary a
		where a.type = #{type} and a.key = #{key}
	</select>
	
	<update id="updateValue">
		update sys_dictionary set value = #{value}
		where type = #{type} and `key` = #{key}
	</update>
</mapper>