<?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.sunxung.factoring.mapper.sys.DictionaryMapper">

	<resultMap type="Dictionary" id="dictionaryResult">
		<result property="id" column="id"/>
		<result property="name" column="name"/>
		<result property="parentId" column="parentId"/>
		<result property="code" column="code"/>
		<result property="gradation" column="gradation"/>
		<result property="gmtCreate" column="gmt_create"/>
		<result property="gmtModified" column="gmt_modified"/>
	</resultMap>

	<insert id="add" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="Dictionary">
		insert into t_dictionary
			(name, parentId, code, gradation )
		values
			(#{name}, #{parentId}, #{code}, #{gradation})
	</insert>

	<select id="get" parameterType="java.lang.Long" resultMap="dictionaryResult">
		select * from t_dictionary where id = #{value}
	</select>

	<select id="getByCode" parameterType="java.lang.String" resultMap="dictionaryResult">
		select * from t_dictionary where code = #{value}
	</select>

	<select id="getByNameAndParentCode" resultMap="dictionaryResult">
		select * from t_dictionary where name = #{name} and parentId = ( select id from t_dictionary where code = #{parentCode} )
	</select>

	<select id="findByParentId" parameterType="java.lang.Long" resultMap="dictionaryResult">
		select * from t_dictionary where parentId = #{value}
	</select>

	<select id="findByParentIdIsNull" resultMap="dictionaryResult">
		select * from t_dictionary where parentId is null or parentId=''
	</select>

	<select id="findByParentCode" parameterType="java.lang.String" resultMap="dictionaryResult">
		select * from t_dictionary where parentId = ( select id from t_dictionary where code = #{value} )
	</select>

	<select id="findByParentCodeAndCode" parameterType="java.lang.String" resultMap="dictionaryResult">
		select * from t_dictionary
		where parentId = ( select id from t_dictionary where code = #{parentCode} ) and code like CONCAT('%',#{code},'%')
	</select>

</mapper>
