From 5d901b5e3f033e8b04e53420d68626cbd87431c8 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 06 五月 2022 10:12:34 +0800 Subject: [PATCH] 使用阿里代码规范。规范代码写法 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java | 102 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 92 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java index 434bbd4..addc431 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java @@ -1,8 +1,14 @@ package com.genersoft.iot.vmp.vmanager.gb28181.alarm; +import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.service.IDeviceAlarmService; import com.genersoft.iot.vmp.service.IGbStreamService; +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; @@ -31,7 +37,17 @@ @Autowired private IDeviceAlarmService deviceAlarmService; + @Autowired + private ISIPCommander commander; + + @Autowired + private ISIPCommanderForPlatform commanderForPlatform; + + @Autowired + private IVideoManagerStorage storage; + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private SimpleDateFormat formatForGB = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); /** * 鍒嗛〉鏌ヨ鎶ヨ @@ -69,16 +85,30 @@ @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime ) { - if (StringUtils.isEmpty(alarmPriority)) alarmPriority = null; - if (StringUtils.isEmpty(alarmMethod)) alarmMethod = null; - if (StringUtils.isEmpty(alarmType)) alarmType = null; - if (StringUtils.isEmpty(startTime)) startTime = null; - if (StringUtils.isEmpty(endTime)) endTime = null; + if (StringUtils.isEmpty(alarmPriority)) { + alarmPriority = null; + } + if (StringUtils.isEmpty(alarmMethod)) { + alarmMethod = null; + } + if (StringUtils.isEmpty(alarmType)) { + alarmType = null; + } + if (StringUtils.isEmpty(startTime)) { + startTime = null; + } + if (StringUtils.isEmpty(endTime)) { + endTime = null; + } try { - if (startTime != null) format.parse(startTime); - if (endTime != null) format.parse(endTime); + if (startTime != null) { + format.parse(startTime); + } + if (endTime != null) { + format.parse(endTime); + } } catch (ParseException e) { return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } @@ -109,9 +139,15 @@ @RequestParam(required = false) String deviceIds, @RequestParam(required = false) String time ) { - if (StringUtils.isEmpty(id)) id = null; - if (StringUtils.isEmpty(deviceIds)) deviceIds = null; - if (StringUtils.isEmpty(time)) time = null; + if (StringUtils.isEmpty(id)) { + id = null; + } + if (StringUtils.isEmpty(deviceIds)) { + deviceIds = null; + } + if (StringUtils.isEmpty(time)) { + time = null; + } try { if (time != null) { format.parse(time); @@ -133,5 +169,51 @@ return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); } + /** + * 娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡 + * + * @param deviceId 鎶ヨid + * @return + */ + @ApiOperation("娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡") + @GetMapping("/test/notify/alarm") + @ApiImplicitParams({ + @ApiImplicitParam(name="deviceId", value = "deviceId", required = true ,dataTypeClass = Integer.class) + }) + public ResponseEntity<WVPResult<String>> delete( + @RequestParam(required = false) String deviceId + ) { + if (StringUtils.isEmpty(deviceId)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + Device device = storage.queryVideoDevice(deviceId); + ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId); + DeviceAlarm deviceAlarm = new DeviceAlarm(); + deviceAlarm.setChannelId(deviceId); + deviceAlarm.setAlarmDescription("test"); + deviceAlarm.setAlarmMethod("1"); + deviceAlarm.setAlarmPriority("1"); + deviceAlarm.setAlarmTime(formatForGB.format(System.currentTimeMillis())); + deviceAlarm.setAlarmType("1"); + deviceAlarm.setLongitude(115.33333); + deviceAlarm.setLatitude(39.33333); + + if (device != null && platform == null) { + commander.sendAlarmMessage(device, deviceAlarm); + }else if (device == null && platform != null){ + commanderForPlatform.sendAlarmMessage(platform, deviceAlarm); + }else { + WVPResult wvpResult = new WVPResult(); + wvpResult.setCode(0); + wvpResult.setMsg("鏃犳硶纭畾" + deviceId + "鏄钩鍙拌繕鏄澶�"); + return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); + } + + WVPResult wvpResult = new WVPResult(); + wvpResult.setCode(0); + wvpResult.setMsg("success"); + return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); + } + } -- Gitblit v1.8.0