tsurumure 6 hónapja
szülő
commit
543e1fb9af

+ 6 - 4
db/sys_file_category.sql

@@ -8,14 +8,16 @@ DROP TABLE IF EXISTS `sys_file_category`;
 CREATE TABLE `sys_file_category` (
     PRIMARY KEY (`id`),
     `id` BIGINT AUTO_INCREMENT COMMENT 'ID',
+    `user_id` BIGINT NOT NULL COMMENT '用户ID',
     `category_name` VARCHAR(255) NOT NULL COMMENT '分类名称',
     `suffix` VARCHAR(1000) NOT NULL COMMENT '文件后缀',
     `sort` INT DEFAULT '1' COMMENT '排序',
     `status` TINYINT(1) DEFAULT '1' COMMENT '资讯状态 (-1禁用, 1启用)'
 ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='系统文件分类表';
 
-INSERT INTO sys_file_category(category_name, suffix) VALUES
-    ('图片', 'jpg, jpeg, png, gif, bmp, tiff, webp'),
-    ('视频', 'mp4, avi, mov, mkv, wmv, flv, webm'),
-    ('音频', 'mp3, wav, ogg, aac')
+INSERT INTO sys_file_category(user_id, category_name, suffix, sort) VALUES
+    (1, '图片', 'jpg, jpeg, png, gif, bmp, tiff, webp', 3),
+    (1, '视频', 'mp4, avi, mov, mkv, wmv, flv, webm', 2),
+    (1, '音频', 'mp3, wav, ogg, aac', 1),
+    (2, '音频', 'mp3, wav, ogg, aac', 4)
 ;

+ 4 - 0
src/main/java/com/backendsys/modules/sdk/tencentcloud/cos/service/TencentCosService.java

@@ -16,6 +16,10 @@ public interface TencentCosService {
     // [腾讯云COS] 删除对象
     void deleteObject(String object_key);
 
+    // [腾讯云COS] 批量删除对象
+    void deleteObjects(String object_keys);
+
+
     // [腾讯云COS] 查询对象是否存在
     boolean doesObjectExist(String object_key);
 

+ 8 - 0
src/main/java/com/backendsys/modules/sdk/tencentcloud/cos/service/impl/TencentCosServiceImpl.java

@@ -218,6 +218,14 @@ public class TencentCosServiceImpl implements TencentCosService {
         cosClient.shutdown();
     }
 
+    // [腾讯云COS] 批量删除对象
+    // https://cloud.tencent.com/document/product/436/65939#841fe310-bdf8-4789-9bc0-26ea844e316d
+    @Override
+    public void deleteObjects(String object_keys) {
+    }
+
+
+
     // [腾讯云COS] 获得临时图片地址
     @Override
     public URL generateUrl(String object_key, Integer minutes) {

+ 56 - 0
src/main/java/com/backendsys/modules/upload/controller/SysFileCategoryController.java

@@ -0,0 +1,56 @@
+package com.backendsys.modules.upload.controller;
+
+import com.backendsys.modules.common.aspect.SysLog;
+import com.backendsys.modules.common.config.security.utils.SecurityUtil;
+import com.backendsys.modules.common.utils.Result;
+import com.backendsys.modules.upload.entity.SysFile;
+import com.backendsys.modules.upload.entity.SysFileCategory;
+import com.backendsys.modules.upload.service.SysFileCategoryService;
+import com.backendsys.modules.upload.service.SysFileService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+@Validated
+@RestController
+@Tag(name = "文件分类管理")
+public class SysFileCategoryController {
+
+    @Autowired
+    private SysFileCategoryService sysFileCategoryService;
+
+    @Operation(summary = "获取文件分类列表 (全部)")
+    @GetMapping("/api/upload/getUploadFileCategoryAllList")
+    public Result getUploadFileCategoryAllList(@Validated SysFileCategory sysFileCategory) {
+        return Result.success().put("data", sysFileCategoryService.selectUploadFileCategoryList(sysFileCategory));
+    }
+
+    @Operation(summary = "获取文件分类列表 (我的)")
+    @GetMapping("/api/upload/getUploadFileCategoryList")
+    public Result getUploadFileCategoryList(@Validated SysFileCategory sysFileCategory) {
+        sysFileCategory.setUser_id(SecurityUtil.getUserId());
+        return Result.success().put("data", sysFileCategoryService.selectUploadFileCategoryList(sysFileCategory));
+    }
+
+//
+//    @SysLog("上传文件 (普通上传)")
+//    @Operation(summary = "上传文件 (普通上传,单文件上传不超过 100MB)")
+//    @PreAuthorize("@sr.hasPermission(1.1)")
+//    @PostMapping("/api/upload/uploadSmall")
+//    public Result uploadSmall(@RequestParam("file") MultipartFile multipartFile, Long category_id) {
+//        return Result.success().put("data", sysFileService.uploadSmall(multipartFile, category_id));
+//    }
+//
+//    @SysLog("删除上传文件")
+//    @Operation(summary = "删除上传文件")
+//    @PreAuthorize("@sr.hasPermission(1.1)")
+//    @DeleteMapping("/api/upload/removeUploadFile")
+//    public Result removeUploadFile(@Validated(SysFile.Delete.class) @RequestBody SysFile sysFile) {
+//        return Result.success().put("data", sysFileService.removeUploadFile(sysFile));
+//    }
+
+}

+ 28 - 4
src/main/java/com/backendsys/modules/upload/controller/SysFileController.java

@@ -2,6 +2,7 @@ package com.backendsys.modules.upload.controller;
 
 import com.backendsys.modules.common.aspect.SysLog;
 import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
+import com.backendsys.modules.common.config.security.utils.SecurityUtil;
 import com.backendsys.modules.common.utils.Result;
 import com.backendsys.modules.upload.entity.SysFile;
 import com.backendsys.modules.upload.service.SysFileService;
@@ -15,7 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 @Validated
 @RestController
-@Tag(name = "上传文件")
+@Tag(name = "文件管理")
 public class SysFileController {
 
     @Autowired
@@ -25,9 +26,16 @@ public class SysFileController {
      * 获取上传文件列表
      * - 缩略图 (?imageView2/1/w/100/h/100/q/60)
      */
-    @Operation(summary = "获取上传文件列表")
+    @Operation(summary = "获取文件列表 (全部)")
+    @GetMapping("/api/upload/getUploadFileAllList")
+    public Result getUploadFileAllList(@Validated SysFile sysFile) {
+        return Result.success().put("data", sysFileService.selectUploadFileList(sysFile));
+    }
+
+    @Operation(summary = "获取文件列表 (我的)")
     @GetMapping("/api/upload/getUploadFileList")
     public Result getUploadFileList(@Validated SysFile sysFile) {
+        sysFile.setUser_id(SecurityUtil.getUserId());
         return Result.success().put("data", sysFileService.selectUploadFileList(sysFile));
     }
 
@@ -39,12 +47,28 @@ public class SysFileController {
         return Result.success().put("data", sysFileService.uploadSmall(multipartFile, category_id));
     }
 
-    @SysLog("删除上传文件")
-    @Operation(summary = "删除上传文件")
+    @SysLog("删除文件")
+    @Operation(summary = "删除文件")
     @PreAuthorize("@sr.hasPermission(1.1)")
     @DeleteMapping("/api/upload/removeUploadFile")
     public Result removeUploadFile(@Validated(SysFile.Delete.class) @RequestBody SysFile sysFile) {
         return Result.success().put("data", sysFileService.removeUploadFile(sysFile));
     }
 
+    @SysLog("删除文件 (批量)")
+    @Operation(summary = "删除文件 (批量)")
+    @PreAuthorize("@sr.hasPermission(1.1)")
+    @DeleteMapping("/api/upload/removeUploadFileBatch")
+    public Result removeUploadFileBatch(@Validated(SysFile.DeleteBatch.class) @RequestBody SysFile sysFile) {
+        return Result.success().put("data", sysFileService.removeUploadFileBatch(sysFile));
+    }
+
+    @SysLog("编辑文件 (名称)")
+    @Operation(summary = "编辑文件 (名称)")
+    @PreAuthorize("@sr.hasPermission(1.1)")
+    @PutMapping("/api/upload/updateUploadFile")
+    public Result updateUploadFile(@Validated(SysFile.Update.class) @RequestBody SysFile sysFile) {
+        return Result.success().put("data", sysFileService.updateUploadFile(sysFile));
+    }
+
 }

+ 15 - 0
src/main/java/com/backendsys/modules/upload/dao/SysFileCategoryDao.java

@@ -0,0 +1,15 @@
+package com.backendsys.modules.upload.dao;
+
+import com.backendsys.modules.upload.entity.SysFile;
+import com.backendsys.modules.upload.entity.SysFileCategory;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface SysFileCategoryDao extends BaseMapper<SysFileCategory> {
+
+    List<SysFileCategory> selectUploadFileCategoryList(SysFileCategory sysFileCategory);
+
+}

+ 18 - 0
src/main/java/com/backendsys/modules/upload/entity/SysFile.java

@@ -1,29 +1,47 @@
 package com.backendsys.modules.upload.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
 import lombok.Data;
 
 @Data
 @TableName("sys_file")
 public class SysFile {
 
+    public static interface Update{}
     public static interface Delete{}
+    public static interface DeleteBatch{}
 
     @TableId(type = IdType.AUTO)
+    @NotNull(message = "id 不能为空", groups = { Update.class })
     private Long id;
+
     private Long category_id;
+
+    @TableField(exist = false)
+    private String category_name;
     private String request_id;
     private String upload_id;
     private Long user_id;
+
+    @NotEmpty(message = "文件名不能为空", groups = { Update.class })
+    @Size(max = 100, message = "资讯分类名称长度不超过 {max} 字符", groups = { Update.class })
     private String name;
     private String content_type;
     private String url;
     private String url_thumb;
     @NotEmpty(message = "object_key 不能为空", groups = { Delete.class })
     private String object_key;
+
+    @TableField(exist = false)
+    @NotNull(message = "object_keys 不能为空", groups = { DeleteBatch.class })
+    private String object_keys;
+
     private Long size;
     private String md5;
     private Integer target;         // 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)

+ 39 - 0
src/main/java/com/backendsys/modules/upload/entity/SysFileCategory.java

@@ -0,0 +1,39 @@
+package com.backendsys.modules.upload.entity;
+
+import com.backendsys.entity.validator.RangeArray;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+import org.hibernate.validator.constraints.Range;
+
+@Data
+@TableName("sys_file_category")
+public class SysFileCategory {
+
+    public static interface Create{}
+    public static interface Update{}
+    public static interface Delete{}
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    private Long user_id;
+    @Size(max = 20, message = "资讯分类名称长度不超过 {max} 字符", groups = { Create.class, Update.class })
+    @NotBlank(message="资讯分类名称不能为空", groups = { Create.class, Update.class })
+    private String category_name;
+
+    @TableField(exist = false)
+    private Integer category_file_count;
+
+    private String suffix;
+    @Range(min = 1, max = 9999, message = "排序必须在 {min} 到 {max} 之间", groups = { Create.class, Update.class })
+    private Integer sort;
+    @RangeArray(message="状态取值有误,范围应是(-1禁用, 1启用)", value = {"-1", "1"}, groups = { Create.class, Update.class })
+    private Integer status;
+
+}

+ 14 - 0
src/main/java/com/backendsys/modules/upload/service/SysFileCategoryService.java

@@ -0,0 +1,14 @@
+package com.backendsys.modules.upload.service;
+
+import com.backendsys.modules.upload.entity.SysFile;
+import com.backendsys.modules.upload.entity.SysFileCategory;
+import com.backendsys.utils.response.PageEntity;
+
+import java.util.List;
+
+public interface SysFileCategoryService {
+
+    // 获取文件分类列表
+    List<SysFileCategory> selectUploadFileCategoryList(SysFileCategory sysFileCategory);
+
+}

+ 8 - 2
src/main/java/com/backendsys/modules/upload/service/SysFileService.java

@@ -8,12 +8,18 @@ import java.util.Map;
 
 public interface SysFileService {
 
-    // 获取上传文件列表
+    // 获取文件列表
     PageEntity selectUploadFileList(SysFile sysFile);
 
     // 上传文件 (单文件大小不超过 n)
     SysFile uploadSmall(MultipartFile file, Long category_id);
 
-    // 删除上传文件
+    // 删除文件
     Map<String, Object> removeUploadFile(SysFile sysFile);
+
+    // 删除文件 (批量)
+    Map<String, Object> removeUploadFileBatch(SysFile sysFile);
+
+    // 编辑文件
+    Map<String, Object> updateUploadFile(SysFile sysFile);
 }

+ 28 - 0
src/main/java/com/backendsys/modules/upload/service/impl/SysFileCategoryServiceImpl.java

@@ -0,0 +1,28 @@
+package com.backendsys.modules.upload.service.impl;
+
+import com.backendsys.modules.upload.dao.SysFileCategoryDao;
+import com.backendsys.modules.upload.entity.SysFile;
+import com.backendsys.modules.upload.entity.SysFileCategory;
+import com.backendsys.modules.upload.service.SysFileCategoryService;
+import com.backendsys.utils.response.PageEntity;
+import com.backendsys.utils.response.PageInfoResult;
+import com.backendsys.utils.v2.PageUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class SysFileCategoryServiceImpl implements SysFileCategoryService {
+
+    @Autowired
+    private SysFileCategoryDao sysFileCategoryDao;
+
+    /**
+     * 获取文件分类列表
+     */
+    @Override
+    public List<SysFileCategory> selectUploadFileCategoryList(SysFileCategory sysFileCategory) {
+        return sysFileCategoryDao.selectUploadFileCategoryList(sysFileCategory);
+    }
+}

+ 28 - 2
src/main/java/com/backendsys/modules/upload/service/impl/SysFileServiceImpl.java

@@ -49,7 +49,7 @@ public class SysFileServiceImpl implements SysFileService {
     private SysCommonService sysCommonService;
 
     /**
-     * 获取上传文件列表
+     * 获取文件列表
      */
     @Override
     public PageEntity selectUploadFileList(SysFile sysFile) {
@@ -217,7 +217,7 @@ public class SysFileServiceImpl implements SysFileService {
     }
 
     /**
-     * 删除上传文件 (包括缩略图,如果有的话)
+     * 删除文件 (包括缩略图,如果有的话)
      */
     @Override
     public Map<String, Object> removeUploadFile(SysFile sysFile) {
@@ -255,4 +255,30 @@ public class SysFileServiceImpl implements SysFileService {
         return Map.of("object_key", object_key);
     }
 
+    /**
+     * 删除文件 (批量)
+     */
+    @Override
+    public Map<String, Object> removeUploadFileBatch(SysFile sysFile) {
+
+        String object_keys = sysFile.getObject_keys();
+
+        return null;
+    }
+
+
+    /**
+     * 编辑文件 (仅名称)
+     */
+    @Override
+    public Map<String, Object> updateUploadFile(SysFile sysFile) {
+
+        SysFile entity = new SysFile();
+        entity.setId(sysFile.getId());
+        entity.setName(sysFile.getName());
+        sysFileDao.updateById(entity);
+
+        return Map.of("id", sysFile.getId());
+    }
+
 }

+ 44 - 0
src/main/resources/mapper/upload/SysFileCategoryDao.xml

@@ -0,0 +1,44 @@
+<?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.backendsys.modules.upload.dao.SysFileCategoryDao">
+
+    <sql id="includeFileCategory">
+        fc.id,
+        fc.user_id,
+        fc.category_name,
+        COALESCE(fc.suffix, '') suffix,
+        fc.sort,
+        fc.status
+    </sql>
+
+    <resultMap id="resultMapFileCategoryList" type="com.backendsys.modules.upload.entity.SysFileCategory">
+        <id property="id" column="id" jdbcType="BIGINT" />
+        <result property="user_id" column="user_id" javaType="java.lang.Long" />
+        <result property="category_name" column="category_name" />
+        <result property="category_file_count" column="category_file_count" javaType="java.lang.Integer" />
+        <result property="suffix" column="suffix" />
+        <result property="suffix" column="suffix" />
+        <result property="sort" column="sort" javaType="java.lang.Integer" />
+        <result property="status" column="status" javaType="java.lang.Integer" />
+    </resultMap>
+
+    <select id="selectUploadFileCategoryList" resultMap="resultMapFileCategoryList">
+        SELECT <include refid="includeFileCategory" />, COUNT(f.id) AS category_file_count
+        FROM sys_file_category fc
+        LEFT JOIN sys_file f ON fc.id = f.category_id
+        <where>
+            <if test="user_id != null and user_id != ''">
+                AND fc.user_id = #{user_id}
+            </if>
+            <if test="category_name != null and category_name != ''">
+                AND fc.category_name LIKE CONCAT('%', #{category_name}, '%')
+            </if>
+            <if test="status != null and status != ''">
+                AND fc.status = #{status}
+            </if>
+        </where>
+        GROUP BY fc.id
+        ORDER BY fc.sort DESC
+    </select>
+
+</mapper>

+ 26 - 22
src/main/resources/mapper/upload/SysFileDao.xml

@@ -3,27 +3,29 @@
 <mapper namespace="com.backendsys.modules.upload.dao.SysFileDao">
 
     <sql id="includeFile">
-        id,
-        COALESCE(category_id, '') category_id,
-        COALESCE(request_id, '') request_id,
-        COALESCE(upload_id, '') upload_id,
-        user_id,
-        name,
-        content_type,
-        url,
-        COALESCE(url_thumb, '') url_thumb,
-        COALESCE(object_key, '') object_key,
-        size,
-        md5,
-        target,
-        create_time,
-        update_time
+        f.id,
+        COALESCE(f.category_id, '') category_id,
+        COALESCE(fc.category_name, '') category_name,
+        COALESCE(f.request_id, '') request_id,
+        COALESCE(f.upload_id, '') upload_id,
+        f.user_id,
+        f.name,
+        f.content_type,
+        f.url,
+        COALESCE(f.url_thumb, '') url_thumb,
+        COALESCE(f.object_key, '') object_key,
+        f.size,
+        f.md5,
+        f.target,
+        f.create_time,
+        f.update_time
     </sql>
 
     <!-- type="java.util.LinkedHashMap" -->
     <resultMap id="resultMapFileList" type="com.backendsys.modules.upload.entity.SysFile">
         <id property="id" column="id" jdbcType="BIGINT" />
         <result property="category_id" column="category_id" javaType="java.lang.Long" />
+        <result property="category_name" column="category_name" />
         <result property="request_id" column="request_id" />
         <result property="upload_id" column="upload_id" />
         <result property="user_id" column="user_id" javaType="java.lang.Long" />
@@ -40,25 +42,27 @@
     </resultMap>
 
     <select id="selectUploadFileList" resultMap="resultMapFileList">
-        SELECT <include refid="includeFile" /> FROM sys_file
+        SELECT <include refid="includeFile" />
+        FROM sys_file f
+        LEFT JOIN sys_file_category fc ON f.category_id = fc.id
         <where>
             <if test="name != null and name != ''">
-                AND name LIKE CONCAT('%', #{name}, '%')
+                AND f.name LIKE CONCAT('%', #{name}, '%')
             </if>
             <if test="category_id != null and category_id != ''">
-                AND category_id = #{category_id}
+                AND f.category_id = #{category_id}
             </if>
             <if test="user_id != null and user_id != ''">
-                AND user_id = #{user_id}
+                AND f.user_id = #{user_id}
             </if>
             <if test="object_key != null and object_key != ''">
-                AND object_key = #{object_key}
+                AND f.object_key = #{object_key}
             </if>
             <if test="target != null and target != ''">
-                AND target = #{target}
+                AND f.target = #{target}
             </if>
         </where>
-        ORDER BY create_time DESC
+        ORDER BY f.create_time DESC
     </select>
 
 </mapper>