diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java b/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java index 4c54eca..10aa8c9 100644 --- a/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java +++ b/inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java @@ -4,9 +4,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.inspect.base.core.constant.Color; 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.constant.IvsConst; +import com.inspect.ivs.domain.Temp; +import com.inspect.ivs.domain.TempConfiguration; import com.inspect.ivs.service.IvsCommonService; import com.inspect.ivs.util.UriUtils; import com.inspect.ivs.view.IvsPlatformSnapshotView; @@ -16,15 +17,10 @@ import com.inspect.ivs.vo.IvsDevChanListVo; import com.inspect.ivs.vo.IvsDevChanSnapVo; import java.io.*; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; 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.client.methods.HttpGet; @@ -34,12 +30,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; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping({"/api/v1/device"}) @@ -50,12 +42,117 @@ public class IvsDeviceController { private String activeProfile; @Value("${ivs.version:3800}") private String version; + @Value("${ivs.address}") + private String address; private final IvsCommonService ivsCommonService; public IvsDeviceController(IvsCommonService ivsCommonService) { this.ivsCommonService = ivsCommonService; } + + /** + * 设置红外规则 + */ + @PostMapping("/setHwConfig") + public String setHwConfig(@RequestBody TempConfiguration tempConfiguration) throws Exception { + JSONObject json = new JSONObject(); + JSONObject configItem = new JSONObject(); + List> alarmSettingListEx = new ArrayList<>(); + Map alarmSettings = new HashMap<>(); + alarmSettings.put("preDuration", 0); + alarmSettings.put("preThreshold", 22); + alarmSettingListEx.add(alarmSettings); + //设置blockBodyTemp + List> radiometryRuleExList = new ArrayList<>(); + Map 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> radiometryRuleList = new ArrayList<>(); + JSONObject radiometryRule = new JSONObject(); + Map localParam = new HashMap<>(); + List> alarmSettingList = new ArrayList<>(); + Map 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"}) public ResponseEntity channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { if (version.equals("1800")) { @@ -136,7 +233,7 @@ public class IvsDeviceController { public byte[] Ivs1800channelSnap(IvsDevChanSnapVo ivsDevChanSnapVo) throws Exception { log.info("++++++++++++++++++++++++执行1800channelsnap截图接口++++++++++++++++++++++++++++++"); - String url = "https://172.27.144.61:18531/snapshot/manualsnapshot"; + String url = address+"/snapshot/manualsnapshot"; Map controlMap = new HashMap<>(); controlMap.put("cameraCode", ivsDevChanSnapVo.getCameraCode()); String requestMsg = JSON.toJSONString(controlMap); diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/domain/Temp.java b/inspect-ivs/src/main/java/com/inspect/ivs/domain/Temp.java new file mode 100644 index 0000000..10ad50e --- /dev/null +++ b/inspect-ivs/src/main/java/com/inspect/ivs/domain/Temp.java @@ -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; +} diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/domain/TempConfiguration.java b/inspect-ivs/src/main/java/com/inspect/ivs/domain/TempConfiguration.java new file mode 100644 index 0000000..0e7caef --- /dev/null +++ b/inspect-ivs/src/main/java/com/inspect/ivs/domain/TempConfiguration.java @@ -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> 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:中间 + * 7:ISO + */ + private Integer resultType; + + //报警阈值温度(可选) + private Double threshold; + +} diff --git a/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java b/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java index 3179136..edf2031 100644 --- a/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java +++ b/inspect-ivs/src/main/java/com/inspect/ivs/service/IvsCommonService.java @@ -15,6 +15,7 @@ import java.io.*; import java.net.*; import java.nio.charset.StandardCharsets; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.poi.ss.formula.functions.T; import org.slf4j.Logger; @@ -157,7 +158,7 @@ public class IvsCommonService { public T postJson(Object requestParam, String uri, Class clazz) { 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, Response:{}", t.toJSONString()); return this.checkResultCodeAndConvertResult(t, clazz); @@ -174,7 +175,7 @@ public class IvsCommonService { StringBuilder result = new StringBuilder(); String urlNameString = url; // 定义一个通用的连接对象 - HttpURLConnection conn= null; + HttpURLConnection conn = null; try { URL console = new URL(urlNameString); SslUtils.ignoreSsl(); @@ -191,22 +192,77 @@ public class IvsCommonService { out = conn.getOutputStream(); out.write(param.getBytes()); out.flush(); - try (InputStream is = conn.getInputStream()){ + try (InputStream is = conn.getInputStream()) { // log.info("返回sendssl方法"); return readStream(is); } catch (Exception e) { e.printStackTrace(); } - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); - } - finally { + } finally { if (conn != null) { conn.disconnect(); } } 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 { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; @@ -219,6 +275,53 @@ public class IvsCommonService { // log.info("返回readStream方法{}" , 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) { JSONObject jsonObject = new JSONObject(); jsonObject