<?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.hzya.frame.sys.file.download.dao.impl.FileDownloadDaoImpl">
	<resultMap id="get-FileDownloadEntity-result" type="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		<!--主键ID -->
		<result property="id" column="id" />
		<!--文件名称 -->
		<result property="filename" column="filename" />
		<!--文件新名称 -->
		<result property="filesavename" column="filesavename" />
		<!--文件类型 -->
		<result property="type" column="type" />
		<!--文件大小（kb） -->
		<result property="file_size" column="file_size" />
		<!--描述 -->
		<result property="description" column="description" />
		<!--文件路径 -->
		<result property="filepath" column="filepath" />
		<!--创建人 -->
		<result property="create_user_id" column="create_user_id" />
		<!--创建时间 -->
		<result property="create_time" column="create_time" />
		<!--修改人 -->
		<result property="modify_user_id" column="modify_user_id" />
		<!--修改时间 -->
		<result property="modify_time" column="modify_time" />
		<!--状态Y正常N删除 -->
		<result property="sts" column="sts" />
		<!--文件类型 -->
		<result property="fileType" column="file_type" />
	</resultMap>

	<sql id="FileDownloadEntity_Base_Column_List">
		id,
		filename,
		filesavename,
		type,
		file_size,
		description,
		filepath,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts,
		file_type
	</sql>

	<!--通过ID获取数据 -->
	<select id="FileDownloadEntity_get" resultMap="get-FileDownloadEntity-result">
		select
		<include refid="FileDownloadEntity_Base_Column_List" />
		from sys_file where id = #{ id } and sts='Y'
	</select>

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-FileDownloadEntity-result" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		select
		<include refid="FileDownloadEntity_Base_Column_List" />
		from sys_file
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !=''  ">id=#{id}</if>
			<if test="filename != null and filename !='' "> and filename = #{filename}</if>
			<if test="filesavename != null and filesavename !='' "> and filesavename = #{filesavename}</if>
			<if test="type != null and type !='' "> and type = #{type}</if>
			<if test="fileType != null and fileType !='' "> and file_type = #{fileType}</if>
			<if test="file_size != null "> and file_size = #{file_size}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="filepath != null and filepath !='' "> and filepath = #{filepath}</if>
			<if test="create_user_id != null "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null "> and modify_time = #{modify_time}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
			and sts='Y'
		</trim>
		<if test=" sort =='' "> order by id desc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
	</select>

	<!-- 查询符合条件的数量 -->
	<select id="FileDownloadEntity_count" resultType="Integer" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		select count(1) from sys_file
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null ">id = #{id}</if>
			<if test="filename != null and filename !='' "> and filename = #{filename} </if>
			<if test="filesavename != null and filesavename !='' "> and filesavename = #{filesavename} </if>
			<if test="type != null and type !='' "> and type = #{type} </if>
			<if test="fileType != null and fileType !='' "> and file_type = #{fileType} </if>
			<if test="file_size != null "> and file_size = #{file_size}  </if>
			<if test="description != null and description !='' "> and description = #{description} </if>
			<if test="filepath != null and filepath !='' "> and filepath = #{filepath} </if>
			<if test="create_user_id != null "> and create_user_id = #{create_user_id}  </if>
			<if test="create_time != null "> and create_time = #{create_time}  </if>
			<if test="modify_user_id != null "> and modify_user_id = #{modify_user_id}  </if>
			<if test="modify_time != null "> and modify_time = #{modify_time}  </if>
			<if test="sts != null and sts !='' "> and sts = #{sts} </if>
			and sts='Y'
		</trim>
		<if test=" sort =='' "> order by id desc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null "> order by ${sort} ${order}</if>
	</select>

	<!-- 分页查询列表 采用like格式 -->
	<select id="FileDownloadEntity_list_like" resultMap="get-FileDownloadEntity-result" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		select
		<include refid="FileDownloadEntity_Base_Column_List" />
		from sys_file
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null ">id = #{id}</if>
			<if test="filename != null and filename !='' "> and filename like concat('%',#{filename},'%') </if>
			<if test="filesavename != null and filesavename !='' "> and filesavename like concat('%',#{filesavename},'%') </if>
			<if test="type != null and type !='' "> and type like concat('%',#{type},'%') </if>
		    <if test="fileType != null and fileType !='' "> and file_type like concat('%',#{fileType},'%') </if>
			<if test="file_size != null "> and file_size = #{file_size}</if>
			<if test="description != null and description !='' "> and description like concat('%',#{description},'%') </if>
			<if test="filepath != null and filepath !='' "> and filepath like concat('%',#{filepath},'%') </if>
			<if test="create_user_id != null "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null and create_time !='' "> and create_time like concat('%',#{create_time},'%') </if>
			<if test="modify_user_id != null "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> and modify_time like concat('%',#{modify_time},'%') </if>
			<if test="sts != null and sts !='' "> and sts like concat('%',#{sts},'%') </if>
			and sts='Y'
		</trim>
		<if test=" sort =='' "> order by id desc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>

	<!-- 查询列表 字段采用or格式 -->
	<select id="FileDownloadEntity_list_or" resultMap="get-FileDownloadEntity-result" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		select
		<include refid="FileDownloadEntity_Base_Column_List" />
		from sys_file
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null ">id = #{id}</if>
			<if test="filename != null and filename !='' "> or filename = #{filename} </if>
			<if test="filesavename != null and filesavename !='' "> or filesavename = #{filesavename} </if>
			<if test="type != null and type !='' "> or type = #{type} </if>
		    <if test="fileType != null and fileType !='' "> or file_type = #{fileType} </if>
			<if test="file_size != null "> or file_size = #{file_size}</if>
			<if test="description != null and description !='' "> or description = #{description} </if>
			<if test="filepath != null and filepath !='' "> or filepath = #{filepath} </if>
			<if test="create_user_id != null "> or create_user_id = #{create_user_id}</if>
			<if test="create_time != null and create_time !='' "> or create_time = #{create_time} </if>
			<if test="modify_user_id != null "> or modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> or modify_time = #{modify_time} </if>
			<if test="sts != null and sts !='' "> or sts = #{sts} </if>
			and sts='Y'
		</trim>
		<if test=" sort =='' "> order by id desc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>
	<!-- 新增 -->
	<insert id="FileDownloadEntity_insert" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		insert into sys_file(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="filename != null and filename !='' "> filename, </if>
			<if test="filesavename != null and filesavename !='' "> filesavename, </if>
			<if test="type != null and type !='' "> type, </if>
		    <if test="fileType != null and fileType !='' "> file_type, </if>
			<if test="file_size != null ">file_size,</if>
			<if test="description != null and description !='' "> description, </if>
			<if test="filepath != null and filepath !='' "> filepath, </if>
			<if test="create_user_id != null ">create_user_id,</if>
			<if test="modify_user_id != null ">modify_user_id,</if>
			create_time,
			modify_time,
			sts
		</trim>
		)values
		(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="filename != null and filename !='' "> #{filename}, </if>
			<if test="filesavename != null and filesavename !='' "> #{filesavename}, </if>
			<if test="type != null and type !='' "> #{type}, </if>
		    <if test="fileType != null and fileType !='' "> #{fileType}, </if>
			<if test="file_size != null ">#{file_size},</if>
			<if test="description != null and description !='' "> #{description}, </if>
			<if test="filepath != null and filepath !='' "> #{filepath}, </if>
			<if test="create_user_id != null ">#{create_user_id},</if>
			<if test="modify_user_id != null ">#{modify_user_id},</if>
			<if test="create_time != null "> #{create_time} ,</if>
			<if test="create_time  == null "> now(),</if>
			<if test="modify_time != null "> #{modify_time},</if>
			<if test="modify_time  == null "> now(),</if>
			'Y'
		</trim>
		)
		<selectKey  resultType="Long" order="AFTER">
			select
			last_insert_id() as id
		</selectKey>
	</insert>

	<!-- 修改 -->
	<update id="FileDownloadEntity_update" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		update sys_file set
		<trim suffix="" suffixOverrides=",">
			<if test="filename != null and filename !='' "> filename = #{filename},</if>
			<if test="filesavename != null and filesavename !='' "> filesavename = #{filesavename},</if>
			<if test="type != null and type !='' "> type = #{type},</if>
			<if test="fileType != null and fileType !='' "> file_type = #{fileType},</if>
			<if test="file_size != null ">file_size = #{file_size},</if>
			<if test="description != null and description !='' "> description = #{description},</if>
			<if test="filepath != null and filepath !='' "> filepath = #{filepath},</if>
			<if test="create_user_id != null ">create_user_id = #{create_user_id},</if>
			<if test="modify_user_id != null ">modify_user_id = #{modify_user_id},</if>
			<if test="modify_time != null "> modify_time =#{modify_time}  </if>
			<if test="modify_time  == null "> modify_time = now()</if>
		</trim>
		where id = #{id}
	</update>

	<!-- 逻辑删除 -->
	<update id="FileDownloadEntity_logicDelete" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		update sys_file set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id} where
		id = #{id}
	</update>

	<!-- 逻辑删除多条件 -->
	<update id="FileDownloadEntity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		update sys_file set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id}
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null ">id=#{id}</if>
			<if test="filename != null and filename !='' "> and filename = #{filename}</if>
			<if test="filesavename != null and filesavename !='' "> and filesavename = #{filesavename}</if>
			<if test="type != null and type !='' "> and type = #{type}</if>
		    <if test="fileType != null and fileType !='' "> and file_type = #{fileType}</if>
			<if test="file_size != null "> and file_size = #{file_size}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="filepath != null and filepath !='' "> and filepath = #{filepath}</if>
			<if test="create_user_id != null "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null and create_time !='' "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> and modify_time = #{modify_time}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
		</trim>
	</update>

	<!-- 物理删除 -->
	<delete id="FileDownloadEntity_delete" parameterType="com.hzya.frame.sys.file.download.entity.FileDownloadEntity">
		delete from sys_file where id =#{id}
	</delete>
</mapper>
