feat(ops): 工单详情安保图片 URL 预签名支持
- OrderCenterController.getDetail 对 extInfo 中 imageUrl/resultImgUrls 生成预签名地址 - RPC 异常时降级返回原始 URL,避免接口整体失败 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.viewsh.module.ops.controller.admin;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.viewsh.framework.common.pojo.CommonResult;
|
||||
import com.viewsh.framework.common.pojo.PageResult;
|
||||
import com.viewsh.module.infra.api.file.FileApi;
|
||||
import com.viewsh.module.ops.api.clean.QuickStatsRespDTO;
|
||||
import com.viewsh.module.ops.controller.admin.workorder.vo.statistics.DashboardStatsRespVO;
|
||||
import com.viewsh.module.ops.controller.admin.workorder.vo.statistics.WorkspaceStatsRespVO;
|
||||
@@ -23,7 +25,9 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.viewsh.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@@ -43,6 +47,8 @@ public class OrderCenterController {
|
||||
|
||||
@Resource
|
||||
private OrderQueryService orderQueryService;
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
|
||||
@Autowired(required = false)
|
||||
private CleanDashboardService cleanDashboardService;
|
||||
@@ -64,6 +70,8 @@ public class OrderCenterController {
|
||||
@PreAuthorize("@ss.hasPermission('ops:order-center:query')")
|
||||
public CommonResult<OrderDetailVO> getDetail(@PathVariable("id") Long id) {
|
||||
OrderDetailVO detail = orderQueryService.getDetail(id);
|
||||
// 私有桶:对 extInfo 中的图片 URL 生成预签名访问地址
|
||||
presignExtInfoImageUrls(detail);
|
||||
return success(detail);
|
||||
}
|
||||
|
||||
@@ -127,4 +135,43 @@ public class OrderCenterController {
|
||||
return success(opsStatisticsService.getWorkspaceStats());
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 extInfo 中的图片 URL 生成预签名访问地址
|
||||
*/
|
||||
private void presignExtInfoImageUrls(OrderDetailVO detail) {
|
||||
if (detail == null || detail.getExtInfo() == null) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> extInfo = detail.getExtInfo();
|
||||
// imageUrl:单个告警截图
|
||||
Object imageUrl = extInfo.get("imageUrl");
|
||||
if (imageUrl instanceof String url && StrUtil.isNotEmpty(url)) {
|
||||
try {
|
||||
extInfo.put("imageUrl", fileApi.presignGetUrl(url, null).getCheckedData());
|
||||
} catch (Exception e) {
|
||||
log.warn("[presignExtInfoImageUrls] imageUrl 签名失败: {}", url, e);
|
||||
}
|
||||
}
|
||||
// resultImgUrls:处理结果图片,JSON 数组字符串 如 ["url1","url2"]
|
||||
Object resultImgUrls = extInfo.get("resultImgUrls");
|
||||
if (resultImgUrls instanceof String urlsJson && StrUtil.isNotEmpty(urlsJson)) {
|
||||
try {
|
||||
List<String> urls = cn.hutool.json.JSONUtil.toList(urlsJson, String.class);
|
||||
List<String> signedUrls = urls.stream()
|
||||
.map(u -> {
|
||||
try {
|
||||
return fileApi.presignGetUrl(u, null).getCheckedData();
|
||||
} catch (Exception e) {
|
||||
log.warn("[presignExtInfoImageUrls] resultImgUrl 签名失败: {}", u, e);
|
||||
return u;
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
extInfo.put("resultImgUrls", cn.hutool.json.JSONUtil.toJsonStr(signedUrls));
|
||||
} catch (Exception e) {
|
||||
log.warn("[presignExtInfoImageUrls] 解析 resultImgUrls 失败: {}", resultImgUrls, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user