From c25a99d60bef3d3bbd59fee895bd658928fd00db Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 10 一月 2024 16:17:29 +0800 Subject: [PATCH] 修复空指针异常 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java | 48 ++++++++++++++++++++++++++++++------------------ 1 files changed, 30 insertions(+), 18 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 c8bd3f4..6f2a585 --- 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 @@ -10,28 +10,29 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 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.responses.ApiResponse; 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.ObjectUtils; -import org.springframework.util.StringUtils; 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; @@ -70,11 +71,11 @@ if (ObjectUtils.isEmpty(deviceIds)) { deviceIds = null; } + if (ObjectUtils.isEmpty(time)) { time = null; - } - if (!DateUtil.verification(time, DateUtil.formatter) ){ - return null; + }else if (!DateUtil.verification(time, DateUtil.formatter) ){ + throw new ControllerException(ErrorCode.ERROR400.getCode(), "time鏍煎紡涓�" + DateUtil.PATTERN); } List<String> deviceIdList = null; if (deviceIds != null) { @@ -102,15 +103,25 @@ 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 { throw new ControllerException(ErrorCode.ERROR100.getCode(),"鏃犳硶纭畾" + deviceId + "鏄钩鍙拌繕鏄澶�"); } @@ -159,16 +170,17 @@ if (ObjectUtils.isEmpty(alarmType)) { alarmType = null; } + 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; - } - - - if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){ - throw new ControllerException(ErrorCode.ERROR100.getCode(), "寮�濮嬫椂闂存垨缁撴潫鏃堕棿鏍煎紡鏈夎"); + }else if (!DateUtil.verification(endTime, DateUtil.formatter) ){ + throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime鏍煎紡涓�" + DateUtil.PATTERN); } return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod, -- Gitblit v1.8.0