refactor(ops): 安保工单图片预签名下沉至 SecurityOrderExtQueryHandler
将 OrderCenterController 中的 presignExtInfoImageUrls 方法移除, 预签名逻辑下沉至 SecurityOrderExtQueryHandler 数据组装阶段, 通过 OssPresignHelper 就地处理 imageUrl 和 resultImgUrls。 security-biz 新增 infra-api 依赖,RpcConfiguration 注册 FileApi。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
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;
|
||||
@@ -25,9 +23,7 @@ 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;
|
||||
|
||||
@@ -47,8 +43,6 @@ public class OrderCenterController {
|
||||
|
||||
@Resource
|
||||
private OrderQueryService orderQueryService;
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
|
||||
@Autowired(required = false)
|
||||
private CleanDashboardService cleanDashboardService;
|
||||
@@ -69,10 +63,7 @@ public class OrderCenterController {
|
||||
@Parameter(name = "id", description = "工单ID", required = true)
|
||||
@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);
|
||||
return success(orderQueryService.getDetail(id));
|
||||
}
|
||||
|
||||
@GetMapping("/stats")
|
||||
@@ -135,43 +126,4 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.viewsh.module.ops.framework.rpc.config;
|
||||
|
||||
import com.viewsh.module.infra.api.file.FileApi;
|
||||
import com.viewsh.module.iot.api.device.IotDeviceControlApi;
|
||||
import com.viewsh.module.iot.api.device.IotDeviceQueryApi;
|
||||
import com.viewsh.module.iot.api.device.IotDeviceStatusQueryApi;
|
||||
@@ -12,7 +13,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
NotifyMessageSendApi.class,
|
||||
IotDeviceControlApi.class,
|
||||
IotDeviceQueryApi.class,
|
||||
IotDeviceStatusQueryApi.class
|
||||
IotDeviceStatusQueryApi.class,
|
||||
FileApi.class
|
||||
})
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
||||
@@ -31,6 +31,13 @@
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 依赖 infra-api:使用文件预签名 -->
|
||||
<dependency>
|
||||
<groupId>com.viewsh</groupId>
|
||||
<artifactId>viewsh-module-infra-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.viewsh</groupId>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.viewsh.module.ops.security.service.securityorder;
|
||||
|
||||
import com.viewsh.module.infra.api.file.FileApi;
|
||||
import com.viewsh.module.infra.api.file.OssPresignHelper;
|
||||
import com.viewsh.module.ops.dal.dataobject.workorder.OpsOrderDO;
|
||||
import com.viewsh.module.ops.security.dal.dataobject.workorder.OpsOrderSecurityExtDO;
|
||||
import com.viewsh.module.ops.security.dal.mysql.workorder.OpsOrderSecurityExtMapper;
|
||||
@@ -27,6 +29,8 @@ public class SecurityOrderExtQueryHandler implements OrderExtQueryHandler {
|
||||
|
||||
@Resource
|
||||
private OpsOrderSecurityExtMapper securityExtMapper;
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
|
||||
private static final String ORDER_TYPE_SECURITY = WorkOrderTypeEnum.SECURITY.getType();
|
||||
|
||||
@@ -88,12 +92,12 @@ public class SecurityOrderExtQueryHandler implements OrderExtQueryHandler {
|
||||
extInfo.put("alarmType", ext.getAlarmType());
|
||||
extInfo.put("cameraId", ext.getCameraId());
|
||||
extInfo.put("roiId", ext.getRoiId());
|
||||
extInfo.put("imageUrl", ext.getImageUrl());
|
||||
extInfo.put("imageUrl", OssPresignHelper.presignQuietly(fileApi, ext.getImageUrl()));
|
||||
extInfo.put("assignedUserId", ext.getAssignedUserId());
|
||||
extInfo.put("assignedUserName", ext.getAssignedUserName());
|
||||
extInfo.put("assignedTeamId", ext.getAssignedTeamId());
|
||||
extInfo.put("result", ext.getResult());
|
||||
extInfo.put("resultImgUrls", ext.getResultImgUrls());
|
||||
extInfo.put("resultImgUrls", OssPresignHelper.presignJsonArrayQuietly(fileApi, ext.getResultImgUrls()));
|
||||
extInfo.put("dispatchedTime", ext.getDispatchedTime());
|
||||
extInfo.put("confirmedTime", ext.getConfirmedTime());
|
||||
extInfo.put("completedTime", ext.getCompletedTime());
|
||||
|
||||
Reference in New Issue
Block a user