package com.ruoyi.fuzhou.service.impl;
|
|
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONObject;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.fuzhou.config.HikConfig;
|
import com.ruoyi.fuzhou.domain.CameraPTZ;
|
import com.ruoyi.fuzhou.domain.HikEvent;
|
import com.ruoyi.fuzhou.domain.HikEventObj;
|
import com.ruoyi.fuzhou.mapper.HikEventMapper;
|
import com.ruoyi.fuzhou.service.HikService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Service
|
public class HikServiceImpl extends ServiceImpl<HikEventMapper, HikEvent>
|
implements HikService {
|
@Autowired
|
private HikConfig hikConfig;
|
@Autowired
|
private HikEventMapper hikEventMapper;
|
|
@Override
|
public Map<String,Integer> getCameraOnline(String[] indexCodes){
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String onlineApi = ARTEMIS_PATH +
|
"/api/nms/v1/online/camera/get";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", onlineApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
Map<String,Integer> onlineMap = new LinkedHashMap<>();
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("indexCodes", indexCodes);
|
jsonBody.put("pageNo", 1);
|
jsonBody.put("pageSize", 999);
|
String body = jsonBody.toJSONString();
|
|
try {
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
JSONObject res = JSON.parseObject(result);
|
|
JSONObject data = res.getJSONObject("data");
|
JSONArray jsonArray = data.getJSONArray("list");
|
for (Object object : jsonArray){
|
String objJson = object.toString();
|
JSONObject jsonObject = JSON.parseObject(objJson);
|
if(jsonObject.get("indexCode")!=null && jsonObject.get("online")!=null){
|
onlineMap.put(jsonObject.getString("indexCode"),jsonObject.getIntValue("online"));
|
}
|
}
|
return onlineMap;
|
}catch (Exception e){
|
System.out.println(e.getMessage());
|
}
|
return onlineMap;
|
}
|
|
@Override
|
public JSONObject subByEventTypes(HikEventObj hikEventObj) throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String subEventApi = ARTEMIS_PATH +
|
"/api/eventService/v1/eventSubscriptionByEventTypes";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", subEventApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
JSONObject res = new JSONObject();
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("eventTypes",hikEventObj.getEventTypes());
|
jsonBody.put("eventDest", hikEventObj.getEventDest());
|
jsonBody.put("subType", hikEventObj.getSubType());
|
jsonBody.put("eventLvl", hikEventObj.getEventLvl());
|
String body = jsonBody.toJSONString();
|
|
try {
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
res = JSON.parseObject(result);
|
return res;
|
}catch (Exception e){
|
System.out.println(e.getMessage());
|
}
|
return res;
|
}
|
|
@Override
|
public JSONObject unSubByEventTypes(HikEventObj hikEventObj) throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String unSubEventApi = ARTEMIS_PATH +
|
"/api/eventService/v1/eventUnSubscriptionByEventTypes";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", unSubEventApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
JSONObject res = new JSONObject();
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("eventTypes",hikEventObj.getEventTypes());
|
|
String body = jsonBody.toJSONString();
|
|
try {
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
res = JSON.parseObject(result);
|
return res;
|
}catch (Exception e){
|
System.out.println(e.getMessage());
|
}
|
return res;
|
}
|
|
@Override
|
public JSONObject eventView() throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String eventApi = ARTEMIS_PATH +
|
"/api/eventService/v1/eventSubscriptionView";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", eventApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
JSONObject res = new JSONObject();
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
|
String body = jsonBody.toJSONString();
|
|
try {
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
res = JSON.parseObject(result);
|
return res;
|
}catch (Exception e){
|
System.out.println(e.getMessage());
|
}
|
return res;
|
}
|
|
@Override
|
public boolean saveInsert(HikEvent hikEvent){
|
int res = hikEventMapper.insert(hikEvent);
|
if(res != 0){
|
return true;
|
}else {
|
return false;
|
}
|
}
|
|
@Override
|
public TableDataInfo getList(HikEvent hikEvent) {
|
Integer offset = (hikEvent.getPageNum()-1)*hikEvent.getPageSize();
|
hikEvent.setOffset(offset);
|
List<HikEvent> list = hikEventMapper.getPageList(hikEvent);
|
Integer total = hikEventMapper.getTotal(hikEvent);
|
TableDataInfo tableDataInfo = new TableDataInfo();
|
tableDataInfo.setRows(list);
|
tableDataInfo.setTotal(total);
|
return tableDataInfo;
|
}
|
|
@Override
|
public JSONObject cameraCommand(CameraPTZ cameraPTZ) throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String urlApi = ARTEMIS_PATH +
|
"/api/video/v1/ptzs/controlling";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", urlApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", cameraPTZ.getCameraIndexCode());
|
jsonBody.put("action", cameraPTZ.getAction());
|
jsonBody.put("command", cameraPTZ.getCommand());
|
jsonBody.put("speed", cameraPTZ.getSpeed());
|
jsonBody.put("presetIndex", cameraPTZ.getPresetIndex());
|
|
String body = jsonBody.toJSONString();
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
JSONObject res = JSON.parseObject(result);
|
|
return res;
|
}
|
|
@Override
|
public String getCameraPreviewURL(String cameraName) throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String previewURLsApi = ARTEMIS_PATH +
|
"/api/video/v2/cameras/previewURLs";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
String cameraIndexCode = getCameraIndexCode(cameraName);
|
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", cameraIndexCode);
|
jsonBody.put("streamType", 0);
|
jsonBody.put("protocol", "ws");
|
jsonBody.put("transmode", 1);
|
jsonBody.put("expand", "transcode=0");
|
String body = jsonBody.toJSONString();
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
JSONObject res = JSON.parseObject(result);
|
|
JSONObject data = res.getJSONObject("data");
|
String url = data.getString("url");
|
|
return url;
|
}
|
|
private String getCameraIndexCode(String cameraName) throws Exception {
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String previewURLsApi = ARTEMIS_PATH +
|
"/api/resource/v2/camera/search";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("name", cameraName);
|
jsonBody.put("pageNo", 1);
|
jsonBody.put("pageSize", 10);
|
String body = jsonBody.toJSONString();
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
JSONObject res = JSON.parseObject(result);
|
JSONArray array = res.getJSONObject("data").getJSONArray("list");
|
JSONObject data = array.getJSONObject(0);
|
String cameraIndexCode = data.getString("indexCode");
|
|
return cameraIndexCode;
|
}
|
|
@Override
|
public String getCameraURL(String cameraIndexCode) throws Exception{
|
final String ARTEMIS_PATH = "/artemis";
|
/**
|
* STEP3:设置接口的URI地址
|
*/
|
final String previewURLsApi = ARTEMIS_PATH +
|
"/api/video/v2/cameras/previewURLs";
|
Map<String, String> path = new HashMap<String, String>(2) {
|
{
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
}
|
};
|
//组装参数
|
JSONObject jsonBody = new JSONObject();
|
jsonBody.put("cameraIndexCode", cameraIndexCode);
|
jsonBody.put("streamType", 0);
|
jsonBody.put("protocol", "ws");
|
jsonBody.put("transmode", 1);
|
jsonBody.put("expand", "transcode=0");
|
String body = jsonBody.toJSONString();
|
String result = hikConfig.hkpost(path, body);// post请求application/json类型参数
|
|
JSONObject res = JSON.parseObject(result);
|
|
JSONObject data = res.getJSONObject("data");
|
String url = data.getString("url");
|
|
return url;
|
}
|
|
// public static void main(String[] args) {
|
// String ipAddr = "10.3.10.66";
|
// try {
|
// InetAddress address = InetAddress.getByName(ipAddr);
|
// boolean res = address.isReachable(5000);
|
// if(res){
|
// System.out.println(ipAddr+"联通");
|
// }else {
|
// System.out.println(ipAddr+"不通");
|
// }
|
// }catch (Exception e){
|
// System.out.println(e.getMessage());
|
// }
|
//
|
// }
|
|
}
|