From 62f716be9cd1cee2a5fba566db3fcd43bd9fc4cc Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 03 四月 2024 15:04:33 +0800
Subject: [PATCH] 添加idea logo
---
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java | 106 ++++++++++++++++++++++++++---------------------------
1 files changed, 52 insertions(+), 54 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
old mode 100644
new mode 100755
index 79b7d58..10c99a5
--- 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,5 +1,7 @@
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
@@ -8,26 +10,31 @@
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
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.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
-import java.time.LocalDateTime;
+import javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
+import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
@Tag(name = "鎶ヨ淇℃伅绠$悊")
-@CrossOrigin
+
@RestController
@RequestMapping("/api/alarm")
public class AlarmController {
+
+ private final static Logger logger = LoggerFactory.getLogger(AlarmController.class);
@Autowired
private IDeviceAlarmService deviceAlarmService;
@@ -51,26 +58,26 @@
* @return
*/
@DeleteMapping("/delete")
- @Operation(summary = "鍒犻櫎鎶ヨ")
+ @Operation(summary = "鍒犻櫎鎶ヨ", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "id", description = "ID")
@Parameter(name = "deviceIds", description = "澶氫釜璁惧id,閫楀彿鍒嗛殧")
@Parameter(name = "time", description = "缁撴潫鏃堕棿")
- public ResponseEntity<WVPResult<String>> delete(
+ public Integer delete(
@RequestParam(required = false) Integer id,
@RequestParam(required = false) String deviceIds,
@RequestParam(required = false) String time
) {
- if (StringUtils.isEmpty(id)) {
+ if (ObjectUtils.isEmpty(id)) {
id = null;
}
- if (StringUtils.isEmpty(deviceIds)) {
+ if (ObjectUtils.isEmpty(deviceIds)) {
deviceIds = null;
}
- if (StringUtils.isEmpty(time)) {
+
+ if (ObjectUtils.isEmpty(time)) {
time = null;
- }
- if (!DateUtil.verification(time, DateUtil.formatter) ){
- return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
+ }else if (!DateUtil.verification(time, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "time鏍煎紡涓�" + DateUtil.PATTERN);
}
List<String> deviceIdList = null;
if (deviceIds != null) {
@@ -78,12 +85,7 @@
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);
+ return deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
}
/**
@@ -93,14 +95,9 @@
* @return
*/
@GetMapping("/test/notify/alarm")
- @Operation(summary = "娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡")
+ @Operation(summary = "娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿")
- public ResponseEntity<WVPResult<String>> delete(
- @RequestParam(required = false) String deviceId
- ) {
- if (StringUtils.isEmpty(deviceId)) {
- return new ResponseEntity<>(HttpStatus.NOT_FOUND);
- }
+ public void delete(@RequestParam String deviceId) {
Device device = storage.queryVideoDevice(deviceId);
ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId);
DeviceAlarm deviceAlarm = new DeviceAlarm();
@@ -108,26 +105,29 @@
deviceAlarm.setAlarmDescription("test");
deviceAlarm.setAlarmMethod("1");
deviceAlarm.setAlarmPriority("1");
- deviceAlarm.setAlarmTime(DateUtil.formatterISO8601.format(LocalDateTime.now()));
+ deviceAlarm.setAlarmTime(DateUtil.getNow());
deviceAlarm.setAlarmType("1");
deviceAlarm.setLongitude(115.33333);
deviceAlarm.setLatitude(39.33333);
if (device != null && platform == null) {
- commander.sendAlarmMessage(device, deviceAlarm);
+
+ try {
+ commander.sendAlarmMessage(device, deviceAlarm);
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+
+ }
}else if (device == null && platform != null){
- commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
+ try {
+ commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
+ }
}else {
- WVPResult wvpResult = new WVPResult();
- wvpResult.setCode(0);
- wvpResult.setMsg("鏃犳硶纭畾" + deviceId + "鏄钩鍙拌繕鏄澶�");
- return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
+ throw new ControllerException(ErrorCode.ERROR100.getCode(),"鏃犳硶纭畾" + deviceId + "鏄钩鍙拌繕鏄澶�");
}
- WVPResult wvpResult = new WVPResult();
- wvpResult.setCode(0);
- wvpResult.setMsg("success");
- return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
}
/**
@@ -143,7 +143,7 @@
* @param endTime 缁撴潫鏃堕棿
* @return
*/
- @Operation(summary = "鍒嗛〉鏌ヨ鎶ヨ")
+ @Operation(summary = "鍒嗛〉鏌ヨ鎶ヨ", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "page",description = "褰撳墠椤�",required = true)
@Parameter(name = "count",description = "姣忛〉鏌ヨ鏁伴噺",required = true)
@Parameter(name = "deviceId",description = "璁惧id")
@@ -153,7 +153,7 @@
@Parameter(name = "startTime",description = "寮�濮嬫椂闂�")
@Parameter(name = "endTime",description = "缁撴潫鏃堕棿")
@GetMapping("/all")
- public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
+ public PageInfo<DeviceAlarm> getAll(
@RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String deviceId,
@@ -163,31 +163,29 @@
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime
) {
- if (StringUtils.isEmpty(alarmPriority)) {
+ if (ObjectUtils.isEmpty(alarmPriority)) {
alarmPriority = null;
}
- if (StringUtils.isEmpty(alarmMethod)) {
+ if (ObjectUtils.isEmpty(alarmMethod)) {
alarmMethod = null;
}
- if (StringUtils.isEmpty(alarmType)) {
+ if (ObjectUtils.isEmpty(alarmType)) {
alarmType = null;
}
- if (StringUtils.isEmpty(startTime)) {
+
+ if (ObjectUtils.isEmpty(startTime)) {
startTime = null;
+ }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
}
- if (StringUtils.isEmpty(endTime)) {
+
+ if (ObjectUtils.isEmpty(endTime)) {
endTime = null;
+ }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
}
-
- if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
- return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
- }
-
- PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
+ return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
alarmType, startTime, endTime);
- return new ResponseEntity<>(allAlarm, HttpStatus.OK);
}
-
-
}
--
Gitblit v1.8.0