优化内存溢出的问题
优化zlm集群默认zlm的存储
添加报警的存储以及相关接口
添加单元测试
| | |
| | | <scope>system</scope> |
| | | <systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-test</artifactId> |
| | | <!-- <scope>test</scope>--> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | |
| | |
| | | import org.springframework.scheduling.annotation.EnableScheduling;
|
| | | import springfox.documentation.oas.annotations.EnableOpenApi;
|
| | |
|
| | | /**
|
| | | *
|
| | | */
|
| | | @SpringBootApplication
|
| | | @EnableScheduling
|
| | | @EnableOpenApi
|
| | |
| | | public static void restart() {
|
| | | context.close();
|
| | | VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args);
|
| | | |
| | | }
|
| | | |
| | |
|
| | | }
|
| | |
| | | public class DeviceAlarm {
|
| | |
|
| | | /**
|
| | | * 数据库id
|
| | | */
|
| | | private String id;
|
| | |
|
| | | /**
|
| | | * 设备Id
|
| | | */
|
| | | private String deviceId;
|
| | |
| | | private String alarmType;
|
| | |
|
| | |
|
| | | public String getId() {
|
| | | return id;
|
| | | }
|
| | |
|
| | | public void setId(String id) {
|
| | | this.id = id;
|
| | | }
|
| | |
|
| | | public String getDeviceId() {
|
| | | return deviceId;
|
| | | }
|
| | |
| | |
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
| | | import com.genersoft.iot.vmp.service.IMediaServerService;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.response.impl.*;
|
| | |
| | |
|
| | | @Autowired
|
| | | private SIPCommanderFroPlatform cmderFroPlatform;
|
| | |
|
| | | @Autowired
|
| | | private IDeviceAlarmService deviceAlarmService;
|
| | |
|
| | | @Autowired
|
| | | private RedisUtil redis;
|
| | |
| | | processor.setOffLineDetector(offLineDetector);
|
| | | processor.setCmder(cmder);
|
| | | processor.setCmderFroPlatform(cmderFroPlatform);
|
| | | processor.setDeviceAlarmService(deviceAlarmService);
|
| | | processor.setStorager(storager);
|
| | | processor.setRedisCatchStorage(redisCatchStorage);
|
| | | return processor;
|
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.SipURI;
|
| | | import javax.sip.Dialog;
|
| | | import javax.sip.DialogState;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.header.FromHeader;
|
| | | import javax.sip.header.HeaderAddress;
|
| | | import javax.sip.header.ToHeader;
|
| | |
| | | */
|
| | | private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | public IRedisCatchStorage getRedisCatchStorage() {
|
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
| | |
|
| | | import javax.sdp.*;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.SipFactory;
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.Address;
|
| | | import javax.sip.address.SipURI;
|
| | | import javax.sip.header.*;
|
| | |
| | | Response response = null;
|
| | | try {
|
| | | response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | } catch (ParseException | SipException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | */
|
| | | private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
| | | response.setReasonPhrase(msg);
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | import java.text.ParseException;
|
| | | import java.util.*;
|
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.SipURI;
|
| | |
|
| | | import javax.sip.header.FromHeader;
|
| | | import javax.sip.header.HeaderAddress;
|
| | | import javax.sip.header.ToHeader;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.ListeningPoint;
|
| | | import javax.sip.ObjectInUseException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.SipProvider;
|
| | | import javax.sip.message.Request;
|
| | | import javax.sip.message.Response;
|
| | |
|
| | |
| | | import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.utils.GpsUtil;
|
| | |
| | | private DeferredResultHolder deferredResultHolder;
|
| | |
|
| | | private DeviceOffLineDetector offLineDetector;
|
| | |
|
| | | private IDeviceAlarmService deviceAlarmService;
|
| | |
|
| | | private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_";
|
| | |
|
| | |
| | | storager.insertMobilePosition(mobilePosition);
|
| | | }
|
| | | }
|
| | | // TODO: 需要实现存储报警信息、报警分类
|
| | | System.out.println("存储报警信息、报警分类");
|
| | | // 存储报警信息、报警分类
|
| | | deviceAlarmService.add(deviceAlarm);
|
| | |
|
| | | if (offLineDetector.isOnline(deviceId)) {
|
| | | publisher.deviceAlarmEventPublish(deviceAlarm);
|
| | |
| | | }else{
|
| | | logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404");
|
| | | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | // if (device != null && device.getOnline() == 1) {
|
| | |
| | | */
|
| | | private void responseAck(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | /***
|
| | |
| | | */
|
| | | private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | |
|
| | | private Element getRootElement(RequestEvent evt) throws DocumentException {
|
| | |
| | | public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
|
| | | this.cmderFroPlatform = cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) {
|
| | | this.deviceAlarmService = deviceAlarmService;
|
| | | }
|
| | | }
|
| | |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Request; |
| | | import javax.sip.message.Response; |
| | |
| | | */ |
| | | private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { |
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); |
| | | getServerTransaction(evt).sendResponse(response); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | serverTransaction.sendResponse(response); |
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); |
| | | } |
| | | |
| | | private Element getRootElement(RequestEvent evt) throws DocumentException { |
| | |
| | |
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.ServerTransaction;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.header.AuthorizationHeader;
|
| | | import javax.sip.header.ContactHeader;
|
| | |
| | | ExpiresHeader expiresHeader = (ExpiresHeader) request.getHeader(Expires.NAME);
|
| | | if (expiresHeader == null) {
|
| | | response = getMessageFactory().createResponse(Response.BAD_REQUEST, request);
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | return;
|
| | | }
|
| | | // 添加Contact头
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | // 注册成功
|
| | | // 保存到redis
|
| | | // 下发catelog查询目录
|
| | |
| | | * 处理SUBSCRIBE请求
|
| | | *
|
| | | * @param evt
|
| | | * @param layer
|
| | | * @param transaction
|
| | | * @param config |
| | | */
|
| | | @Override
|
| | | public void process(RequestEvent evt) {
|
| | |
| | | ServerTransaction transaction = getServerTransaction(evt);
|
| | | if (transaction != null) {
|
| | | transaction.sendResponse(response);
|
| | | transaction.getDialog().delete();
|
| | | transaction.terminate();
|
| | | } else {
|
| | | logger.info("processRequest serverTransactionId is null.");
|
| | |
| | | *
|
| | | * @param evt
|
| | | * @param layer
|
| | | * @param transaction
|
| | | * @param config
|
| | | */
|
| | | @Override
|
| | | public void process(ResponseEvent evt, SipLayer layer, SipConfig config) {
|
| | | // TODO Auto-generated method stub
|
| | | System.out.println( );
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | mediaServerService.clearMediaServerForOnline(); |
| | | |
| | | // 将配置文件的meida配置写入数据库 |
| | | MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort( |
| | | mediaConfig.getIp(), mediaConfig.getHttpPort()); |
| | | if (presetMediaServer != null) { |
| | | MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); |
| | | mediaSerItem.setId(presetMediaServer.getId()); |
| | | mediaServerService.update(mediaSerItem); |
| | | }else { |
| | | if (mediaConfig.getId() != null) { |
| | | MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); |
| | | mediaServerService.add(mediaSerItem); |
| | | } |
| | | } |
| | | // MediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort( |
| | | // mediaConfig.getIp(), mediaConfig.getHttpPort()); |
| | | // if (presetMediaServer != null) { |
| | | // MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); |
| | | // mediaSerItem.setId(presetMediaServer.getId()); |
| | | // mediaServerService.update(mediaSerItem); |
| | | // }else { |
| | | // if (mediaConfig.getId() != null) { |
| | | // MediaServerItem mediaSerItem = mediaConfig.getMediaSerItem(); |
| | | // mediaServerService.add(mediaSerItem); |
| | | // } |
| | | // } |
| | | |
| | | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| | | hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null, |
| | |
| | | logger.info("等待默认zlm接入..."); |
| | | |
| | | // 获取所有的zlm, 并开启主动连接 |
| | | List<MediaServerItem> all = mediaServerService.getAll(); |
| | | if (presetMediaServer == null) { |
| | | List<MediaServerItem> all = mediaServerService.getAllFromDatabase(); |
| | | if (all.size() == 0) { |
| | | all.add(mediaConfig.getMediaSerItem()); |
| | | } |
| | | for (MediaServerItem mediaServerItem : all) { |
| | |
| | | Set<String> allZlmId = startGetMedia.keySet(); |
| | | for (String id : allZlmId) { |
| | | logger.error("[ {} ]]主动连接失败,不再主动连接", id); |
| | | startGetMedia.put(id, false); |
| | | } |
| | | startGetMedia = null; |
| | | } |
| | | // TODO 清理数据库中与redis不匹配的zlm |
| | | } |
| | | }, 60 * 1000 * 2); |
| | | } |
| | | |
| | | public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) { |
| | | if (startGetMedia == null) return null; |
| | | if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) return null; |
| | | JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem); |
| | | ZLMServerConfig ZLMServerConfig = null; |
New file |
| | |
| | | package com.genersoft.iot.vmp.service; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; |
| | | import com.github.pagehelper.PageInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 报警相关业务处理 |
| | | */ |
| | | public interface IDeviceAlarmService { |
| | | |
| | | /** |
| | | * 根据多个添加获取报警列表 |
| | | * @param page 当前页 |
| | | * @param count 每页数量 |
| | | * @param deviceId 设备id |
| | | * @param alarmPriority 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情- |
| | | * @param alarmMethod 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, |
| | | * 7其他报警;可以为直接组合如12为电话报警或 设备报警- |
| | | * @param alarmType 报警类型 |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | * @return 报警列表 |
| | | */ |
| | | PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, |
| | | String alarmType, String startTime, String endTime); |
| | | |
| | | /** |
| | | * 添加一个报警 |
| | | * @param deviceAlarm 添加报警 |
| | | */ |
| | | void add(DeviceAlarm deviceAlarm); |
| | | |
| | | /** |
| | | * 清空时间以前的报警 |
| | | * @param id 数据库id |
| | | * @param deviceIdList 制定需要清理的设备id |
| | | * @param time 不写时间则清空所有时间的 |
| | | */ |
| | | void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); |
| | | |
| | | } |
| | |
| | | |
| | | List<MediaServerItem> getAll(); |
| | | |
| | | List<MediaServerItem> getAllFromDatabase(); |
| | | |
| | | List<MediaServerItem> getAllOnline(); |
| | | |
| | | MediaServerItem getOne(String generalMediaServerId); |
New file |
| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService; |
| | | import com.genersoft.iot.vmp.storager.dao.DeviceAlarmMapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class DeviceAlarmServiceImpl implements IDeviceAlarmService { |
| | | |
| | | @Autowired |
| | | private DeviceAlarmMapper deviceAlarmMapper; |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) { |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceAlarm> all = deviceAlarmMapper.query(deviceId, alarmPriority, alarmMethod, alarmType, startTime, endTime); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | @Override |
| | | public void add(DeviceAlarm deviceAlarm) { |
| | | deviceAlarmMapper.add(deviceAlarm); |
| | | } |
| | | |
| | | @Override |
| | | public void clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time) { |
| | | deviceAlarmMapper.clearAlarmBeforeTime(id, deviceIdList, time); |
| | | } |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<MediaServerItem> getAllFromDatabase() { |
| | | return mediaServerMapper.queryAll(); |
| | | } |
| | | |
| | | @Override |
| | | public List<MediaServerItem> getAllOnline() { |
| | | String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX; |
| | |
| | | if (mediaConfig.getRtspSSLPort() == 0) serverItemFromConfig.setRtspSSLPort(zlmServerConfig.getRtspSSlport()); |
| | | if (mediaConfig.getRtpProxyPort() == 0) serverItemFromConfig.setRtpProxyPort(zlmServerConfig.getRtpProxyPort()); |
| | | if (serverItem != null){ |
| | | // 可能是同一个zlm但id发生了变化 |
| | | if (!serverItem.getId().equals(zlmServerConfig.getGeneralMediaServerId())) { |
| | | mediaServerMapper.delOne(serverItem.getId()); |
| | | redisUtil.del(VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId()); |
| | | |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); |
| | | serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); |
| | | redisUtil.set(key, serverItemFromConfig); |
| | | mediaServerMapper.add(serverItemFromConfig); |
| | | mediaServerMapper.delDefault(); |
| | | mediaServerMapper.add(serverItemFromConfig); |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); |
| | | MediaServerItem serverItemInRedis = (MediaServerItem)redisUtil.get(key); |
| | | if (serverItemInRedis != null) { |
| | | serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig()); |
| | | }else { |
| | | mediaServerMapper.update(serverItemFromConfig); |
| | | serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); |
| | | } |
| | | redisUtil.set(key, serverItemFromConfig); |
| | | }else { |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); |
| | | serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); |
New file |
| | |
| | | package com.genersoft.iot.vmp.storager.dao; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| | | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| | | import org.apache.ibatis.annotations.*; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 用于存储设备的报警信息 |
| | | */ |
| | | @Mapper |
| | | @Repository |
| | | public interface DeviceAlarmMapper { |
| | | |
| | | @Insert("INSERT INTO device_alarm (deviceId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " + |
| | | "VALUES ('${deviceId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')") |
| | | int add(DeviceAlarm alarm); |
| | | |
| | | |
| | | @Select(value = {" <script>" + |
| | | " SELECT * FROM device_alarm " + |
| | | " WHERE 1=1 " + |
| | | " <if test=\"deviceId != null\" > AND deviceId = '${deviceId}'</if>" + |
| | | " <if test=\"alarmPriority != null\" > AND alarmPriority = '${alarmPriority}' </if>" + |
| | | " <if test=\"alarmMethod != null\" > AND alarmMethod = '${alarmMethod}' </if>" + |
| | | " <if test=\"alarmType != null\" > AND alarmType = '${alarmType}' </if>" + |
| | | " <if test=\"startTime != null\" > AND alarmTime >= '${startTime}' </if>" + |
| | | " <if test=\"endTime != null\" > AND alarmTime <= '${endTime}' </if>" + |
| | | " ORDER BY alarmTime ASC " + |
| | | " </script>"}) |
| | | List<DeviceAlarm> query(String deviceId, String alarmPriority, String alarmMethod, |
| | | String alarmType, String startTime, String endTime); |
| | | |
| | | |
| | | @Delete(" <script>" + |
| | | "DELETE FROM device_alarm WHERE 1=1 " + |
| | | " <if test=\"deviceIdList != null and id == null \" > AND deviceId in " + |
| | | "<foreach collection='deviceIdList' item='item' open='(' separator=',' close=')' > '${item}'</foreach>" + |
| | | "</if>" + |
| | | " <if test=\"time != null and id == null \" > AND alarmTime <= '${time}'</if>" + |
| | | " <if test=\"id != null\" > AND id = ${id}</if>" + |
| | | " </script>" |
| | | ) |
| | | int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time); |
| | | } |
| | |
| | | @Select("DELETE FROM media_server WHERE id='${id}'") |
| | | void delOne(String id); |
| | | |
| | | @Select("DELETE FROM media_server WHERE ip='${host}' and httpPort=${port}") |
| | | void delOneByIPAndPort(String host, int port); |
| | | |
| | | @Select("DELETE FROM media_server WHERE defaultServer=1;") |
| | | void delDefault(); |
| | | |
| | | @Select("SELECT * FROM media_server WHERE ip='${host}' and httpPort=${port}") |
| | | MediaServerItem queryOneByHostAndPort(String host, int port); |
| | | } |
New file |
| | |
| | | package com.genersoft.iot.vmp.vmanager.gb28181.alarm; |
| | | |
| | | import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; |
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService; |
| | | import com.genersoft.iot.vmp.service.IGbStreamService; |
| | | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| | | import com.github.pagehelper.PageInfo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.models.auth.In; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.StringUtils; |
| | | 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 = "报警信息管理") |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping("/api/alarm") |
| | | public class AlarmController { |
| | | |
| | | @Autowired |
| | | private IDeviceAlarmService deviceAlarmService; |
| | | |
| | | private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | /** |
| | | * 分页查询报警 |
| | | * |
| | | * @param deviceId 设备id |
| | | * @param page 当前页 |
| | | * @param count 每页查询数量 |
| | | * @param alarmPriority 报警级别 |
| | | * @param alarmMethod 报警方式 |
| | | * @param alarmType 报警类型 |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | * @return |
| | | */ |
| | | @ApiOperation("分页查询报警") |
| | | @GetMapping("/all") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name="deviceId", value = "设备id", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class), |
| | | @ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class), |
| | | @ApiImplicitParam(name="alarmPriority", value = "查询内容" ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="alarmMethod", value = "查询内容" ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="alarmType", value = "查询内容" ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class), |
| | | }) |
| | | public ResponseEntity<PageInfo<DeviceAlarm>> getAll( |
| | | int page, int count, |
| | | @RequestParam(required = false) String deviceId, |
| | | @RequestParam(required = false) String alarmPriority, |
| | | @RequestParam(required = false) String alarmMethod, |
| | | @RequestParam(required = false) String alarmType, |
| | | @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; |
| | | |
| | | |
| | | try { |
| | | format.parse(startTime); |
| | | format.parse(endTime); |
| | | } catch (ParseException e) { |
| | | return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod, |
| | | alarmType, startTime, endTime); |
| | | return new ResponseEntity<>(allAlarm, HttpStatus.OK); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除报警 |
| | | * |
| | | * @param id 报警id |
| | | * @param deviceIds 多个设备id,逗号分隔 |
| | | * @param time 结束时间(这个时间之前的报警会被删除) |
| | | * @return |
| | | */ |
| | | @ApiOperation("分页查询报警") |
| | | @DeleteMapping("/delete") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name="id", value = "ID", required = false ,dataTypeClass = Integer.class), |
| | | @ApiImplicitParam(name="deviceIds", value = "多个设备id,逗号分隔", required = false ,dataTypeClass = String.class), |
| | | @ApiImplicitParam(name="time", value = "结束时间", required = false ,dataTypeClass = String.class), |
| | | }) |
| | | public ResponseEntity<WVPResult<String>> delete( |
| | | @RequestParam(required = false) Integer id, |
| | | @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; |
| | | try { |
| | | if (time != null) { |
| | | 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); |
| | | WVPResult wvpResult = new WVPResult(); |
| | | wvpResult.setCode(0); |
| | | wvpResult.setMsg("success"); |
| | | return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK); |
| | | } |
| | | |
| | | |
| | | } |