Commit 5d901b5e3f033e8b04e53420d68626cbd87431c8
1 parent
c286ecb4
使用阿里代码规范。规范代码写法
Showing
4 changed files
with
99 additions
and
30 deletions
src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java
| 1 | package com.genersoft.iot.vmp.common; | 1 | package com.genersoft.iot.vmp.common; |
| 2 | 2 | ||
| 3 | +/** | ||
| 4 | + * 为API重命名, 方便向数据库记录数据的时候展示 | ||
| 5 | + * @author lin | ||
| 6 | + */ | ||
| 3 | public class ApiSaveConstant { | 7 | public class ApiSaveConstant { |
| 4 | 8 | ||
| 5 | public static String getVal(String key) { | 9 | public static String getVal(String key) { |
| @@ -35,8 +39,9 @@ public class ApiSaveConstant { | @@ -35,8 +39,9 @@ public class ApiSaveConstant { | ||
| 35 | return "[设备控制] 强制关键帧"; | 39 | return "[设备控制] 强制关键帧"; |
| 36 | case "home_position": | 40 | case "home_position": |
| 37 | return "[设备控制] 看守位控制"; | 41 | return "[设备控制] 看守位控制"; |
| 42 | + default: | ||
| 43 | + return ""; | ||
| 38 | } | 44 | } |
| 39 | - break; | ||
| 40 | case "query": | 45 | case "query": |
| 41 | if (keyItemArray.length <= 5) { | 46 | if (keyItemArray.length <= 5) { |
| 42 | return null; | 47 | return null; |
| @@ -51,23 +56,30 @@ public class ApiSaveConstant { | @@ -51,23 +56,30 @@ public class ApiSaveConstant { | ||
| 51 | return "[设备查询] 同步设备通道"; | 56 | return "[设备查询] 同步设备通道"; |
| 52 | case "delete": | 57 | case "delete": |
| 53 | return "[设备查询] 移除设备"; | 58 | return "[设备查询] 移除设备"; |
| 59 | + default: | ||
| 60 | + return ""; | ||
| 54 | } | 61 | } |
| 55 | - break; | ||
| 56 | case "channel": | 62 | case "channel": |
| 57 | return "[设备查询] 更新通道信息"; | 63 | return "[设备查询] 更新通道信息"; |
| 58 | case "transport": | 64 | case "transport": |
| 59 | return "[设备查询] 修改数据流传输模式"; | 65 | return "[设备查询] 修改数据流传输模式"; |
| 66 | + default: | ||
| 67 | + return ""; | ||
| 60 | } | 68 | } |
| 61 | - break; | 69 | + default: |
| 70 | + return ""; | ||
| 62 | } | 71 | } |
| 72 | + | ||
| 73 | + break; | ||
| 63 | case "gbStream": | 74 | case "gbStream": |
| 64 | switch (keyItemArray[3]) { | 75 | switch (keyItemArray[3]) { |
| 65 | case "del": | 76 | case "del": |
| 66 | return "移除通道与国标的关联"; | 77 | return "移除通道与国标的关联"; |
| 67 | case "add": | 78 | case "add": |
| 68 | return "添加通道与国标的关联"; | 79 | return "添加通道与国标的关联"; |
| 80 | + default: | ||
| 81 | + return ""; | ||
| 69 | } | 82 | } |
| 70 | - break; | ||
| 71 | case "media": | 83 | case "media": |
| 72 | break; | 84 | break; |
| 73 | case "position": | 85 | case "position": |
| @@ -85,8 +97,9 @@ public class ApiSaveConstant { | @@ -85,8 +97,9 @@ public class ApiSaveConstant { | ||
| 85 | return "向上级平台添加国标通道"; | 97 | return "向上级平台添加国标通道"; |
| 86 | case "del_channel_for_gb": | 98 | case "del_channel_for_gb": |
| 87 | return "从上级平台移除国标通道"; | 99 | return "从上级平台移除国标通道"; |
| 100 | + default: | ||
| 101 | + return ""; | ||
| 88 | } | 102 | } |
| 89 | - break; | ||
| 90 | case "platform_gb_stream": | 103 | case "platform_gb_stream": |
| 91 | break; | 104 | break; |
| 92 | case "play": | 105 | case "play": |
| @@ -101,32 +114,36 @@ public class ApiSaveConstant { | @@ -101,32 +114,36 @@ public class ApiSaveConstant { | ||
| 101 | return "结束转码"; | 114 | return "结束转码"; |
| 102 | case "broadcast": | 115 | case "broadcast": |
| 103 | return "语音广播"; | 116 | return "语音广播"; |
| 117 | + default: | ||
| 118 | + return ""; | ||
| 104 | } | 119 | } |
| 105 | - break; | ||
| 106 | case "download": | 120 | case "download": |
| 107 | switch (keyItemArray[3]) { | 121 | switch (keyItemArray[3]) { |
| 108 | case "start": | 122 | case "start": |
| 109 | return "开始历史媒体下载"; | 123 | return "开始历史媒体下载"; |
| 110 | case "stop": | 124 | case "stop": |
| 111 | return "停止历史媒体下载"; | 125 | return "停止历史媒体下载"; |
| 126 | + default: | ||
| 127 | + return ""; | ||
| 112 | } | 128 | } |
| 113 | - break; | ||
| 114 | case "playback": | 129 | case "playback": |
| 115 | switch (keyItemArray[3]) { | 130 | switch (keyItemArray[3]) { |
| 116 | case "start": | 131 | case "start": |
| 117 | return "开始视频回放"; | 132 | return "开始视频回放"; |
| 118 | case "stop": | 133 | case "stop": |
| 119 | return "停止视频回放"; | 134 | return "停止视频回放"; |
| 135 | + default: | ||
| 136 | + return ""; | ||
| 120 | } | 137 | } |
| 121 | - break; | ||
| 122 | case "ptz": | 138 | case "ptz": |
| 123 | switch (keyItemArray[3]) { | 139 | switch (keyItemArray[3]) { |
| 124 | case "control": | 140 | case "control": |
| 125 | return "云台控制"; | 141 | return "云台控制"; |
| 126 | case "front_end_command": | 142 | case "front_end_command": |
| 127 | return "通用前端控制命令"; | 143 | return "通用前端控制命令"; |
| 144 | + default: | ||
| 145 | + return ""; | ||
| 128 | } | 146 | } |
| 129 | - break; | ||
| 130 | case "gb_record": | 147 | case "gb_record": |
| 131 | break; | 148 | break; |
| 132 | case "onvif": | 149 | case "onvif": |
| @@ -146,16 +163,18 @@ public class ApiSaveConstant { | @@ -146,16 +163,18 @@ public class ApiSaveConstant { | ||
| 146 | return "启用代理"; | 163 | return "启用代理"; |
| 147 | case "stop": | 164 | case "stop": |
| 148 | return "停用代理"; | 165 | return "停用代理"; |
| 166 | + default: | ||
| 167 | + return ""; | ||
| 149 | } | 168 | } |
| 150 | - break; | ||
| 151 | case "push": | 169 | case "push": |
| 152 | switch (keyItemArray[3]) { | 170 | switch (keyItemArray[3]) { |
| 153 | case "save_to_gb": | 171 | case "save_to_gb": |
| 154 | return "将推流添加到国标"; | 172 | return "将推流添加到国标"; |
| 155 | case "remove_form_gb": | 173 | case "remove_form_gb": |
| 156 | return "将推流移出到国标"; | 174 | return "将推流移出到国标"; |
| 175 | + default: | ||
| 176 | + return ""; | ||
| 157 | } | 177 | } |
| 158 | - break; | ||
| 159 | case "user": | 178 | case "user": |
| 160 | switch (keyItemArray[3]) { | 179 | switch (keyItemArray[3]) { |
| 161 | case "login": | 180 | case "login": |
| @@ -166,8 +185,11 @@ public class ApiSaveConstant { | @@ -166,8 +185,11 @@ public class ApiSaveConstant { | ||
| 166 | return "添加用户"; | 185 | return "添加用户"; |
| 167 | case "delete": | 186 | case "delete": |
| 168 | return "删除用户"; | 187 | return "删除用户"; |
| 188 | + default: | ||
| 189 | + return ""; | ||
| 169 | } | 190 | } |
| 170 | - break; | 191 | + default: |
| 192 | + return ""; | ||
| 171 | } | 193 | } |
| 172 | } | 194 | } |
| 173 | return null; | 195 | return null; |
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
| @@ -13,6 +13,7 @@ import java.io.IOException; | @@ -13,6 +13,7 @@ import java.io.IOException; | ||
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * 处理匿名用户访问逻辑 | 15 | * 处理匿名用户访问逻辑 |
| 16 | + * @author lin | ||
| 16 | */ | 17 | */ |
| 17 | @Component | 18 | @Component |
| 18 | public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint { | 19 | public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint { |
| @@ -21,7 +22,6 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi | @@ -21,7 +22,6 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi | ||
| 21 | 22 | ||
| 22 | @Override | 23 | @Override |
| 23 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) { | 24 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) { |
| 24 | -// logger.debug("用户需要登录,访问[{}]失败,AuthenticationException=[{}]", request.getRequestURI(), e.getMessage()); | ||
| 25 | // 允许跨域 | 25 | // 允许跨域 |
| 26 | response.setHeader("Access-Control-Allow-Origin", "*"); | 26 | response.setHeader("Access-Control-Allow-Origin", "*"); |
| 27 | // 允许自定义请求头token(允许head跨域) | 27 | // 允许自定义请求头token(允许head跨域) |
| @@ -30,7 +30,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi | @@ -30,7 +30,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi | ||
| 30 | JSONObject jsonObject = new JSONObject(); | 30 | JSONObject jsonObject = new JSONObject(); |
| 31 | jsonObject.put("code", "-1"); | 31 | jsonObject.put("code", "-1"); |
| 32 | jsonObject.put("msg", "请登录后重新请求"); | 32 | jsonObject.put("msg", "请登录后重新请求"); |
| 33 | - if (request.getRequestURI().contains("api/user/login")){ | 33 | + String logUri = "api/user/login"; |
| 34 | + if (request.getRequestURI().contains(logUri)){ | ||
| 34 | jsonObject.put("msg", e.getMessage()); | 35 | jsonObject.put("msg", e.getMessage()); |
| 35 | } | 36 | } |
| 36 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | 37 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarmMethod.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.bean; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 报警方式 | ||
| 5 | + * @author lin | ||
| 6 | + * 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, | ||
| 7 | + * 7其他报警;可以为直接组合如12为电话报警或 设备报警- | ||
| 8 | + */ | ||
| 9 | +public enum DeviceAlarmMethod { | ||
| 10 | + // 1为电话报警 | ||
| 11 | + Telephone(1), | ||
| 12 | + | ||
| 13 | + // 2为设备报警 | ||
| 14 | + Device(2), | ||
| 15 | + | ||
| 16 | + // 3为短信报警 | ||
| 17 | + SMS(3), | ||
| 18 | + | ||
| 19 | + // 4为 GPS报警 | ||
| 20 | + GPS(4), | ||
| 21 | + | ||
| 22 | + // 5为视频报警 | ||
| 23 | + Video(5), | ||
| 24 | + | ||
| 25 | + // 6为设备故障报警 | ||
| 26 | + DeviceFailure(6), | ||
| 27 | + | ||
| 28 | + // 7其他报警 | ||
| 29 | + Other(7); | ||
| 30 | + | ||
| 31 | + private final int val; | ||
| 32 | + | ||
| 33 | + DeviceAlarmMethod(int val) { | ||
| 34 | + this.val=val; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public int getVal() { | ||
| 38 | + return val; | ||
| 39 | + } | ||
| 40 | +} |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
| @@ -32,7 +32,7 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; | @@ -32,7 +32,7 @@ import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*; | ||
| 32 | @Component | 32 | @Component |
| 33 | public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | 33 | public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| 34 | 34 | ||
| 35 | - private Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class); | 35 | + private final Logger logger = LoggerFactory.getLogger(AlarmNotifyMessageHandler.class); |
| 36 | private final String cmdType = "Alarm"; | 36 | private final String cmdType = "Alarm"; |
| 37 | 37 | ||
| 38 | @Autowired | 38 | @Autowired |
| @@ -85,24 +85,27 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -85,24 +85,27 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 85 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); | 85 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| 86 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); | 86 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| 87 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); | 87 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); |
| 88 | - if (getText(rootElement, "AlarmDescription") == null) { | 88 | + String alarmDescription = getText(rootElement, "AlarmDescription"); |
| 89 | + if (alarmDescription == null) { | ||
| 89 | deviceAlarm.setAlarmDescription(""); | 90 | deviceAlarm.setAlarmDescription(""); |
| 90 | } else { | 91 | } else { |
| 91 | - deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | 92 | + deviceAlarm.setAlarmDescription(alarmDescription); |
| 92 | } | 93 | } |
| 93 | - if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | ||
| 94 | - deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | 94 | + String longitude = getText(rootElement, "Longitude"); |
| 95 | + if (longitude != null && NumericUtil.isDouble(longitude)) { | ||
| 96 | + deviceAlarm.setLongitude(Double.parseDouble(longitude)); | ||
| 95 | } else { | 97 | } else { |
| 96 | deviceAlarm.setLongitude(0.00); | 98 | deviceAlarm.setLongitude(0.00); |
| 97 | } | 99 | } |
| 98 | - if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | ||
| 99 | - deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | 100 | + String latitude = getText(rootElement, "Latitude"); |
| 101 | + if (latitude != null && NumericUtil.isDouble(latitude)) { | ||
| 102 | + deviceAlarm.setLatitude(Double.parseDouble(latitude)); | ||
| 100 | } else { | 103 | } else { |
| 101 | deviceAlarm.setLatitude(0.00); | 104 | deviceAlarm.setLatitude(0.00); |
| 102 | } | 105 | } |
| 103 | 106 | ||
| 104 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { | 107 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| 105 | - if ( deviceAlarm.getAlarmMethod().equals("4")) { | 108 | + if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) { |
| 106 | MobilePosition mobilePosition = new MobilePosition(); | 109 | MobilePosition mobilePosition = new MobilePosition(); |
| 107 | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); | 110 | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); |
| 108 | mobilePosition.setTime(deviceAlarm.getAlarmTime()); | 111 | mobilePosition.setTime(deviceAlarm.getAlarmTime()); |
| @@ -122,7 +125,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -122,7 +125,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 122 | } | 125 | } |
| 123 | } | 126 | } |
| 124 | if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) { | 127 | if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) { |
| 125 | - if (deviceAlarm.getAlarmMethod().equals("5")) { | 128 | + if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { |
| 126 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); | 129 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); |
| 127 | } | 130 | } |
| 128 | } | 131 | } |
| @@ -173,25 +176,28 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | @@ -173,25 +176,28 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme | ||
| 173 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); | 176 | deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); |
| 174 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); | 177 | deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); |
| 175 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); | 178 | deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); |
| 176 | - if (getText(rootElement, "AlarmDescription") == null) { | 179 | + String alarmDescription = getText(rootElement, "AlarmDescription"); |
| 180 | + if (alarmDescription == null) { | ||
| 177 | deviceAlarm.setAlarmDescription(""); | 181 | deviceAlarm.setAlarmDescription(""); |
| 178 | } else { | 182 | } else { |
| 179 | - deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | 183 | + deviceAlarm.setAlarmDescription(alarmDescription); |
| 180 | } | 184 | } |
| 181 | - if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | ||
| 182 | - deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | 185 | + String longitude = getText(rootElement, "Longitude"); |
| 186 | + if (longitude != null && NumericUtil.isDouble(longitude)) { | ||
| 187 | + deviceAlarm.setLongitude(Double.parseDouble(longitude)); | ||
| 183 | } else { | 188 | } else { |
| 184 | deviceAlarm.setLongitude(0.00); | 189 | deviceAlarm.setLongitude(0.00); |
| 185 | } | 190 | } |
| 186 | - if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | ||
| 187 | - deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | 191 | + String latitude = getText(rootElement, "Latitude"); |
| 192 | + if (latitude != null && NumericUtil.isDouble(latitude)) { | ||
| 193 | + deviceAlarm.setLatitude(Double.parseDouble(latitude)); | ||
| 188 | } else { | 194 | } else { |
| 189 | deviceAlarm.setLatitude(0.00); | 195 | deviceAlarm.setLatitude(0.00); |
| 190 | } | 196 | } |
| 191 | 197 | ||
| 192 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { | 198 | if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { |
| 193 | 199 | ||
| 194 | - if (deviceAlarm.getAlarmMethod().equals("5")) { | 200 | + if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) { |
| 195 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); | 201 | deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType")); |
| 196 | } | 202 | } |
| 197 | } | 203 | } |