|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.inspect.ivs.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.inspect.base.core.constant.Color; |
|
|
|
import com.inspect.base.core.domain.Response; |
|
|
|
@ -14,9 +15,9 @@ import com.inspect.ivs.vo.IvsChanSnapVo; |
|
|
|
import com.inspect.ivs.vo.IvsDevChanListVo; |
|
|
|
import com.inspect.ivs.vo.IvsDevChanSnapVo; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.*; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.TimerTask; |
|
|
|
import java.util.concurrent.Callable; |
|
|
|
@ -33,6 +34,8 @@ import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.core.io.InputStreamResource; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
@ -45,7 +48,8 @@ public class IvsDeviceController { |
|
|
|
|
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
private String activeProfile; |
|
|
|
|
|
|
|
@Value("${ivs.version:3800}") |
|
|
|
private String version; |
|
|
|
private final IvsCommonService ivsCommonService; |
|
|
|
|
|
|
|
public IvsDeviceController(IvsCommonService ivsCommonService) { |
|
|
|
@ -54,53 +58,68 @@ public class IvsDeviceController { |
|
|
|
|
|
|
|
@GetMapping({"channelsnap"}) |
|
|
|
public ResponseEntity<InputStreamResource> channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { |
|
|
|
int index = 0; |
|
|
|
final int TRY_TIMES = 3; |
|
|
|
final long mDelay = 3000; |
|
|
|
while (index < TRY_TIMES) { |
|
|
|
log.info(Color.MAGENTA + "[IVS] SNAPSHOT: {}, TRY TIMES: {}" + Color.END, ivsDevChanSnapVo.getCameraCode(), index); |
|
|
|
try { |
|
|
|
IvsSnapshotView ivsSnapshotView = ivsCommonService.get(UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); |
|
|
|
IvsChanSnapVo ivsChanSnapVo = new IvsChanSnapVo(ivsDevChanSnapVo.getCameraCode(), |
|
|
|
ivsDevChanSnapVo.getDomainCode(), |
|
|
|
ivsSnapshotView.getTaskID() |
|
|
|
); |
|
|
|
|
|
|
|
if ("prod".equals(activeProfile)) { |
|
|
|
log.info("[IVS] prod env get stream delay 9000ms"); |
|
|
|
Thread.sleep(9000L); |
|
|
|
} else { |
|
|
|
Thread.sleep(2000L); |
|
|
|
} |
|
|
|
if (version.equals("1800")) { |
|
|
|
byte[] bytes = Ivs1800channelSnap(ivsDevChanSnapVo); |
|
|
|
String filePath = "/home/1.JPG"; // 替换为你想保存图片的本地路径 |
|
|
|
try (FileOutputStream fos = new FileOutputStream(filePath)) { |
|
|
|
fos.write(bytes); |
|
|
|
log.info("图片已成功保存到本地:" + filePath); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.info("保存图片时出现错误:" + e.getMessage()); |
|
|
|
} |
|
|
|
// byte[] bytes = readStream(content); |
|
|
|
InputStream inputStream = new ByteArrayInputStream(bytes); |
|
|
|
return ResponseEntity.ok().body(new InputStreamResource(inputStream)); |
|
|
|
} else { |
|
|
|
int index = 0; |
|
|
|
|
|
|
|
final int TRY_TIMES = 3; |
|
|
|
final long mDelay = 3000; |
|
|
|
while (index < TRY_TIMES) { |
|
|
|
log.info(Color.MAGENTA + "[IVS] SNAPSHOT: {}, TRY TIMES: {}" + Color.END, ivsDevChanSnapVo.getCameraCode(), index); |
|
|
|
try { |
|
|
|
IvsSnapshotView ivsSnapshotView = ivsCommonService.get(UriUtils.parse(IvsConst.URI_PLATFORM_SNAPSHOT, ivsDevChanSnapVo), IvsSnapshotView.class); |
|
|
|
IvsChanSnapVo ivsChanSnapVo = new IvsChanSnapVo(ivsDevChanSnapVo.getCameraCode(), |
|
|
|
ivsDevChanSnapVo.getDomainCode(), |
|
|
|
ivsSnapshotView.getTaskID() |
|
|
|
); |
|
|
|
|
|
|
|
if ("prod".equals(activeProfile)) { |
|
|
|
log.info("[IVS] prod env get stream delay 9000ms"); |
|
|
|
Thread.sleep(9000L); |
|
|
|
} else { |
|
|
|
Thread.sleep(2000L); |
|
|
|
} |
|
|
|
|
|
|
|
IvsPlatformSnapshotView snapShotView = ivsCommonService.postJson( |
|
|
|
ivsChanSnapVo, |
|
|
|
IvsConst.URI_SNAPSHOT_LIST, |
|
|
|
IvsPlatformSnapshotView.class); |
|
|
|
if (snapShotView != null && snapShotView.getSnapshotInfoList() != null |
|
|
|
&& snapShotView.getSnapshotInfoList().getSnapshotInfos() != null |
|
|
|
&& !snapShotView.getSnapshotInfoList().getSnapshotInfos().isEmpty()) { |
|
|
|
String cameraCode = snapShotView.getSnapshotInfoList().getSnapshotInfos().get(0).getCameraCode(); |
|
|
|
String pictureUrl = snapShotView.getSnapshotInfoList().getSnapshotInfos().get(0).getPictureUrl(); |
|
|
|
log.info(Color.MAGENTA + "[IVS] TRYS: {}, SNAPSHOT cameraCode: {}, pictureUrl: {}" + Color.END, index, cameraCode, pictureUrl); |
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
HttpResponse httpResponse = httpClient.execute(new HttpGet(pictureUrl)); |
|
|
|
InputStream content = httpResponse.getEntity().getContent(); |
|
|
|
byte[] bytes = readStream(content); |
|
|
|
InputStream inputStream = new ByteArrayInputStream(bytes); |
|
|
|
log.info(Color.MAGENTA + "[IVS] tries: {}, pictureUrl: {}, size: {} END" + Color.END, index, pictureUrl, bytes.length); |
|
|
|
return ResponseEntity.ok().body(new InputStreamResource(inputStream)); |
|
|
|
IvsPlatformSnapshotView snapShotView = ivsCommonService.postJson( |
|
|
|
ivsChanSnapVo, |
|
|
|
IvsConst.URI_SNAPSHOT_LIST, |
|
|
|
IvsPlatformSnapshotView.class); |
|
|
|
if (snapShotView != null && snapShotView.getSnapshotInfoList() != null |
|
|
|
&& snapShotView.getSnapshotInfoList().getSnapshotInfos() != null |
|
|
|
&& !snapShotView.getSnapshotInfoList().getSnapshotInfos().isEmpty()) { |
|
|
|
String cameraCode = snapShotView.getSnapshotInfoList().getSnapshotInfos().get(0).getCameraCode(); |
|
|
|
String pictureUrl = snapShotView.getSnapshotInfoList().getSnapshotInfos().get(0).getPictureUrl(); |
|
|
|
log.info(Color.MAGENTA + "[IVS] TRYS: {}, SNAPSHOT cameraCode: {}, pictureUrl: {}" + Color.END, index, cameraCode, pictureUrl); |
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
HttpResponse httpResponse = httpClient.execute(new HttpGet(pictureUrl)); |
|
|
|
InputStream content = httpResponse.getEntity().getContent(); |
|
|
|
byte[] bytes = readStream(content); |
|
|
|
InputStream inputStream = new ByteArrayInputStream(bytes); |
|
|
|
log.info(Color.MAGENTA + "[IVS] tries: {}, pictureUrl: {}, size: {} END" + Color.END, index, pictureUrl, bytes.length); |
|
|
|
return ResponseEntity.ok().body(new InputStreamResource(inputStream)); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn(Color.MAGENTA + "[IVS] SNAPSHOT EXCEPTION: {}" + Color.END, e.getMessage()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn(Color.MAGENTA + "[IVS] SNAPSHOT EXCEPTION: {}" + Color.END, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
index++; |
|
|
|
Thread.sleep(mDelay); |
|
|
|
index++; |
|
|
|
Thread.sleep(mDelay); |
|
|
|
} |
|
|
|
return ResponseEntity.ok().body(null); |
|
|
|
} |
|
|
|
|
|
|
|
return ResponseEntity.ok().body(null); |
|
|
|
} |
|
|
|
|
|
|
|
public byte[] readStream(InputStream inStream) throws Exception { |
|
|
|
@ -115,6 +134,17 @@ public class IvsDeviceController { |
|
|
|
return outStream.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
public byte[] Ivs1800channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { |
|
|
|
log.info("++++++++++++++++++++++++执行1800channelsnap截图接口++++++++++++++++++++++++++++++"); |
|
|
|
String url = "https://172.27.144.61:18531/snapshot/manualsnapshot"; |
|
|
|
Map<String, Object> controlMap = new HashMap<>(); |
|
|
|
controlMap.put("cameraCode", ivsDevChanSnapVo.getCameraCode()); |
|
|
|
String requestMsg = JSON.toJSONString(controlMap); |
|
|
|
// byte[] bytes = ivsCommonService.sendSSLPost(url, requestMsg); |
|
|
|
// log.info("++++++++++++++++++++++++执行1800channelsnap截图接口++++++++++++++++++++++++++++++ :{}"+bytes); |
|
|
|
return ivsCommonService.sendSSLPost(url, requestMsg); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @GetMapping({"channelsnap"}) |
|
|
|
// public Response channelSnap(IvsDevChanSnapVo sipbDeviceChannelSnapVo, HttpServletResponse httpServletResponse) throws Exception { |
|
|
|
@ -184,42 +214,42 @@ public class IvsDeviceController { |
|
|
|
return sum; |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
Timer timer = new Timer(); |
|
|
|
|
|
|
|
// 创建一个Callable任务 |
|
|
|
Callable<Integer> task = new Callable<Integer>() { |
|
|
|
@Override |
|
|
|
public Integer call() throws Exception { |
|
|
|
int sum = 0; |
|
|
|
for (int i = 1; i <= 10; i++) { |
|
|
|
System.out.println("i:" + i); |
|
|
|
sum += i; |
|
|
|
} |
|
|
|
return sum; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 将Callable任务包装成FutureTask |
|
|
|
FutureTask<Integer> futureTask = new FutureTask<>(task); |
|
|
|
|
|
|
|
// 设置定时任务 |
|
|
|
timer.schedule(new TimerTask() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
futureTask.run(); |
|
|
|
} |
|
|
|
}, 1000); |
|
|
|
|
|
|
|
try { |
|
|
|
// 获取定时任务的返回结果 |
|
|
|
int result = futureTask.get(); |
|
|
|
System.out.println("定时任务的返回结果是:" + result); |
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
timer.cancel(); |
|
|
|
System.out.println("定时任务的返回结果是"); |
|
|
|
} |
|
|
|
// public static void main(String[] args) { |
|
|
|
// Timer timer = new Timer(); |
|
|
|
// |
|
|
|
// // 创建一个Callable任务 |
|
|
|
// Callable<Integer> task = new Callable<Integer>() { |
|
|
|
// @Override |
|
|
|
// public Integer call() throws Exception { |
|
|
|
// int sum = 0; |
|
|
|
// for (int i = 1; i <= 10; i++) { |
|
|
|
// System.out.println("i:" + i); |
|
|
|
// sum += i; |
|
|
|
// } |
|
|
|
// return sum; |
|
|
|
// } |
|
|
|
// }; |
|
|
|
// |
|
|
|
// // 将Callable任务包装成FutureTask |
|
|
|
// FutureTask<Integer> futureTask = new FutureTask<>(task); |
|
|
|
// |
|
|
|
// // 设置定时任务 |
|
|
|
// timer.schedule(new TimerTask() { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
// futureTask.run(); |
|
|
|
// } |
|
|
|
// }, 1000); |
|
|
|
// |
|
|
|
// try { |
|
|
|
// // 获取定时任务的返回结果 |
|
|
|
// int result = futureTask.get(); |
|
|
|
// System.out.println("定时任务的返回结果是:" + result); |
|
|
|
// } catch (InterruptedException | ExecutionException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// timer.cancel(); |
|
|
|
// System.out.println("定时任务的返回结果是"); |
|
|
|
// } |
|
|
|
} |