<?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="org.springblade.system.mapper.FilesClassifyMarkMapper">
	<insert id="add">
		INSERT INTO da_ky_files_classify_mark
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="classifyMarkName != null and classifyMarkName != ''">classify_mark_name,</if>
			<if test="remark != null and remark != ''">remark,</if>
			<if test="createUserId != null">create_user_id,</if>
			<if test="createUserName != null and createUserName != ''">create_user_name,</if>
			<if test="updateUserId != null">update_user_id,</if>
			<if test="updateUserName != null and updateUserName != ''">update_user_name,</if>
		</trim>
		VALUES
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="classifyMarkName != null and classifyMarkName != ''">#{classifyMarkName},</if>
			<if test="remark != null and remark != ''">#{remark},</if>
			<if test="createUserId != null">#{createUserId},</if>
			<if test="createUserName != null and createUserName != ''">#{createUserName},</if>
			<if test="updateUserId != null">#{updateUserId},</if>
			<if test="updateUserName != null and updateUserName != ''">#{updateUserName},</if>
		</trim>
	</insert>
	<update id="edit">
		UPDATE da_ky_files_classify_mark
		<set>
			<if test="classifyMarkName != null and classifyMarkName != ''">classify_mark_name = #{classifyMarkName},</if>
			<if test="remark != null and remark != ''">remark = #{remark},</if>
			<if test="updateUserId != null">update_user_id = #{updateUserId},</if>
			<if test="updateUserName != null and updateUserName != ''">update_user_name = #{updateUserName},</if>
		</set>
		WHERE
			id = #{id}
	</update>
	<delete id="del">
		DELETE FROM da_ky_files_classify_mark
		WHERE
	    id = #{id}
	</delete>

	<select id="list" resultType="org.springblade.system.domain.FilesClassifyMarkDto">
		SELECT
			id,
			classify_mark_name AS classifyMarkName,
			remark,
			create_time AS createTime,
			update_time AS updateTime,
			create_user_id AS createUserId,
			create_user_name AS createUserName,
			update_user_id AS updateUserId,
			update_user_name AS updateUserName,
			del_flag AS delFlag
		FROM
			da_ky_files_classify_mark
		WHERE
			del_flag = '1'
		<if test="classifyMarkName != null and classifyMarkName != ''">
			AND INSTR(classify_mark_name, #{classifyMarkName}) > 0
		</if>
		ORDER BY
			create_time DESC
	</select>
    <select id="getUseByFilesContents" resultType="java.lang.Integer">
		SELECT
			COUNT(1)
		FROM
			da_ky_files_contents
		WHERE
			del_flag = '1'
		AND
			classify_mark = #{id}
	</select>
	<select id="getUseByProFilesContents" resultType="java.lang.Integer">
		SELECT
			COUNT(1)
		FROM
			da_ky_pro_files_contents
		WHERE
			del_flag = '1'
		AND
			classify_mark = #{id}
	</select>
	<select id="isExit" resultType="java.lang.Integer">
		SELECT COUNT(*)
		FROM da_ky_files_classify_mark
		WHERE classify_mark_name = #{classifyMarkName}
		AND id != #{id}
		AND del_flag = 1
	</select>
	<select id="listByName" resultType="org.springblade.system.domain.FilesClassifyMarkDto">
		SELECT
		id,
		classify_mark_name AS classifyMarkName,
		remark,
		create_time AS createTime,
		update_time AS updateTime,
		create_user_id AS createUserId,
		create_user_name AS createUserName,
		update_user_id AS updateUserId,
		update_user_name AS updateUserName,
		del_flag AS delFlag
		FROM
		da_ky_files_classify_mark
		WHERE
		del_flag = '1'
			AND classify_mark_name = #{classifyMarkName}
		ORDER BY
		create_time DESC
	</select>
</mapper>
