|
@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
|
import cn.hutool.extra.qrcode.QrConfig;
|
|
@@ -59,6 +60,7 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -534,38 +536,52 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteByList(List<ScenePlus> plusList,Long userId) throws FileSystemException {
|
|
|
- HashMap<Long ,Long >cameraMap = new HashMap<>();
|
|
|
+ public void deleteByList(List<ScenePlus> plusList, List<String> reserve, boolean reserveSource) throws FileSystemException {
|
|
|
if(CollUtil.isEmpty(plusList)){
|
|
|
return;
|
|
|
}
|
|
|
List<Long> plusIds = plusList.parallelStream().map(ScenePlus::getId).collect(Collectors.toList());
|
|
|
HashMap<Long, ScenePlusExt> plusMap = scenePlusExtService.getByPlusIds(plusIds);
|
|
|
|
|
|
- for (ScenePlus scenePlus : plusList) {
|
|
|
- if(scenePlus.getCameraId()!= null && plusMap.get(scenePlus.getId())!=null){
|
|
|
- cameraMap.merge(scenePlus.getCameraId(), plusMap.get(scenePlus.getId()).getSpace(), Long::sum);
|
|
|
- }
|
|
|
- sceneDelLogService.saveLog(scenePlus.getNum(),userId);
|
|
|
- }
|
|
|
-
|
|
|
- //删除编辑和展示文件
|
|
|
- for (ScenePlus plus : plusList) {
|
|
|
- ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(plus.getId());
|
|
|
- String bucket = scenePlusExt.getYunFileBucket();
|
|
|
- ossUtil.deleteObject(bucket, String.format(UploadFilePath.VIEW_PATH, plus.getNum()));
|
|
|
- ossUtil.deleteObject(bucket, String.format(UploadFilePath.EDIT_PATH, plus.getNum()));
|
|
|
- }
|
|
|
scenePlusService.removeByIds(plusIds);
|
|
|
scenePlusExtService.removeByPlusIds(plusIds);
|
|
|
|
|
|
- //删除原始资源文件
|
|
|
- for (Long key : plusMap.keySet()) {
|
|
|
- ScenePlusExt ext = plusMap.get(key);
|
|
|
- if(StrUtil.isNotEmpty(ext.getDataSource()) && ext.getDataSource().length() > 5){
|
|
|
- FileUtil.del(ext.getDataSource());
|
|
|
+ ThreadUtil.execAsync(() -> {
|
|
|
+ //删除编辑和展示文件
|
|
|
+ for (ScenePlus plus : plusList) {
|
|
|
+ try {
|
|
|
+ ScenePlusExt scenePlusExt = plusMap.get(plus.getId());
|
|
|
+ String bucket = scenePlusExt.getYunFileBucket();
|
|
|
+ ossUtil.deleteObject(bucket, String.format(UploadFilePath.EDIT_PATH, plus.getNum()));
|
|
|
+ if(CollUtil.isEmpty(reserve)){
|
|
|
+ ossUtil.deleteObject(bucket, String.format(UploadFilePath.VIEW_PATH, plus.getNum()));
|
|
|
+ }else{
|
|
|
+ ossUtil.deleteObject(bucket, String.format(UploadFilePath.USER_VIEW_PATH, plus.getNum()));
|
|
|
+ List<String> viewFiles = ossUtil.listFiles(bucket, String.format(UploadFilePath.VIEW_PATH, plus.getNum()));
|
|
|
+ viewFiles.stream().forEach(key -> {
|
|
|
+ if(!reserve.stream().anyMatch(path -> key.contains(path))){
|
|
|
+ try {
|
|
|
+ ossUtil.deleteObject(bucket, key);
|
|
|
+ } catch (FileSystemException e) {
|
|
|
+ log.info("删除失败,key:{}", key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (FileSystemException e) {
|
|
|
+ log.error("删除场景展示数据失败, num:{}", plus.getNum(), e);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ //删除原始资源文件
|
|
|
+ if(!reserveSource){
|
|
|
+ for (Long key : plusMap.keySet()) {
|
|
|
+ ScenePlusExt ext = plusMap.get(key);
|
|
|
+ if(StrUtil.isNotEmpty(ext.getDataSource()) && ext.getDataSource().length() > 5){
|
|
|
+ FileUtil.del(ext.getDataSource());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|