Files
senmesh-zc/src/main/java/com/senmesh/sfile/mapper/UserFileMapper.xml
ran.shang e99b717e48 file
2025-12-31 18:10:10 +08:00

100 lines
3.5 KiB
XML

<?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.senmesh.sfile.dao.UserFileMapper">
<select id="list" resultType="com.senmesh.sfile.dto.UserFileDTO">
SELECT t.*
<include refid="queryFromSql"></include>
ORDER BY t.id DESC
</select>
<sql id="queryFromSql">
FROM x_user_file t
WHERE t.deleted = 0
<if test='param.id != null'>
AND t.id = #{param.id}
</if>
<if test='param.userId != null'>
AND t.user_id = #{param.userId}
</if>
<if test='param.rootType != null and param.rootType.trim() != ""'>
AND t.root_type = #{param.rootType}
</if>
<if test='param.fileType != null and param.fileType.trim() != ""'>
AND t.file_type = #{param.fileType}
</if>
<if test='param.fileName != null and param.fileName.trim() != ""'>
AND t.file_name = #{param.fileName}
</if>
<if test='param.fileNameLike != null and param.fileNameLike.trim() != ""'>
<bind name="fileNameLike" value="'%' + param.fileNameLike + '%'"/>
AND t.file_name LIKE #{fileNameLike}
</if>
<if test='param.parentId != null'>
AND t.parent_id = #{param.parentId}
</if>
<if test='param.fileCode != null and param.fileCode.trim() != ""'>
AND t.file_code = #{param.fileCode}
</if>
<if test='param.fileStatus != null and param.fileStatus.trim() != ""'>
AND t.file_status = #{param.fileStatus}
</if>
<if test='param.pathLike != null and param.pathLike.trim() != ""'>
<bind name="pathLike" value="param.pathLike + '%'"/>
AND t.path LIKE #{pathLike}
</if>
</sql>
<update id="updatePathByParentIdChange">
UPDATE x_user_file child
INNER JOIN x_user_file current ON current.id = #{fileId} AND current.deleted = 0
LEFT JOIN x_user_file parent ON parent.id = #{newParentId} AND parent.deleted = 0
SET child.path = CASE
WHEN child.id = #{fileId} THEN
CASE
WHEN #{newParentId} = 0 THEN CAST(#{fileId} AS CHAR)
ELSE CONCAT(parent.path, ',', #{fileId})
END
ELSE
REPLACE(child.path,
CONCAT(current.path, ','),
CASE
WHEN #{newParentId} = 0 THEN CONCAT(#{fileId}, ',')
ELSE CONCAT(parent.path, ',', #{fileId}, ',')
END)
END
WHERE (child.id = #{fileId} OR child.path LIKE CONCAT(current.path, ',%'))
AND child.deleted = 0
AND child.user_id = current.user_id
AND child.root_type = current.root_type
</update>
<update id="deleteFileWithChildren">
UPDATE x_user_file child
INNER JOIN x_user_file current ON current.id = #{fileId} AND current.deleted = 0
SET child.deleted = 1,
child.update_by = #{operateUserId},
child.update_time = NOW()
WHERE (child.id = #{fileId} OR child.path LIKE CONCAT(current.path, ',%'))
AND child.deleted = 0
AND child.user_id = current.user_id
AND child.root_type = current.root_type
</update>
<update id="updateStatusWithChildren">
UPDATE x_user_file child
INNER JOIN x_user_file current ON current.id = #{fileId}
AND current.deleted = 0
AND current.file_status = #{oldStatus}
SET child.file_status = #{newStatus},
child.update_by = #{operateUserId},
child.update_time = NOW()
WHERE (child.id = #{fileId} OR child.path LIKE CONCAT(current.path, ',%'))
AND child.deleted = 0
AND child.user_id = current.user_id
AND child.root_type = current.root_type
</update>
</mapper>