|
|
@@ -0,0 +1,65 @@
|
|
|
+package com.etotem.cfc.controller;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.service.AicdsDetectionService;
|
|
|
+import com.etotem.cfc.util.ParamUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 爱云医 AI 检测接入层控制器(转发代理),能力键 {@code ai.aiyunyi.controller}(S-cfc-474)。
|
|
|
+ *
|
|
|
+ * <p>按设计 §4.1:以 {@code POST /api/aiyunyi/**} 统一收口爱云医前端请求,控制器只做
|
|
|
+ * 「取参 → 调服务编排 → 包 {@link Result}」,不直接操作 Mapper / 不绕过服务层直连第三方。
|
|
|
+ * 鉴权复用 {@code JwtInterceptor}({@code /api/aiyunyi/**} 已纳入登录门),本类再通过
|
|
|
+ * {@code @RequestAttribute("role")} 做角色闸门(双层防线)。</p>
|
|
|
+ *
|
|
|
+ * <p>错误归一(§4.5):服务层异常一律归一为 {@code Result.error},不把原始异常/第三方报文直出前端。</p>
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/aiyunyi")
|
|
|
+public class AicdsController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AicdsDetectionService aicdsDetectionService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 照片/视频检测统一入口:{@code POST /api/aiyunyi/detect}(§5 检测时序入口)。
|
|
|
+ *
|
|
|
+ * <p>控制器仅取参并转发给编排宿主,检测编排细节由服务层负责。</p>
|
|
|
+ *
|
|
|
+ * @param params 业务参数(detectionPackageItemId / detectionReportUserId 等)
|
|
|
+ * @param role JwtInterceptor 注入的登录角色,anonymous/空白一律 403
|
|
|
+ * @return 统一 {@code Result} 契约
|
|
|
+ */
|
|
|
+ @PostMapping("/detect")
|
|
|
+ public Result<Object> detect(@RequestBody(required = false) Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAllowedRole(role)) {
|
|
|
+ return Result.forbidden("无权限调用爱云医检测");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ long packageItemId = ParamUtils.getLong(params == null ? null : params.get("detectionPackageItemId"), 0L);
|
|
|
+ long reportUserId = ParamUtils.getLong(params == null ? null : params.get("detectionReportUserId"), 0L);
|
|
|
+ // 统一经编排服务转发(§4.1 分层),控制器不直连网关或第三方。
|
|
|
+ Object data = aicdsDetectionService.detectVideo(packageItemId, reportUserId);
|
|
|
+ return Result.success(data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("爱云医检测调用失败: {}", e.getMessage());
|
|
|
+ return Result.error("爱云医检测调用失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 角色闸门:仅已登录角色可调用;anonymous / 空白角色拒绝(JwtInterceptor 登录门之外的第二道防线)。 */
|
|
|
+ private boolean isAllowedRole(String role) {
|
|
|
+ return role != null && !role.trim().isEmpty() && !"anonymous".equalsIgnoreCase(role.trim());
|
|
|
+ }
|
|
|
+}
|