|
|
|
@ -1,10 +1,15 @@
|
|
|
|
|
package com.os.ems.base.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
|
|
|
|
import com.os.common.config.RuoYiConfig;
|
|
|
|
|
import com.os.common.utils.DateUtils;
|
|
|
|
|
import com.os.common.utils.StringUtils;
|
|
|
|
|
import com.os.common.utils.uuid.IdUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import com.os.ems.base.mapper.EmsAlarmActionStepMapper;
|
|
|
|
@ -28,6 +33,12 @@ public class EmsAlarmActionStepServiceImpl implements IEmsAlarmActionStepService
|
|
|
|
|
@Autowired
|
|
|
|
|
private EmsAlarmActionStepImageMapper emsAlarmActionStepImageMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件上传路径配置
|
|
|
|
|
*/
|
|
|
|
|
private final String uploadPath = RuoYiConfig.getUploadPath();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询报警规则具体措施步骤
|
|
|
|
|
*
|
|
|
|
@ -143,7 +154,7 @@ public class EmsAlarmActionStepServiceImpl implements IEmsAlarmActionStepService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 1. 先删除该规则下的所有现有步骤和图片
|
|
|
|
|
// 1. 先删除该规则下的所有现有步骤和图片(包括物理文件)
|
|
|
|
|
List<EmsAlarmActionStep> existingSteps = emsAlarmActionStepMapper.selectEmsAlarmActionStepByRuleObjId(ruleObjId);
|
|
|
|
|
for (EmsAlarmActionStep existingStep : existingSteps) {
|
|
|
|
|
// 删除步骤关联的图片
|
|
|
|
@ -151,7 +162,12 @@ public class EmsAlarmActionStepServiceImpl implements IEmsAlarmActionStepService
|
|
|
|
|
imageQuery.setActionStepObjId(existingStep.getObjId());
|
|
|
|
|
List<EmsAlarmActionStepImage> existingImages = emsAlarmActionStepImageMapper.selectEmsAlarmActionStepImageList(imageQuery);
|
|
|
|
|
for (EmsAlarmActionStepImage image : existingImages) {
|
|
|
|
|
emsAlarmActionStepImageMapper.deleteEmsAlarmActionStepImageByObjId(image.getObjId());
|
|
|
|
|
try {
|
|
|
|
|
deleteImageFile(image.getImageUrl());
|
|
|
|
|
emsAlarmActionStepImageMapper.deleteEmsAlarmActionStepImageByObjId(image.getObjId());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("文件删除失败,导致事务回滚: " + e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 删除步骤
|
|
|
|
|
emsAlarmActionStepMapper.deleteEmsAlarmActionStepByObjId(existingStep.getObjId());
|
|
|
|
@ -188,4 +204,49 @@ public class EmsAlarmActionStepServiceImpl implements IEmsAlarmActionStepService
|
|
|
|
|
throw new RuntimeException("批量保存措施步骤失败: " + e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除图片物理文件
|
|
|
|
|
*
|
|
|
|
|
* @param imageUrl 图片URL
|
|
|
|
|
*/
|
|
|
|
|
private void deleteImageFile(String imageUrl) {
|
|
|
|
|
if (StringUtils.isEmpty(imageUrl) || StringUtils.isEmpty(uploadPath)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 解析图片URL,获取相对路径
|
|
|
|
|
// 例如:/profile/upload/2024/05/29/xxx.jpg -> upload/2024/05/29/xxx.jpg
|
|
|
|
|
String relativePath = null;
|
|
|
|
|
if (imageUrl.startsWith("/profile/")) {
|
|
|
|
|
relativePath = imageUrl.substring("/profile/".length());
|
|
|
|
|
} else if (imageUrl.contains("/upload/")) {
|
|
|
|
|
int uploadIndex = imageUrl.indexOf("/upload/");
|
|
|
|
|
relativePath = imageUrl.substring(uploadIndex + 1); // 去掉前面的"/"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(relativePath)) {
|
|
|
|
|
// URL解码,处理中文文件名
|
|
|
|
|
relativePath = URLDecoder.decode(relativePath, "UTF-8");
|
|
|
|
|
|
|
|
|
|
// 构建完整的文件路径
|
|
|
|
|
String fullPath = uploadPath + File.separator + relativePath.replace("/", File.separator);
|
|
|
|
|
File file = new File(fullPath);
|
|
|
|
|
|
|
|
|
|
if (file.exists() && file.isFile()) {
|
|
|
|
|
boolean deleted = file.delete();
|
|
|
|
|
if (deleted) {
|
|
|
|
|
System.out.println("成功删除图片文件: " + fullPath);
|
|
|
|
|
} else {
|
|
|
|
|
System.err.println("删除图片文件失败: " + fullPath);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("图片文件不存在,无需删除: " + fullPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("删除图片文件时发生异常: " + imageUrl + ", 错误信息: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|