diff --git a/code/java/天气灾害预警/.idea/.gitignore b/code/java/.idea/.gitignore
similarity index 100%
rename from code/java/天气灾害预警/.idea/.gitignore
rename to code/java/.idea/.gitignore
diff --git a/code/java/天气灾害预警/.idea/compiler.xml b/code/java/.idea/compiler.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/compiler.xml
rename to code/java/.idea/compiler.xml
diff --git a/code/java/天气灾害预警/.idea/disaster_warning.iml b/code/java/.idea/disaster_warning.iml
similarity index 100%
rename from code/java/天气灾害预警/.idea/disaster_warning.iml
rename to code/java/.idea/disaster_warning.iml
diff --git a/code/java/天气灾害预警/.idea/encodings.xml b/code/java/.idea/encodings.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/encodings.xml
rename to code/java/.idea/encodings.xml
diff --git a/code/java/天气灾害预警/.idea/jarRepositories.xml b/code/java/.idea/jarRepositories.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/jarRepositories.xml
rename to code/java/.idea/jarRepositories.xml
diff --git a/code/java/天气灾害预警/.idea/misc.xml b/code/java/.idea/misc.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/misc.xml
rename to code/java/.idea/misc.xml
diff --git a/code/java/天气灾害预警/.idea/runConfigurations/compile.xml b/code/java/.idea/runConfigurations/compile.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/runConfigurations/compile.xml
rename to code/java/.idea/runConfigurations/compile.xml
diff --git a/code/java/天气灾害预警/.idea/uiDesigner.xml b/code/java/.idea/uiDesigner.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/uiDesigner.xml
rename to code/java/.idea/uiDesigner.xml
diff --git a/code/java/天气灾害预警/.idea/vcs.xml b/code/java/.idea/vcs.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/vcs.xml
rename to code/java/.idea/vcs.xml
diff --git a/code/java/天气灾害预警/.idea/天气灾害预警.xml b/code/java/.idea/天气灾害预警.xml
similarity index 100%
rename from code/java/天气灾害预警/.idea/天气灾害预警.xml
rename to code/java/.idea/天气灾害预警.xml
diff --git a/code/java/天气灾害预警/config.json b/code/java/天气灾害预警/config.json
new file mode 100644
index 0000000..bc47edd
--- /dev/null
+++ b/code/java/天气灾害预警/config.json
@@ -0,0 +1,41 @@
+{
+ "title": "天气灾害预警配置文件",
+ "key": "fe9fa8eeeb6f4301a92541eed565dd15",
+ "query_url": "https://devapi.qweather.com/v7/warning/now?",
+ "cities": [
+ {
+ "city_name": "厦门",
+ "city_code": "101230201"
+ },
+ {
+ "city_name": "同安",
+ "city_code": "101230202"
+ },
+ {
+ "city_name": "思明",
+ "city_code": "101230203"
+ },
+ {
+ "city_name": "海沧",
+ "city_code": "101230204"
+ },
+ {
+ "city_name": "湖里",
+ "city_code": "101230205"
+ },
+ {
+ "city_name": "集美",
+ "city_code": "101230206"
+ },
+ {
+ "city_name": "翔安",
+ "city_code": "101230207"
+ }
+ ],
+ "notify_stuffs": [
+ {
+ "stuff_name": "王炜",
+ "mobile_phone": "15959215339"
+ }
+ ]
+}
diff --git a/code/java/天气灾害预警/disaster_warning.iml b/code/java/天气灾害预警/disaster_warning.iml
index cce7f67..90a51a4 100644
--- a/code/java/天气灾害预警/disaster_warning.iml
+++ b/code/java/天气灾害预警/disaster_warning.iml
@@ -1,52 +1,29 @@
-
-
-
-
-
-
-
+
+
+
+
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -131,22 +108,5 @@ under the License.
-
-
-
+
diff --git a/code/java/天气灾害预警/disaster_warning.ipr b/code/java/天气灾害预警/disaster_warning.ipr
index 2556f6a..2844792 100644
--- a/code/java/天气灾害预警/disaster_warning.ipr
+++ b/code/java/天气灾害预警/disaster_warning.ipr
@@ -20,9 +20,6 @@
-
-
-
@@ -44,20 +41,12 @@
-
-
-
-
-
-
-
-
@@ -78,6 +67,127 @@
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
diff --git a/code/java/天气灾害预警/disaster_warning.iws b/code/java/天气灾害预警/disaster_warning.iws
index ca9cbbb..100a6b5 100644
--- a/code/java/天气灾害预警/disaster_warning.iws
+++ b/code/java/天气灾害预警/disaster_warning.iws
@@ -5,13 +5,30 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
@@ -176,6 +193,13 @@
+
+
+
@@ -236,7 +260,9 @@
-
+
+
+
@@ -259,6 +285,11 @@
+
+
+
+
+
@@ -271,6 +302,14 @@
+
+
+
+
+
+
+
+
@@ -288,6 +327,11 @@
+
+
+
+
+
@@ -327,6 +371,8 @@
1647538422605
+
+
@@ -368,6 +414,17 @@
+
+
+
+
+
@@ -420,4 +477,15 @@
+
+
+
+
+ file://$PROJECT_DIR$/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java
+ 40
+
+
+
+
+
\ No newline at end of file
diff --git a/code/java/天气灾害预警/pom.xml b/code/java/天气灾害预警/pom.xml
index 8368ca3..74b4bdb 100644
--- a/code/java/天气灾害预警/pom.xml
+++ b/code/java/天气灾害预警/pom.xml
@@ -4,7 +4,6 @@
com.cpic.xim
disaster_warning
1.0-SNAPSHOT
-
org.apache.httpcomponents
@@ -67,21 +66,15 @@
-
dev
-
-
-
+
true
test
-
-
+
false
diff --git a/code/java/天气灾害预警/src/main/java/AppMain.java b/code/java/天气灾害预警/src/main/java/AppMain.java
index fc03866..3dad3ea 100644
--- a/code/java/天气灾害预警/src/main/java/AppMain.java
+++ b/code/java/天气灾害预警/src/main/java/AppMain.java
@@ -4,41 +4,63 @@
* @LastEditors: Kane
* @LastEditTime: 2022-03-18 00:37:56
* @FilePath: \天气灾害预警\src\main\java\AppMain.java
- * @Description:
- *
- * Copyright (c) ${2022} by Kane, All Rights Reserved.
+ * @Description:
+ *
+ * Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
-import com.cpic.xim.disaster_warning.QWeatherDisasterWarning;
-import com.cpic.xim.disaster_warning.WeatherDisasterWarningGrabber;
+
+import com.cpic.xim.config.City;
+import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
+import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
+import com.cpic.xim.config.WeatherDisasterNotifyConfig;
import java.io.IOException;
-//import java.nio.file.FileSystems;
-//import java.nio.file.Path;
+import java.util.Vector;
public class AppMain
{
+ private static final String CONFIG_FILE_PATH = "./config.json";
+
public static void main( String[] args )
{
- String cityCode = "101230201";
- QWeatherDisasterWarning warning;
- String json = WeatherDisasterWarningGrabber.getWeatherDisasterWarningJSON( cityCode );
-
- if ( json.isEmpty() == true )
- {
- System.out.println( "获取天气信息失败!" );
- }
+ String cityCode = "101230201";
+ String json;
+ QWeatherDisasterWarning warning = null;
+ WeatherDisasterNotifyConfig config = null;
+ //读取配置
try
{
- warning = WeatherDisasterWarningGrabber.convertWeatherDisasterWarning( json );
+ config = WeatherDisasterNotifyConfig.load( CONFIG_FILE_PATH );
}
catch ( IOException error )
{
- error.printStackTrace();
+ System.out.println( "读取配置文件失败!" );
+ System.out.println( error.getMessage() );
+
+ return;
}
-// if ( warning.)
+ Vector cities = config.getCities();
+ String queryURL = config.getQueryUrl();
+ String userKey = config.getKey();
- System.out.println( "1111" );
+ for ( City city : cities )
+ {
+ try
+ {
+ json = WeatherDisasterWarningGrabber.getWeatherDisasterWarningJSON( queryURL,
+ userKey,
+ city.getCityCode() );
+ warning = WeatherDisasterWarningGrabber.convertWeatherDisasterWarning( json );
+ }
+ catch ( IOException error )
+ {
+ System.out.println( "查询" + city.getCityName() + "出现异常!");
+ System.out.println( error.getMessage() );
+
+ continue;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/City.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/City.java
new file mode 100644
index 0000000..9efeaeb
--- /dev/null
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/City.java
@@ -0,0 +1,52 @@
+package com.cpic.xim.config;
+
+import java.util.Objects;
+
+public class City
+{
+ public City() {}
+
+ public String getCityName()
+ {
+ return cityName;
+ }
+
+ public void setCityName( String cityName )
+ {
+ this.cityName = cityName;
+ }
+
+ public String getCityCode()
+ {
+ return cityCode;
+ }
+
+ public void setCityCode( String cityCode )
+ {
+ this.cityCode = cityCode;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+ City city = (City) o;
+ return cityName.equals( city.cityName ) && cityCode.equals( city.cityCode );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash( cityName, cityCode );
+ }
+
+ private String cityName;
+ private String cityCode;
+}
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/CpicxmStuff.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/CpicxmStuff.java
new file mode 100644
index 0000000..643dbfb
--- /dev/null
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/CpicxmStuff.java
@@ -0,0 +1,52 @@
+package com.cpic.xim.config;
+
+import java.util.Objects;
+
+public class CpicxmStuff
+{
+ public CpicxmStuff() {};
+
+ public String getStuffName()
+ {
+ return stuffName;
+ }
+
+ public void setStuffName( String stuffName )
+ {
+ this.stuffName = stuffName;
+ }
+
+ public String getMobilePhone()
+ {
+ return mobilePhone;
+ }
+
+ public void setMobilePhone( String mobilePhone )
+ {
+ this.mobilePhone = mobilePhone;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( !( o instanceof CpicxmStuff ) )
+ {
+ return false;
+ }
+ CpicxmStuff that = (CpicxmStuff) o;
+ return stuffName.equals( that.stuffName ) && mobilePhone.equals( that.mobilePhone );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash( stuffName, mobilePhone );
+ }
+
+ private String stuffName;
+ private String mobilePhone;
+}
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java
new file mode 100644
index 0000000..b88daaa
--- /dev/null
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/config/WeatherDisasterNotifyConfig.java
@@ -0,0 +1,118 @@
+package com.cpic.xim.config;
+
+import java.io.FileReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Vector;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+
+public class WeatherDisasterNotifyConfig
+{
+ private static final int BUFFER_SIZE = 1024;
+
+ public static WeatherDisasterNotifyConfig load( String filePath )
+ throws IOException
+
+ {
+ WeatherDisasterNotifyConfig config = null;
+ ObjectMapper mapper = new ObjectMapper();
+ FileReader configFile = null;
+ StringBuffer json = null;
+ char[] buffer = new char[BUFFER_SIZE];
+
+ //设置json属性
+ mapper.setPropertyNamingStrategy( PropertyNamingStrategy.SNAKE_CASE );
+
+ try{
+ configFile = new FileReader( filePath );
+ json = new StringBuffer();
+
+ int length = configFile.read( buffer );
+
+ while ( length != -1 )
+ {
+ json.append( buffer );
+
+ length = configFile.read( buffer );
+ }
+
+ config = mapper.readValue( json.toString(), WeatherDisasterNotifyConfig.class );
+ }
+ finally
+ {
+ if ( configFile != null )
+ {
+ try
+ {
+ configFile.close();
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return config;
+ }
+
+ public WeatherDisasterNotifyConfig() {};
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle( String title )
+ {
+ this.title = title;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public void setKey( String key )
+ {
+ this.key = key;
+ }
+
+ public String getQueryUrl()
+ {
+ return queryUrl;
+ }
+
+ public void setQueryUrl( String queryUrl )
+ {
+ this.queryUrl = queryUrl;
+ }
+
+ public Vector getCities()
+ {
+ return cities;
+ }
+
+ public void setCities( Vector cities )
+ {
+ this.cities = cities;
+ }
+
+ public Vector getNotifyStuffs()
+ {
+ return notifyStuffs;
+ }
+
+ public void setNotifyStuffs( Vector notifyStuffs )
+ {
+ this.notifyStuffs = notifyStuffs;
+ }
+
+ private String title;
+ private String key;
+ private String queryUrl;
+ private Vector cities;
+ private Vector notifyStuffs;
+}
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarning.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java
similarity index 97%
rename from code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarning.java
rename to code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java
index 7b0d677..e527a88 100644
--- a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarning.java
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarning.java
@@ -1,4 +1,4 @@
-package com.cpic.xim.disaster_warning;
+package com.cpic.xim.notify.disaster;
import java.util.Vector;
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningItem.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java
similarity index 99%
rename from code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningItem.java
rename to code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java
index 9f702bd..ad4ba37 100644
--- a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningItem.java
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningItem.java
@@ -1,4 +1,4 @@
-package com.cpic.xim.disaster_warning;
+package com.cpic.xim.notify.disaster;
import java.util.Objects;
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningRefer.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningRefer.java
similarity index 95%
rename from code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningRefer.java
rename to code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningRefer.java
index c243d5a..39d2581 100644
--- a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/QWeatherDisasterWarningRefer.java
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/QWeatherDisasterWarningRefer.java
@@ -8,7 +8,7 @@
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
-package com.cpic.xim.disaster_warning;
+package com.cpic.xim.notify.disaster;
//import java.util.Objects;
diff --git a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/WeatherDisasterWarningGrabber.java b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java
similarity index 91%
rename from code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/WeatherDisasterWarningGrabber.java
rename to code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java
index ce53792..f96890e 100644
--- a/code/java/天气灾害预警/src/main/java/com/cpic/xim/disaster_warning/WeatherDisasterWarningGrabber.java
+++ b/code/java/天气灾害预警/src/main/java/com/cpic/xim/notify/disaster/WeatherDisasterWarningGrabber.java
@@ -1,4 +1,4 @@
-package com.cpic.xim.disaster_warning;
+package com.cpic.xim.notify.disaster;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -22,11 +22,13 @@ public class WeatherDisasterWarningGrabber
* @param cityCode 城市或区域代码
* @return 返回警报的json字符串
*/
- public static String getWeatherDisasterWarningJSON( String cityCode )
+ public static String getWeatherDisasterWarningJSON( String queryURL,
+ String userKey,
+ String cityCode )
{
//拼接url字符串
String json = "";
- String requestURL = QUERY_URL + "key=" + USER_KEY + "&location=" + cityCode;
+ String requestURL = queryURL + "key=" + userKey + "&location=" + cityCode;
//链接用
HttpURLConnection connection = null;
diff --git a/code/java/天气灾害预警/workspace.code-workspace b/code/java/天气灾害预警/workspace.code-workspace
deleted file mode 100644
index 15c77e1..0000000
--- a/code/java/天气灾害预警/workspace.code-workspace
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "folders": [
- {
- "path": "."
- }
- ],
- "settings": {
- "java.configuration.updateBuildConfiguration": "automatic"
- }
-}
\ No newline at end of file