Ver código fonte

feat:共通文件上传逻辑重写(使用中间表记录控制租户文件)、前端调用上传接口实例

韩帛霖 11 meses atrás
pai
commit
8f9937f74e

+ 96 - 96
zkqy-admin/src/main/java/com/zkqy/web/controller/common/CommonFileController.java

@@ -144,102 +144,102 @@ public class CommonFileController {
         }
     }
 
-    /**
-     * 租户通用上传文件接口(需携带租户标识)
-     *
-     * @param file
-     * @param base64
-     * @return
-     */
-    @PostMapping("/tenantUploadFile")
-    public AjaxResult tenantUploadFile(MultipartFile file, boolean base64) {
-        try {
-            // 每个租户都有属于自己的文件夹
-            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
-            // 上传文件路径
-            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
-            AjaxResult ajax = success();
-            // 当前文件是否使用base64来进行存储
-            if (base64) {
-                // 从MultipartFile获取字节数组
-                byte[] bytes = file.getBytes();
-                // 将字节数组转换为Base64编码的字符串
-                String base64Encoded = Base64.getEncoder().encodeToString(bytes);
-                String key = UUID.randomUUID().toString();
-                // 存储字节流  redis暂存30分钟
-                redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
-                ajax.put("base64", key);
-            } else {
-                // 上传并返回新文件名称
-                String fileName = FileUploadUtils.upload(filePath, file);
-                // 存储文件
-                String url = serverConfig.getUrl() + fileName;
-                ajax.put("url", url);
-                ajax.put("fileName", fileName);
-                ajax.put("newFileName", FileUtils.getName(fileName));
-                ajax.put("originalFilename", file.getOriginalFilename());
-            }
-            return ajax;
-        } catch (Exception e) {
-            return AjaxResult.error(e.getMessage());
-        }
-    }
-
-
-    /**
-     * * 租户通用批量上传文件接口(需携带租户标识)
-     * * * 批量上传无法使用流文件逻辑
-     *
-     * @param request
-     * @param files
-     * @return
-     */
-    @PostMapping("/tenantUploadFiles")
-    @RequestBody
-    public AjaxResult tenantUploadFiles(HttpServletRequest request, List<MultipartFile> files) {
-        try {
-            // 每个租户都有属于自己的文件夹
-            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
-            // 上传文件路径
-            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
-            List<String> urls = new ArrayList<String>();
-            List<String> fileNames = new ArrayList<String>();
-            List<String> newFileNames = new ArrayList<String>();
-            List<String> originalFilenames = new ArrayList<String>();
-            List<String> base64Keys = new ArrayList<String>();
-            AjaxResult ajax = success();
-            for (MultipartFile file : files) {
-                boolean is = Boolean.parseBoolean(request.getParameter(file.getOriginalFilename().split("\\.")[0]));
-                if (is) {
-                    // 从MultipartFile获取字节数组
-                    byte[] bytes = file.getBytes();
-                    // 将字节数组转换为Base64编码的字符串
-                    String base64Encoded = Base64.getEncoder().encodeToString(bytes);
-                    String key = UUID.randomUUID().toString();
-                    // 存储字节流  redis暂存30分钟
-                    redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
-                    base64Keys.add("file:base64:" + key);
-                    ajax.put("base64", StringUtils.join(base64Keys, FILE_DELIMETER));
-                } else {
-                    // 上传并返回新文件名称
-                    String fileName = FileUploadUtils.upload(filePath, file);
-                    String url = serverConfig.getUrl() + fileName;
-                    urls.add(url);
-                    fileNames.add(fileName);
-                    newFileNames.add(FileUtils.getName(fileName));
-                    originalFilenames.add(file.getOriginalFilename());
-
-                    ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
-                    ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
-                    ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
-                    ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
-                }
-            }
-            return ajax;
-        } catch (Exception e) {
-            return AjaxResult.error(e.getMessage());
-        }
-    }
+//    /**
+//     * 租户通用上传文件接口(需携带租户标识)
+//     *
+//     * @param file
+//     * @param base64
+//     * @return
+//     */
+//    @PostMapping("/tenantUploadFile")
+//    public AjaxResult tenantUploadFile(MultipartFile file, boolean base64) {
+//        try {
+//            // 每个租户都有属于自己的文件夹
+//            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
+//            // 上传文件路径
+//            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
+//            AjaxResult ajax = success();
+//            // 当前文件是否使用base64来进行存储
+//            if (base64) {
+//                // 从MultipartFile获取字节数组
+//                byte[] bytes = file.getBytes();
+//                // 将字节数组转换为Base64编码的字符串
+//                String base64Encoded = Base64.getEncoder().encodeToString(bytes);
+//                String key = UUID.randomUUID().toString();
+//                // 存储字节流  redis暂存30分钟
+//                redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
+//                ajax.put("base64", key);
+//            } else {
+//                // 上传并返回新文件名称
+//                String fileName = FileUploadUtils.upload(filePath, file);
+//                // 存储文件
+//                String url = serverConfig.getUrl() + fileName;
+//                ajax.put("url", url);
+//                ajax.put("fileName", fileName);
+//                ajax.put("newFileName", FileUtils.getName(fileName));
+//                ajax.put("originalFilename", file.getOriginalFilename());
+//            }
+//            return ajax;
+//        } catch (Exception e) {
+//            return AjaxResult.error(e.getMessage());
+//        }
+//    }
+//
+//
+//    /**
+//     * * 租户通用批量上传文件接口(需携带租户标识)
+//     * * * 批量上传无法使用流文件逻辑
+//     *
+//     * @param request
+//     * @param files
+//     * @return
+//     */
+//    @PostMapping("/tenantUploadFiles")
+//    @RequestBody
+//    public AjaxResult tenantUploadFiles(HttpServletRequest request, List<MultipartFile> files) {
+//        try {
+//            // 每个租户都有属于自己的文件夹
+//            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
+//            // 上传文件路径
+//            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
+//            List<String> urls = new ArrayList<String>();
+//            List<String> fileNames = new ArrayList<String>();
+//            List<String> newFileNames = new ArrayList<String>();
+//            List<String> originalFilenames = new ArrayList<String>();
+//            List<String> base64Keys = new ArrayList<String>();
+//            AjaxResult ajax = success();
+//            for (MultipartFile file : files) {
+//                boolean is = Boolean.parseBoolean(request.getParameter(file.getOriginalFilename().split("\\.")[0]));
+//                if (is) {
+//                    // 从MultipartFile获取字节数组
+//                    byte[] bytes = file.getBytes();
+//                    // 将字节数组转换为Base64编码的字符串
+//                    String base64Encoded = Base64.getEncoder().encodeToString(bytes);
+//                    String key = UUID.randomUUID().toString();
+//                    // 存储字节流  redis暂存30分钟
+//                    redisCache.setCacheObject(key, base64Encoded, Constants.BYTESTREAM_EXPIRATION, TimeUnit.MINUTES);
+//                    base64Keys.add("file:base64:" + key);
+//                    ajax.put("base64", StringUtils.join(base64Keys, FILE_DELIMETER));
+//                } else {
+//                    // 上传并返回新文件名称
+//                    String fileName = FileUploadUtils.upload(filePath, file);
+//                    String url = serverConfig.getUrl() + fileName;
+//                    urls.add(url);
+//                    fileNames.add(fileName);
+//                    newFileNames.add(FileUtils.getName(fileName));
+//                    originalFilenames.add(file.getOriginalFilename());
+//
+//                    ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
+//                    ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
+//                    ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
+//                    ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
+//                }
+//            }
+//            return ajax;
+//        } catch (Exception e) {
+//            return AjaxResult.error(e.getMessage());
+//        }
+//    }
 
     /**
      * 通用上传请求(多个)

+ 225 - 0
zkqy-business/src/main/java/com/zkqy/business/controller/FileManagementController.java

@@ -0,0 +1,225 @@
+package com.zkqy.business.controller;
+
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zkqy.business.entity.FileManagement;
+import com.zkqy.business.service.IFileManagementService;
+import com.zkqy.common.config.ZkqyConfig;
+import com.zkqy.common.constant.Constants;
+import com.zkqy.common.core.redis.RedisCache;
+import com.zkqy.common.utils.SecurityUtils;
+import com.zkqy.common.utils.StringUtils;
+import com.zkqy.common.utils.file.FileUploadUtils;
+import com.zkqy.common.utils.file.FileUtils;
+import com.zkqy.framework.config.ServerConfig;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+import com.zkqy.common.annotation.Log;
+import com.zkqy.common.core.controller.BaseController;
+import com.zkqy.common.core.domain.AjaxResult;
+import com.zkqy.common.enums.BusinessType;
+import com.zkqy.common.utils.poi.ExcelUtil;
+import com.zkqy.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+
+/**
+ * 文件管理(业务数据关联)Controller
+ *
+ * @author hzh
+ * @date 2024-07-04
+ */
+@RestController
+@RequestMapping("/system/fileManagement")
+@Api(value = "/system/fileManagement", description = "文件管理(业务数据关联)-接口")
+public class FileManagementController extends BaseController {
+    @Autowired
+    private IFileManagementService fileManagementService;
+
+    @Resource
+    private RedisCache redisCache;
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+
+    @Autowired
+    private ObjectMapper objectMapper;  // 用于JSON转换
+
+    private static final String FILE_DELIMETER = ",";
+
+
+    /**
+     * 租户通用上传文件接口(需携带租户标识)
+     *
+     * @param file
+     * @param fileManagementJson
+     * @return
+     */
+    @Transactional
+    @PostMapping("/tenantUploadFile")
+    public AjaxResult tenantUploadFile(@RequestParam("file") MultipartFile file,
+                                       @RequestParam("fileManagement") String fileManagementJson) {
+        try {
+            FileManagement fileManagement = objectMapper.readValue(fileManagementJson, FileManagement.class);
+            // 每个租户都有属于自己的文件夹
+            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
+            // 上传文件路径
+            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
+            AjaxResult ajax = success();
+            String fileGroupKey = UUID.randomUUID().toString();
+            // 处理文件、封装数据
+            switch (fileManagement.getFileType()) {
+                case "filePattern":
+                    String fileName = FileUploadUtils.upload(filePath, file);
+                    String url = serverConfig.getUrl() + fileName;
+                    fileManagement.setFileDownloadUrl(url);
+                    fileManagement.setFilePath(fileName);
+                    break;
+                case "base64":
+                    byte[] bytes = file.getBytes();
+                    String base64Encoded = Base64.getEncoder().encodeToString(bytes);
+                    fileManagement.setFileContent(base64Encoded);
+                    break;
+                case "bytes":
+                    fileManagement.setFileData(file.getBytes());
+                    break;
+            }
+            fileManagement.setOriginalFileName(file.getOriginalFilename());
+            fileManagement.setFileGroupKey(fileGroupKey);
+            fileManagement.setFileSize(fileManagement.getFileSize());
+            // 插入文件信息
+            fileManagementService.insertFileManagement(fileManagement);
+            ajax.put("fileGroupKey", fileGroupKey);
+            return ajax;
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * * 租户通用批量上传文件接口(需携带租户标识)
+     * * * 批量上传无法使用流文件逻辑
+     *
+     * @param files
+     * @param fileManagementJson
+     * @return
+     */
+    @PostMapping("/tenantUploadFiles")
+    public AjaxResult tenantUploadFiles(@RequestParam("files") MultipartFile[] files, @RequestParam("fileManagement") String fileManagementJson) {
+        try {
+            FileManagement fileManagement = objectMapper.readValue(fileManagementJson, FileManagement.class);
+            // 每个租户都有属于自己的文件夹
+            String tenantCode = SecurityUtils.getLoginUser().getUser().getTenant().getTenantCode();
+            // 上传文件路径
+            String filePath = ZkqyConfig.getUploadPath() + "/" + tenantCode;
+            AjaxResult ajax = success();
+            String fileGroupKey = UUID.randomUUID().toString();
+            for (MultipartFile file : files) {
+                if (file.isEmpty()) {
+                    continue;
+                }
+                // 处理文件、封装数据
+                switch (fileManagement.getFileType()) {
+                    case "filePattern":
+                        String fileName = FileUploadUtils.upload(filePath, file);
+                        String url = serverConfig.getUrl() + fileName;
+                        fileManagement.setFileDownloadUrl(url);
+                        fileManagement.setFilePath(fileName);
+                        break;
+                    case "base64":
+                        byte[] bytes = file.getBytes();
+                        String base64Encoded = Base64.getEncoder().encodeToString(bytes);
+                        fileManagement.setFileContent(base64Encoded);
+                        break;
+                    case "bytes":
+                        fileManagement.setFileData(file.getBytes());
+                        break;
+                }
+                fileManagement.setOriginalFileName(file.getOriginalFilename());
+                fileManagement.setFileGroupKey(fileGroupKey);
+                fileManagement.setFileSize(fileManagement.getFileSize());
+                // 插入文件信息
+                fileManagementService.insertFileManagement(fileManagement);
+            }
+            ajax.put("fileGroupKey", fileGroupKey);
+            return ajax;
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+
+    /**
+     * 查询文件管理(业务数据关联)列表
+     */
+    @GetMapping("/list")
+    @ApiOperation(value = "查询文件管理(业务数据关联)列表")
+    public TableDataInfo list(FileManagement fileManagement) {
+        startPage();
+        List<FileManagement> list = fileManagementService.selectFileManagementList(fileManagement);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出文件管理(业务数据关联)列表
+     */
+    @Log(title = "文件管理(业务数据关联)", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    @ApiOperation(value = "导出文件管理(业务数据关联)列表")
+    public void export(HttpServletResponse response, FileManagement fileManagement) {
+        List<FileManagement> list = fileManagementService.selectFileManagementList(fileManagement);
+        ExcelUtil<FileManagement> util = new ExcelUtil<FileManagement>(FileManagement.class);
+        util.exportExcel(response, list, "文件管理(业务数据关联)数据");
+    }
+
+    /**
+     * 获取文件管理(业务数据关联)详细信息
+     */
+    @GetMapping(value = "/{id}")
+    @ApiOperation(value = "获取文件管理(业务数据关联)详细信息")
+    public AjaxResult getInfo(@PathVariable("id") Long id) {
+        return success(fileManagementService.selectFileManagementById(id));
+    }
+
+    /**
+     * 新增文件管理(业务数据关联)
+     */
+    @Log(title = "文件管理(业务数据关联)", businessType = BusinessType.INSERT)
+    @PostMapping
+    @ApiOperation(value = "新增文件管理(业务数据关联)")
+    public AjaxResult add(@RequestBody FileManagement fileManagement) {
+        return toAjax(fileManagementService.insertFileManagement(fileManagement));
+    }
+
+    /**
+     * 修改文件管理(业务数据关联)
+     */
+    @Log(title = "文件管理(业务数据关联)", businessType = BusinessType.UPDATE)
+    @PutMapping
+    @ApiOperation(value = "修改文件管理(业务数据关联)")
+    public AjaxResult edit(@RequestBody FileManagement fileManagement) {
+        return toAjax(fileManagementService.updateFileManagement(fileManagement));
+    }
+
+    /**
+     * 删除文件管理(业务数据关联)
+     */
+    @Log(title = "文件管理(业务数据关联)", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    @ApiOperation(value = "删除文件管理(业务数据关联)")
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(fileManagementService.deleteFileManagementByIds(ids));
+    }
+}

+ 238 - 0
zkqy-business/src/main/java/com/zkqy/business/entity/FileManagement.java

@@ -0,0 +1,238 @@
+package com.zkqy.business.entity;
+
+import com.zkqy.common.core.domain.BaseEntityPlus;
+import com.zkqy.common.annotation.Excel;
+
+import java.util.Arrays;
+
+/**
+ * 文件管理(业务数据关联)对象 file_management
+ *
+ * @author hzh
+ * @date 2024-07-04
+ */
+public class FileManagement extends BaseEntityPlus {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 文件组标识
+     */
+    private String fileGroupKey;
+
+    /**
+     * 原始文件名称
+     */
+    @Excel(name = "原始文件名称")
+    private String originalFileName;
+
+    /**
+     * 新文件名称
+     */
+    @Excel(name = "新文件名称")
+    private String newFileName;
+
+    /**
+     * 服务器文件相对路径
+     */
+    @Excel(name = "服务器文件相对路径")
+    private String filePath;
+
+    /**
+     * 文件类型(filePattern:文件形式、base64:64编码形式、bytes:字节形式)
+     */
+    @Excel(name = "文件类型", readConverterExp = "filePattern:文件形式、base64:64编码形式、bytes:字节形式")
+    private String fileType;
+
+    /**
+     * 文件大小
+     */
+    @Excel(name = "文件大小")
+    private Long fileSize;
+
+    /**
+     * 文件内容
+     */
+    @Excel(name = "文件内容")
+    private String fileContent;
+
+    /**
+     * 文件字节数据
+     */
+    @Excel(name = "文件字节数据")
+    private byte[] fileData;
+
+    /**
+     * 文件下载地址(只有文件形式会有值)
+     */
+    @Excel(name = "文件下载地址(只有文件形式会有值)")
+    private String fileDownloadUrl;
+
+    /**
+     * 创建者编号
+     */
+    @Excel(name = "创建者编号")
+    private Long createById;
+
+    /**
+     * 更新者编号
+     */
+    @Excel(name = "更新者编号")
+    private Long updateById;
+
+    /**
+     * 删除标志(0:否;2:是)
+     */
+    private String delFlag;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getFileGroupKey() {
+        return fileGroupKey;
+    }
+
+    public void setFileGroupKey(String fileGroupKey) {
+        this.fileGroupKey = fileGroupKey;
+    }
+
+    public String getOriginalFileName() {
+        return originalFileName;
+    }
+
+    public void setOriginalFileName(String originalFileName) {
+        this.originalFileName = originalFileName;
+    }
+
+    public String getNewFileName() {
+        return newFileName;
+    }
+
+    public void setNewFileName(String newFileName) {
+        this.newFileName = newFileName;
+    }
+
+    public String getFilePath() {
+        return filePath;
+    }
+
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+
+    public String getFileType() {
+        return fileType;
+    }
+
+    public void setFileType(String fileType) {
+        this.fileType = fileType;
+    }
+
+    public Long getFileSize() {
+        return fileSize;
+    }
+
+    public void setFileSize(Long fileSize) {
+        this.fileSize = fileSize;
+    }
+
+    public String getFileContent() {
+        return fileContent;
+    }
+
+    public void setFileContent(String fileContent) {
+        this.fileContent = fileContent;
+    }
+
+    public byte[] getFileData() {
+        return fileData;
+    }
+
+    public void setFileData(byte[] fileData) {
+        this.fileData = fileData;
+    }
+
+    public String getFileDownloadUrl() {
+        return fileDownloadUrl;
+    }
+
+    public void setFileDownloadUrl(String fileDownloadUrl) {
+        this.fileDownloadUrl = fileDownloadUrl;
+    }
+
+    @Override
+    public Long getCreateById() {
+        return createById;
+    }
+
+    @Override
+    public void setCreateById(Long createById) {
+        this.createById = createById;
+    }
+
+    @Override
+    public Long getUpdateById() {
+        return updateById;
+    }
+
+    @Override
+    public void setUpdateById(Long updateById) {
+        this.updateById = updateById;
+    }
+
+    public String getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(String delFlag) {
+        this.delFlag = delFlag;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("FileManagement{");
+        sb.append("id=").append(id);
+        sb.append(", fileGroupKey='").append(fileGroupKey).append('\'');
+        sb.append(", originalFileName='").append(originalFileName).append('\'');
+        sb.append(", newFileName='").append(newFileName).append('\'');
+        sb.append(", filePath='").append(filePath).append('\'');
+        sb.append(", fileType='").append(fileType).append('\'');
+        sb.append(", fileSize=").append(fileSize);
+        sb.append(", fileContent='").append(fileContent).append('\'');
+        sb.append(", fileData=").append(Arrays.toString(fileData));
+        sb.append(", fileDownloadUrl='").append(fileDownloadUrl).append('\'');
+        sb.append(", createById=").append(createById);
+        sb.append(", updateById=").append(updateById);
+        sb.append(", delFlag='").append(delFlag).append('\'');
+        sb.append('}');
+        return sb.toString();
+    }
+
+    public FileManagement() {
+    }
+
+    public FileManagement(Long id, String fileGroupKey, String originalFileName, String newFileName, String filePath, String fileType, Long fileSize, String fileContent, byte[] fileData, String fileDownloadUrl, Long createById, Long updateById, String delFlag) {
+        this.id = id;
+        this.fileGroupKey = fileGroupKey;
+        this.originalFileName = originalFileName;
+        this.newFileName = newFileName;
+        this.filePath = filePath;
+        this.fileType = fileType;
+        this.fileSize = fileSize;
+        this.fileContent = fileContent;
+        this.fileData = fileData;
+        this.fileDownloadUrl = fileDownloadUrl;
+        this.createById = createById;
+        this.updateById = updateById;
+        this.delFlag = delFlag;
+    }
+}

+ 61 - 0
zkqy-business/src/main/java/com/zkqy/business/mapper/FileManagementMapper.java

@@ -0,0 +1,61 @@
+package com.zkqy.business.mapper;
+
+import com.zkqy.business.entity.FileManagement;
+
+import java.util.List;
+
+/**
+ * 文件管理(业务数据关联)Mapper接口
+ *
+ * @author hzh
+ * @date 2024-07-04
+ */
+public interface FileManagementMapper {
+    /**
+     * 查询文件管理(业务数据关联)
+     *
+     * @param id 文件管理(业务数据关联)主键
+     * @return 文件管理(业务数据关联)
+     */
+    public FileManagement selectFileManagementById(Long id);
+
+    /**
+     * 查询文件管理(业务数据关联)列表
+     *
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 文件管理(业务数据关联)集合
+     */
+    public List<FileManagement> selectFileManagementList(FileManagement fileManagement);
+
+    /**
+     * 新增文件管理(业务数据关联)
+     *
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    public int insertFileManagement(FileManagement fileManagement);
+
+    /**
+     * 修改文件管理(业务数据关联)
+     *
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    public int updateFileManagement(FileManagement fileManagement);
+
+    /**
+     * 删除文件管理(业务数据关联)
+     *
+     * @param id 文件管理(业务数据关联)主键
+     * @return 结果
+     */
+    public int deleteFileManagementById(Long id);
+
+    /**
+     * 批量删除文件管理(业务数据关联)
+     *
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteFileManagementByIds(Long[] ids);
+}

+ 62 - 0
zkqy-business/src/main/java/com/zkqy/business/service/IFileManagementService.java

@@ -0,0 +1,62 @@
+package com.zkqy.business.service;
+
+import com.zkqy.business.entity.FileManagement;
+
+import java.util.List;
+
+/**
+ * 文件管理(业务数据关联)Service接口
+ * 
+ * @author hzh
+ * @date 2024-07-04
+ */
+public interface IFileManagementService 
+{
+    /**
+     * 查询文件管理(业务数据关联)
+     * 
+     * @param id 文件管理(业务数据关联)主键
+     * @return 文件管理(业务数据关联)
+     */
+    public FileManagement selectFileManagementById(Long id);
+
+    /**
+     * 查询文件管理(业务数据关联)列表
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 文件管理(业务数据关联)集合
+     */
+    public List<FileManagement> selectFileManagementList(FileManagement fileManagement);
+
+    /**
+     * 新增文件管理(业务数据关联)
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    public int insertFileManagement(FileManagement fileManagement);
+
+    /**
+     * 修改文件管理(业务数据关联)
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    public int updateFileManagement(FileManagement fileManagement);
+
+    /**
+     * 批量删除文件管理(业务数据关联)
+     * 
+     * @param ids 需要删除的文件管理(业务数据关联)主键集合
+     * @return 结果
+     */
+    public int deleteFileManagementByIds(Long[] ids);
+
+    /**
+     * 删除文件管理(业务数据关联)信息
+     * 
+     * @param id 文件管理(业务数据关联)主键
+     * @return 结果
+     */
+    public int deleteFileManagementById(Long id);
+}

+ 97 - 0
zkqy-business/src/main/java/com/zkqy/business/service/impl/FileManagementServiceImpl.java

@@ -0,0 +1,97 @@
+package com.zkqy.business.service.impl;
+
+import java.util.List;
+
+import com.zkqy.business.entity.FileManagement;
+import com.zkqy.business.mapper.FileManagementMapper;
+import com.zkqy.business.service.IFileManagementService;
+import com.zkqy.common.utils.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 文件管理(业务数据关联)Service业务层处理
+ * 
+ * @author hzh
+ * @date 2024-07-04
+ */
+@Service
+public class FileManagementServiceImpl implements IFileManagementService
+{
+    @Autowired
+    private FileManagementMapper fileManagementMapper;
+
+    /**
+     * 查询文件管理(业务数据关联)
+     * 
+     * @param id 文件管理(业务数据关联)主键
+     * @return 文件管理(业务数据关联)
+     */
+    @Override
+    public FileManagement selectFileManagementById(Long id)
+    {
+        return fileManagementMapper.selectFileManagementById(id);
+    }
+
+    /**
+     * 查询文件管理(业务数据关联)列表
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 文件管理(业务数据关联)
+     */
+    @Override
+    public List<FileManagement> selectFileManagementList(FileManagement fileManagement)
+    {
+        return fileManagementMapper.selectFileManagementList(fileManagement);
+    }
+
+    /**
+     * 新增文件管理(业务数据关联)
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    @Override
+    public int insertFileManagement(FileManagement fileManagement)
+    {
+        fileManagement.setCreateTime(DateUtils.getNowDate());
+        return fileManagementMapper.insertFileManagement(fileManagement);
+    }
+
+    /**
+     * 修改文件管理(业务数据关联)
+     * 
+     * @param fileManagement 文件管理(业务数据关联)
+     * @return 结果
+     */
+    @Override
+    public int updateFileManagement(FileManagement fileManagement)
+    {
+        fileManagement.setUpdateTime(DateUtils.getNowDate());
+        return fileManagementMapper.updateFileManagement(fileManagement);
+    }
+
+    /**
+     * 批量删除文件管理(业务数据关联)
+     * 
+     * @param ids 需要删除的文件管理(业务数据关联)主键
+     * @return 结果
+     */
+    @Override
+    public int deleteFileManagementByIds(Long[] ids)
+    {
+        return fileManagementMapper.deleteFileManagementByIds(ids);
+    }
+
+    /**
+     * 删除文件管理(业务数据关联)信息
+     * 
+     * @param id 文件管理(业务数据关联)主键
+     * @return 结果
+     */
+    @Override
+    public int deleteFileManagementById(Long id)
+    {
+        return fileManagementMapper.deleteFileManagementById(id);
+    }
+}

+ 156 - 0
zkqy-business/src/main/resources/mapper/dragmapper/FileManagementMapper.xml

@@ -0,0 +1,156 @@
+<?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.zkqy.business.mapper.FileManagementMapper">
+
+    <resultMap type="com.zkqy.business.entity.FileManagement" id="FileManagementResult">
+        <result property="id" column="id"/>
+        <result property="fileGroupKey" column="file_group_key"/>
+        <result property="originalFileName" column="original_file_name"/>
+        <result property="newFileName" column="new_file_name"/>
+        <result property="filePath" column="file_path"/>
+        <result property="fileType" column="file_type"/>
+        <result property="fileSize" column="file_size"/>
+        <result property="fileContent" column="file_content"/>
+        <result property="fileData" column="file_data"/>
+        <result property="fileDownloadUrl" column="file_download_url"/>
+        <result property="remark" column="remark"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createById" column="create_by_id"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateById" column="update_by_id"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+    </resultMap>
+
+    <sql id="selectFileManagementVo">
+        select id,
+               original_file_name,
+               new_file_name,
+               file_path,
+               file_type,
+               file_size,
+               file_content,
+               file_data,
+               file_download_url,
+               remark,
+               create_by,
+               create_by_id,
+               create_time,
+               update_by,
+               update_by_id,
+               update_time,
+               del_flag
+        from {DBNAME}.file_management
+    </sql>
+
+    <select id="selectFileManagementList" parameterType="com.zkqy.business.entity.FileManagement"
+            resultMap="FileManagementResult">
+        <include refid="selectFileManagementVo"/>
+        <where>
+            <if test="fileGroupKey != null  and fileGroupKey != ''">and file_group_key = #{fileGroupKey}</if>
+            <if test="originalFileName != null  and originalFileName != ''">and original_file_name like concat('%',
+                #{originalFileName}, '%')
+            </if>
+            <if test="newFileName != null  and newFileName != ''">and new_file_name like concat('%', #{newFileName},
+                '%')
+            </if>
+            <if test="filePath != null  and filePath != ''">and file_path = #{filePath}</if>
+            <if test="fileType != null  and fileType != ''">and file_type = #{fileType}</if>
+            <if test="fileSize != null ">and file_size = #{fileSize}</if>
+            <if test="fileContent != null  and fileContent != ''">and file_content = #{fileContent}</if>
+            <if test="fileData != null  and fileData != ''">and file_data = #{fileData}</if>
+            <if test="fileDownloadUrl != null  and fileDownloadUrl != ''">and file_download_url = #{fileDownloadUrl}
+            </if>
+            <if test="createById != null ">and create_by_id = #{createById}</if>
+            <if test="updateById != null ">and update_by_id = #{updateById}</if>
+        </where>
+    </select>
+
+    <select id="selectFileManagementById" parameterType="Long" resultMap="FileManagementResult">
+        <include refid="selectFileManagementVo"/>
+        where id = #{id}
+    </select>
+
+    <insert id="insertFileManagement" parameterType="com.zkqy.business.entity.FileManagement" useGeneratedKeys="true"
+            keyProperty="id">
+        insert into {DBNAME}.file_management
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="fileGroupKey != null">file_group_key,</if>
+            <if test="originalFileName != null">original_file_name,</if>
+            <if test="newFileName != null">new_file_name,</if>
+            <if test="filePath != null">file_path,</if>
+            <if test="fileType != null">file_type,</if>
+            <if test="fileSize != null">file_size,</if>
+            <if test="fileContent != null">file_content,</if>
+            <if test="fileData != null">file_data,</if>
+            <if test="fileDownloadUrl != null">file_download_url,</if>
+            <if test="remark != null">remark,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createById != null">create_by_id,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateById != null">update_by_id,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="delFlag != null">del_flag,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="fileGroupKey != null">#{fileGroupKey},</if>
+            <if test="originalFileName != null">#{originalFileName},</if>
+            <if test="newFileName != null">#{newFileName},</if>
+            <if test="filePath != null">#{filePath},</if>
+            <if test="fileType != null">#{fileType},</if>
+            <if test="fileSize != null">#{fileSize},</if>
+            <if test="fileContent != null">#{fileContent},</if>
+            <if test="fileData != null">#{fileData},</if>
+            <if test="fileDownloadUrl != null">#{fileDownloadUrl},</if>
+            <if test="remark != null">#{remark},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createById != null">#{createById},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateById != null">#{updateById},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="delFlag != null">#{delFlag},</if>
+        </trim>
+    </insert>
+
+    <update id="updateFileManagement" parameterType="com.zkqy.business.entity.FileManagement">
+        update {DBNAME}.file_management
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="fileGroupKey != null">file_group_key = #{fileGroupKey},</if>
+            <if test="originalFileName != null">original_file_name = #{originalFileName},</if>
+            <if test="newFileName != null">new_file_name = #{newFileName},</if>
+            <if test="filePath != null">file_path = #{filePath},</if>
+            <if test="fileType != null">file_type = #{fileType},</if>
+            <if test="fileSize != null">file_size = #{fileSize},</if>
+            <if test="fileContent != null">file_content = #{fileContent},</if>
+            <if test="fileData != null">file_data = #{fileData},</if>
+            <if test="fileDownloadUrl != null">file_download_url = #{fileDownloadUrl},</if>
+            <if test="remark != null">remark = #{remark},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createById != null">create_by_id = #{createById},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateById != null">update_by_id = #{updateById},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteFileManagementById" parameterType="Long">
+        delete
+        from {DBNAME}.file_management
+        where id = #{id}
+    </delete>
+
+    <delete id="deleteFileManagementByIds" parameterType="String">
+        delete from {DBNAME}.file_management where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>

+ 8 - 0
zkqy-ui/src/api/homePage/index.js

@@ -39,3 +39,11 @@ export function getLogin() {
       method: 'get',
     })
 }
+
+export function uploadFilesTenant(data) {
+  return request({
+    url: '/system/fileManagement/tenantUploadFiles',
+    method: 'post',
+    data: data,
+  })
+}

+ 86 - 49
zkqy-ui/src/views/index.vue

@@ -2,28 +2,57 @@
   <div class="app-container home">
 
     <!--    <div>-->
+    <!--  文件上传测试调用  -->
     <!--      <button @click="upload.open = true">上传</button>-->
-    <!--      <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>-->
-
-    <!--        &lt;!&ndash;        :on-progress="handleFileUploadProgress"-->
-    <!--                           :on-success="handleFileSuccess"&ndash;&gt;-->
-    <!--        <el-upload ref="upload" :headers="upload.headers"-->
-    <!--                   :action="upload.url" :disabled="upload.isUploading"-->
-
-    <!--                   :auto-upload="false"-->
-    <!--                   :file-list="upload.fileList"-->
-    <!--                   multiple drag>-->
-    <!--          <i class="el-icon-upload"></i>-->
-
-
-    <!--          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>-->
-    <!--          <div class="el-upload__tip text-center" slot="tip"></div>-->
-    <!--        </el-upload>-->
-    <!--        <div slot="footer" class="dialog-footer">-->
-    <!--          <el-button type="primary" @click="submitFileForm">确 定</el-button>-->
-    <!--          <el-button @click="upload.open = false">取 消</el-button>-->
-    <!--        </div>-->
-    <!--      </el-dialog>-->
+
+    <!--      <el-select v-model="filetype" placeholder="请选择">-->
+    <!--        <el-option label="文件形式" value="filePattern"/>-->
+    <!--        <el-option label="字节形式" value="bytes"/>-->
+    <!--        <el-option label="编码形式" value="base64"/>-->
+    <!--      </el-select>-->
+
+    <!--      &lt;!&ndash;      :action="upload.url"&ndash;&gt;-->
+
+
+    <!--      <el-upload-->
+    <!--        action="#"-->
+    <!--        :http-request="customUpload"-->
+    <!--        :visible.sync="upload.open"-->
+    <!--        :on-success="handleSuccess"-->
+    <!--        :on-error="handleError"-->
+    <!--        :before-upload="beforeUpload"-->
+
+    <!--        :headers="upload.headers"-->
+    <!--        :auto-upload="false"-->
+    <!--        multiple-->
+    <!--        ref="upload">-->
+    <!--        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>-->
+    <!--        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>-->
+    <!--      </el-upload>-->
+
+    <!--      &lt;!&ndash;            <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>&ndash;&gt;-->
+
+    <!--      &lt;!&ndash;              &lt;!&ndash;        :on-progress="handleFileUploadProgress"&ndash;&gt;-->
+    <!--      &lt;!&ndash;                                 :on-success="handleFileSuccess"&ndash;&gt;&ndash;&gt;-->
+    <!--      &lt;!&ndash;              <el-upload ref="upload" :headers="upload.headers"&ndash;&gt;-->
+    <!--      &lt;!&ndash;                         :action="upload.url" :disabled="upload.isUploading"&ndash;&gt;-->
+
+    <!--      &lt;!&ndash;                         :auto-upload="false"&ndash;&gt;-->
+    <!--      &lt;!&ndash;                         :file-list="upload.fileList"&ndash;&gt;-->
+    <!--      &lt;!&ndash;                         multiple drag>&ndash;&gt;-->
+    <!--      &lt;!&ndash;                <i class="el-icon-upload"></i>&ndash;&gt;-->
+
+
+    <!--      &lt;!&ndash;                <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>&ndash;&gt;-->
+    <!--      &lt;!&ndash;                <div class="el-upload__tip text-center" slot="tip"></div>&ndash;&gt;-->
+    <!--      &lt;!&ndash;              </el-upload>&ndash;&gt;-->
+    <!--      &lt;!&ndash;              <div slot="footer" class="dialog-footer">&ndash;&gt;-->
+    <!--      &lt;!&ndash;                <el-button type="primary" @click="submitFileForm">确 定</el-button>&ndash;&gt;-->
+    <!--      &lt;!&ndash;                <el-button @click="upload.open = false">取 消</el-button>&ndash;&gt;-->
+    <!--      &lt;!&ndash;              </div>&ndash;&gt;-->
+    <!--      &lt;!&ndash;            </el-dialog>&ndash;&gt;-->
+
+
     <!--    </div>-->
 
 
@@ -137,13 +166,14 @@ import {
   getPipeline,
   getOperation,
   getMaterial,
-  getLogin,
+  getLogin, uploadFilesTenant,
 } from "@/api/homePage/index";
 
 export default {
   name: "Index",
   data() {
     return {
+      filetype: "",
       chartObj: {
         myChart1: null,
         myChart2: null,
@@ -151,34 +181,10 @@ export default {
         myChart4: null,
       },
       processList: [],
-      swiperList: [
-        /* {
-          name: "111",
-          ip: "192.168.1.1"
-        },
-        {
-          name: "222",
-          ip: "192.168.1.2"
-        },
-        {
-          name: "333",
-          ip: "192.168.1.3"
-        },
-        {
-          name: "444",
-          ip: "192.168.1.4"
-        },
-        {
-          name: "555",
-          ip: "192.168.1.5"
-        },
-        {
-          name: "666",
-          ip: "192.168.1.6"
-        }, */
-      ],
+      swiperList: [],
       // 用户导入参数
       upload: {
+        formData: {},
         // 文件列表
         fileList: [],
         // 是否显示弹出层(用户导入)
@@ -192,7 +198,7 @@ export default {
         // 设置上传的请求头部
         headers: {Authorization: "Bearer " + getToken()},
         // 上传的地址
-        url: process.env.VUE_APP_BASE_API1 + "common/tenantUploadFiles",
+        url: process.env.VUE_APP_BASE_API1 + "system/fileManagement/tenantUploadFiles",
       },
       // 版本号
       version: "3.8.5",
@@ -208,6 +214,37 @@ export default {
     this.initData();
   },
   methods: {
+
+    // 自定义上传
+    customUpload(options) {
+      const formData = new FormData();
+      for (const file of this.$refs.upload.uploadFiles) {
+        formData.append('files', file.raw);
+      }
+      formData.append('fileManagement', this.upload.formData.fileManagement);
+      // 上传文件
+      uploadFilesTenant(formData).then(response => {
+        options.onSuccess(response.data, options.file);
+      }).catch(error => {
+        options.onError(error);
+      });
+    },
+    handleSuccess(response, file, fileList) {
+      console.log('上传成功', response);
+    },
+    handleError(err, file, fileList) {
+      console.log('上传失败', err);
+    },
+    beforeUpload(file) {
+      console.log('上传文件之前', file);
+      return true; // 返回false会取消上传
+    },
+    submitUpload() {
+      this.upload.formData.fileManagement = JSON.stringify({fileType: this.filetype});
+      // 手动触发上传
+      this.$refs.upload.submit();
+    },
+
     initData() {
       //任务统计
       getTask().then((response) => {