diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java b/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java index 2d659a3..c4e6cf7 100644 --- a/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java +++ b/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java @@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.IOException; + @RestController @RequestMapping({"/api/v1/control"}) public class IvsControlController { @@ -31,6 +33,7 @@ public class IvsControlController { private final IvsResourceRetryableDelegate ivsResourceRetryableDelegate; @Value("${ivs.version:3800}") private String version; + public IvsControlController( RedisService redisService, IvsCommonService ivsCommonService, IvsResourceRetryableDelegate ivsResourceRetryableDelegate) { @@ -76,19 +79,27 @@ public class IvsControlController { redisService.setCacheMapValue(IvsConst.IVS_PRESET_MAP, ivsPresetVo.getPreset(), ivsPresetVo.getPreset()); return Response.ok(); } else if (command.equals("goto")) { - log.info("IVS_PRESET GOTO: {}, CameraCode: {}", ivsPresetVo.getCommand(), ivsPresetVo.getCameraCode()); - JSONObject paramJson = new JSONObject(); - paramJson.put("cameraCode", ivsPresetVo.getCameraCode()); - log.debug("============================VERSION {}", version); - if(version.equals("1800")){ - paramJson.put("controlCode", 11); - } else { - paramJson.put("controlCode", "11"); +// log.info("IVS_PRESET GOTO: {}, CameraCode: {}", ivsPresetVo.getCommand(), ivsPresetVo.getCameraCode()); +// JSONObject paramJson = new JSONObject(); +// paramJson.put("cameraCode", ivsPresetVo.getCameraCode()); +// log.debug("============================VERSION {}", version); +// if (version.equals("1800")) { +// paramJson.put("controlCode", 11); +// } else { +// paramJson.put("controlCode", "11"); +// } +// paramJson.put("controlPara1", ivsPresetVo.getPreset()); +// paramJson.put("controlPara2", ""); +// ivsCommonService.postJson(ivsResourceRetryableDelegate.getLabel(), paramJson, IvsConst.URI_PTZ_CONTROL, IvsResult.class); + try { + String uuid = ivsResourceRetryableDelegate.getLabel(); + log.info("URI_PTZ_CONTROL GOTO UUID: {}, CameraCode: {}", uuid, ivsPresetVo.getCameraCode()); + ivsPresetVo.setUUID(uuid); + return ivsResourceRetryableDelegate.gotoSnapshotPresetRetryable(version, ivsPresetVo); + } catch (IOException e) { + log.info("presetGoto UUID:{}, MSG: {}", ivsPresetVo.getUUID(), e.getMessage() + " final fail"); + return Response.fail(); } - paramJson.put("controlPara1", ivsPresetVo.getPreset()); - paramJson.put("controlPara2", ""); - ivsCommonService.postJson(ivsResourceRetryableDelegate.getLabel(), paramJson, IvsConst.URI_PTZ_CONTROL, IvsResult.class); - return Response.ok(); } else if (command.equals("remove")) { String code = ivsPresetVo.getCode(); String[] codeArray = code.split(StringUtils.HASHTAG); diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java b/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java index b451652..eec11b4 100644 --- a/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java +++ b/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsResourceRetryableDelegate.java @@ -1,12 +1,16 @@ package com.inspect.ivs.service; +import com.alibaba.fastjson.JSONObject; +import com.inspect.base.core.domain.Response; import com.inspect.base.core.utils.StringUtils; +import com.inspect.ivs.base.feign.domain.IvsResult; import com.inspect.ivs.constant.IvsConst; import com.inspect.ivs.util.UriUtils; import com.inspect.ivs.view.IvsPlatformSnapshotView; import com.inspect.ivs.view.IvsSnapshotView; import com.inspect.ivs.vo.IvsChanSnapVo; import com.inspect.ivs.vo.IvsDevChanSnapVo; +import com.inspect.ivs.vo.IvsPresetVo; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -42,6 +46,41 @@ public class IvsResourceRetryableDelegate { @Resource private IvsCommonService ivsCommonService; + @Retryable( + value = IOException.class, + maxAttempts = RETRYABLE_MAX, + backoff = @Backoff(delay = 2000)) // 每次重试间隔 2 秒 + public Response gotoSnapshotPresetRetryable(String version, IvsPresetVo ivsPresetVo) throws IOException{ + int retryCount = RetrySynchronizationManager.getContext() != null + ? RetrySynchronizationManager.getContext().getRetryCount() + 1 + : 1; + log.info("URI_PTZ_CONTROL GOTO: retryCount: {}, UUID: {}", retryCount, ivsPresetVo.getUUID()); + JSONObject paramJson = new JSONObject(); + paramJson.put("cameraCode", ivsPresetVo.getCameraCode()); + log.debug("URI_PTZ_CONTROL GOTO: IVS VERSION: {}", version); + if (version.equals("1800")) { + paramJson.put("controlCode", 11); + } else { + paramJson.put("controlCode", "11"); + } + paramJson.put("controlPara1", ivsPresetVo.getPreset()); + paramJson.put("controlPara2", ""); + try { + ivsCommonService.postJson(ivsPresetVo.getUUID(), paramJson, IvsConst.URI_PTZ_CONTROL, IvsResult.class); + } catch (Exception e) { + log.info("URI_PTZ_CONTROL GOTO FAIL retryCount: {}, UUID: {}", retryCount, ivsPresetVo.getUUID()); + throw new IOException("URI_PTZ_CONTROL GOTO: FAIL UUID: " + ivsPresetVo.getUUID() + ", retryCount: " + retryCount); + } + return Response.ok(); + } + + @SuppressWarnings("unused") + @Recover + public Response recover(IOException e, String version, IvsPresetVo ivsPresetVo) { + log.info("URI_PTZ_CONTROL GOTO RECOVER UUID: {}, MSG: {}", ivsPresetVo.getUUID(), e.getMessage()); + return Response.fail(); + } + @Retryable( value = IOException.class, maxAttempts = RETRYABLE_MAX, @@ -53,7 +92,7 @@ public class IvsResourceRetryableDelegate { log.info("URI_PLATFORM_SNAPSHOT retryCount: {}, UUID: {}", retryCount, ivsDevChanSnapVo.getUUID()); IvsSnapshotView ivsSnapshotView; try { - ivsSnapshotView = ivsCommonService.get(getLabel(), UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); + ivsSnapshotView = ivsCommonService.get(ivsDevChanSnapVo.getUUID(), UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); log.info("URI_PLATFORM_SNAPSHOT SUCCESS retryCount: {}, UUID: {}", retryCount, ivsDevChanSnapVo.getUUID()); } catch (Exception e) { log.info("URI_PLATFORM_SNAPSHOT FAIL retryCount: {}, UUID: {}", retryCount, ivsDevChanSnapVo.getUUID()); @@ -81,7 +120,7 @@ public class IvsResourceRetryableDelegate { log.info("URI_SNAPSHOT_LIST retryCount: {}, UUID: {}", retryCount, ivsChanSnapVo.getUUID()); IvsPlatformSnapshotView snapShotView; try { - snapShotView = ivsCommonService.postJson(getLabel(), ivsChanSnapVo, IvsConst.URI_SNAPSHOT_LIST, IvsPlatformSnapshotView.class); + snapShotView = ivsCommonService.postJson(ivsChanSnapVo.getUUID(), ivsChanSnapVo, IvsConst.URI_SNAPSHOT_LIST, IvsPlatformSnapshotView.class); log.info("URI_SNAPSHOT_LIST SUCCESS retryCount: {}, UUID: {}", retryCount, ivsChanSnapVo.getUUID()); } catch (Exception e) { log.info("URI_SNAPSHOT_LIST FAIL retryCount: {}, UUID: {}", retryCount, ivsChanSnapVo.getUUID()); diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/vo/IvsPresetVo.java b/inspect-ivs/src/main/java/com/inspect/ivs/vo/IvsPresetVo.java index 5c7c9dd..8daa291 100644 --- a/inspect-ivs/src/main/java/com/inspect/ivs/vo/IvsPresetVo.java +++ b/inspect-ivs/src/main/java/com/inspect/ivs/vo/IvsPresetVo.java @@ -13,6 +13,7 @@ public class IvsPresetVo implements Serializable { private String cameraCode; private String presetName; private int focusSwitch = 0; + private String UUID; public void setCode(String code) { this.cameraCode = this.code = code; @@ -86,6 +87,14 @@ public class IvsPresetVo implements Serializable { this.focusSwitch = focusSwitch; } + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + public boolean equals(Object o) { if(o == this) { return true; diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/constant/AnalyseConstants.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/constant/AnalyseConstants.java index e54d570..abfdc84 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/constant/AnalyseConstants.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/constant/AnalyseConstants.java @@ -40,4 +40,6 @@ public class AnalyseConstants { public static final String ALGORITHM_REQUEST_QUEUE = "algorithm:request:queue"; public static final String ALGORITHM_RESPONSE_QUEUE = "algorithm:response:queue"; + + public static final String LUMINOSITY_REQUEST_QUEUE = "luminosity:request:queue"; } diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java index 8f93977..cf71ab3 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java @@ -247,6 +247,12 @@ public class AnalysisServiceImpl implements IAnalysisService { analyseResult.getResultList().get(0).getResults().get(0).getType(), analyseResult ); + + // 发给光明大模型处理 + redisService.redisTemplate.opsForList().rightPush( + AnalyseConstants.LUMINOSITY_REQUEST_QUEUE, + new Gson().toJson(analyseRequest) + ); } analyseResult.setFilter("0"); // 设置大模型标志为0