|
|
|
@ -17,6 +17,8 @@ import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.core.io.InputStreamResource; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.retry.annotation.Backoff; |
|
|
|
@ -24,6 +26,7 @@ import org.springframework.retry.annotation.Recover; |
|
|
|
import org.springframework.retry.annotation.Retryable; |
|
|
|
import org.springframework.retry.support.RetrySynchronizationManager; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.StreamUtils; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
@ -33,6 +36,8 @@ import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@Component |
|
|
|
@ -43,6 +48,9 @@ public class IvsResourceRetryableDelegate { |
|
|
|
|
|
|
|
private static final int RETRYABLE_MAX = 20; |
|
|
|
|
|
|
|
@Value("${task.test-mode:false}") |
|
|
|
private boolean testMode; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private IvsCommonService ivsCommonService; |
|
|
|
|
|
|
|
@ -50,11 +58,16 @@ public class IvsResourceRetryableDelegate { |
|
|
|
value = IOException.class, |
|
|
|
maxAttempts = RETRYABLE_MAX, |
|
|
|
backoff = @Backoff(delay = 2000)) // 每次重试间隔 2 秒 |
|
|
|
public Response<Void> gotoSnapshotPresetRetryable(String version, IvsPresetVo ivsPresetVo) throws IOException{ |
|
|
|
public Response<Void> 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()); |
|
|
|
log.info("URI_PTZ_CONTROL GOTO: retryCount: {}, UUID: {}, CODE: {}, ID: {}, NAME: {}", |
|
|
|
retryCount, |
|
|
|
ivsPresetVo.getUUID(), |
|
|
|
ivsPresetVo.getCameraCode(), |
|
|
|
ivsPresetVo.getPatrolPointId(), |
|
|
|
ivsPresetVo.getPresetName()); |
|
|
|
JSONObject paramJson = new JSONObject(); |
|
|
|
paramJson.put("cameraCode", ivsPresetVo.getCameraCode()); |
|
|
|
log.debug("URI_PTZ_CONTROL GOTO: IVS VERSION: {}", version); |
|
|
|
@ -89,10 +102,21 @@ public class IvsResourceRetryableDelegate { |
|
|
|
int retryCount = RetrySynchronizationManager.getContext() != null |
|
|
|
? RetrySynchronizationManager.getContext().getRetryCount() + 1 |
|
|
|
: 1; |
|
|
|
log.info("URI_PLATFORM_SNAPSHOT retryCount: {}, UUID: {}", retryCount, ivsDevChanSnapVo.getUUID()); |
|
|
|
log.info("URI_PLATFORM_SNAPSHOT retryCount: {}, UUID: {}, ID: {}, NAME: {}", |
|
|
|
retryCount, |
|
|
|
ivsDevChanSnapVo.getUUID(), |
|
|
|
ivsDevChanSnapVo.getPatrolPointId(), |
|
|
|
ivsDevChanSnapVo.getPresetName()); |
|
|
|
IvsSnapshotView ivsSnapshotView; |
|
|
|
try { |
|
|
|
ivsSnapshotView = ivsCommonService.get(ivsDevChanSnapVo.getUUID(), UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); |
|
|
|
Set<String> ignoredKeys = new HashSet<>(); |
|
|
|
ignoredKeys.add("uUID"); |
|
|
|
ignoredKeys.add("presetName"); |
|
|
|
ignoredKeys.add("patrolPointId"); |
|
|
|
final String uri = UriUtils.parseIgnored(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo, ignoredKeys); |
|
|
|
//ivsSnapshotView = ivsCommonService.get(ivsDevChanSnapVo.getUUID(), UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); |
|
|
|
log.info("URI_PLATFORM_SNAPSHOT retryCount: {}, UUID: {}, URI: {}", retryCount, ivsDevChanSnapVo.getUUID(), uri); |
|
|
|
ivsSnapshotView = ivsCommonService.get(ivsDevChanSnapVo.getUUID(), uri, 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()); |
|
|
|
@ -117,10 +141,21 @@ public class IvsResourceRetryableDelegate { |
|
|
|
int retryCount = RetrySynchronizationManager.getContext() != null |
|
|
|
? RetrySynchronizationManager.getContext().getRetryCount() + 1 |
|
|
|
: 1; |
|
|
|
log.info("URI_SNAPSHOT_LIST retryCount: {}, UUID: {}", retryCount, ivsChanSnapVo.getUUID()); |
|
|
|
log.info("URI_SNAPSHOT_LIST retryCount: {}, UUID: {}, ID: {}, NAME: {}", |
|
|
|
retryCount, |
|
|
|
ivsChanSnapVo.getUUID(), |
|
|
|
ivsChanSnapVo.getPatrolPointId(), |
|
|
|
ivsChanSnapVo.getPresetName()); |
|
|
|
IvsPlatformSnapshotView snapShotView; |
|
|
|
try { |
|
|
|
snapShotView = ivsCommonService.postJson(ivsChanSnapVo.getUUID(), ivsChanSnapVo, IvsConst.URI_SNAPSHOT_LIST, IvsPlatformSnapshotView.class); |
|
|
|
ivsChanSnapVo.setUUID(null); |
|
|
|
ivsChanSnapVo.setPresetName(null); |
|
|
|
ivsChanSnapVo.setPatrolPointId(null); |
|
|
|
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()); |
|
|
|
@ -197,12 +232,25 @@ public class IvsResourceRetryableDelegate { |
|
|
|
try { |
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(bufferedImage, "png", os); |
|
|
|
return new ByteArrayInputStream(os.toByteArray()); |
|
|
|
byte[] bytes; |
|
|
|
if (testMode) { |
|
|
|
bytes = loadDefaultImage(); |
|
|
|
} else { |
|
|
|
bytes = os.toByteArray(); |
|
|
|
} |
|
|
|
return new ByteArrayInputStream(bytes); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException("生成错误图片失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public byte[] loadDefaultImage() throws IOException { |
|
|
|
ClassPathResource imgFile = new ClassPathResource("images/ivs_default.jpg"); |
|
|
|
return StreamUtils.copyToByteArray(imgFile.getInputStream()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getLabel() { |
|
|
|
return UUID.randomUUID().toString().trim().replaceAll(StringUtils.DASH, StringUtils.EMPTY); |
|
|
|
} |
|
|
|
|