|  |  |  | 
|---|
|  |  |  | 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.utils.DateUtil; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 
|---|
|  |  |  | import com.github.pagehelper.PageInfo; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Api(tags = "报警信息管理") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IDeviceAlarmService deviceAlarmService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ISIPCommander commander; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ISIPCommanderForPlatform commanderForPlatform; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IVideoManagerStorage storage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | *  分页查询报警 | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public ResponseEntity<PageInfo<DeviceAlarm>> getAll( | 
|---|
|  |  |  | int page, int count, | 
|---|
|  |  |  | @RequestParam int page, | 
|---|
|  |  |  | @RequestParam int count, | 
|---|
|  |  |  | @RequestParam(required = false)  String deviceId, | 
|---|
|  |  |  | @RequestParam(required = false) String alarmPriority, | 
|---|
|  |  |  | @RequestParam(required = false) String alarmMethod, | 
|---|
|  |  |  | 
|---|
|  |  |  | @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 { | 
|---|
|  |  |  | format.parse(startTime); | 
|---|
|  |  |  | format.parse(endTime); | 
|---|
|  |  |  | if (startTime != null) { | 
|---|
|  |  |  | DateUtil.format.parse(startTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (endTime != null) { | 
|---|
|  |  |  | DateUtil.format.parse(endTime); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param time 结束时间(这个时间之前的报警会被删除) | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation("分页查询报警") | 
|---|
|  |  |  | @ApiOperation("删除报警") | 
|---|
|  |  |  | @DeleteMapping("/delete") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), | 
|---|
|  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | DateUtil.format.parse(time); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String[] deviceIdArray = deviceIds.split(","); | 
|---|
|  |  |  | List<String> deviceIdList = Arrays.asList(deviceIdArray); | 
|---|
|  |  |  | deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); | 
|---|
|  |  |  | List<String> deviceIdList = null; | 
|---|
|  |  |  | if (deviceIds != null) { | 
|---|
|  |  |  | String[] deviceIdArray = deviceIds.split(","); | 
|---|
|  |  |  | deviceIdList = Arrays.asList(deviceIdArray); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time); | 
|---|
|  |  |  | WVPResult wvpResult = new WVPResult(); | 
|---|
|  |  |  | wvpResult.setCode(0); | 
|---|
|  |  |  | wvpResult.setMsg("success"); | 
|---|
|  |  |  | wvpResult.setData(count); | 
|---|
|  |  |  | 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(DateUtil.formatISO8601.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"); | 
|---|