<?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.huatek.frame.base.mapper.DictionnaireMapper">

	<resultMap id="BaseDicResultMap" type="com.huatek.frame.base.vo.DictionnaireVO">
		<id column="id" jdbcType="VARCHAR" property="id" />
		<result column="name" jdbcType="VARCHAR" property="name" />
		<result column="code" jdbcType="VARCHAR" property="code" />
		<result column="deleted" jdbcType="VARCHAR" property="deleted" />
	</resultMap>
	<sql id="Base_Dictionnaire_Column_List">
		name as name, code as code, deleted as deleted, id as id
	</sql>

	<select id="selectDictionnairePage" parameterType="com.huatek.frame.base.dto.DictionnaireDTO"
		resultMap="BaseDicResultMap">
		select
		<include refid="Base_Dictionnaire_Column_List" />
			from sys_dictionnaire
		where 
			deleted=#{deleted}
		<if test="name != null and  name != '' ">
			and name like CONCAT('%',#{name},'%')
		</if> 
		<if test="code != null and  code != '' ">
			and code like CONCAT('%',#{code},'%')
		</if>
		order by code asc, name asc
	</select>
	
	<resultMap id="DicResultMap" type="com.huatek.frame.base.vo.DictionnaireVO">
		<id property="id" jdbcType="VARCHAR" column="id" />
		<result property="name" jdbcType="VARCHAR" column="name" />
		<result property="code" jdbcType="VARCHAR" column="code" />
		<result property="deleted" jdbcType="VARCHAR" column="deleted" />
		<collection property="details"  ofType="com.huatek.frame.base.entity.DictionnaireDetail"   column="{id=id,deleted=deleted}" select="selectDicdetails"/>    			
	</resultMap>  
	
	<select id="selectDictionnaires" resultMap="DicResultMap" parameterType="java.lang.String">
		select 
			<include refid="Base_Dictionnaire_Column_List" />
		from 
     		sys_dictionnaire  
		where 
			deleted=#{deleted}
	</select>

	<select id="findDictionnaireByKey" resultType="com.huatek.frame.base.entity.Dictionnaire" parameterType="java.lang.String">
		select
			*
		from
		sys_dictionnaire
		where
		deleted = 0
		and code = #{key}
	</select>
	
	<select id="selectDicdetails" resultType="com.huatek.frame.base.entity.DictionnaireDetail" parameterType="java.util.HashMap">
		select 
			id,dname,dcode
		from 
     		sys_dictionnaire_detail 
		where 
			deleted=#{deleted}
		and 
			pid=#{id}
	</select> 

</mapper>