From 5197b10d4e840c23e36e5ae43af3150819039290 Mon Sep 17 00:00:00 2001 From: shanao <178391389@qq.com> Date: Sun, 8 Sep 2024 22:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accident/AccidentRecordsController.java | 19 +++++++++- .../accident/AccidentRecordsService.java | 7 ++++ .../impl/AccidentRecordsServiceImpl.java | 5 +++ .../accident/AccidentRecordsMapper.xml | 38 +++++++++---------- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java index 39644d59..78fa1773 100644 --- a/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java +++ b/src/main/java/com/zcloud/controller/accident/AccidentRecordsController.java @@ -140,7 +140,7 @@ public class AccidentRecordsController extends BaseController { * @return 是否成功 */ @RequestMapping("/import/photos") - public Map importPhotos(@RequestParam("file") MultipartFile file) { + public Map importPhotos(@RequestParam MultipartFile file) { if (file == null || file.isEmpty()) { throw new RuntimeException("文件不能为空"); } @@ -150,6 +150,23 @@ public class AccidentRecordsController extends BaseController { return result; } + /** + * 删除图片 + * + * @param path 文件路径 + * @return 是否成功 + */ + @RequestMapping("/delete/photos/{path}") + public Map deletePhotos(@PathVariable("path") String path) { + if (StrUtil.isEmpty(path)) { + throw new RuntimeException("路径不能为空"); + } + accidentRecordsService.deletePhotos(path); + Map result = new HashMap<>(); + result.put("result", "success"); // 路径 + return result; + } + /** * 查看图片 * diff --git a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java index a87167a9..0ccf466f 100644 --- a/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java +++ b/src/main/java/com/zcloud/service/accident/AccidentRecordsService.java @@ -77,4 +77,11 @@ public interface AccidentRecordsService { * @param response 响应 */ void viewPhotos(String path, HttpServletResponse response); + + /** + * 删除图片 + * + * @param path 路径 + */ + void deletePhotos(String path); } diff --git a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java index a3bfe6b0..11aedceb 100644 --- a/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java +++ b/src/main/java/com/zcloud/service/accident/impl/AccidentRecordsServiceImpl.java @@ -179,4 +179,9 @@ public class AccidentRecordsServiceImpl implements AccidentRecordsService { } ServletUtil.write(response, FileUtil.touch(path)); } + + @Override + public void deletePhotos(String path) { + FileUtil.del("./image/" + path); + } } diff --git a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml index ac15f802..3c926481 100644 --- a/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml +++ b/src/main/resources/mybatis/datasource/accident/AccidentRecordsMapper.xml @@ -34,26 +34,26 @@