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 @@