From 7c07f7dfd09d094bdb5472aeec2d090f78d02730 Mon Sep 17 00:00:00 2001 From: liuxiao <1732399289qq.com> Date: Wed, 7 Aug 2024 15:54:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=89=87=E4=B8=8A=E4=BC=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysOssController.java | 64 +++++++++++-------- .../com/ruoyi/official/domain/GwIndex.java | 6 ++ .../domain/bo/FileChunkFilelistBo.java | 2 - .../ruoyi/official/domain/bo/GwIndexBo.java | 5 ++ .../ruoyi/official/domain/vo/GwIndexVo.java | 5 ++ .../impl/FileChunkFilelistServiceImpl.java | 2 +- 6 files changed, 55 insertions(+), 29 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java index efc4adf..b3ddff3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java @@ -98,40 +98,52 @@ public class SysOssController extends BaseController { */ @Log(title = "本地文件上传", businessType = BusinessType.INSERT) @PostMapping("/addPartsUpload") - public R> addPartsUpload(@RequestPart("file") MultipartFile file, HttpServletRequest req) { - Map map=new HashMap<>(); - String realPath = req.getSession().getServletContext().getRealPath("/uploadFile/"); - String format = sdf.format(new Date()); - ///www/wwwroot/guanwang/web/image/file/upload/ - // String filePath=uploadPath+"/file/upload/"; - File folder = new File(realPath + format); - if (!folder.isDirectory()){ - folder.mkdirs(); - } - String oldName = file.getOriginalFilename(); - String newName = UUID.randomUUID().toString() + oldName.substring(oldName.lastIndexOf("."), oldName.length()); + public R> addPartsUpload(@RequestPart("file") MultipartFile file) { + Map map = new HashMap<>(); + + String filePath = uploadPath + "/file/upload/"; try { - file.transferTo(new File(realPath,newName)); - String filePath = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + "/uploadFile" + format + newName; - Long image = iSysImageService.uploadImage(newName,filePath); - map.put("url",filePath); - map.put("fileName",newName); - map.put("ossId",image.toString()); + if (file.isEmpty()) { + return R.warn("文件为空"); + } + + String fileName = System.currentTimeMillis() + "-" + file.getOriginalFilename(); + //文件上传的路径(当前项目的根目录) + + System.err.println(filePath); + // 创建目标目录(如果不存在) + File directory = new File(filePath); + if (!directory.exists()) { + directory.mkdirs(); + } + // 保存文件到目标目录 + File uploadFile = new File(directory.getAbsolutePath() + File.separator + fileName); + file.transferTo(uploadFile); + //上传服务器地址 + String pathFan = filePath.replace("\\", "/"); + //filePath获取到的地址斜杠是“ \ ”的(单斜杠是特殊符号,得用双斜杠代替),得换成“ / ”才能访问到 + //返回全路径图片地址 + String returnPath = ("http://47.121.27.78:8008/upload/" + fileName).replace("\\", "/"); + //修改数据库 + Long image = iSysImageService.uploadImage(fileName, returnPath); + System.err.println("替换后:" + pathFan); + map.put("url", returnPath); + map.put("fileName", fileName); + map.put("ossId", image.toString()); return R.ok(map); - } catch (IOException ex) { - ex.printStackTrace(); + } catch (IOException e) { + return R.warn("文件上传失败: " + e); } - return R.warn("文件上传失败!"); } - /** - * 下载OSS对象 - * - * @param ossId OSS对象ID - */ + /** + * 下载OSS对象 + * + * @param ossId OSS对象ID + */ @SaCheckPermission("system:oss:download") @GetMapping("/download/{ossId}") public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException { diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java index 1a277f0..fb36f29 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java @@ -49,6 +49,12 @@ public class GwIndex extends BaseEntity { */ private String titleEnglish; + + /** + * 链接 + */ + private String twLink; + /** * 业务名称英文描述 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/FileChunkFilelistBo.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/FileChunkFilelistBo.java index 8df0e06..3a853e5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/FileChunkFilelistBo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/FileChunkFilelistBo.java @@ -60,13 +60,11 @@ public class FileChunkFilelistBo extends BaseEntity { /** * 创建者id */ - @NotNull(message = "创建者id不能为空", groups = { AddGroup.class, EditGroup.class }) private Long createUserId; /** * 更新者id */ - @NotNull(message = "更新者id不能为空", groups = { AddGroup.class, EditGroup.class }) private Long updateUserId; diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java index de1aec0..7c1aa45 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java @@ -40,6 +40,11 @@ public class GwIndexBo extends BaseEntity { */ private String fileType; + /** + * 链接 + */ + private String twLink; + /** * 业务类型 0:石油化工业务 1:基建业务 2:铁矿石业务 3:燃气业务 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java index e5df299..11cea12 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java @@ -59,6 +59,11 @@ public class GwIndexVo { @ExcelProperty(value = "业务名称") private String businessName; + /** + * 链接 + */ + private String twLink; + /** * 图片标题英文描述 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java index 4ee16a0..1bd14e6 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java @@ -310,7 +310,7 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService { } } catch (IOException e) { - log.error("合并出现错误:" + e.getMessage(), e); + log.error("合并出现错误:" + e); throw new RuntimeException("合并出现错误," + e.getMessage()); } }