From 5d901b5e3f033e8b04e53420d68626cbd87431c8 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 06 五月 2022 10:12:34 +0800
Subject: [PATCH] 使用阿里代码规范。规范代码写法
---
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java | 5 +
src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java | 46 +++++++++++----
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java | 40 +++++++++++++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java | 38 +++++++-----
4 files changed, 99 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java b/src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java
index e91d1ca..ed1c2b9 100644
--- a/src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java
+++ b/src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java
@@ -1,5 +1,9 @@
package com.genersoft.iot.vmp.common;
+/**
+ * 涓篈PI閲嶅懡鍚�, 鏂逛究鍚戞暟鎹簱璁板綍鏁版嵁鐨勬椂鍊欏睍绀�
+ * @author lin
+ */
public class ApiSaveConstant {
public static String getVal(String key) {
@@ -35,8 +39,9 @@
return "[璁惧鎺у埗] 寮哄埗鍏抽敭甯�";
case "home_position":
return "[璁惧鎺у埗] 鐪嬪畧浣嶆帶鍒�";
+ default:
+ return "";
}
- break;
case "query":
if (keyItemArray.length <= 5) {
return null;
@@ -51,23 +56,30 @@
return "[璁惧鏌ヨ] 鍚屾璁惧閫氶亾";
case "delete":
return "[璁惧鏌ヨ] 绉婚櫎璁惧";
+ default:
+ return "";
}
- break;
case "channel":
return "[璁惧鏌ヨ] 鏇存柊閫氶亾淇℃伅";
case "transport":
return "[璁惧鏌ヨ] 淇敼鏁版嵁娴佷紶杈撴ā寮�";
+ default:
+ return "";
}
- break;
+ default:
+ return "";
}
+
+ break;
case "gbStream":
switch (keyItemArray[3]) {
case "del":
return "绉婚櫎閫氶亾涓庡浗鏍囩殑鍏宠仈";
case "add":
return "娣诲姞閫氶亾涓庡浗鏍囩殑鍏宠仈";
+ default:
+ return "";
}
- break;
case "media":
break;
case "position":
@@ -85,8 +97,9 @@
return "鍚戜笂绾у钩鍙版坊鍔犲浗鏍囬�氶亾";
case "del_channel_for_gb":
return "浠庝笂绾у钩鍙扮Щ闄ゅ浗鏍囬�氶亾";
+ default:
+ return "";
}
- break;
case "platform_gb_stream":
break;
case "play":
@@ -101,32 +114,36 @@
return "缁撴潫杞爜";
case "broadcast":
return "璇煶骞挎挱";
+ default:
+ return "";
}
- break;
case "download":
switch (keyItemArray[3]) {
case "start":
return "寮�濮嬪巻鍙插獟浣撲笅杞�";
case "stop":
return "鍋滄鍘嗗彶濯掍綋涓嬭浇";
+ default:
+ return "";
}
- break;
case "playback":
switch (keyItemArray[3]) {
case "start":
return "寮�濮嬭棰戝洖鏀�";
case "stop":
return "鍋滄瑙嗛鍥炴斁";
+ default:
+ return "";
}
- break;
case "ptz":
switch (keyItemArray[3]) {
case "control":
return "浜戝彴鎺у埗";
case "front_end_command":
return "閫氱敤鍓嶇鎺у埗鍛戒护";
+ default:
+ return "";
}
- break;
case "gb_record":
break;
case "onvif":
@@ -146,16 +163,18 @@
return "鍚敤浠g悊";
case "stop":
return "鍋滅敤浠g悊";
+ default:
+ return "";
}
- break;
case "push":
switch (keyItemArray[3]) {
case "save_to_gb":
return "灏嗘帹娴佹坊鍔犲埌鍥芥爣";
case "remove_form_gb":
return "灏嗘帹娴佺Щ鍑哄埌鍥芥爣";
+ default:
+ return "";
}
- break;
case "user":
switch (keyItemArray[3]) {
case "login":
@@ -166,8 +185,11 @@
return "娣诲姞鐢ㄦ埛";
case "delete":
return "鍒犻櫎鐢ㄦ埛";
+ default:
+ return "";
}
- break;
+ default:
+ return "";
}
}
return null;
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java b/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
index 2356b57..95b2262 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
@@ -13,6 +13,7 @@
/**
* 澶勭悊鍖垮悕鐢ㄦ埛璁块棶閫昏緫
+ * @author lin
*/
@Component
public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint {
@@ -21,7 +22,6 @@
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) {
-// logger.debug("鐢ㄦ埛闇�瑕佺櫥褰曪紝璁块棶[{}]澶辫触锛孉uthenticationException=[{}]", request.getRequestURI(), e.getMessage());
// 鍏佽璺ㄥ煙
response.setHeader("Access-Control-Allow-Origin", "*");
// 鍏佽鑷畾涔夎姹傚ごtoken(鍏佽head璺ㄥ煙)
@@ -30,7 +30,8 @@
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", "-1");
jsonObject.put("msg", "璇风櫥褰曞悗閲嶆柊璇锋眰");
- if (request.getRequestURI().contains("api/user/login")){
+ String logUri = "api/user/login";
+ if (request.getRequestURI().contains(logUri)){
jsonObject.put("msg", e.getMessage());
}
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java
new file mode 100644
index 0000000..ff8761e
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java
@@ -0,0 +1,40 @@
+package com.genersoft.iot.vmp.gb28181.bean;
+
+/**
+ * 鎶ヨ鏂瑰紡
+ * @author lin
+ * 1涓虹數璇濇姤璀�, 2涓鸿澶囨姤璀�, 3涓虹煭淇℃姤璀�, 4涓� GPS鎶ヨ, 5涓鸿棰戞姤璀�, 6涓鸿澶囨晠闅滄姤璀�,
+ * 7鍏朵粬鎶ヨ;鍙互涓虹洿鎺ョ粍鍚堝12涓虹數璇濇姤璀︽垨 璁惧鎶ヨ-
+ */
+public enum DeviceAlarmMethod {
+ // 1涓虹數璇濇姤璀�
+ Telephone(1),
+
+ // 2涓鸿澶囨姤璀�
+ Device(2),
+
+ // 3涓虹煭淇℃姤璀�
+ SMS(3),
+
+ // 4涓� GPS鎶ヨ
+ GPS(4),
+
+ // 5涓鸿棰戞姤璀�
+ Video(5),
+
+ // 6涓鸿澶囨晠闅滄姤璀�
+ DeviceFailure(6),
+
+ // 7鍏朵粬鎶ヨ
+ Other(7);
+
+ private final int val;
+
+ DeviceAlarmMethod(int val) {
+ this.val=val;
+ }
+
+ public int getVal() {
+ return val;
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
index fa20d51..b7e222d 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
@@ -32,7 +32,7 @@
@Component
public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
- private Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class);
+ private final Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class);
private final String cmdType = "Alarm";
@Autowired
@@ -85,24 +85,27 @@
deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority"));
deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod"));
deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime"));
- if (getText(rootElement, "AlarmDescription") == null) {
+ String alarmDescription = getText(rootElement, "AlarmDescription");
+ if (alarmDescription == null) {
deviceAlarm.setAlarmDescription("");
} else {
- deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription"));
+ deviceAlarm.setAlarmDescription(alarmDescription);
}
- if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) {
- deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude")));
+ String longitude = getText(rootElement, "Longitude");
+ if (longitude != null && NumericUtil.isDouble(longitude)) {
+ deviceAlarm.setLongitude(Double.parseDouble(longitude));
} else {
deviceAlarm.setLongitude(0.00);
}
- if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) {
- deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude")));
+ String latitude = getText(rootElement, "Latitude");
+ if (latitude != null && NumericUtil.isDouble(latitude)) {
+ deviceAlarm.setLatitude(Double.parseDouble(latitude));
} else {
deviceAlarm.setLatitude(0.00);
}
if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
- if ( deviceAlarm.getAlarmMethod().equals("4")) {
+ if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) {
MobilePosition mobilePosition = new MobilePosition();
mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
mobilePosition.setTime(deviceAlarm.getAlarmTime());
@@ -122,7 +125,7 @@
}
}
if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) {
- if (deviceAlarm.getAlarmMethod().equals("5")) {
+ if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) {
deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
}
}
@@ -173,25 +176,28 @@
deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority"));
deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod"));
deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime"));
- if (getText(rootElement, "AlarmDescription") == null) {
+ String alarmDescription = getText(rootElement, "AlarmDescription");
+ if (alarmDescription == null) {
deviceAlarm.setAlarmDescription("");
} else {
- deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription"));
+ deviceAlarm.setAlarmDescription(alarmDescription);
}
- if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) {
- deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude")));
+ String longitude = getText(rootElement, "Longitude");
+ if (longitude != null && NumericUtil.isDouble(longitude)) {
+ deviceAlarm.setLongitude(Double.parseDouble(longitude));
} else {
deviceAlarm.setLongitude(0.00);
}
- if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) {
- deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude")));
+ String latitude = getText(rootElement, "Latitude");
+ if (latitude != null && NumericUtil.isDouble(latitude)) {
+ deviceAlarm.setLatitude(Double.parseDouble(latitude));
} else {
deviceAlarm.setLatitude(0.00);
}
if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
- if (deviceAlarm.getAlarmMethod().equals("5")) {
+ if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) {
deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
}
}
--
Gitblit v1.8.0