diff --git a/code/java/DisasterWarning/.vscode/settings.json b/code/java/DisasterWarning/.vscode/settings.json index 3d2b9ba..a635df5 100644 --- a/code/java/DisasterWarning/.vscode/settings.json +++ b/code/java/DisasterWarning/.vscode/settings.json @@ -1,6 +1,6 @@ { "java.configuration.updateBuildConfiguration": "automatic", - "java.format.settings.url": "D:\\工作文档\\配置备份\\vscode\\eclipse-java-google-style.xml", + "java.format.settings.url": "E:\\工作文档\\4、配置备份\\vscode\\eclipse-java-google-style.xml", "[java]": { "editor.detectIndentation": true } diff --git a/code/java/DisasterWarning/config.json b/code/java/DisasterWarning/config.json index dcd83b3..8eea163 100644 --- a/code/java/DisasterWarning/config.json +++ b/code/java/DisasterWarning/config.json @@ -7,8 +7,8 @@ "proxy_setting": { "enable": true, "proxy_mode": "http", - "ip_address": "172.16.39.2", - "port": 18080 + "proxy_address": "172.16.39.2", + "proxy_port": 18080 }, "cities": [ { diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java index dd1892d..fb04bba 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-04-24 10:21:46 * @LastEditors: Kane - * @LastEditTime: 2022-05-10 16:16:28 + * @LastEditTime: 2022-11-04 15:03:05 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\WeatherDisasterNotifyConfig.java * @Description: * @@ -11,7 +11,7 @@ package com.cpic.xim.config; import java.util.Vector; - +import com.cpic.xim.config.db.ProxySetting; import com.fasterxml.jackson.annotation.JsonProperty; @@ -67,6 +67,15 @@ public class WeatherDisasterNotifyConfig this.queryInterval = queryInterval; } + public ProxySetting getProxySetting() + { + return proxySetting; + } + + public void setProxySetting( ProxySetting proxySetting ) + { + this.proxySetting = proxySetting; + } public void setCities( Vector cities ) { @@ -105,6 +114,9 @@ public class WeatherDisasterNotifyConfig @JsonProperty( "query_interval") private int queryInterval; + @JsonProperty( "proxy_setting") + private ProxySetting proxySetting; + @JsonProperty( "wechat_officalaccount_url") private String wechatOfficalAccountURL; diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/OracleConfigManager.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/OracleConfigManager.java index 3a32004..cda3f4a 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/OracleConfigManager.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/OracleConfigManager.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-04-25 21:45:12 * @LastEditors: Kane - * @LastEditTime: 2022-05-03 22:34:37 + * @LastEditTime: 2022-11-04 14:51:25 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigManager.java * @Description: oracle数据库配置文件加载类 * diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/ProxySetting.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/ProxySetting.java new file mode 100644 index 0000000..6d82af7 --- /dev/null +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/config/db/ProxySetting.java @@ -0,0 +1,116 @@ +/* + * @Author: Kane + * @Date: 2022-11-04 14:18:19 + * @LastEditors: Kane + * @LastEditTime: 2022-11-04 15:01:58 + * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\ProxySetting.java + * @Description: 用于存放代理服务器设置的类。 + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ +package com.cpic.xim.config.db; + +import com.fasterxml.jackson.annotation.*;; + +/***************************************************** + * 用于存放代理服务器设置的类。 + *****************************************************/ +public class ProxySetting +{ + public ProxySetting() + {} + + public boolean isEnable() + { + return enable; + } + + public void setEnable( boolean enable ) + { + this.enable = enable; + } + + public String getProxyMode() + { + return proxyMode; + } + + public void setProxyMode( String proxyMode ) + { + this.proxyMode = proxyMode; + } + + public String getProxy_address() + { + return proxy_address; + } + + public void setProxy_address( String proxy_address ) + { + this.proxy_address = proxy_address; + } + + public int getProxy_port() + { + return proxy_port; + } + + public void setProxy_port( int proxy_port ) + { + this.proxy_port = proxy_port; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + (enable ? 1231 : 1237); + result = prime * result + ((proxyMode == null) ? 0 : proxyMode.hashCode()); + result = prime * result + ((proxy_address == null) ? 0 : proxy_address.hashCode()); + result = prime * result + proxy_port; + return result; + } + + @Override + public boolean equals( Object obj ) + { + if ( this == obj) + return true; + if ( obj == null) + return false; + if ( getClass() != obj.getClass()) + return false; + ProxySetting other = (ProxySetting) obj; + if ( enable != other.enable) + return false; + if ( proxyMode == null) + { + if ( other.proxyMode != null) + return false; + } else if ( !proxyMode.equals( other.proxyMode )) + return false; + if ( proxy_address == null) + { + if ( other.proxy_address != null) + return false; + } else if ( !proxy_address.equals( other.proxy_address )) + return false; + if ( proxy_port != other.proxy_port) + return false; + return true; + } + + @JsonProperty( "enable") + private boolean enable = true; + + @JsonProperty( "proxy_mode") + private String proxyMode = "http"; + + @JsonProperty( "proxy_address") + private String proxy_address; + + @JsonProperty( "proxy_port") + private int proxy_port; + +} diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java index ee4f9b5..0f7ecdb 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java @@ -6,13 +6,15 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; //import com.fasterxml.jackson.annotation.JsonIgnore; -public class QWeatherDisasterWarningItem { - public QWeatherDisasterWarningItem() { - } +public class QWeatherDisasterWarningItem +{ + public QWeatherDisasterWarningItem() + {} - public QWeatherDisasterWarningItem(String id, String sender, Date pubTime, String title, String status, - String level, String severity, String severityColor, String type, String typeName, String text, - String related, String urgency, String certainty) { + public QWeatherDisasterWarningItem( String id, String sender, Date pubTime, String title, + String status, String level, String severity, String severityColor, String type, + String typeName, String text, String related, String urgency, String certainty) + { this.id = id; this.sender = sender; this.pubTime = pubTime; @@ -30,7 +32,8 @@ public class QWeatherDisasterWarningItem { } @Override - public int hashCode() { + public int hashCode() + { final int prime = 31; int result = 1; result = prime * result + ((certainty == null) ? 0 : certainty.hashCode()); @@ -51,204 +54,247 @@ public class QWeatherDisasterWarningItem { } @Override - public boolean equals(Object obj) { - if (this == obj) + public boolean equals( Object obj ) + { + if ( this == obj) return true; - if (obj == null) + if ( obj == null) return false; - if (getClass() != obj.getClass()) + if ( getClass() != obj.getClass()) return false; QWeatherDisasterWarningItem other = (QWeatherDisasterWarningItem) obj; - if (certainty == null) { - if (other.certainty != null) + if ( certainty == null) + { + if ( other.certainty != null) return false; - } else if (!certainty.equals(other.certainty)) + } else if ( !certainty.equals( other.certainty )) return false; - if (id == null) { - if (other.id != null) + if ( id == null) + { + if ( other.id != null) return false; - } else if (!id.equals(other.id)) + } else if ( !id.equals( other.id )) return false; - if (level == null) { - if (other.level != null) + if ( level == null) + { + if ( other.level != null) return false; - } else if (!level.equals(other.level)) + } else if ( !level.equals( other.level )) return false; - if (pubTime == null) { - if (other.pubTime != null) + if ( pubTime == null) + { + if ( other.pubTime != null) return false; - } else if (!pubTime.equals(other.pubTime)) + } else if ( !pubTime.equals( other.pubTime )) return false; - if (related == null) { - if (other.related != null) + if ( related == null) + { + if ( other.related != null) return false; - } else if (!related.equals(other.related)) + } else if ( !related.equals( other.related )) return false; - if (sender == null) { - if (other.sender != null) + if ( sender == null) + { + if ( other.sender != null) return false; - } else if (!sender.equals(other.sender)) + } else if ( !sender.equals( other.sender )) return false; - if (severity == null) { - if (other.severity != null) + if ( severity == null) + { + if ( other.severity != null) return false; - } else if (!severity.equals(other.severity)) + } else if ( !severity.equals( other.severity )) return false; - if (severityColor == null) { - if (other.severityColor != null) + if ( severityColor == null) + { + if ( other.severityColor != null) return false; - } else if (!severityColor.equals(other.severityColor)) + } else if ( !severityColor.equals( other.severityColor )) return false; - if (status == null) { - if (other.status != null) + if ( status == null) + { + if ( other.status != null) return false; - } else if (!status.equals(other.status)) + } else if ( !status.equals( other.status )) return false; - if (text == null) { - if (other.text != null) + if ( text == null) + { + if ( other.text != null) return false; - } else if (!text.equals(other.text)) + } else if ( !text.equals( other.text )) return false; - if (title == null) { - if (other.title != null) + if ( title == null) + { + if ( other.title != null) return false; - } else if (!title.equals(other.title)) + } else if ( !title.equals( other.title )) return false; - if (type == null) { - if (other.type != null) + if ( type == null) + { + if ( other.type != null) return false; - } else if (!type.equals(other.type)) + } else if ( !type.equals( other.type )) return false; - if (typeName == null) { - if (other.typeName != null) + if ( typeName == null) + { + if ( other.typeName != null) return false; - } else if (!typeName.equals(other.typeName)) + } else if ( !typeName.equals( other.typeName )) return false; - if (urgency == null) { - if (other.urgency != null) + if ( urgency == null) + { + if ( other.urgency != null) return false; - } else if (!urgency.equals(other.urgency)) + } else if ( !urgency.equals( other.urgency )) return false; return true; } - public String getId() { + public String getId() + { return id; } - public void setId(String id) { + public void setId( String id ) + { this.id = id; } - public String getSender() { + public String getSender() + { return sender; } - public void setSender(String sender) { + public void setSender( String sender ) + { this.sender = sender; } - public Date getPubTime() { + public Date getPubTime() + { return pubTime; } - public void setPubTime(Date pubTime) { + public void setPubTime( Date pubTime ) + { this.pubTime = pubTime; } - public String getTitle() { + public String getTitle() + { return title; } - public void setTitle(String title) { + public void setTitle( String title ) + { this.title = title; } - public String getStatus() { + public String getStatus() + { return status; } - public void setStatus(String status) { + public void setStatus( String status ) + { this.status = status; } - public String getLevel() { + public String getLevel() + { return level; } - public void setLevel(String level) { + public void setLevel( String level ) + { this.level = level; } - public String getSeverity() { + public String getSeverity() + { return severity; } - public void setSeverity(String severity) { + public void setSeverity( String severity ) + { this.severity = severity; } - public String getSeverityColor() { + public String getSeverityColor() + { return severityColor; } - public void setSeverityColor(String severityColor) { + public void setSeverityColor( String severityColor ) + { this.severityColor = severityColor; } - public String getType() { + public String getType() + { return type; } - public void setType(String type) { + public void setType( String type ) + { this.type = type; } - public String getTypeName() { + public String getTypeName() + { return typeName; } - public void setTypeName(String typeName) { + public void setTypeName( String typeName ) + { this.typeName = typeName; } - public String getText() { + public String getText() + { return text; } - public void setText(String text) { + public void setText( String text ) + { this.text = text; } - public String getRelated() { + public String getRelated() + { return related; } - public void setRelated(String related) { + public void setRelated( String related ) + { this.related = related; } - public String getUrgency() { + public String getUrgency() + { return urgency; } - public void setUrgency(String urgency) { + public void setUrgency( String urgency ) + { this.urgency = urgency; } - public String getCertainty() { + public String getCertainty() + { return certainty; } - public void setCertainty(String certainty) { + public void setCertainty( String certainty ) + { this.certainty = certainty; } private String id; private String sender; - @JsonProperty("pubTime") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX") + @JsonProperty( "pubTime") + @JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX") private Date pubTime; private String title; diff --git a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java index 77c9fc9..7e790a3 100644 --- a/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java +++ b/code/java/DisasterWarning/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java @@ -19,17 +19,17 @@ import java.util.zip.GZIPInputStream; /** * */ -public class WeatherDisasterWarningGrabber { +public class WeatherDisasterWarningGrabber +{ /*** * 从和风天气获取天气警报json字符串 * * @param cityCode 城市或区域代码 * @return 返回警报的json字符串 */ - public static String getWeatherDisasterWarningJSON(String queryURL, - String userKey, - String cityCode, - boolean useProxy) { + public static String getWeatherDisasterWarningJSON( String queryURL, String userKey, + String cityCode, boolean useProxy ) + { // 拼接url字符串 String json = ""; String requestURL = queryURL + "key=" + userKey + "&location=" + cityCode; @@ -41,54 +41,73 @@ public class WeatherDisasterWarningGrabber { BufferedReader bufferedReader = null; StringBuilder buffer = new StringBuilder(); - try { - url = new URL(requestURL); + try + { + url = new URL( requestURL ); connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setConnectTimeout(15000); - connection.setReadTimeout(60000); + connection.setRequestMethod( "GET" ); + connection.setConnectTimeout( 15000 ); + connection.setReadTimeout( 60000 ); connection.connect(); // 如果responseCode为200,说明访问成功! - if (connection.getResponseCode() == 200) { + if ( connection.getResponseCode() == 200) + { // 注意,和风使用了gzip压缩响应体 - inputStream = new GZIPInputStream(connection.getInputStream()); - bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + inputStream = new GZIPInputStream( connection.getInputStream() ); + bufferedReader = + new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) ); // 读出数据 String temp = bufferedReader.readLine(); - while (temp != null) { - buffer.append(temp); + while (temp != null) + { + buffer.append( temp ); temp = bufferedReader.readLine(); } json = buffer.toString(); } - } catch (MalformedURLException error) { + } + catch ( MalformedURLException error ) + { error.printStackTrace(); - } catch (IOException error) { - System.out.println("读取失败!"); - } finally { - if (bufferedReader != null) { - try { + } + catch ( IOException error ) + { + System.out.println( "读取失败!" ); + } + finally + { + if ( bufferedReader != null) + { + try + { bufferedReader.close(); - } catch (IOException error) { + } + catch ( IOException error ) + { error.printStackTrace(); } } - if (inputStream != null) { - try { + if ( inputStream != null) + { + try + { inputStream.close(); - } catch (IOException error) { + } + catch ( IOException error ) + { error.printStackTrace(); } } - if (connection != null) { + if ( connection != null) + { connection.disconnect(); } } @@ -103,10 +122,11 @@ public class WeatherDisasterWarningGrabber { * @return 返回 QWeatherDisasterWarning 对象。 * @throws IOException */ - public static QWeatherDisasterWarning convertWeatherDisasterWarning(String json) - throws IOException { + public static QWeatherDisasterWarning convertWeatherDisasterWarning( String json ) + throws IOException + { ObjectMapper mapper = new ObjectMapper(); - QWeatherDisasterWarning warning = mapper.readValue(json, QWeatherDisasterWarning.class); + QWeatherDisasterWarning warning = mapper.readValue( json, QWeatherDisasterWarning.class ); return warning; }