From 7d56f64f5fc337a32d70dbfc537445ca1126129d Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 09 Feb 2022 14:32:54 +0800
Subject: [PATCH] 督办单加入事务注解
---
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java | 53 +++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 41 insertions(+), 12 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 8237bfa..7a6d770 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,13 +11,15 @@
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.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
-import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
-import java.io.FileNotFoundException;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -36,21 +38,19 @@
* @since 2022-01-12
*/
@Service
+@Slf4j
public class SupervisionServiceImpl extends ServiceImpl<SupervisionMapper, Supervision> implements SupervisionService {
@Autowired
private SupervisionMapper supervisionMapper;
@Override
+ @Transactional
public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
-
- String path = null;
- try {
- path = ResourceUtils.getURL("classpath:").getPath() + "static/img/";
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
+ //������jar���������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ //���jar������������������������������upload������������������������������������
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
Map<String, Object> result = new HashMap<>();
@@ -126,10 +126,13 @@
}
@Override
+ @Transactional
public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) {
- String path = this.getClass().getClassLoader()
- .getResource("").getFile() + "static/img/";
+ //������jar���������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ //���jar������������������������������upload������������������������������������
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
Map<String, Object> result = new HashMap<>();
@@ -165,4 +168,30 @@
supervisionMapper.updateById(supervision);
return result;
}
+
+ @Override
+ @Transactional
+ 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);
+
+
+ //���������������������������������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
+ for (String image : images) {
+ String realPath = path + File.separator + image;
+ File file = new File(realPath);
+ if (file.exists() && file.isFile()) {
+ file.delete();
+ }
+ }
+ }
}
--
Gitblit v1.8.0