648540858
3 years ago
21 changed files with 17061 additions and 2298 deletions
@ -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); |
|||
|
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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 >= '${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); |
|||
} |
@ -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.
File diff suppressed because it is too large
Loading…
Reference in new issue