package com.ruoyi.dataInterchange.controller;
|
|
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.dataInterchange.util.haikang.Artemis;
|
import com.ruoyi.dataInterchange.util.haikang.model.ExactCondition1;
|
import com.ruoyi.dataInterchange.util.haikang.model.FindCameraPageRequest;
|
import com.ruoyi.dataInterchange.util.haikang.model.FindVehicleByLicensePlateRequest;
|
import com.ruoyi.dataInterchange.util.haikang.model.PreviewURLsRequest;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.ArrayList;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2025/5/28 18:35
|
*/
|
@RestController
|
@RequestMapping(value = "/haikang")
|
public class HaiKangContent {
|
|
/**
|
* 根据车牌号获取海康实时视频预览地址
|
* @param vehicleLicensePlate
|
* @return
|
*/
|
@PostMapping("/getCarPreviewURLs")
|
public R<String> getCarPreviewURLs(@RequestParam("vehicleLicensePlate") String vehicleLicensePlate){
|
try {
|
FindVehicleByLicensePlateRequest findVehicleByLicensePlateRequest = new FindVehicleByLicensePlateRequest();
|
findVehicleByLicensePlateRequest.setVehicleLicensePlate(vehicleLicensePlate);
|
String vehicleByLicensePlate = Artemis.findVehicleByLicensePlate(findVehicleByLicensePlateRequest);
|
JSONObject jsonObject = JSONObject.parseObject(vehicleByLicensePlate);
|
String code = jsonObject.getString("code");
|
if(!"0".equals(code)){
|
return R.fail("获取海康实时视频预览地址失败");
|
}
|
JSONObject data = jsonObject.getJSONObject("data");
|
//车辆编号
|
String indexCode = data.getString("indexCode");
|
//主设备编号
|
String primaryDeviceIndexCode = data.getString("primaryDeviceIndexCode");
|
//根据车辆编号和设备编号获取监控点信息列表
|
FindCameraPageRequest findCameraPageRequest = new FindCameraPageRequest();
|
findCameraPageRequest.setPageNo(1);
|
findCameraPageRequest.setPageSize(1000);
|
ExactCondition1 exactCondition = new ExactCondition1();
|
exactCondition.setDeviceIndexCodes(new ArrayList<String>(){{
|
add(primaryDeviceIndexCode);
|
}});
|
exactCondition.setVehicleIndexCodes(new ArrayList<String>(){{
|
add(indexCode);
|
}});
|
findCameraPageRequest.setExactCondition(exactCondition);
|
String cameraPage = Artemis.findCameraPage(findCameraPageRequest);
|
jsonObject = JSONObject.parseObject(cameraPage);
|
code = jsonObject.getString("code");
|
if(!"0".equals(code)){
|
return R.fail("获取海康实时视频预览地址失败");
|
}
|
data = jsonObject.getJSONObject("data");
|
JSONArray list = data.getJSONArray("list");
|
//监控点编号
|
String indexCode1 = "";
|
for (int i = 0; i < list.size(); i++) {
|
com.alibaba.fastjson2.JSONObject jsonObject1 = list.getJSONObject(i);
|
String cameraName = jsonObject1.getString("cameraName");
|
if("驾驶位".equals(cameraName)){
|
indexCode1 = jsonObject1.getString("indexCode");
|
}
|
}
|
//根据监控点编号获取监控预览url
|
PreviewURLsRequest previewURLsRequest = new PreviewURLsRequest();
|
previewURLsRequest.setCameraIndexCode(indexCode1);
|
String s = Artemis.previewURLs(previewURLsRequest);
|
jsonObject = JSONObject.parseObject(s);
|
code = jsonObject.getString("code");
|
if(!"0".equals(code)){
|
return R.fail("获取海康实时视频预览地址失败");
|
}
|
data = jsonObject.getJSONObject("data");
|
String url = data.getString("url");
|
return R.ok(url);
|
}catch (Exception e){
|
return R.fail("获取海康实时视频预览地址失败");
|
}
|
}
|
|
}
|