2025-11-05 14:42:56 +08:00
|
|
|
|
<?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.sdm.data.dao.FileStorageMapper">
|
2025-12-24 17:20:40 +08:00
|
|
|
|
<select id="getdefaultNodeNameByNodeSize" resultType="java.lang.String">
|
|
|
|
|
|
select
|
|
|
|
|
|
originalName
|
|
|
|
|
|
from
|
|
|
|
|
|
(
|
|
|
|
|
|
select
|
|
|
|
|
|
file_metadata_info.originalName,
|
|
|
|
|
|
SUM(dirSize.totalSize) AS totalSize
|
|
|
|
|
|
from
|
|
|
|
|
|
(
|
|
|
|
|
|
select
|
|
|
|
|
|
fs.dirId ,
|
|
|
|
|
|
SUM(fs.fileSize) AS totalSize
|
|
|
|
|
|
from
|
|
|
|
|
|
file_storage fs
|
|
|
|
|
|
where
|
|
|
|
|
|
fs.dirId
|
2026-01-21 09:31:48 +08:00
|
|
|
|
in(select id from file_metadata_info fmi where fmi.relatedResourceUuidOwnType = #{queryNodeType} and fmi.tenantId = #{tenantId} )
|
2025-12-24 17:20:40 +08:00
|
|
|
|
group by
|
|
|
|
|
|
fs.dirId) dirSize
|
|
|
|
|
|
left join file_metadata_info ON
|
|
|
|
|
|
dirSize.dirId = file_metadata_info.id
|
2026-01-21 09:23:50 +08:00
|
|
|
|
where file_metadata_info.tenantId = #{tenantId}
|
2025-12-24 17:20:40 +08:00
|
|
|
|
group by
|
|
|
|
|
|
file_metadata_info.originalName
|
|
|
|
|
|
order by
|
|
|
|
|
|
totalSize DESC
|
|
|
|
|
|
) tmp
|
|
|
|
|
|
LIMIT #{limitNum}
|
|
|
|
|
|
</select>
|
2025-11-05 14:42:56 +08:00
|
|
|
|
|
|
|
|
|
|
<select id="selectNodeSizeByNodeType" resultType="com.sdm.data.model.dto.NodeSizeDTO">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
dirId,
|
|
|
|
|
|
SUM(fileSize) AS totalSize
|
|
|
|
|
|
FROM file_storage
|
2025-12-04 20:47:47 +08:00
|
|
|
|
WHERE
|
|
|
|
|
|
file_storage.tenantId = #{tenantId}
|
|
|
|
|
|
and
|
|
|
|
|
|
dirId IN
|
2025-11-05 14:42:56 +08:00
|
|
|
|
<foreach collection="directoryIds" item="id" open="(" separator="," close=")">
|
|
|
|
|
|
#{id}
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
|
|
|
|
|
|
<if test="intervalMonths != null and intervalMonths > 0">
|
|
|
|
|
|
AND createTime >= DATE_SUB(NOW(), INTERVAL #{intervalMonths} MONTH)
|
|
|
|
|
|
</if>
|
|
|
|
|
|
GROUP BY dirId;
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="statDirStorageByTargetYm" resultType="com.sdm.data.model.dto.NodeSizeDTO">
|
|
|
|
|
|
<!-- 1. 统计:目标年月之前的历史累计存储(不包含目标年月) -->
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
dirId,
|
2025-12-30 17:19:08 +08:00
|
|
|
|
'BEFORE' AS statDimension, -- 示例:BEFORE_202410
|
2025-11-05 14:42:56 +08:00
|
|
|
|
SUM(fileSize) AS totalSize -- 总占用字节数(原始单位)
|
|
|
|
|
|
FROM file_storage
|
|
|
|
|
|
WHERE
|
2025-12-04 20:47:47 +08:00
|
|
|
|
file_storage.tenantId = #{tenantId}
|
|
|
|
|
|
and
|
2025-11-05 14:42:56 +08:00
|
|
|
|
dirId IN
|
|
|
|
|
|
<foreach collection="dirIds" item="dirId" open="(" separator="," close=")">
|
|
|
|
|
|
#{dirId}
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
AND createYearMonth < #{targetYm}
|
|
|
|
|
|
GROUP BY dirId
|
|
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 2. 统计:目标年月的当月增量存储(仅包含目标年月) -->
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
dirId,
|
2025-12-30 17:19:08 +08:00
|
|
|
|
'INCREMENT' AS statDimension, -- 示例:INCREMENT_202410
|
2025-11-05 14:42:56 +08:00
|
|
|
|
SUM(fileSize) AS totalSize
|
|
|
|
|
|
FROM file_storage
|
|
|
|
|
|
WHERE
|
2025-12-04 20:47:47 +08:00
|
|
|
|
file_storage.tenantId = #{tenantId}
|
|
|
|
|
|
and
|
2025-11-05 14:42:56 +08:00
|
|
|
|
dirId IN
|
|
|
|
|
|
<foreach collection="dirIds" item="dirId" open="(" separator="," close=")">
|
|
|
|
|
|
#{dirId}
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
AND createYearMonth = #{targetYm}
|
|
|
|
|
|
GROUP BY dirId
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="getTotalFileSizeByCreator" resultType="com.sdm.data.model.dto.UserTotalFileSizeDTO">
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
userId,
|
|
|
|
|
|
SUM(fileSize) AS totalSize
|
|
|
|
|
|
FROM file_storage
|
2025-12-24 17:20:40 +08:00
|
|
|
|
WHERE tenantId = #{tenantId}
|
|
|
|
|
|
<if test="userIds != null and userIds.size() > 0">
|
|
|
|
|
|
AND userId IN
|
|
|
|
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
|
|
|
|
|
#{userId}
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
</if>
|
2025-11-05 14:42:56 +08:00
|
|
|
|
<if test="intervalMonths != null and intervalMonths > 0">
|
|
|
|
|
|
AND createTime >= DATE_SUB(NOW(), INTERVAL #{intervalMonths} MONTH)
|
|
|
|
|
|
</if>
|
2025-12-24 17:20:40 +08:00
|
|
|
|
GROUP BY userId
|
|
|
|
|
|
ORDER BY totalSize DESC
|
|
|
|
|
|
<!-- 只有没传 IDs 时才限制前 10 -->
|
|
|
|
|
|
<if test="userIds == null or userIds.size() == 0">
|
|
|
|
|
|
LIMIT 10
|
|
|
|
|
|
</if>
|
2025-11-05 14:42:56 +08:00
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<select id="getTotalFileSizeByCreatorAndTargetYm" resultType="com.sdm.data.model.dto.UserTotalFileSizeDTO">
|
2025-12-24 17:20:40 +08:00
|
|
|
|
WITH TargetUsers AS (
|
|
|
|
|
|
<choose>
|
|
|
|
|
|
<when test="userIds != null and userIds.size() > 0">
|
|
|
|
|
|
<!-- 直接使用传入的 ID -->
|
|
|
|
|
|
<foreach collection="userIds" item="uid" open="SELECT " separator=" UNION ALL SELECT " close="">
|
|
|
|
|
|
#{uid} as userId
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
</when>
|
|
|
|
|
|
<otherwise>
|
|
|
|
|
|
<!-- 先查出累计最大的前10人 ID -->
|
|
|
|
|
|
SELECT userId
|
|
|
|
|
|
FROM file_storage
|
|
|
|
|
|
WHERE tenantId = #{tenantId}
|
|
|
|
|
|
AND createYearMonth <= #{targetYm}
|
|
|
|
|
|
GROUP BY userId
|
|
|
|
|
|
ORDER BY SUM(fileSize) DESC
|
|
|
|
|
|
LIMIT 10
|
|
|
|
|
|
</otherwise>
|
|
|
|
|
|
</choose>
|
|
|
|
|
|
)
|
|
|
|
|
|
<!-- 使用交叉连接/条件聚合,一次扫描完成统计 -->
|
2025-11-05 14:42:56 +08:00
|
|
|
|
SELECT
|
2025-12-24 17:20:40 +08:00
|
|
|
|
t.userId,
|
|
|
|
|
|
s.statDimension,
|
2025-12-30 17:19:08 +08:00
|
|
|
|
s.totalSize
|
2025-12-24 17:20:40 +08:00
|
|
|
|
FROM TargetUsers t
|
|
|
|
|
|
INNER JOIN (
|
2025-12-30 17:19:08 +08:00
|
|
|
|
-- 1. 历史累计 (内部先 SUM)
|
|
|
|
|
|
SELECT userId, 'BEFORE' as statDimension, SUM(fileSize) as totalSize
|
2025-11-05 14:42:56 +08:00
|
|
|
|
FROM file_storage
|
2025-12-24 17:20:40 +08:00
|
|
|
|
WHERE tenantId = #{tenantId} AND createYearMonth < #{targetYm}
|
2025-12-30 17:19:08 +08:00
|
|
|
|
GROUP BY userId
|
2025-11-05 14:42:56 +08:00
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
2025-12-30 17:19:08 +08:00
|
|
|
|
-- 2. 当月增量 (内部先 SUM)
|
|
|
|
|
|
SELECT userId, 'INCREMENT' as statDimension, SUM(fileSize) as totalSize
|
2025-11-05 14:42:56 +08:00
|
|
|
|
FROM file_storage
|
2025-12-24 17:20:40 +08:00
|
|
|
|
WHERE tenantId = #{tenantId} AND createYearMonth = #{targetYm}
|
2025-12-30 17:19:08 +08:00
|
|
|
|
GROUP BY userId
|
2025-12-24 17:20:40 +08:00
|
|
|
|
) s ON t.userId = s.userId
|
2025-11-05 14:42:56 +08:00
|
|
|
|
</select>
|
2025-11-26 10:06:25 +08:00
|
|
|
|
|
2025-11-26 09:55:01 +08:00
|
|
|
|
<select id="selectBigFiles" resultType="com.sdm.data.model.entity.FileStorage">
|
2025-11-26 10:06:25 +08:00
|
|
|
|
SELECT
|
|
|
|
|
|
distinct
|
2025-12-24 17:20:40 +08:00
|
|
|
|
file_storage.fileName,file_storage.fileId,file_storage.userGroupId,file_storage.userId,file_storage.fileBizType,file_storage.fileSuffix,file_storage.updateTime
|
2025-12-30 17:19:08 +08:00
|
|
|
|
FROM file_metadata_info
|
|
|
|
|
|
inner join file_storage on file_storage.fileId = file_metadata_info.id
|
2025-11-26 09:55:01 +08:00
|
|
|
|
<where>
|
|
|
|
|
|
file_metadata_info.id is not null
|
2025-12-03 15:30:32 +08:00
|
|
|
|
and file_metadata_info.isLatest = #{queryBigFileReq.isLatest}
|
2025-12-04 20:47:47 +08:00
|
|
|
|
and file_metadata_info.tenantId = #{tenantId}
|
|
|
|
|
|
and file_storage.tenantId = #{tenantId}
|
2025-12-03 15:30:32 +08:00
|
|
|
|
<if test="queryBigFileReq.approveTypeList != null and queryBigFileReq.approveTypeList.size()>0">
|
|
|
|
|
|
AND file_metadata_info.approveType IN
|
|
|
|
|
|
<foreach collection="queryBigFileReq.approveTypeList" item="approveType" open="(" separator="," close=")">
|
|
|
|
|
|
#{approveType}
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
</if>
|
2026-01-05 16:23:33 +08:00
|
|
|
|
|
|
|
|
|
|
<if test="queryBigFileReq.dirIds != null and queryBigFileReq.dirIds.size()>0">
|
|
|
|
|
|
AND file_storage.dirId IN
|
|
|
|
|
|
<foreach collection="queryBigFileReq.dirIds" item="dirId" open="(" separator="," close=")">
|
|
|
|
|
|
#{dirId}
|
|
|
|
|
|
</foreach>
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
2026-01-05 16:23:33 +08:00
|
|
|
|
|
2025-11-26 09:55:01 +08:00
|
|
|
|
<if test="queryBigFileReq.fileSuffix != null and queryBigFileReq.fileSuffix != ''">
|
2025-12-03 15:30:32 +08:00
|
|
|
|
AND file_storage.fileSuffix = #{queryBigFileReq.fileSuffix}
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
2025-12-03 15:30:32 +08:00
|
|
|
|
<if test="queryBigFileReq.fileBizType != null and queryBigFileReq.fileBizType.size()>0">
|
|
|
|
|
|
AND file_storage.fileBizType IN
|
|
|
|
|
|
<foreach collection="queryBigFileReq.fileBizType" item="type" open="(" separator="," close=")">
|
|
|
|
|
|
#{type}
|
|
|
|
|
|
</foreach>
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
|
|
|
|
|
<if test="queryBigFileReq.fileName != null and queryBigFileReq.fileName != ''">
|
2025-12-03 15:30:32 +08:00
|
|
|
|
AND file_storage.fileName LIKE CONCAT('%', #{queryBigFileReq.fileName}, '%')
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
|
|
|
|
|
<if test="queryBigFileReq.startTime != null">
|
2025-12-03 15:30:32 +08:00
|
|
|
|
AND file_storage.createTime >= #{queryBigFileReq.startTime}
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
|
|
|
|
|
<if test="queryBigFileReq.endTime != null">
|
2025-12-03 15:30:32 +08:00
|
|
|
|
AND file_storage.createTime <= #{queryBigFileReq.endTime}
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
|
|
|
|
|
<if test="fileSizeInBytes != null">
|
2025-12-03 15:30:32 +08:00
|
|
|
|
AND file_storage.fileSize > #{fileSizeInBytes}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="queryBigFileReq.uploadUserId != null and queryBigFileReq.uploadUserId.size()>0">
|
|
|
|
|
|
AND file_storage.userId IN
|
|
|
|
|
|
<foreach collection="queryBigFileReq.uploadUserId" item="userId" open="(" separator="," close=")">
|
|
|
|
|
|
#{userId}
|
|
|
|
|
|
</foreach>
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</if>
|
2025-12-24 17:20:40 +08:00
|
|
|
|
order by file_storage.updateTime desc
|
2025-11-26 09:55:01 +08:00
|
|
|
|
</where>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</mapper>
|