From 15c966f7bb255db3edea249f8d3354324cbdbf5b Mon Sep 17 00:00:00 2001 From: kils Date: Tue, 30 Apr 2024 17:45:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90=E7=BB=9F=E8=AE=A1=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=80=BB=E5=AD=98=E5=82=A8=E9=87=8F=E3=80=81?= =?UTF-8?q?=E5=90=84=E7=B1=BB=E5=9E=8B=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/mapper/FileMapper.java | 13 ++++ .../system/model/resp/FileStatisticsResp.java | 63 +++++++++++++++++++ .../admin/system/service/FileService.java | 8 +++ .../system/service/impl/FileServiceImpl.java | 19 ++++++ .../admin/webapi/system/FileController.java | 18 +++++- 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 continew-admin-system/src/main/java/top/continew/admin/system/model/resp/FileStatisticsResp.java diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/FileMapper.java b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/FileMapper.java index 19719abd..ba1ad498 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/FileMapper.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/FileMapper.java @@ -16,9 +16,13 @@ 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.resp.FileStatisticsResp; import top.continew.starter.data.mybatis.plus.base.BaseMapper; +import java.util.List; + /** * 文件 Mapper * @@ -26,4 +30,13 @@ import top.continew.starter.data.mybatis.plus.base.BaseMapper; * @since 2023/12/23 10:38 */ public interface FileMapper extends BaseMapper { + + + /** + * 查询文件资源统计 + * + * @return 文件资源统计结果 + */ + @Select("SELECT type,COUNT(1) number,SUM(size) size FROM sys_file GROUP BY type") + List statistics(); } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/FileStatisticsResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/FileStatisticsResp.java new file mode 100644 index 00000000..76e1f853 --- /dev/null +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/FileStatisticsResp.java @@ -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 data; +} \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/FileService.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/FileService.java index 236da0ad..a979e14d 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/FileService.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/FileService.java @@ -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.req.FileReq; 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.extension.crud.service.BaseService; @@ -61,4 +62,11 @@ public interface FileService extends BaseService storageIds); + + /** + * 查询文件资源统计 + * + * @return 资源统计结果 + */ + FileStatisticsResp statistics(); } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/FileServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/FileServiceImpl.java index 2fc45dae..af7fb3bd 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/FileServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/FileServiceImpl.java @@ -16,8 +16,13 @@ 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.URLUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; 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.req.FileReq; 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.StorageService; import top.continew.starter.core.constant.StringConstants; @@ -113,6 +119,19 @@ public class FileServiceImpl extends BaseServiceImpl 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 protected void fill(Object obj) { super.fill(obj); diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/FileController.java b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/FileController.java index 09fe0ce3..0fbd0bbc 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/FileController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/webapi/system/FileController.java @@ -15,18 +15,20 @@ */ package top.continew.admin.webapi.system; - +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; - +import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; - import top.continew.admin.system.model.query.FileQuery; import top.continew.admin.system.model.req.FileReq; 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.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; +import top.continew.starter.log.core.annotation.Log; +import top.continew.starter.web.model.R; /** * 文件管理 API @@ -36,6 +38,16 @@ import top.continew.starter.extension.crud.enums.Api; */ @Tag(name = "文件管理 API") @RestController +@RequiredArgsConstructor @CrudRequestMapping(value = "/system/file", api = {Api.PAGE, Api.UPDATE, Api.DELETE}) public class FileController extends BaseController { + + private final FileService fileService; + + @Log(ignore = true) + @Operation(summary = "查询文件资源统计", description = "查询文件资源统计") + @GetMapping("/statistics") + public R statistics() { + return R.ok(fileService.statistics()); + } } \ No newline at end of file