diff --git a/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java b/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java index 8bdd6a1..2271451 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java @@ -32,7 +32,7 @@ @RequestMapping(value = "/getAIRecords") @ResponseBody public Object getAIRecords(@RequestBody @Valid AlarmAIDTO alarmAIDTO, BindingResult bindingResult) { - System.out.println(alarmAIDTO.getAlarmTime()+"---->"+alarmAIDTO.getAlarmType()+"---->"+alarmAIDTO.getNvrIp()); + logger.info(alarmAIDTO.getAlarmTime()+"---->"+alarmAIDTO.getAlarmType()+"---->"+alarmAIDTO.getNvrIp()); Assert.isFalse(bindingResult.hasErrors(), () -> { throw new BusinessException(CoreExceptionEnum.REQUEST_NULL.getCode(), bindingResult.getFieldError().getDefaultMessage()); }); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java b/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java index 8bdd6a1..2271451 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/system/controller/ReceptionController.java @@ -32,7 +32,7 @@ @RequestMapping(value = "/getAIRecords") @ResponseBody public Object getAIRecords(@RequestBody @Valid AlarmAIDTO alarmAIDTO, BindingResult bindingResult) { - System.out.println(alarmAIDTO.getAlarmTime()+"---->"+alarmAIDTO.getAlarmType()+"---->"+alarmAIDTO.getNvrIp()); + logger.info(alarmAIDTO.getAlarmTime()+"---->"+alarmAIDTO.getAlarmType()+"---->"+alarmAIDTO.getNvrIp()); Assert.isFalse(bindingResult.hasErrors(), () -> { throw new BusinessException(CoreExceptionEnum.REQUEST_NULL.getCode(), bindingResult.getFieldError().getDefaultMessage()); }); diff --git a/casic-server/src/main/java/com/casic/missiles/modular/system/service/impl/HCNetServiceImpl.java b/casic-server/src/main/java/com/casic/missiles/modular/system/service/impl/HCNetServiceImpl.java index 0b3cd0e..7c248cd 100644 --- a/casic-server/src/main/java/com/casic/missiles/modular/system/service/impl/HCNetServiceImpl.java +++ b/casic-server/src/main/java/com/casic/missiles/modular/system/service/impl/HCNetServiceImpl.java @@ -8,10 +8,12 @@ import com.casic.missiles.enums.StatusEnum; import com.casic.missiles.es.DataGasEs; import com.casic.missiles.exception.BusinessException; -import com.casic.missiles.model.response.ResponseData; import com.casic.missiles.modular.system.dto.*; import com.casic.missiles.modular.system.dto.monitor.MonitorBaseInfo; -import com.casic.missiles.modular.system.model.*; +import com.casic.missiles.modular.system.model.AlarmRecord; +import com.casic.missiles.modular.system.model.AlarmRule; +import com.casic.missiles.modular.system.model.BusMonipoiInfo; +import com.casic.missiles.modular.system.model.BusObserpoiInfo; import com.casic.missiles.modular.system.service.*; import com.casic.missiles.modular.system.task.AutoCruiseResertTask; import com.casic.missiles.modular.system.task.AutoCruiseTask; @@ -98,18 +100,9 @@ System.out.println("初始化失败"); return -1L; } - - //注册之前先注销已注册的用户,预览情况下不可注销 -// if (lUserID.longValue() > -1) { -// //先注销 -// hCNetSDK.NET_DVR_Logout(lUserID); -// lUserID = new NativeLong(-1); -// } - // 注册 HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30(); int iPort = 8000; - //System.out.println("注册,设备IP:"+deviceIp); NativeLong lUserID = hCNetSDK.NET_DVR_Login_V30(deviceIp, (short) iPort, userName, password, m_strDeviceInfo); long userId = lUserID.longValue(); if (userId <= -1) { @@ -186,7 +179,6 @@ if (ObjectUtil.isEmpty(serialHandle) || serialHandle < 0) { return false; } - // logger.info("send" + System.currentTimeMillis()); return hCNetSDK.NET_DVR_SerialSend(new NativeLong(serialHandle), new NativeLong(1), pointer, size); } @@ -221,16 +213,13 @@ DeviceInfo deviceInfo = DeviceCommom.selectByUserId(Long.valueOf(userId)); boolean stopRes = false; if (ObjectUtil.isNotEmpty(deviceInfo) && ObjectUtil.isNotEmpty(deviceInfo.getSerialHandle()) && deviceInfo.getSerialHandle() >= 0) { - try { stopRes = stopSerialHandle(deviceInfo.getSerialHandle()); Thread.sleep(300); } catch (Exception e) { e.printStackTrace(); } - } - logger.info("device control, serialHandle = " + deviceInfo.getSerialHandle()); boolean res = PTZControlAll(new NativeLong(userId), iPTZCommand, isStop, speed); if (stopRes) { serialHandle(deviceInfo.getUserId()); @@ -426,7 +415,6 @@ return serialSend(serialHandle, pointer, (int) ((Memory) pointer).getSize()); } - //宇视通 软复位 add 00 9C 00 00 SUM,add需要实时读取 private boolean softReset(Long serialHandle) { int sum = (0x01 + 0x00 + 0x9C + 0x00 + 0x00) % 0x100; @@ -435,7 +423,6 @@ return serialSend(serialHandle, pointer, (int) ((Memory) pointer).getSize()); } - @Override public boolean specialControl(Integer userId, String command, Integer value, Integer speed, Integer stopTime, Integer alarmValue) { Long serialHandle = serialHandle(Long.valueOf(userId)); @@ -455,7 +442,6 @@ case "93": return nodeConfig(serialHandle, value); case "94": -// return riskPointAngleSet(serialHandle, value); return riskPointAngleSetWhole(userId, serialHandle, value); case "95": return alarmTimeSet(serialHandle, value); @@ -464,10 +450,8 @@ case "97": return autoReset(serialHandle, value); case "99": -// return patrolSpeedSet(serialHandle, value); return patrolSpeedSetWhole(userId, serialHandle, value); case "9A": -// return patrolStopTimeSet(serialHandle, value); return patrolStopTimeSetWhole(userId, serialHandle, value); case "6592": return preset0(serialHandle); @@ -487,7 +471,6 @@ return false; } - /** * 宇视通设备一键清除预置点 * 调用65预置位,再调用136预置位 @@ -529,7 +512,6 @@ @Override public boolean interruptStart(String deviceIp) { - BusMonipoiInfo monipoiInfo = monipoiInfoService.selectByDeviceIp(deviceIp); if (ObjectUtil.isNotEmpty(monipoiInfo)) { return CommDoorUtil.interruptStart(monipoiInfo.getDoorIp(), monipoiInfo.getDoorSn()); @@ -679,8 +661,6 @@ default: break; } - -// serialHandle((long)userId); return res; } @@ -849,7 +829,6 @@ return false; } - /** * 插入预置点 */ @@ -915,13 +894,9 @@ } }); } - - //插入新建的预置点 int preset = (presetIndex + 1) == presets[0] ? presets[presets.length - 1] + 1 : presetIndex + 1; - if (DeviceTypeEnum.XST_TYPE.getCode().equals(baseInfo.getType())) { - if (setPreset(serialHandle, preset)) { try { Thread.sleep(300); @@ -1013,7 +988,6 @@ MonitorBaseInfo baseInfo = monipoiInfoService.selectInfoByDeviceIp(deviceInfo.getDeviceIp()); //廊坊设备新指令 if (baseInfo != null && DeviceTypeEnum.XST_TYPE.getCode().equals(baseInfo.getType())) { - try { //先停止 sendStopCommand(serialHandle); @@ -1023,7 +997,6 @@ e.printStackTrace(); return false; } - } else { if (ObjectUtil.isNotEmpty(deviceInfo)) { BusObserpoiInfo obserpoiInfo = obserpoiInfoService.selectByMonitorAndNum(baseInfo.getMonitorId(), presetIndex, cruiseRoute); @@ -1038,56 +1011,6 @@ return false; } } - - /** - * 将预置点添加到巡航路线(已废弃) - */ - private boolean addPresetToCruise(int realHandle, int presetIndex, int cruiseRoute, int speed, int stopTime) { - // 2.1 将预置点加入巡航序列 - boolean add = hCNetSDK.NET_DVR_PTZCruise(new NativeLong(realHandle), HCNetSDK.FILL_PRE_SEQ, (byte) cruiseRoute, (byte) presetIndex, (short) presetIndex); - if (add) { - // 2.2 设置巡航点停顿时间 - boolean dwell = hCNetSDK.NET_DVR_PTZCruise(new NativeLong(realHandle), HCNetSDK.SET_SEQ_DWELL, (byte) cruiseRoute, (byte) presetIndex, (short) stopTime); - if (dwell) { - // 2.3 设置巡航速度 - boolean sp = hCNetSDK.NET_DVR_PTZCruise(new NativeLong(realHandle), HCNetSDK.SET_SEQ_SPEED, (byte) cruiseRoute, (byte) presetIndex, (short) speed); - return sp; - } - } - return false; - } - - /** - * 从巡航路线中删除预置点(已废弃) - * sdk中的接口,从路线中删除一个预置点后,线路会失效 - * 所以删除后先转到当前存在的第一个预置点,并再次设置该预置点 - */ - private boolean deletePresetFromCruise(int userId, int realHandle, int presetIndex, int cruiseRoute) { - // 1.1 将预置点从巡航序列中删除 - boolean delete = hCNetSDK.NET_DVR_PTZCruise(new NativeLong(realHandle), HCNetSDK.CLE_PRE_SEQ, (byte) cruiseRoute, (byte) presetIndex, (short) presetIndex); - // 1.2 查询巡航路径中的预置点 - if (delete) { - HCNetSDK.NET_DVR_CRUISE_POINT firstPoints = getFirstPoints(userId); - if (ObjectUtil.isNotEmpty(firstPoints)) { - // 1.3 转到其中一个预置点 - boolean toPoint = toPreset(realHandle, firstPoints.PresetNum, cruiseRoute); - // 1.4 再次设置该预置点 - if (toPoint) { - try { - Thread.sleep(3 * 1000); - } catch (Exception e) { - e.printStackTrace(); - } - return addPresetToCruise(realHandle, firstPoints.PresetNum, 1, firstPoints.Speed, firstPoints.Dwell); - } - } else { - // 巡航路径中没有其他预置点,则返回true - return true; - } - } - return false; - } - /** * 开启或停止自动巡航 */ @@ -1123,7 +1046,6 @@ } break; case "stop": -// res = hCNetSDK.NET_DVR_PTZCruise(new NativeLong(realHandle), HCNetSDK.STOP_SEQ,(byte) cruiseRoute.intValue(),(byte)0,(byte)0); //廊坊新指令设备 if (null != baseInfo && DeviceTypeEnum.XST_TYPE.getCode().equals(baseInfo.getType())) { res = sendStopCommand(serialHandle); @@ -1145,7 +1067,6 @@ if (ObjectUtil.isEmpty(deviceInfo) || ObjectUtil.isEmpty(deviceInfo.getSerialHandle()) || deviceInfo.getSerialHandle() < 0) { return false; } - // 如果设备已启动自动巡航,不能再次启动 AutoCruiseTask checkTask = TaskCommon.threadMap.get(deviceInfo.getUserId()); if (ObjectUtil.isNotEmpty(checkTask) && checkTask.exit == false) { @@ -1179,19 +1100,6 @@ } return true; } - - private List getDefaultCruisePoints() { - List defaultPoints = new ArrayList<>(); - double pitch = -90; - while (pitch <= 90) { - defaultPoints.add(new BusObserpoiInfo(0.0, pitch, 0)); - defaultPoints.add(new BusObserpoiInfo(180.0, pitch, 0)); - defaultPoints.add(new BusObserpoiInfo(360.0, pitch, 0)); - pitch += 5; - } - return defaultPoints; - } - /** * 停止自动巡航,将对应task的退出标记设为true,退出线程 */ @@ -1241,10 +1149,8 @@ * 水平绝对角度控制,指令格式:FF ADD 00 4B DATA1 DATA2 SUM 其中(DATA1<<8) + DATA2=角度*100 * 垂直绝对角度控制,指令格式:FF ADD 00 4D DATA1 DATA2 SUM,若角度为负,(DATA1<<8) + DATA2=角度*100;若角度为正,(DATA1<<8) + DATA2=36000-角度*100。 */ -// int i= 0; @Override public boolean setPosition(Long userId, Double horizontalAngle, Double verticalAngle) { - //与采集浓度指令错开 //若发送采集指令后控制指令发生在300ms内,则把控制指令延迟至采集指令后300ms if (ObjectUtil.isNotEmpty(this.getTimestampCollcect()) && this.getTimestampCollcect() > 0 && System.currentTimeMillis() - this.getTimestampCollcect() < 300) { @@ -1289,10 +1195,7 @@ logger.info("serical send vertical " + verticalAngle); boolean vres = serialSend(serialHandle, verticalPointer, (int) ((Memory) verticalPointer).getSize()); return hres & vres; - } - - /** * 指令格式:FF 01 00 4C DATA1 DATA2 DATA3 DATA4 SUM * 其中DATA1(高字节)DATA2(低字节)表示水平角度的100倍 @@ -1314,14 +1217,12 @@ } int vSum = (0x01 + 0x00 + 0x4c + hData1 + hData2 + vData1 + vData2) % 0x100; int[] Command = {0xff, 0x01, 0x00, 0x4c, hData1, hData2, vData1, vData2, vSum}; -// int[] Command = {0xff, 0x01, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x4d}; Pointer verticalPointer = intArrayToPointer(Command); logger.info("serical send horizon " + horizontalAngle + "-->serical send vertical " + verticalAngle); return serialSend(serialHandle, verticalPointer, (int) ((Memory) verticalPointer).getSize()); } - /** * int数组转为Pointer */ @@ -1332,8 +1233,6 @@ } return pointer; } - - /** * 透明通道数据回调函数 */ @@ -1344,7 +1243,6 @@ if (dwBufSize < 4) { return; } - // 读取回传数据 byte[] res = new byte[dwBufSize]; char[] chars = new char[dwBufSize]; @@ -1358,7 +1256,6 @@ } chars[i] = (char) res[i]; } - // 查询对应的设备信息,查询不到直接退出 DeviceInfo deviceInfo = DeviceCommom.selectBySerialHandle(lSerialHandle.longValue()); if (ObjectUtil.isEmpty(deviceInfo)) { @@ -1372,9 +1269,7 @@ } } } - private void handlegasDataFromGasData(DeviceInfo deviceInfo, Double gas, Double direction, Double pitch) { -// logger.info(deviceInfo.getDeviceIp().concat(" get vertical angle-->").concat(String.valueOf(pitch)).concat("+ get horizontal angle-->").concat(String.valueOf(direction)).concat("+ get gas data-->").concat(String.valueOf(gas))); System.out.println(new Date() + ":" + deviceInfo.getDeviceIp().concat(" get vertical angle-->").concat(String.valueOf(pitch)).concat("+ get horizontal angle-->").concat(String.valueOf(direction)).concat("+ get gas data-->").concat(String.valueOf(gas))); JSONObject msg = new JSONObject(); msg.put("deviceIp", deviceInfo.getDeviceIp()); @@ -1397,31 +1292,6 @@ webSocket.sendAllMessage(msg.toJSONString()); } - - /** - * 处理垂直角度返回数据 - */ - private void handleVerticalAngle(DeviceInfo deviceInfo, int[] data) { - int tmsb = (int) data[4]; - int tlsb = (int) data[5]; - int tData = tmsb * 256 + tlsb; - double verticalAngle; - if (tData > 18000) { - verticalAngle = (36000 - tData) / 100.0; - } else if (tData < 18000) { - verticalAngle = (0 - tData) / 100.0; - } else { - verticalAngle = tData / 100.0; - } - logger.info(deviceInfo.getDeviceIp().concat(" get vertical angle").concat(String.valueOf(verticalAngle))); - JSONObject msg = new JSONObject(); - msg.put("deviceIp", deviceInfo.getDeviceIp()); - msg.put("userId", deviceInfo.getUserId()); - msg.put("type", "verticalAngle"); - msg.put("value", verticalAngle); - webSocket.sendAllMessage(msg.toJSONString()); - } - /** * 处理甲烷浓度返回数据 */ @@ -1491,22 +1361,6 @@ } /** - * 甲烷数据保存mysql - */ - private DataGas insertDataGas(MonitorBaseInfo monitorBaseInfo, Double concentration, double direction, - double pitch) { - DataGas dataGas = new DataGas(); - dataGas.setMonitorId(monitorBaseInfo.getMonitorId()); - dataGas.setDeviceCode(monitorBaseInfo.getDevcode()); - dataGas.setConcentration(concentration); - dataGas.setDircetion(direction); - dataGas.setPitch(pitch); - dataGas.setLogtime(new Date()); - dataGasService.save(dataGas); - return dataGas; - } - - /** * 甲烷数据保存es */ private DataGasEs insertDataGasEs(MonitorBaseInfo monitorBaseInfo, Double concentration, double direction, @@ -1526,7 +1380,6 @@ return dataGasEs; } - /** * 生成报警(自动消警) */ @@ -1563,10 +1416,8 @@ if (monipoiInfoService.updateStatus(monitorBaseInfo.getDeviceIp(), StatusEnum.STATUS_ONLINE)) { this.sendDeviceStatusData(monitorBaseInfo.getDeviceIp(), "onLine"); } - // 自动消警(同一角度) - int count = alarmRecordService.clearByMonitor(dataGas.getMonitorId(), Double.valueOf(dataGas.getDirection()), Double.valueOf(dataGas.getPitch())); - if (count > 0) { + if ( alarmRecordService.clearByMonitor(dataGas.getMonitorId(), Double.valueOf(dataGas.getDirection()), Double.valueOf(dataGas.getPitch()))>0) { JSONObject msg = new JSONObject(); msg.put("type", "cancelAlarm"); msg.put("monitorId", dataGas.getMonitorId()); @@ -1576,15 +1427,11 @@ } } } - - /** * 生成报警(自动消警) */ private void insertGasAlarm(MonitorBaseInfo monitorBaseInfo, DataGasEs dataGas, Double threshold) { // 判断报警、消警 - //AlarmRule alarmRule = alarmRuleService.selectByMonitor(dataGas.getMonitorId()); - if (threshold != null && dataGas.getConcentration() > threshold) { boolean resumeFlag = false; // 报警,注意消警时限 @@ -1595,7 +1442,6 @@ query.eq("ALARM_PITCH", dataGas.getPitch()); query.isNotNull("RESUME_TIME"); List resumeList = alarmRecordService.list(query); - for (AlarmRecord alarmRecord : resumeList) { long min = (System.currentTimeMillis() - alarmRecord.getCancelTime().getTime()) / (1000 * 60); if (min < alarmRecord.getResumeTime()) { @@ -1659,7 +1505,6 @@ } } } - /** * 查询云台预置点(从设备sdk查询) */ @@ -1670,25 +1515,6 @@ HCNetSDK.NET_DVR_CRUISE_POINT[] points = ret.struCruisePoint; return points.length; } - - /** - * 查询云台第一个有效的预置点 - */ - private HCNetSDK.NET_DVR_CRUISE_POINT getFirstPoints(int userId) { - int cruiseRoute = 1; - HCNetSDK.NET_DVR_CRUISE_RET ret = new HCNetSDK.NET_DVR_CRUISE_RET(); - hCNetSDK.NET_DVR_GetPTZCruise(new NativeLong(userId), new NativeLong(1), new NativeLong(cruiseRoute), ret); - HCNetSDK.NET_DVR_CRUISE_POINT[] points = ret.struCruisePoint; - if (points.length > 0) { - for (int i = 0; i < points.length; i++) { - if (points[i].Speed > 0) { - return points[i]; - } - } - } - return null; - } - /** * 查询云台预置点(从数据库查询) */ @@ -1789,7 +1615,6 @@ e.printStackTrace(); } } - /** * 外协设备自检复位 * 调用65预置位,再调用92预置位,是强制重启功能; @@ -1816,15 +1641,12 @@ } return flag; } - - /** * 甲烷浓度全局阈值设置 * 先调用68号预置位,value预置位 设置浓度等于这个预置位数值乘以100,比如设置浓度阈值为5000则先调用68号预置位,再调用50号预置位; */ public boolean setWholeAlarmValue(Integer userId, Long serialHandle, int value) { - try { //全局变量阈值存库 DeviceInfo deviceInfo = DeviceCommom.selectByUserId(Long.valueOf(userId)); @@ -1965,7 +1787,6 @@ } return false; } - //实现全部有效预置位一起巡航,需要调用一次快捷预置位命令组合“65+126”,然后调用“70+1”便可以将所有有效预置位从小到大依次循环巡航 public boolean allCruise(Long serialHandle) { boolean flag = false; @@ -1993,8 +1814,6 @@ } return flag; } - - @Override public boolean preset(String deviceIp, Integer lineNum, String type) { Long userId = getUserIdByIp(deviceIp); @@ -2048,7 +1867,6 @@ } return userId; } - @Override public void globalSet(GlobalParamsDTO globalParamsDTO) { BusMonipoiInfo monipoiInfo = monipoiInfoService.getById(globalParamsDTO.getId());