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