Browse Source

印尼项目-红外数据获取及规则设置

master
王寅 8 months ago
parent
commit
a6b457f206
4 changed files with 346 additions and 20 deletions
  1. +111
    -14
      inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java
  2. +18
    -0
      inspect-ivs/src/main/java/com/inspect/ivs/domain/Temp.java
  3. +108
    -0
      inspect-ivs/src/main/java/com/inspect/ivs/domain/TempConfiguration.java
  4. +109
    -6
      inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java

+ 111
- 14
inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java View File

@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.inspect.base.core.constant.Color; import com.inspect.base.core.constant.Color;
import com.inspect.base.core.domain.Response; import com.inspect.base.core.domain.Response;
import com.inspect.base.core.exception.ServiceException;
import com.inspect.ivs.base.feign.view.SipbDeviceListView; import com.inspect.ivs.base.feign.view.SipbDeviceListView;
import com.inspect.ivs.constant.IvsConst; import com.inspect.ivs.constant.IvsConst;
import com.inspect.ivs.domain.Temp;
import com.inspect.ivs.domain.TempConfiguration;
import com.inspect.ivs.service.IvsCommonService; import com.inspect.ivs.service.IvsCommonService;
import com.inspect.ivs.util.UriUtils; import com.inspect.ivs.util.UriUtils;
import com.inspect.ivs.view.IvsPlatformSnapshotView; import com.inspect.ivs.view.IvsPlatformSnapshotView;
@ -16,15 +17,10 @@ import com.inspect.ivs.vo.IvsDevChanListVo;
import com.inspect.ivs.vo.IvsDevChanSnapVo; import com.inspect.ivs.vo.IvsDevChanSnapVo;
import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@ -34,12 +30,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping({"/api/v1/device"}) @RequestMapping({"/api/v1/device"})
@ -50,12 +42,117 @@ public class IvsDeviceController {
private String activeProfile; private String activeProfile;
@Value("${ivs.version:3800}") @Value("${ivs.version:3800}")
private String version; private String version;
@Value("${ivs.address}")
private String address;
private final IvsCommonService ivsCommonService; private final IvsCommonService ivsCommonService;
public IvsDeviceController(IvsCommonService ivsCommonService) { public IvsDeviceController(IvsCommonService ivsCommonService) {
this.ivsCommonService = ivsCommonService; this.ivsCommonService = ivsCommonService;
} }
/**
* 设置红外规则
*/
@PostMapping("/setHwConfig")
public String setHwConfig(@RequestBody TempConfiguration tempConfiguration) throws Exception {
JSONObject json = new JSONObject();
JSONObject configItem = new JSONObject();
List<Map<String, Object>> alarmSettingListEx = new ArrayList<>();
Map<String, Object> alarmSettings = new HashMap<>();
alarmSettings.put("preDuration", 0);
alarmSettings.put("preThreshold", 22);
alarmSettingListEx.add(alarmSettings);
//设置blockBodyTemp
List<Map<String, Object>> radiometryRuleExList = new ArrayList<>();
Map<String, Object> ruleItem = new HashMap<>();
ruleItem.put("blockBodyTemp", 0);//写死
ruleItem.put("reflectedTemp", 0);//写死
ruleItem.put("usefReflectedTemp", false);//写死
ruleItem.put("alarmSettingList", alarmSettingListEx);//写死
radiometryRuleExList.add(ruleItem);
// 设置 configItem
configItem.put("radiometryRuleExList", radiometryRuleExList);
List<Map<String, Object>> radiometryRuleList = new ArrayList<>();
JSONObject radiometryRule = new JSONObject();
Map<String, Object> localParam = new HashMap<>();
List<Map<String, Object>> alarmSettingList = new ArrayList<>();
Map<String, Object> alarmSetting = new HashMap<>();
radiometryRule.put("areaSubType", 1);//区域测温的子类型 1矩形
radiometryRule.put("enable", 1);//使能
radiometryRule.put("meterType", 3);//区域
radiometryRule.put("presetId", tempConfiguration.getPresetId());// 预置位id
radiometryRule.put("ruleId", 12);//自己取最大没人用的
radiometryRule.put("samplePeriod", 3);//
radiometryRule.put("name", tempConfiguration.getName());// 定义一个名字
//设置localParam
localParam.put("enable", 1);
localParam.put("objectDistance", 4);
localParam.put("objectEmissivity", 0.9700000286102295);
localParam.put("refalectedTemp", 25);
//设置alarmSettingList
alarmSetting.put("alarmCondition", 1);
alarmSetting.put("duration", 30);
alarmSetting.put("enable", 1);
alarmSetting.put("hysteresis", 0.10000000149011612);
alarmSetting.put("id", 0);
alarmSetting.put("resultType", 2);
alarmSetting.put("threshold", 20.1);
alarmSettingList.add(alarmSetting);
radiometryRule.put("alarmSettingList", alarmSettingList);
radiometryRule.put("localParam", localParam);
//
radiometryRule.put("polygonList", tempConfiguration.getPolygonList());
radiometryRuleList.add(radiometryRule);
configItem.put("radiometryRuleList", radiometryRuleList);
json.put("deviceCode", tempConfiguration.getCameraCode());//
json.put("configType", 500);//写死500
json.put("configItem", configItem);
System.out.println(json);
String message = JSON.toJSONString(json);
String resp = ivsCommonService.sendSSLPostString(address+"/device/setdeviceconfig", message);
return "0";
// JSONObject jsonObject = JSON.parseObject(resp);
// String resultCode = jsonObject.getString("resultCode");
// if(resultCode.equals("0")){
// return Response.ok();
// }
// return Response.fail();
}
/**
* 获取红外数据
* @param
* @return
* @throws Exception
*/
@PostMapping("/temper")
public Response temper(@RequestBody Temp temp){
String cameraCode = temp.getCameraCode(); //cameraCode摄像机编码
int presetId = temp.getPresetId(); //预设位ID
int ruleId = temp.getRuleId(); //规则ID 暂时写死取12就行
// int meterType = temp.getMeterType();
String requestMsg = "presetId=" + presetId+ "&" + "ruleId=" + ruleId + "&" + "meterType=" + 3;
//发送请求
String resp = ivsCommonService.sendsslGetCookie(address+"/device/radiometry-temper/"+cameraCode, requestMsg, "UTF-8");
JSONObject jsonObject = JSON.parseObject(resp);
String resultCode = jsonObject.getString("resultCode");
if(resultCode.equals("0")){
return Response.ok();
}
return Response.fail();
}
@GetMapping({"channelsnap"}) @GetMapping({"channelsnap"})
public ResponseEntity<InputStreamResource> channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { public ResponseEntity<InputStreamResource> channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception {
if (version.equals("1800")) { if (version.equals("1800")) {
@ -136,7 +233,7 @@ public class IvsDeviceController {
public byte[] Ivs1800channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { public byte[] Ivs1800channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception {
log.info("++++++++++++++++++++++++执行1800channelsnap截图接口++++++++++++++++++++++++++++++"); log.info("++++++++++++++++++++++++执行1800channelsnap截图接口++++++++++++++++++++++++++++++");
String url = "https://172.27.144.61:18531/snapshot/manualsnapshot";
String url = address+"/snapshot/manualsnapshot";
Map<String, Object> controlMap = new HashMap<>(); Map<String, Object> controlMap = new HashMap<>();
controlMap.put("cameraCode", ivsDevChanSnapVo.getCameraCode()); controlMap.put("cameraCode", ivsDevChanSnapVo.getCameraCode());
String requestMsg = JSON.toJSONString(controlMap); String requestMsg = JSON.toJSONString(controlMap);


+ 18
- 0
inspect-ivs/src/main/java/com/inspect/ivs/domain/Temp.java View File

@ -0,0 +1,18 @@
package com.inspect.ivs.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Temp {
private String cameraCode;
private int presetId;
private int ruleId;
private int meterType;
private String nvrcode;
}

+ 108
- 0
inspect-ivs/src/main/java/com/inspect/ivs/domain/TempConfiguration.java View File

@ -0,0 +1,108 @@
package com.inspect.ivs.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TempConfiguration {
private String cameraCode;
private Integer configType;
private Integer blockBodyTemp;
/**
* 测温使能
* 0: 不使能
* 1使能
*/
private Integer enable;
//预置点编号
private Integer presetId;
//规则编号
private Integer ruleId;
//自定义名称最大127字节
private String name;
/**
*温模式的类型
* 0未知
* 1
* 2线
* 3区域
*/
private Integer meterType;
//温度采样周期单位
private Integer samplePeriod;
/**
*区域测温的子类型
* 0未知
* 1矩形
* 2椭圆
* 3多边形
*/
private Integer areaSubType;
//是否启用本地配置
private Integer localEnable;
//目标辐射系数 浮点数 0~1
private float objectDistance;
//目标距离
private Integer objectEmissivity;
//标反射温度
private Integer refalectedTemp;
//
private List<Map<String, Object>> polygonList;
//报警唯一编号
//报警编号统一编码
private Integer id;
/**
* 是否开启该点报警
* 0去使能
* 1使能
*/
private Integer alarmEnable;
//下面是可选
/**
* 报警条件
* 0未知
* 1低于
* 2匹配
* 3高于
*/
private Integer alarmCondition;
//阈值温度持续时间 单位
private Integer duration;
//温度误差浮点数比如0.1 表示正负误差在0.1范围内
private float hysteresis;
/**
* 测温报警结果类型
* 0未知
* 1具体值
* 2最大
* 3最小
* 4平均
* 5标准
* 6中间
* 7ISO
*/
private Integer resultType;
//报警阈值温度(可选)
private Double threshold;
}

+ 109
- 6
inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java View File

@ -15,6 +15,7 @@ import java.io.*;
import java.net.*; import java.net.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.poi.ss.formula.functions.T; import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -157,7 +158,7 @@ public class IvsCommonService {
public <T> T postJson(Object requestParam, String uri, Class<T> clazz) { public <T> T postJson(Object requestParam, String uri, Class<T> clazz) {
String cookie = this.getCookie(); String cookie = this.getCookie();
JSONObject t = (JSONObject)((RequestBodySpec)this.http(HttpMethod.POST, uri).contentType(MediaType.APPLICATION_JSON).cookie("JSESSIONID", cookie)).bodyValue(requestParam).retrieve().bodyToMono(JSONObject.class).block();
JSONObject t = (JSONObject) ((RequestBodySpec) this.http(HttpMethod.POST, uri).contentType(MediaType.APPLICATION_JSON).cookie("JSESSIONID", cookie)).bodyValue(requestParam).retrieve().bodyToMono(JSONObject.class).block();
log.info("[CALL IVS] POST, Parameter:{}", JSONObject.toJSONString(requestParam)); log.info("[CALL IVS] POST, Parameter:{}", JSONObject.toJSONString(requestParam));
log.info("[CALL IVS] POST, Response:{}", t.toJSONString()); log.info("[CALL IVS] POST, Response:{}", t.toJSONString());
return this.checkResultCodeAndConvertResult(t, clazz); return this.checkResultCodeAndConvertResult(t, clazz);
@ -174,7 +175,7 @@ public class IvsCommonService {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
String urlNameString = url; String urlNameString = url;
// 定义一个通用的连接对象 // 定义一个通用的连接对象
HttpURLConnection conn= null;
HttpURLConnection conn = null;
try { try {
URL console = new URL(urlNameString); URL console = new URL(urlNameString);
SslUtils.ignoreSsl(); SslUtils.ignoreSsl();
@ -191,22 +192,77 @@ public class IvsCommonService {
out = conn.getOutputStream(); out = conn.getOutputStream();
out.write(param.getBytes()); out.write(param.getBytes());
out.flush(); out.flush();
try (InputStream is = conn.getInputStream()){
try (InputStream is = conn.getInputStream()) {
// log.info("返回sendssl方法"); // log.info("返回sendssl方法");
return readStream(is); return readStream(is);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
finally {
} finally {
if (conn != null) { if (conn != null) {
conn.disconnect(); conn.disconnect();
} }
} }
return null; return null;
} }
/**
* post请求
*
* @param url
* @param param
* @param Cookie
* @return
*/
public String sendSSLPostString(String url, String param) {
String Cookie = this.getCookie();
OutputStream out = null;
StringBuilder result = new StringBuilder();
String urlNameString = url;
// 定义一个通用的连接对象
HttpURLConnection conn;
try {
URL console = new URL(urlNameString);
SslUtils.ignoreSsl();
conn = (HttpsURLConnection) console.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Cookie", Cookie);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.connect();
out = conn.getOutputStream();
out.write(param.getBytes());
out.flush();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String ret = "";
while ((ret = br.readLine()) != null) {
if (ret != null && !"".equals(ret.trim())) {
result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
}
}
conn.disconnect();
br.close();
} catch (ConnectException e) {
log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e);
} catch (SocketTimeoutException e) {
log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e);
} catch (IOException e) {
log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e);
} catch (Exception e) {
log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e);
}
return result.toString();
}
public byte[] readStream(InputStream inStream) throws Exception { public byte[] readStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
@ -219,6 +275,53 @@ public class IvsCommonService {
// log.info("返回readStream方法{}" , outStream.toByteArray()); // log.info("返回readStream方法{}" , outStream.toByteArray());
return outStream.toByteArray(); return outStream.toByteArray();
} }
/**
* 向指定https URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数请求参数应该是 name1=value1&name2=value2 的形式
* @param contentType 编码类型
* @return 所代表远程资源的响应结果
*/
public String sendsslGetCookie(String url, String param, String contentType) {
String Cookie = this.getCookie();
StringBuilder result = new StringBuilder();
BufferedReader in = null;
try {
String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
URL realUrl = new URL(urlNameString);
SslUtils.ignoreSsl();
// URL realUrl = new URL(urlNameString);
// SslUtils.ignoreSsl();
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.setRequestProperty("Cookie", Cookie);
//添加自定义请求头
// 设置请求头
connection.connect();
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception ex) {
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
}
}
return result.toString();
}
public static void main(String[] args) { public static void main(String[] args) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject jsonObject


Loading…
Cancel
Save