<?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.jeeplus.modules.sys.mapper.DictTypeMapper">
    
	<sql id="dictTypeColumns">
		a.id AS "id",
		a.type AS "type",
		a.description AS "description",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.del_flag AS "delFlag"
	</sql>
	
	<sql id="dictTypeJoins">
	</sql>
	
    
	<select id="get" resultType="DictType" >
		SELECT 
			<include refid="dictTypeColumns"/>
		FROM sys_dict_type a
		<include refid="dictTypeJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="DictType" >
		SELECT 
			<include refid="dictTypeColumns"/>
		FROM sys_dict_type a
		<include refid="dictTypeJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="type != null and type != ''">
				AND a.type LIKE 
					<if test="_databaseId == 'postgre'">'%'||#{type}||'%'</if>
					<if test="_databaseId == 'oracle'">'%'||#{type}||'%'</if>
					<if test="_databaseId == 'mssql'">'%'+#{type}+'%'</if>
					<if test="_databaseId == 'mysql'">concat('%',#{type},'%')</if>
			</if>
			<if test="description != null and description != ''">
				AND a.description LIKE 
					<if test="_databaseId == 'postgre'">'%'||#{description}||'%'</if>
					<if test="_databaseId == 'oracle'">'%'||#{description}||'%'</if>
					<if test="_databaseId == 'mssql'">'%'+#{description}+'%'</if>
					<if test="_databaseId == 'mysql'">concat('%',#{description},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="DictType" >
		SELECT 
			<include refid="dictTypeColumns"/>
		FROM sys_dict_type a
		<include refid="dictTypeJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO sys_dict_type(
			id,
			type,
			description,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag
		) VALUES (
			#{id},
			#{type},
			#{description},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_dict_type SET 	
			type = #{type},
			description = #{description},
			update_by = #{updateBy.id},
			update_date = #{updateDate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_dict_type
		WHERE id = #{id}
	</update>

	<!--物理批量删除-->
	<delete id="batchDelete">
		delete from sys_dict_type
		where id IN
		<foreach collection="ids" item="id" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_dict_type SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="DictType" statementType="STATEMENT">
		select * FROM sys_dict_type  where ${propertyName} = '${value}'
	</select>
	
</mapper>