<?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.yunfeiyun.agmp.common.web.system.mapper.SysDictDataMapper">
	
	<resultMap type="SysDictData" id="SysDictDataResult">
		<id     property="dictId"   column="dictId"   />
		<result property="dicttypeCode"   column="dicttypeCode"   />
		<result property="dictName"  column="dictName"  />
		<result property="dictSeq"   column="dictSeq"   />
		<result property="dictCode"   column="dictCode"   />
		<result property="dictValue"  column="dictValue"  />
		<result property="dictAvlstatus"     column="dictAvlstatus"      />
		<result property="dictCreator"   column="dictCreator"   />
		<result property="dictCreateddate" column="dictCreateddate" />
		<result property="dictModifier"   column="dictModifier"   />
		<result property="dictModifieddate" column="dictModifieddate" />
		<result property="dictRemark" column="dictRemark" />
	</resultMap>
	
	<sql id="selectDictDataVo">
        select dictId, dictSeq, dictName, dictValue, dicttypeCode, dictAvlstatus, dictCreator, dictCreateddate, dictRemark
		from SysDict
    </sql>

	<select id="selectDictDataList" parameterType="SysDictData" resultMap="SysDictDataResult">
	    <include refid="selectDictDataVo"/>
		<where>
		    <if test="dicttypeCode != null and dicttypeCode != ''">
				AND dicttypeCode = #{dicttypeCode}
			</if>
			<if test="dictName != null and dictName != ''">
				AND dictName like concat('%', #{dictName}, '%')
			</if>
			<if test="dictNameEq != null and dictNameEq != ''">
				AND dictName = #{dictNameEq}
			</if>
			<if test="dictAvlstatus != null and dictAvlstatus != ''">
				AND dictAvlstatus = #{dictAvlstatus}
			</if>
		</where>
		order by dictSeq asc
	</select>

	<select id="selectDictDataByType" parameterType="SysDictData" resultMap="SysDictDataResult">
		<include refid="selectDictDataVo"/>
		where dictAvlstatus = '0' and dicttypeCode = #{dictType} order by dictSeq asc
	</select>

	<select id="selectDictDataLikeDicttypeCode" parameterType="SysDictData" resultMap="SysDictDataResult">
		<include refid="selectDictDataVo"/>
		where dictAvlstatus = '0' and dicttypeCode = #{dictType} and dictValue like CONCAT(#{dictValue},'%')  order by dictSeq asc
	</select>
	
	<select id="selectDictLabel" resultType="String">
		select dict_label from SysDict
		where dicttypeCode = #{dictType} and dictValue = #{dictValue}
	</select>
	
	<select id="selectDictDataById" parameterType="String" resultMap="SysDictDataResult">
		<include refid="selectDictDataVo"/>
		where dictId = #{dictId}
	</select>
	
	<select id="countDictDataByType" resultType="Integer">
	    select count(1) from SysDict where dicttypeCode=#{dictType}
	</select>
	
	<delete id="deleteDictDataById" parameterType="String">
 		delete from SysDict where dictId = #{dictCode}
 	</delete>
 	
 	<delete id="deleteDictDataByIds" parameterType="String">
 		delete from SysDict where dictId in
 		<foreach collection="array" item="dictCode" open="(" separator="," close=")">
 			#{dictCode}
        </foreach> 
 	</delete>

	<update id="updateDictData" parameterType="SysDictData">
 		update SysDict
 		<set>
 			<if test="dictSeq != null">dictSeq = #{dictSeq},</if>
 			<if test="dictName != null and dictName != ''">dictName = #{dictName},</if>
 			<if test="dictValue != null and dictValue != ''">dictValue = #{dictValue},</if>
 			<if test="dicttypeCode != null and dicttypeCode != ''">dicttypeCode = #{dicttypeCode},</if>
 			<if test="dictAvlstatus != null">dictAvlstatus = #{dictAvlstatus},</if>
 			<if test="dictRemark != null">dictRemark = #{dictRemark},</if>
 			<if test="dictModifier != null and dictModifier != ''">dictModifier = #{dictModifier},</if>
			dictModifieddate = date_format(sysdate(),'%Y-%m-%d %H:%i:%s')
 		</set>
 		where dictId = #{dictId}
	</update>
	
	<update id="updateDictDataType" parameterType="String">
 		update SysDict set dicttypeCode = #{newDictType} where dicttypeCode = #{oldDictType}
	</update>
 	
 	<insert id="insertDictData" parameterType="SysDictData">
 		insert into SysDict(
			<if test="dictId != null and dictId != ''">dictId,</if>
 			<if test="dictSeq != null">dictSeq,</if>
 			<if test="dictName != null and dictName != ''">dictName,</if>
 			<if test="dictValue != null and dictValue != ''">dictValue,</if>
 			<if test="dicttypeCode != null and dicttypeCode != ''">dicttypeCode,</if>
 			<if test="dictAvlstatus != null">dictAvlstatus,</if>
 			<if test="dictRemark != null and dictRemark != ''">dictRemark,</if>
 			<if test="dictCreator != null and dictCreator != ''">dictCreator,</if>
			dictCreateddate
 		)values(
			<if test="dictId != null and dictId != ''">#{dictId},</if>
 		    <if test="dictSeq != null">#{dictSeq},</if>
 		    <if test="dictName != null and dictName != ''">#{dictName},</if>
 			<if test="dictValue != null and dictValue != ''">#{dictValue},</if>
 			<if test="dicttypeCode != null and dicttypeCode != ''">#{dicttypeCode},</if>
 			<if test="dictAvlstatus != null">#{dictAvlstatus},</if>
 			<if test="dictRemark != null and dictRemark != ''">#{dictRemark},</if>
 			<if test="dictCreator != null and dictCreator != ''">#{dictCreator},</if>
		date_format(sysdate(),'%Y-%m-%d %H:%i:%s')
 		)
	</insert>

	<select id="maxValueByDictType" resultType="Integer">
		select max(dictValue + 0) from SysDict where dicttypeCode=#{dicType}
	</select>
</mapper> 