mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-11-04 10:57:10 +08:00 
			
		
		
		
	feat: 文件管理增加资源统计,统计总存储量、各类型文件存储占用
This commit is contained in:
		@@ -16,9 +16,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package top.continew.admin.system.mapper;
 | 
					package top.continew.admin.system.mapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Select;
 | 
				
			||||||
import top.continew.admin.system.model.entity.FileDO;
 | 
					import top.continew.admin.system.model.entity.FileDO;
 | 
				
			||||||
 | 
					import top.continew.admin.system.model.resp.FileStatisticsResp;
 | 
				
			||||||
import top.continew.starter.data.mybatis.plus.base.BaseMapper;
 | 
					import top.continew.starter.data.mybatis.plus.base.BaseMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 文件 Mapper
 | 
					 * 文件 Mapper
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -26,4 +30,13 @@ import top.continew.starter.data.mybatis.plus.base.BaseMapper;
 | 
				
			|||||||
 * @since 2023/12/23 10:38
 | 
					 * @since 2023/12/23 10:38
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public interface FileMapper extends BaseMapper<FileDO> {
 | 
					public interface FileMapper extends BaseMapper<FileDO> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 查询文件资源统计
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return 文件资源统计结果
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Select("SELECT type,COUNT(1) number,SUM(size) size FROM sys_file GROUP BY type")
 | 
				
			||||||
 | 
					    List<FileStatisticsResp> statistics();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					 * you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					 * You may obtain a copy of the License at
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					 * See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					 * limitations under the License.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package top.continew.admin.system.model.resp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import io.swagger.v3.oas.annotations.media.Schema;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import top.continew.admin.system.enums.FileTypeEnum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serial;
 | 
				
			||||||
 | 
					import java.io.Serializable;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 文件资源统计
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Kils
 | 
				
			||||||
 | 
					 * @since 2024/04/30 14:30
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@Schema(description = "文件资源统计")
 | 
				
			||||||
 | 
					public class FileStatisticsResp implements Serializable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Serial
 | 
				
			||||||
 | 
					    private static final long serialVersionUID = 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 文件类型
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Schema(description = "文件类型", example = "")
 | 
				
			||||||
 | 
					    private FileTypeEnum type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 大小(字节)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Schema(description = "大小(字节)", example = "4096")
 | 
				
			||||||
 | 
					    private Long size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 数量
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Schema(description = "数量", example = "1000")
 | 
				
			||||||
 | 
					    private Long number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 分类数据
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Schema(description = "分类数据")
 | 
				
			||||||
 | 
					    private List<FileStatisticsResp> data;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -22,6 +22,7 @@ import top.continew.admin.system.model.entity.FileDO;
 | 
				
			|||||||
import top.continew.admin.system.model.query.FileQuery;
 | 
					import top.continew.admin.system.model.query.FileQuery;
 | 
				
			||||||
import top.continew.admin.system.model.req.FileReq;
 | 
					import top.continew.admin.system.model.req.FileReq;
 | 
				
			||||||
import top.continew.admin.system.model.resp.FileResp;
 | 
					import top.continew.admin.system.model.resp.FileResp;
 | 
				
			||||||
 | 
					import top.continew.admin.system.model.resp.FileStatisticsResp;
 | 
				
			||||||
import top.continew.starter.data.mybatis.plus.service.IService;
 | 
					import top.continew.starter.data.mybatis.plus.service.IService;
 | 
				
			||||||
import top.continew.starter.extension.crud.service.BaseService;
 | 
					import top.continew.starter.extension.crud.service.BaseService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -61,4 +62,11 @@ public interface FileService extends BaseService<FileResp, FileResp, FileQuery,
 | 
				
			|||||||
     * @return 文件数量
 | 
					     * @return 文件数量
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    Long countByStorageIds(List<Long> storageIds);
 | 
					    Long countByStorageIds(List<Long> storageIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 查询文件资源统计
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return 资源统计结果
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    FileStatisticsResp statistics();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -16,8 +16,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package top.continew.admin.system.service.impl;
 | 
					package top.continew.admin.system.service.impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import cn.hutool.core.collection.CollUtil;
 | 
				
			||||||
 | 
					import cn.hutool.core.io.FileUtil;
 | 
				
			||||||
 | 
					import cn.hutool.core.io.unit.DataSizeUtil;
 | 
				
			||||||
 | 
					import cn.hutool.core.io.unit.DataUnit;
 | 
				
			||||||
import cn.hutool.core.util.StrUtil;
 | 
					import cn.hutool.core.util.StrUtil;
 | 
				
			||||||
import cn.hutool.core.util.URLUtil;
 | 
					import cn.hutool.core.util.URLUtil;
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
				
			||||||
import jakarta.annotation.Resource;
 | 
					import jakarta.annotation.Resource;
 | 
				
			||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import lombok.extern.slf4j.Slf4j;
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
@@ -34,6 +39,7 @@ import top.continew.admin.system.model.entity.StorageDO;
 | 
				
			|||||||
import top.continew.admin.system.model.query.FileQuery;
 | 
					import top.continew.admin.system.model.query.FileQuery;
 | 
				
			||||||
import top.continew.admin.system.model.req.FileReq;
 | 
					import top.continew.admin.system.model.req.FileReq;
 | 
				
			||||||
import top.continew.admin.system.model.resp.FileResp;
 | 
					import top.continew.admin.system.model.resp.FileResp;
 | 
				
			||||||
 | 
					import top.continew.admin.system.model.resp.FileStatisticsResp;
 | 
				
			||||||
import top.continew.admin.system.service.FileService;
 | 
					import top.continew.admin.system.service.FileService;
 | 
				
			||||||
import top.continew.admin.system.service.StorageService;
 | 
					import top.continew.admin.system.service.StorageService;
 | 
				
			||||||
import top.continew.starter.core.constant.StringConstants;
 | 
					import top.continew.starter.core.constant.StringConstants;
 | 
				
			||||||
@@ -113,6 +119,19 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
 | 
				
			|||||||
        return baseMapper.lambdaQuery().in(FileDO::getStorageId, storageIds).count();
 | 
					        return baseMapper.lambdaQuery().in(FileDO::getStorageId, storageIds).count();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public FileStatisticsResp statistics() {
 | 
				
			||||||
 | 
					        FileStatisticsResp resp = new FileStatisticsResp();
 | 
				
			||||||
 | 
					        List<FileStatisticsResp> statisticsList = baseMapper.statistics();
 | 
				
			||||||
 | 
					        if (CollUtil.isEmpty(statisticsList)) {
 | 
				
			||||||
 | 
					            return resp;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        resp.setData(statisticsList);
 | 
				
			||||||
 | 
					        resp.setSize(statisticsList.stream().mapToLong(FileStatisticsResp::getSize).sum());
 | 
				
			||||||
 | 
					        resp.setNumber(statisticsList.stream().mapToLong(FileStatisticsResp::getNumber).sum());
 | 
				
			||||||
 | 
					        return resp;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void fill(Object obj) {
 | 
					    protected void fill(Object obj) {
 | 
				
			||||||
        super.fill(obj);
 | 
					        super.fill(obj);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,18 +15,20 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package top.continew.admin.webapi.system;
 | 
					package top.continew.admin.webapi.system;
 | 
				
			||||||
 | 
					import io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
import io.swagger.v3.oas.annotations.tags.Tag;
 | 
					import io.swagger.v3.oas.annotations.tags.Tag;
 | 
				
			||||||
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import org.springframework.web.bind.annotation.*;
 | 
					import org.springframework.web.bind.annotation.*;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import top.continew.admin.system.model.query.FileQuery;
 | 
					import top.continew.admin.system.model.query.FileQuery;
 | 
				
			||||||
import top.continew.admin.system.model.req.FileReq;
 | 
					import top.continew.admin.system.model.req.FileReq;
 | 
				
			||||||
import top.continew.admin.system.model.resp.FileResp;
 | 
					import top.continew.admin.system.model.resp.FileResp;
 | 
				
			||||||
 | 
					import top.continew.admin.system.model.resp.FileStatisticsResp;
 | 
				
			||||||
import top.continew.admin.system.service.FileService;
 | 
					import top.continew.admin.system.service.FileService;
 | 
				
			||||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
 | 
					import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
 | 
				
			||||||
import top.continew.starter.extension.crud.controller.BaseController;
 | 
					import top.continew.starter.extension.crud.controller.BaseController;
 | 
				
			||||||
import top.continew.starter.extension.crud.enums.Api;
 | 
					import top.continew.starter.extension.crud.enums.Api;
 | 
				
			||||||
 | 
					import top.continew.starter.log.core.annotation.Log;
 | 
				
			||||||
 | 
					import top.continew.starter.web.model.R;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 文件管理 API
 | 
					 * 文件管理 API
 | 
				
			||||||
@@ -36,6 +38,16 @@ import top.continew.starter.extension.crud.enums.Api;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
@Tag(name = "文件管理 API")
 | 
					@Tag(name = "文件管理 API")
 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
 | 
					@RequiredArgsConstructor
 | 
				
			||||||
@CrudRequestMapping(value = "/system/file", api = {Api.PAGE, Api.UPDATE, Api.DELETE})
 | 
					@CrudRequestMapping(value = "/system/file", api = {Api.PAGE, Api.UPDATE, Api.DELETE})
 | 
				
			||||||
public class FileController extends BaseController<FileService, FileResp, FileResp, FileQuery, FileReq> {
 | 
					public class FileController extends BaseController<FileService, FileResp, FileResp, FileQuery, FileReq> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final FileService fileService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Log(ignore = true)
 | 
				
			||||||
 | 
					    @Operation(summary = "查询文件资源统计", description = "查询文件资源统计")
 | 
				
			||||||
 | 
					    @GetMapping("/statistics")
 | 
				
			||||||
 | 
					    public R<FileStatisticsResp> statistics() {
 | 
				
			||||||
 | 
					        return R.ok(fileService.statistics());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user