<?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="iot.lidee.system.mapper.SysDictTypeMapper">

	<resultMap type="iot.lidee.common.core.domain.entity.SysDictType" id="SysDictTypeResult">
		<id     property="dictId"     column="dict_id"     />
		<result property="dictName"   column="dict_name"   />
		<result property="dictType"   column="dict_type"   />
		<result property="status"     column="status"      />
		<result property="createBy"   column="create_by"   />
		<result property="createTime" column="create_time" />
		<result property="updateBy"   column="update_by"   />
		<result property="updateTime" column="update_time" />
	</resultMap>

	<sql id="selectDictTypeVo">
		select dict_id, dict_name, dict_type, status, create_by, create_time, remark
		from sys_dict_type
	</sql>

	<select id="selectDictTypeList" parameterType="iot.lidee.common.core.domain.entity.SysDictType" resultMap="SysDictTypeResult">
		select d.dict_id,
		case
		when #{language} = 'zh-CN' then d.dict_name
		when #{language} = 'en-US' then t.en_us
		else d.dict_name
		end as dict_name,
		d.dict_type, d.status, d.create_by, d.create_time, d.remark
		from sys_dict_type d
		left join sys_dict_type_translate t on d.dict_id = t.id
		<where>
			<if test="dictName != null and dictName != ''">
				AND d.dict_name like concat('%', #{dictName}, '%')
			</if>
			<if test="status != null and status != ''">
				AND d.status = #{status}
			</if>
			<if test="dictType != null and dictType != ''">
				AND d.dict_type like concat('%', #{dictType}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
				and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
			</if>
			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
				and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
			</if>
		</where>
	</select>

	<select id="selectDictTypeAll" resultMap="SysDictTypeResult">
		select d.dict_id,
			   case
				   when #{language} = 'zh-CN' then d.dict_name
				   when #{language} = 'en-US' then t.en_us
				   else d.dict_name
				   end as dict_name,
			   d.dict_type, d.status, d.create_by, d.create_time, d.remark
		from sys_dict_type d
				 left join sys_dict_type_translate t on d.dict_id = t.id
	</select>

	<select id="selectDictTypeById" resultMap="SysDictTypeResult">
		select d.dict_id,
			   case
				   when #{language} = 'zh-CN' then d.dict_name
				   when #{language} = 'en-US' then t.en_us
				   else d.dict_name
				   end as dict_name,
			   d.dict_type, d.status, d.create_by, d.create_time, d.remark
		from sys_dict_type d
				 left join sys_dict_type_translate t on d.dict_id = t.id
		where d.dict_id = #{dictId}
	</select>

	<select id="selectDictTypeByType" parameterType="String" resultMap="SysDictTypeResult">
		select d.dict_id,
			   case
				   when #{language} = 'zh-CN' then d.dict_name
				   when #{language} = 'en-US' then t.en_us
				   else d.dict_name
				   end as dict_name,
			   d.dict_type, d.status, d.create_by, d.create_time, d.remark
		from sys_dict_type d
				 left join sys_dict_type_translate t on d.dict_id = t.id
		where d.dict_type = #{dictType}
	</select>

	<select id="checkDictTypeUnique" parameterType="String" resultMap="SysDictTypeResult">
		select d.dict_id,
			   case
				   when #{language} = 'zh-CN' then d.dict_name
				   when #{language} = 'en-US' then t.en_us
				   else d.dict_name
				   end as dict_name,
			   d.dict_type, d.status, d.create_by, d.create_time, d.remark
		from sys_dict_type d
				 left join sys_dict_type_translate t on d.dict_id = t.id
		where d.dict_type = #{dictType} limit 1
	</select>

	<delete id="deleteDictTypeById" parameterType="Long">
		delete from sys_dict_type where dict_id = #{dictId}
	</delete>

	<delete id="deleteDictTypeByIds" parameterType="Long">
		delete from sys_dict_type where dict_id in
		<foreach collection="array" item="dictId" open="(" separator="," close=")">
			#{dictId}
		</foreach>
	</delete>

	<update id="updateDictType" parameterType="iot.lidee.common.core.domain.entity.SysDictType">
		update sys_dict_type
		<set>
			<if test="dictName != null and dictName != ''">dict_name = #{dictName},</if>
			<if test="dictType != null and dictType != ''">dict_type = #{dictType},</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 dict_id = #{dictId}
	</update>

	<insert id="insertDictType" parameterType="iot.lidee.common.core.domain.entity.SysDictType">
		insert into sys_dict_type(
		<if test="dictName != null and dictName != ''">dict_name,</if>
		<if test="dictType != null and dictType != ''">dict_type,</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="dictName != null and dictName != ''">#{dictName},</if>
		<if test="dictType != null and dictType != ''">#{dictType},</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>
