优化内存溢出的问题

优化zlm集群默认zlm的存储
添加报警的存储以及相关接口
添加单元测试
This commit is contained in:
648540858 2021-08-04 18:00:22 +08:00
parent db33e99e55
commit 0cfd24826f
21 changed files with 17061 additions and 2298 deletions

View File

@ -221,6 +221,12 @@
<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>

View File

@ -8,6 +8,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.oas.annotations.EnableOpenApi;
/**
*
*/
@SpringBootApplication
@EnableScheduling
@EnableOpenApi
@ -22,7 +25,7 @@ public class VManageBootstrap extends LogManager {
public static void restart() {
context.close();
VManageBootstrap.context = SpringApplication.run(VManageBootstrap.class, args);
}
}

View File

@ -3,6 +3,11 @@ package com.genersoft.iot.vmp.gb28181.bean;
public class DeviceAlarm {
/**
* 数据库id
*/
private String id;
/**
* 设备Id
*/
@ -45,6 +50,14 @@ public class DeviceAlarm {
private String alarmType;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDeviceId() {
return deviceId;
}

View File

@ -9,6 +9,7 @@ import javax.sip.message.Response;
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.*;
@ -73,6 +74,9 @@ public class SIPProcessorFactory {
@Autowired
private SIPCommanderFroPlatform cmderFroPlatform;
@Autowired
private IDeviceAlarmService deviceAlarmService;
@Autowired
private RedisUtil redis;
@ -178,6 +182,7 @@ public class SIPProcessorFactory {
processor.setOffLineDetector(offLineDetector);
processor.setCmder(cmder);
processor.setCmderFroPlatform(cmderFroPlatform);
processor.setDeviceAlarmService(deviceAlarmService);
processor.setStorager(storager);
processor.setRedisCatchStorage(redisCatchStorage);
return processor;

View File

@ -1,11 +1,7 @@
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;
@ -107,7 +103,9 @@ public class ByeRequestProcessor extends SIPRequestAbstractProcessor {
*/
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() {

View File

@ -1,10 +1,7 @@
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.*;
@ -239,7 +236,9 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
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();
}
@ -384,13 +383,17 @@ public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
*/
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();
}
/**

View File

@ -4,17 +4,12 @@ import java.io.ByteArrayInputStream;
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;
@ -35,6 +30,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcesso
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;
@ -84,6 +80,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
private DeviceOffLineDetector offLineDetector;
private IDeviceAlarmService deviceAlarmService;
private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_";
private static final String MESSAGE_KEEP_ALIVE = "Keepalive";
@ -738,7 +736,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
storager.insertMobilePosition(mobilePosition);
}
}
// TODO: 需要实现存储报警信息报警分类
System.out.println("存储报警信息、报警分类");
// 存储报警信息报警分类
deviceAlarmService.add(deviceAlarm);
if (offLineDetector.isOnline(deviceId)) {
publisher.deviceAlarmEventPublish(deviceAlarm);
@ -779,7 +779,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
}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) {
@ -987,7 +989,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/
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();
}
/***
@ -999,7 +1003,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/
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 {
@ -1049,4 +1055,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
this.cmderFroPlatform = cmderFroPlatform;
}
public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) {
this.deviceAlarmService = deviceAlarmService;
}
}

View File

@ -6,6 +6,7 @@ import java.util.Iterator;
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;
@ -342,7 +343,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
*/
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 {

View File

@ -7,6 +7,7 @@ import java.util.Locale;
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;
@ -112,7 +113,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
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头
@ -159,7 +162,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
}
}
getServerTransaction(evt).sendResponse(response);
ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
// 注册成功
// 保存到redis
// 下发catelog查询目录

View File

@ -27,9 +27,6 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor {
* 处理SUBSCRIBE请求
*
* @param evt
* @param layer
* @param transaction
* @param config
*/
@Override
public void process(RequestEvent evt) {
@ -46,6 +43,7 @@ public class SubscribeRequestProcessor extends SIPRequestAbstractProcessor {
ServerTransaction transaction = getServerTransaction(evt);
if (transaction != null) {
transaction.sendResponse(response);
transaction.getDialog().delete();
transaction.terminate();
} else {
logger.info("processRequest serverTransactionId is null.");

View File

@ -21,13 +21,11 @@ public class ByeResponseProcessor implements ISIPResponseProcessor {
*
* @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( );
}
}

View File

@ -45,18 +45,18 @@ public class ZLMRunner implements CommandLineRunner {
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,
@ -73,8 +73,8 @@ public class ZLMRunner implements CommandLineRunner {
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) {
@ -99,14 +99,16 @@ public class ZLMRunner implements CommandLineRunner {
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;

View File

@ -0,0 +1,43 @@
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);
}

View File

@ -14,6 +14,8 @@ public interface IMediaServerService {
List<MediaServerItem> getAll();
List<MediaServerItem> getAllFromDatabase();
List<MediaServerItem> getAllOnline();
MediaServerItem getOne(String generalMediaServerId);

View File

@ -0,0 +1,37 @@
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);
}
}

View File

@ -181,6 +181,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
return result;
}
@Override
public List<MediaServerItem> getAllFromDatabase() {
return mediaServerMapper.queryAll();
}
@Override
public List<MediaServerItem> getAllOnline() {
String key = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX;
@ -251,18 +257,16 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
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()));

View File

@ -0,0 +1,48 @@
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 &gt;= '${startTime}' </if>" +
" <if test=\"endTime != null\" > AND alarmTime &lt;= '${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 &lt;= '${time}'</if>" +
" <if test=\"id != null\" > AND id = ${id}</if>" +
" </script>"
)
int clearAlarmBeforeTime(Integer id, List<String> deviceIdList, String time);
}

View File

@ -94,6 +94,12 @@ public interface MediaServerMapper {
@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);
}

View File

@ -0,0 +1,131 @@
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);
}
}

Binary file not shown.

18930
web_src/package-lock.json generated

File diff suppressed because it is too large Load Diff