From 4b1358aa1acf1da5b9f0791dee0c9149b4162963 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 18 Jan 2022 09:21:14 +0800
Subject: [PATCH] 图片删除测试
---
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java | 40 +++++++++++++++++++++++++++++++++++-----
1 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
index 1f2f3e2..e38adbc 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
@@ -11,11 +11,14 @@
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.FileUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -34,6 +37,7 @@
* @since 2022-01-12
*/
@Service
+@Slf4j
public class SupervisionServiceImpl extends ServiceImpl<SupervisionMapper, Supervision> implements SupervisionService {
@Autowired
@@ -41,10 +45,10 @@
@Override
public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
-
- String path = this.getClass().getClassLoader()
- .getResource("").getFile() + "static/img/";
- System.out.println("image path=>" + path);
+ //������jar���������������
+ ApplicationHome h = new ApplicationHome(getClass());
+ //���jar������������������������������upload������������������������������������
+ String path = h.getSource().getParentFile().toString() + "/static/img";
Map<String, Object> result = new HashMap<>();
@@ -123,7 +127,7 @@
public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) {
String path = this.getClass().getClassLoader()
- .getResource("").getFile() + "static/img/";
+ .getResource("").getFile() + "static/img";
Map<String, Object> result = new HashMap<>();
@@ -159,4 +163,30 @@
supervisionMapper.updateById(supervision);
return result;
}
+
+ @Override
+ public void deleteSupervision(Integer supervisionId) {
+ QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("id", "images").eq("id", supervisionId);
+ Supervision supervision = supervisionMapper.selectOne(queryWrapper);
+ String[] images = supervision.getImages().split(",");
+
+ //������������
+ supervision.setIsDelete(Constants.DELETE);
+ supervision.setImages(null);
+ supervisionMapper.updateById(supervision);
+
+
+ //���������������������������������������
+ String path = this.getClass().getClassLoader()
+ .getResource("").getFile() + "static/img";
+ for (String image : images) {
+ String realPath = path + File.separator + image;
+ File file = new File(realPath);
+ log.info(realPath);
+ if (file.exists() && file.isFile()) {
+ file.delete();
+ }
+ }
+ }
}
--
Gitblit v1.8.0