diff --git a/src/main/java/com/gxwebsoft/cms/controller/CmsCaseController.java b/src/main/java/com/gxwebsoft/cms/controller/CmsCaseController.java index 1ac4f82..8e2752e 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/CmsCaseController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/CmsCaseController.java @@ -50,10 +50,6 @@ public class CmsCaseController extends BaseController { @Operation(summary = "添加客户案例") @PostMapping() public ApiResult save(@RequestBody CmsCase cmsCase) { - User loginUser = getLoginUser(); - if (loginUser != null) { - cmsCase.setUserId(loginUser.getUserId()); - } if (cmsCaseService.save(cmsCase)) { return success("添加成功"); } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/FileController.java b/src/main/java/com/gxwebsoft/common/system/controller/FileController.java index e61068d..84eea48 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/FileController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/FileController.java @@ -86,6 +86,50 @@ public class FileController extends BaseController { } } + @PreAuthorize("hasAuthority('sys:file:upload')") + @Operation(summary = "批量上传文件") + @PostMapping("/uploads") + public ApiResult> uploads(@RequestParam("files") MultipartFile[] files, + HttpServletRequest request) { + List list = new ArrayList<>(); + try { + String dir = getUploadDir(); + String requestURL = config.getFileServer() + "/api/file"; + // 云存储配置(与单文件上传保持一致) + final String s = redisUtil.get("setting:upload:" + getTenantId()); + final JSONObject jsonObject = JSONObject.parseObject(s); + final String uploadMethod = jsonObject == null ? "file" : jsonObject.getString("uploadMethod"); + final String bucketDomain = jsonObject == null ? "" : jsonObject.getString("bucketDomain"); + for (MultipartFile file : files) { + File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName()); + String path = upload.getAbsolutePath().replace("\\", "/").substring(dir.length() - 1); + String originalName = file.getOriginalFilename(); + FileRecord result = new FileRecord(); + result.setCreateUserId(getLoginUserId()); + result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName); + result.setLength(upload.length()); + result.setPath(path); + String contentType = FileServerUtil.getContentType(upload); + result.setContentType(contentType); + if (FileServerUtil.isImage(contentType)) { + result.setThumbnail(requestURL + "/thumbnail" + path); + } + result.setDownloadUrl(config.getFileServer() + "/download" + path); + String finalPath = path; + if (uploadMethod != null && !"file".equals(uploadMethod)) { + finalPath = bucketDomain + path; + } + result.setUrl(finalPath); + fileRecordService.save(result); + list.add(result); + } + return success(list); + } catch (Exception e) { + e.printStackTrace(); + return fail("上传失败", list).setError(e.toString()); + } + } + @PreAuthorize("hasAuthority('sys:file:upload')") @Operation(summary = "上传base64文件") @PostMapping("/upload/base64")