<?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.ics.system.mapper.DictDataMapper">
	
	<resultMap type="com.ics.system.domain.DictData" id="DictDataResult">
		<id     property="id"   	  column="id"   	   />
		<result property="dictSort"   column="dict_sort"   />
		<result property="dictLabel"  column="dict_label"  />
		<result property="dictValue"  column="dict_value"  />
		<result property="dictType"   column="dict_type"   />
		<result property="cssClass"   column="css_class"   />
		<result property="listClass"  column="list_class"  />
		<result property="isDefault"  column="is_default"  />
		<result property="status"     column="status"      />
		<result property="version"    column="version"     />
        <result property="deleteFlag" column="delete_flag" />
		<result property="createBy"   column="create_by"   />
		<result property="createTime" column="create_time" />
		<result property="updateBy"   column="update_by"   />
		<result property="updateTime" column="update_time" />
		<result property="tenantId"   column="tenant_id"   />
	</resultMap>
	
	<sql id="selectDictDataVo">
        SELECT id,
			   dict_sort,
			   dict_label,
			   dict_value,
			   dict_type,
			   css_class,
			   list_class,
			   is_default,
			   status,
			   create_by,
			   create_time,
			   remark
		FROM sys_dict_data
    </sql>

	<select id="selectDictDataList" parameterType="com.ics.system.domain.DictData" resultMap="DictDataResult">
	    <include refid="selectDictDataVo"/>
		<where>
		    <if test="dictType != null and dictType != ''">
				AND dict_type = #{dictType}
			</if>
			<if test="dictLabel != null and dictLabel != ''">
				AND dict_label LIKE concat('%', #{dictLabel}, '%')
			</if>
			<if test="status != null and status != ''">
				AND status = #{status}
			</if>
		</where>
	</select>
	
	<select id="selectDictDataByType" parameterType="com.ics.system.domain.DictData" resultMap="DictDataResult">
		<include refid="selectDictDataVo"/>
		WHERE status = '0' AND dict_type = #{dictType} ORDER BY dict_sort ASC
	</select>
	
	<select id="selectDictLabel" resultType="String">
		SELECT dict_label FROM sys_dict_data WHERE dict_type = #{dictType} AND dict_value = #{dictValue}
	</select>
	
	<select id="selectDictDataById" parameterType="Long" resultMap="DictDataResult">
		<include refid="selectDictDataVo"/>
		WHERE id = #{id}
	</select>
	
	<select id="countDictDataByType" resultType="Integer">
	    SELECT count(1) FROM sys_dict_data WHERE dict_type =#{dicttype}
	</select>
	
	<delete id="deleteDictDataById" parameterType="Long">
 		DELETE FROM sys_dict_data WHERE id = #{id}
 	</delete>
	
 	<delete id="deleteDictDataByIds" parameterType="String">
		DELETE FROM sys_dict_data WHERE id IN
 		<foreach collection="array" item="id" open="(" separator="," close=")">
 			#{id}
        </foreach> 
 	</delete>
 	
	<update id="updateDictData" parameterType="com.ics.system.domain.DictData">
 		UPDATE sys_dict_data
 		<set>
 			<if test="dictSort != null and dictSort != ''">dict_sort = #{dictSort},</if>
 			<if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
 			<if test="dictValue != null and dictValue != ''">dict_value = #{dictValue},</if>
 			<if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
 			<if test="cssClass != null">css_class = #{cssClass},</if>
 			<if test="listClass != null">list_class = #{listClass},</if>
 			<if test="isDefault != null and isDefault != ''">is_default = #{isDefault},</if>
 			<if test="status != null">status = #{status},</if>
 			<if test="remark != null">remark = #{remark},</if>
 			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
 			update_time = sysdate()
 		</set>
 		WHERE id = #{id}
	</update>
	
	<update id="updateDictDataType" parameterType="String">
 		UPDATE sys_dict_data SET dict_type = #{newDictType} WHERE dict_type = #{oldDictType}
	</update>
 	
 	<insert id="insertDictData" parameterType="com.ics.system.domain.DictData">
 		INSERT INTO sys_dict_data(
 			<if test="dictSort != null and dictSort != ''">dict_sort,</if>
 			<if test="dictLabel != null and dictLabel != ''">dict_label,</if>
 			<if test="dictValue != null and dictValue != ''">dict_value,</if>
 			<if test="dictType != null and dictType != ''">dict_type,</if>
 			<if test="cssClass != null and cssClass != ''">css_class,</if>
 			<if test="listClass != null and listClass != ''">list_class,</if>
 			<if test="isDefault != null and isDefault != ''">is_default,</if>
 			<if test="status != null">status,</if>
 			<if test="remark != null and remark != ''">remark,</if>
 			<if test="createBy != null and createBy != ''">create_by,</if>
 			create_time
 		)VALUES(
 		    <if test="dictSort != null and dictSort != ''">#{dictSort},</if>
 		    <if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
 			<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
 			<if test="dictType != null and dictType != ''">#{dictType},</if>
 			<if test="cssClass != null and cssClass != ''">#{cssClass},</if>
 			<if test="listClass != null and listClass != ''">#{listClass},</if>
 			<if test="isDefault != null and isDefault != ''">#{isDefault},</if>
 			<if test="status != null">#{status},</if>
 			<if test="remark != null and remark != ''">#{remark},</if>
 			<if test="createBy != null and createBy != ''">#{createBy},</if>
 			sysdate()
 		)
	</insert>
	
</mapper> 