From ffb21248cb270475ce9156b5056e591e14cbc20d Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 30 五月 2023 11:20:22 +0800
Subject: [PATCH] 去除多余配置
---
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java | 246 +++++++++++++++++++++++++++++-------------------
1 files changed, 149 insertions(+), 97 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
index 434bbd4..6f2a585 100644
--- 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,37 +1,132 @@
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
+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.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.vmanager.bean.WVPResult;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+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 javax.sip.InvalidArgumentException;
+import javax.sip.SipException;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Date;
import java.util.List;
-@Api(tags = "鎶ヨ淇℃伅绠$悊")
-@CrossOrigin
+@Tag(name = "鎶ヨ淇℃伅绠$悊")
+
@RestController
@RequestMapping("/api/alarm")
public class AlarmController {
+ private final static Logger logger = LoggerFactory.getLogger(AlarmController.class);
+
@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;
+
+
+ /**
+ * 鍒犻櫎鎶ヨ
+ *
+ * @param id 鎶ヨid
+ * @param deviceIds 澶氫釜璁惧id,閫楀彿鍒嗛殧
+ * @param time 缁撴潫鏃堕棿(杩欎釜鏃堕棿涔嬪墠鐨勬姤璀︿細琚垹闄�)
+ * @return
+ */
+ @DeleteMapping("/delete")
+ @Operation(summary = "鍒犻櫎鎶ヨ")
+ @Parameter(name = "id", description = "ID")
+ @Parameter(name = "deviceIds", description = "澶氫釜璁惧id,閫楀彿鍒嗛殧")
+ @Parameter(name = "time", description = "缁撴潫鏃堕棿")
+ public Integer delete(
+ @RequestParam(required = false) Integer id,
+ @RequestParam(required = false) String deviceIds,
+ @RequestParam(required = false) String time
+ ) {
+ if (ObjectUtils.isEmpty(id)) {
+ id = null;
+ }
+ if (ObjectUtils.isEmpty(deviceIds)) {
+ deviceIds = null;
+ }
+
+ if (ObjectUtils.isEmpty(time)) {
+ time = null;
+ }else if (!DateUtil.verification(time, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "time鏍煎紡涓�" + DateUtil.PATTERN);
+ }
+ List<String> deviceIdList = null;
+ if (deviceIds != null) {
+ String[] deviceIdArray = deviceIds.split(",");
+ deviceIdList = Arrays.asList(deviceIdArray);
+ }
+
+ return deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
+ }
+
+ /**
+ * 娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡
+ *
+ * @param deviceId 鎶ヨid
+ * @return
+ */
+ @GetMapping("/test/notify/alarm")
+ @Operation(summary = "娴嬭瘯鍚戜笂绾�/璁惧鍙戦�佹ā鎷熸姤璀﹂�氱煡")
+ @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿")
+ public void delete(@RequestParam String deviceId) {
+ 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.getNow());
+ deviceAlarm.setAlarmType("1");
+ deviceAlarm.setLongitude(115.33333);
+ deviceAlarm.setLatitude(39.33333);
+
+ if (device != null && platform == null) {
+
+ try {
+ commander.sendAlarmMessage(device, deviceAlarm);
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+
+ }
+ }else if (device == null && platform != null){
+ try {
+ commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
+ }
+ }else {
+ throw new ControllerException(ErrorCode.ERROR100.getCode(),"鏃犳硶纭畾" + deviceId + "鏄钩鍙拌繕鏄澶�");
+ }
+
+ }
/**
* 鍒嗛〉鏌ヨ鎶ヨ
@@ -46,92 +141,49 @@
* @param endTime 缁撴潫鏃堕棿
* @return
*/
- @ApiOperation("鍒嗛〉鏌ヨ鎶ヨ")
+ @Operation(summary = "鍒嗛〉鏌ヨ鎶ヨ")
+ @Parameter(name = "page",description = "褰撳墠椤�",required = true)
+ @Parameter(name = "count",description = "姣忛〉鏌ヨ鏁伴噺",required = true)
+ @Parameter(name = "deviceId",description = "璁惧id")
+ @Parameter(name = "alarmPriority",description = "鏌ヨ鍐呭")
+ @Parameter(name = "alarmMethod",description = "鏌ヨ鍐呭")
+ @Parameter(name = "alarmType",description = "姣忛〉鏌ヨ鏁伴噺")
+ @Parameter(name = "startTime",description = "寮�濮嬫椂闂�")
+ @Parameter(name = "endTime",description = "缁撴潫鏃堕棿")
@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(
- @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 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 {
- if (startTime != null) format.parse(startTime);
- if (endTime != null) 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
+ public PageInfo<DeviceAlarm> getAll(
+ @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 alarmType,
+ @RequestParam(required = false) String startTime,
+ @RequestParam(required = false) String endTime
) {
- 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);
+ if (ObjectUtils.isEmpty(alarmPriority)) {
+ alarmPriority = null;
}
- List<String> deviceIdList = null;
- if (deviceIds != null) {
- String[] deviceIdArray = deviceIds.split(",");
- deviceIdList = Arrays.asList(deviceIdArray);
+ if (ObjectUtils.isEmpty(alarmMethod)) {
+ alarmMethod = null;
+ }
+ if (ObjectUtils.isEmpty(alarmType)) {
+ alarmType = null;
}
- 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);
+ if (ObjectUtils.isEmpty(startTime)) {
+ startTime = null;
+ }else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime鏍煎紡涓�" + DateUtil.PATTERN);
+ }
+
+ if (ObjectUtils.isEmpty(endTime)) {
+ endTime = null;
+ }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
+ throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN);
+ }
+
+ return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
+ alarmType, startTime, endTime);
}
-
-
}
--
Gitblit v1.8.0