提交修改
This commit is contained in:
1 parent
bc70052bf8
commit
82ecb8621d
3 files changed
+190
-25
No files matched your search
+51
-8
@@ -22,6 +22,7 @@ import org.dromara.hq.domain.vo.HqPmRepairAttachmentVo;
|
||||
import org.dromara.hq.mapper.HqPmRepairAttachmentMapper;
|
||||
import org.dromara.hq.mapper.HqPmRepairOrderMapper;
|
||||
import org.dromara.hq.service.IHqPmRepairAttachmentService;
|
||||
import org.dromara.system.service.ISysOssService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -44,6 +45,7 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
|
||||
|
||||
private final HqPmRepairAttachmentMapper baseMapper;
|
||||
private final HqPmRepairOrderMapper repairOrderMapper;
|
||||
private final ISysOssService sysOssService;
|
||||
|
||||
/**
|
||||
* 查询报修附件
|
||||
@@ -160,11 +162,31 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
|
||||
for (HqPmRepairAttachmentVo attachment : attachments) {
|
||||
try {
|
||||
if (StringUtils.isNotBlank(attachment.getFilePath())) {
|
||||
OssFactory.instance().delete(attachment.getFilePath());
|
||||
// 从文件路径中提取ossId
|
||||
String filePath = attachment.getFilePath();
|
||||
if (filePath.contains("/resource/oss/download/")) {
|
||||
String ossIdStr = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
try {
|
||||
Long ossId = Long.parseLong(ossIdStr);
|
||||
sysOssService.deleteWithValidByIds(List.of(ossId), true);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法从文件路径中解析ossId: {}", filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 删除缩略图
|
||||
if (StringUtils.isNotBlank(attachment.getThumbnailPath())) {
|
||||
OssFactory.instance().delete(attachment.getThumbnailPath());
|
||||
// 从缩略图路径中提取ossId
|
||||
String thumbnailPath = attachment.getThumbnailPath();
|
||||
if (thumbnailPath.contains("/resource/oss/download/")) {
|
||||
String ossIdStr = thumbnailPath.substring(thumbnailPath.lastIndexOf("/") + 1);
|
||||
try {
|
||||
Long ossId = Long.parseLong(ossIdStr);
|
||||
sysOssService.deleteWithValidByIds(List.of(ossId), true);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法从缩略图路径中解析ossId: {}", thumbnailPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("删除OSS文件失败: {}", e.getMessage());
|
||||
@@ -196,14 +218,15 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
|
||||
String contentType = file.getContentType();
|
||||
long fileSize = file.getSize();
|
||||
|
||||
// 上传文件到OSS
|
||||
UploadResult uploadResult = OssFactory.instance().uploadSuffix(file.getBytes(), fileExtension, contentType);
|
||||
// 通过SysOssService上传文件,获取ossId
|
||||
var sysOssVo = sysOssService.upload(file);
|
||||
|
||||
// 构建附件信息
|
||||
HqPmRepairAttachmentBo bo = new HqPmRepairAttachmentBo();
|
||||
bo.setOrderId(orderId);
|
||||
bo.setFileName(originalFilename);
|
||||
bo.setFilePath(uploadResult.getUrl());
|
||||
// bo.setFilePath("/resource/oss/download/" + sysOssVo.getOssId());
|
||||
bo.setFilePath(sysOssVo.getOssId().toString());
|
||||
bo.setFileSize(fileSize);
|
||||
bo.setFileType(getFileType(contentType));
|
||||
bo.setFileExtension(fileExtension);
|
||||
@@ -220,7 +243,7 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
|
||||
} else {
|
||||
throw new RuntimeException("保存附件信息失败");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("上传附件失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("上传附件失败: " + e.getMessage());
|
||||
}
|
||||
@@ -265,10 +288,30 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
|
||||
// 删除OSS文件
|
||||
try {
|
||||
if (StringUtils.isNotBlank(attachment.getFilePath())) {
|
||||
OssFactory.instance().delete(attachment.getFilePath());
|
||||
// 从文件路径中提取ossId
|
||||
String filePath = attachment.getFilePath();
|
||||
if (filePath.contains("/resource/oss/download/")) {
|
||||
String ossIdStr = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
try {
|
||||
Long ossId = Long.parseLong(ossIdStr);
|
||||
sysOssService.deleteWithValidByIds(List.of(ossId), true);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法从文件路径中解析ossId: {}", filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(attachment.getThumbnailPath())) {
|
||||
OssFactory.instance().delete(attachment.getThumbnailPath());
|
||||
// 从缩略图路径中提取ossId
|
||||
String thumbnailPath = attachment.getThumbnailPath();
|
||||
if (thumbnailPath.contains("/resource/oss/download/")) {
|
||||
String ossIdStr = thumbnailPath.substring(thumbnailPath.lastIndexOf("/") + 1);
|
||||
try {
|
||||
Long ossId = Long.parseLong(ossIdStr);
|
||||
sysOssService.deleteWithValidByIds(List.of(ossId), true);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法从缩略图路径中解析ossId: {}", thumbnailPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("删除OSS文件失败: {}", e.getMessage());
|
||||
|
||||
Reference in new issue
Block a user