Compare commits
No commits in common. "54d73db62f9858e21c61abd57dcbdefc1cb696f3" and "2dbe40b7a8d65cac011fe4e399c039e40e755425" have entirely different histories.
54d73db62f
...
2dbe40b7a8
|
@ -98,5 +98,3 @@ code/java/天气灾害预警/target/
|
||||||
code/java/天气灾害预警/out/
|
code/java/天气灾害预警/out/
|
||||||
*.jar
|
*.jar
|
||||||
*.iws
|
*.iws
|
||||||
*.log
|
|
||||||
*.lck
|
|
||||||
|
|
|
@ -133,7 +133,4 @@ $RECYCLE.BIN/
|
||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
|
||||||
target/*
|
target/*
|
||||||
|
|
||||||
logs/*
|
|
||||||
logs
|
|
|
@ -3,7 +3,6 @@
|
||||||
"key": "fe9fa8eeeb6f4301a92541eed565dd15",
|
"key": "fe9fa8eeeb6f4301a92541eed565dd15",
|
||||||
"query_url": "https://devapi.qweather.com/v7/warning/now?",
|
"query_url": "https://devapi.qweather.com/v7/warning/now?",
|
||||||
"wechat_officalaccount_url": "https://cxxmwx.cpic.com.cn/app/index.php?i=2&c=entry&do=send_group_tpl_api&m=ok_tplmessage",
|
"wechat_officalaccount_url": "https://cxxmwx.cpic.com.cn/app/index.php?i=2&c=entry&do=send_group_tpl_api&m=ok_tplmessage",
|
||||||
"query_interval": 10,
|
|
||||||
"cities": [
|
"cities": [
|
||||||
{
|
{
|
||||||
"city_name": "厦门",
|
"city_name": "厦门",
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
{
|
{
|
||||||
"tns_name": "xmcx1",
|
"tns_name": "xmcx1",
|
||||||
"ip_addr": "10.39.0.86",
|
"ip_addr": "10.39.0.86",
|
||||||
"jdbc_url": "jdbc:oracle:thin:@10.39.0.86:1521:xmcx1",
|
"user_name": "",
|
||||||
"table_space": "wechat",
|
"password": "",
|
||||||
"user_name": "wechat",
|
|
||||||
"password": "@rn7Q+t5zeyKIZ~s",
|
|
||||||
"tables": [
|
"tables": [
|
||||||
{
|
{
|
||||||
"table_name": "weather_disaster_notify",
|
"table_name": "",
|
||||||
"table_description": "天气预警消息表"
|
"table_description": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
|
||||||
|
|
||||||
.level = INFO
|
|
||||||
|
|
||||||
java.util.logging.FileHandler.pattern = ./logs/log_%u.log
|
|
||||||
java.util.logging.FileHandler.limit = 50000
|
|
||||||
java.util.logging.FileHandler.count = 1
|
|
||||||
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
|
|
||||||
java.util.logging.FileHandler.append = true;
|
|
|
@ -5,13 +5,6 @@
|
||||||
<artifactId>disaster_warning</artifactId>
|
<artifactId>disaster_warning</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>com.oracle</groupId>
|
|
||||||
<artifactId>ojdbc8</artifactId>
|
|
||||||
<version>1.0</version>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${project.basedir}/lib/ojdbc8.jar</systemPath>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
|
@ -23,7 +16,7 @@
|
||||||
<version>4.13.2</version>
|
<version>4.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>
|
<dependency>
|
||||||
<groupId>commons-beanutils</groupId>
|
<groupId>commons-beanutils</groupId>
|
||||||
<artifactId>commons-beanutils</artifactId>
|
<artifactId>commons-beanutils</artifactId>
|
||||||
<version>1.9.4</version>
|
<version>1.9.4</version>
|
||||||
|
@ -53,7 +46,7 @@
|
||||||
<artifactId>json-lib</artifactId>
|
<artifactId>json-lib</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.4</version>
|
||||||
<classifier>jdk15</classifier>
|
<classifier>jdk15</classifier>
|
||||||
</dependency> -->
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
|
@ -79,40 +72,6 @@
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>compile</defaultGoal>
|
<defaultGoal>compile</defaultGoal>
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>3.0.0-M6</version>
|
|
||||||
<configuration>
|
|
||||||
<skipTests>true</skipTests>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>AppMain</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assmenbly</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
</build>
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
|
|
|
@ -2,62 +2,41 @@
|
||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 10:53:49
|
* @Date: 2022-04-22 10:53:49
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-05-10 16:28:07
|
* @LastEditTime: 2022-04-23 23:22:57
|
||||||
* @FilePath: \DisasterWarning\src\main\java\AppMain.java
|
* @FilePath: \DisasterWarning\src\main\java\AppMain.java
|
||||||
* @Description: 和风天气预警推送厦门太保公众号主程序!
|
* @Description: 和风天气预警推送厦门太保公众号主程序!
|
||||||
*
|
*
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
import com.cpic.xim.config.AppConfigManager;
|
|
||||||
import com.cpic.xim.config.City;
|
import com.cpic.xim.config.City;
|
||||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
|
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
|
||||||
import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
|
import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
|
||||||
import com.cpic.xim.wechat.officalAccount.sendMessage;
|
|
||||||
import com.cpic.xim.config.WeatherDisasterNotifyConfig;
|
import com.cpic.xim.config.WeatherDisasterNotifyConfig;
|
||||||
import java.io.FileInputStream;
|
import com.cpic.xim.wechat.officalAccount.sendMessage;
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Vector;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
public class AppMain
|
public class AppMain
|
||||||
{
|
{
|
||||||
// private final static String LOG_FILE_PATH = "./logs/app%u.log";
|
private static final String CONFIG_FILE_PATH = "./config.json";
|
||||||
|
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
String json;
|
String json;
|
||||||
WeatherDisasterNotifyConfig config = null;
|
WeatherDisasterNotifyConfig config = null;
|
||||||
QWeatherDisasterWarning warning = null;
|
QWeatherDisasterWarning warning = null;
|
||||||
Logger logger = null;
|
|
||||||
|
|
||||||
// 配置logger
|
|
||||||
try
|
|
||||||
{
|
|
||||||
setRootLogger();
|
|
||||||
|
|
||||||
logger = Logger.getLogger( "com.cpicxim" );
|
|
||||||
}
|
|
||||||
catch ( IOException error )
|
|
||||||
{
|
|
||||||
System.out.println( "配置logger失败,原因:" + error.getMessage() );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取配置
|
// 读取配置
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config = AppConfigManager.getConfig();
|
config = WeatherDisasterNotifyConfig.load( CONFIG_FILE_PATH );
|
||||||
}
|
}
|
||||||
catch ( IOException error )
|
catch (IOException error)
|
||||||
{
|
{
|
||||||
System.out.println( "读取配置文件失败!" );
|
System.out.println( "读取配置文件失败!" );
|
||||||
System.out.println( error.getMessage() );
|
System.out.println( error.getMessage() );
|
||||||
|
|
||||||
logger.log( Level.SEVERE, "读取配置文件失败:{0}", error.getMessage() );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,91 +45,30 @@ public class AppMain
|
||||||
String userKey = config.getKey();
|
String userKey = config.getKey();
|
||||||
|
|
||||||
// 遍历所有城市,查询是否有警报,有则推送。
|
// 遍历所有城市,查询是否有警报,有则推送。
|
||||||
while (true)
|
for ( City city : cities)
|
||||||
{
|
{
|
||||||
for ( City city : cities )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
json = WeatherDisasterWarningGrabber.getWeatherDisasterWarningJSON( queryURL,
|
|
||||||
userKey, city.getCityCode() );
|
|
||||||
warning = WeatherDisasterWarningGrabber.convertWeatherDisasterWarning( json );
|
|
||||||
|
|
||||||
logger.log( Level.INFO, "查询{0}天气预警,结果:{1}。", new Object[]
|
|
||||||
{ city.getCityName(), json} );
|
|
||||||
|
|
||||||
// 判断是否有警报
|
|
||||||
if ( warning.getWarning().isEmpty() == true)
|
|
||||||
{
|
|
||||||
logger.log( Level.INFO, "查询{0}天气预警,无警报!。", new Object[]
|
|
||||||
{ city.getCityName()} );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[]
|
|
||||||
{ city.getCityName()} );
|
|
||||||
|
|
||||||
sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
|
|
||||||
warning );
|
|
||||||
|
|
||||||
logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[]
|
|
||||||
{ city.getCityName()} );
|
|
||||||
|
|
||||||
sendMessage.saveWeatherDisasterWarning( city.getCityName(), warning );
|
|
||||||
}
|
|
||||||
catch ( IOException error )
|
|
||||||
{
|
|
||||||
System.out.println( "查询" + city.getCityName() + "出现异常!" );
|
|
||||||
System.out.println( error.getMessage() );
|
|
||||||
|
|
||||||
logger.log( Level.SEVERE, "查询 {0} 出现异常:{1}。", new Object[]
|
|
||||||
{ city.getCityName(), error.getMessage()} );
|
|
||||||
}
|
|
||||||
catch ( SQLException error )
|
|
||||||
{
|
|
||||||
logger.log( Level.SEVERE, "查询 {0} 写入数据库失败:{1}。", new Object[]
|
|
||||||
{ city.getCityName(), error.getMessage()} );
|
|
||||||
}
|
|
||||||
catch ( ClassNotFoundException error )
|
|
||||||
{
|
|
||||||
logger.log( Level.SEVERE, "查询 {0} 加载oracle驱动失败:{1}。", new Object[]
|
|
||||||
{ city.getCityName(), error.getMessage()} );
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
logger.log( Level.SEVERE, "查询 {0} 出现未知错误:{1}。", new Object[]
|
|
||||||
{ city.getCityName(), error.getMessage()} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.log( Level.INFO, "查询结束,休眠{0}分钟。", config.getQueryInterval() );
|
json = WeatherDisasterWarningGrabber.getWeatherDisasterWarningJSON( queryURL,
|
||||||
Thread.sleep( config.getQueryInterval() * 1000 * 60 );
|
userKey, city.getCityCode() );
|
||||||
|
warning = WeatherDisasterWarningGrabber.convertWeatherDisasterWarning( json );
|
||||||
|
|
||||||
|
// 判断是否有警报
|
||||||
|
if ( warning.getWarning().isEmpty() == true)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
|
||||||
|
warning );
|
||||||
}
|
}
|
||||||
catch ( InterruptedException error )
|
catch (IOException error)
|
||||||
{
|
{
|
||||||
logger.log( Level.SEVERE, "线程休眠异常,错误信息:{0}", new Object[]
|
System.out.println( "查询" + city.getCityName() + "出现异常!" );
|
||||||
{ error.getMessage()} );
|
System.out.println( error.getMessage() );
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置JUL的logger。
|
|
||||||
*/
|
|
||||||
private static void setRootLogger() throws IOException
|
|
||||||
{
|
|
||||||
LogManager logManager = LogManager.getLogManager();
|
|
||||||
// 使用外部的配置文件。
|
|
||||||
FileInputStream configFile = new FileInputStream( "./logging.properties" );
|
|
||||||
// 使用jar中的配置文件。
|
|
||||||
// InputStream configFile =
|
|
||||||
// AppMain.class.getClassLoader().getResourceAsStream( "logging.properties" );
|
|
||||||
|
|
||||||
logManager.readConfiguration( configFile );
|
|
||||||
|
|
||||||
Logger.getLogger( "com.cpicxim" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-05-10 16:06:14
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-05-10 16:09:07
|
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\AppConfigManager.java
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.cpic.xim.config;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
||||||
|
|
||||||
public class AppConfigManager
|
|
||||||
{
|
|
||||||
private static final int BUFFER_SIZE = 1024;
|
|
||||||
private static final String CONFIG_FILE_CHARSET = "UTF-8";
|
|
||||||
private static final String CONFIG_FILE_PATH = "./config.json";
|
|
||||||
private static WeatherDisasterNotifyConfig appConfig = null;
|
|
||||||
|
|
||||||
public static WeatherDisasterNotifyConfig getConfig() throws IOException
|
|
||||||
|
|
||||||
{
|
|
||||||
if ( appConfig != null)
|
|
||||||
{
|
|
||||||
return appConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
FileInputStream configFile = null;
|
|
||||||
InputStreamReader in = null;
|
|
||||||
StringBuffer json = null;
|
|
||||||
char[] buffer = new char[BUFFER_SIZE];
|
|
||||||
|
|
||||||
// 设置json属性
|
|
||||||
mapper.setPropertyNamingStrategy( PropertyNamingStrategy.SNAKE_CASE );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
configFile = new FileInputStream( CONFIG_FILE_PATH );
|
|
||||||
in = new InputStreamReader( configFile, CONFIG_FILE_CHARSET );
|
|
||||||
json = new StringBuffer();
|
|
||||||
|
|
||||||
int length = in.read( buffer );
|
|
||||||
|
|
||||||
while (length != -1)
|
|
||||||
{
|
|
||||||
json.append( buffer );
|
|
||||||
|
|
||||||
length = in.read( buffer );
|
|
||||||
}
|
|
||||||
|
|
||||||
appConfig = mapper.readValue( json.toString(), WeatherDisasterNotifyConfig.class );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if ( configFile != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
configFile.close();
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return appConfig;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +1,62 @@
|
||||||
/*
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-04-24 10:21:46
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-05-10 16:16:28
|
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\WeatherDisasterNotifyConfig.java
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
package com.cpic.xim.config;
|
package com.cpic.xim.config;
|
||||||
|
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
|
|
||||||
public class WeatherDisasterNotifyConfig
|
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 WeatherDisasterNotifyConfig()
|
||||||
{};
|
{};
|
||||||
|
@ -56,18 +96,6 @@ public class WeatherDisasterNotifyConfig
|
||||||
return cities;
|
return cities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getQueryInterval()
|
|
||||||
{
|
|
||||||
return queryInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQueryInterval( int queryInterval )
|
|
||||||
{
|
|
||||||
this.queryInterval = queryInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setCities( Vector<City> cities )
|
public void setCities( Vector<City> cities )
|
||||||
{
|
{
|
||||||
this.cities = cities;
|
this.cities = cities;
|
||||||
|
@ -93,24 +121,14 @@ public class WeatherDisasterNotifyConfig
|
||||||
this.wechatOfficalAccountURL = wechatOfficalAccountURL;
|
this.wechatOfficalAccountURL = wechatOfficalAccountURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty( "title")
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@JsonProperty( "key")
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
@JsonProperty( "query_url")
|
|
||||||
private String queryUrl;
|
private String queryUrl;
|
||||||
|
|
||||||
@JsonProperty( "query_interval")
|
|
||||||
private int queryInterval;
|
|
||||||
|
|
||||||
@JsonProperty( "wechat_officalaccount_url")
|
@JsonProperty( "wechat_officalaccount_url")
|
||||||
private String wechatOfficalAccountURL;
|
private String wechatOfficalAccountURL;
|
||||||
|
|
||||||
@JsonProperty( "cities")
|
|
||||||
private Vector<City> cities;
|
private Vector<City> cities;
|
||||||
|
|
||||||
@JsonProperty( "notify_stuffs")
|
|
||||||
private Vector<CpicxmStuff> notifyStuffs;
|
private Vector<CpicxmStuff> notifyStuffs;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 17:33:30
|
* @Date: 2022-04-22 17:33:30
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-04-27 16:53:13
|
* @LastEditTime: 2022-04-23 23:50:20
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\DBTable.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\DBTable.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
|
@ -12,8 +12,6 @@ package com.cpic.xim.config.db;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public class DBTable
|
public class DBTable
|
||||||
{
|
{
|
||||||
public DBTable()
|
public DBTable()
|
||||||
|
@ -61,9 +59,6 @@ public class DBTable
|
||||||
return Objects.hash( tableName, tableDescription );
|
return Objects.hash( tableName, tableDescription );
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty( "table_name")
|
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
@JsonProperty( "table_description")
|
|
||||||
private String tableDescription;
|
private String tableDescription;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 17:33:30
|
* @Date: 2022-04-22 17:33:30
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-04-25 21:33:07
|
* @LastEditTime: 2022-04-23 23:51:46
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfig.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfig.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
|
@ -11,11 +11,7 @@
|
||||||
package com.cpic.xim.config.db;
|
package com.cpic.xim.config.db;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description oracle数据库相关参数对象。
|
|
||||||
*/
|
|
||||||
public class OracleConfig
|
public class OracleConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -49,17 +45,6 @@ public class OracleConfig
|
||||||
this.jdbcURL = jdbcURL;
|
this.jdbcURL = jdbcURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getTableSpace()
|
|
||||||
{
|
|
||||||
return tableSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTableSpace( String tableSpace )
|
|
||||||
{
|
|
||||||
this.tableSpace = tableSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserName()
|
public String getUserName()
|
||||||
{
|
{
|
||||||
return userName;
|
return userName;
|
||||||
|
@ -90,24 +75,10 @@ public class OracleConfig
|
||||||
this.tables = tables;
|
this.tables = tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty( "tns_name")
|
|
||||||
private String tnsName;
|
private String tnsName;
|
||||||
|
|
||||||
@JsonProperty( "ip_addr")
|
|
||||||
private String ipAddr;
|
private String ipAddr;
|
||||||
|
|
||||||
@JsonProperty( "jdbc_url")
|
|
||||||
private String jdbcURL;
|
private String jdbcURL;
|
||||||
|
|
||||||
@JsonProperty( "table_space")
|
|
||||||
private String tableSpace;
|
|
||||||
|
|
||||||
@JsonProperty( "user_name")
|
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
@JsonProperty( "password")
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@JsonProperty( "tables")
|
|
||||||
private Vector<DBTable> tables;
|
private Vector<DBTable> tables;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-04-25 21:45:12
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-05-03 22:34:37
|
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigManager.java
|
|
||||||
* @Description: oracle数据库配置文件加载类
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
package com.cpic.xim.config.db;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.*;
|
|
||||||
|
|
||||||
public class OracleConfigManager
|
|
||||||
{
|
|
||||||
private static final String CONFIG_FILE_PATH = "./db.json";
|
|
||||||
private static final String CONFIG_FILE_CHARSET = "UTF-8";
|
|
||||||
private static final int BUFFER_SIZE = 1024;
|
|
||||||
private static OracleConfig dbConfig = null;
|
|
||||||
|
|
||||||
private OracleConfigManager()
|
|
||||||
{}
|
|
||||||
|
|
||||||
public static OracleConfig getOracleConfig() throws IOException
|
|
||||||
{
|
|
||||||
FileInputStream file = null;
|
|
||||||
InputStreamReader in = null;
|
|
||||||
StringBuffer json = null;
|
|
||||||
char[] buffer = new char[BUFFER_SIZE];
|
|
||||||
|
|
||||||
if ( dbConfig != null)
|
|
||||||
{
|
|
||||||
return dbConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file = new FileInputStream( CONFIG_FILE_PATH );
|
|
||||||
in = new InputStreamReader( file, CONFIG_FILE_CHARSET );
|
|
||||||
json = new StringBuffer();
|
|
||||||
|
|
||||||
int count = in.read( buffer );
|
|
||||||
|
|
||||||
while (count != -1)
|
|
||||||
{
|
|
||||||
json.append( buffer );
|
|
||||||
|
|
||||||
count = in.read( buffer );
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
|
|
||||||
dbConfig = mapper.readValue( json.toString(), OracleConfig.class );
|
|
||||||
}
|
|
||||||
catch ( IOException error )
|
|
||||||
{
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbConfig;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +1,23 @@
|
||||||
/*
|
|
||||||
* @Author: Kane
|
|
||||||
* @Date: 2022-04-24 10:21:46
|
|
||||||
* @LastEditors: Kane
|
|
||||||
* @LastEditTime: 2022-04-24 11:28:58
|
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\notify\disaster\QWeatherDisasterWarning.java
|
|
||||||
* @Description:
|
|
||||||
*
|
|
||||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
package com.cpic.xim.notify.disaster;
|
package com.cpic.xim.notify.disaster;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public class QWeatherDisasterWarning
|
public class QWeatherDisasterWarning
|
||||||
{
|
{
|
||||||
public QWeatherDisasterWarning()
|
public QWeatherDisasterWarning( String code,
|
||||||
{}
|
String updateTime,
|
||||||
|
String fxLink,
|
||||||
|
Vector<QWeatherDisasterWarningItem> warning,
|
||||||
|
QWeatherDisasterWarningRefer refer )
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
this.fxLink = fxLink;
|
||||||
|
this.warning = warning;
|
||||||
|
this.refer = refer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QWeatherDisasterWarning() {}
|
||||||
|
|
||||||
public String getCode()
|
public String getCode()
|
||||||
{
|
{
|
||||||
|
@ -30,12 +29,12 @@ public class QWeatherDisasterWarning
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getUpdateTime()
|
public String getUpdateTime()
|
||||||
{
|
{
|
||||||
return updateTime;
|
return updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdateTime( Date updateTime )
|
public void setUpdateTime( String updateTime )
|
||||||
{
|
{
|
||||||
this.updateTime = updateTime;
|
this.updateTime = updateTime;
|
||||||
}
|
}
|
||||||
|
@ -70,19 +69,9 @@ public class QWeatherDisasterWarning
|
||||||
this.refer = refer;
|
this.refer = refer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty( "code")
|
private String code;
|
||||||
private String code;
|
private String updateTime;
|
||||||
|
private String fxLink;
|
||||||
@JsonProperty( "updateTime")
|
|
||||||
@JsonFormat( pattern = "yyyy-MM-dd\'T\'HH:mmXXX")
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
@JsonProperty( "fxLink")
|
|
||||||
private String fxLink;
|
|
||||||
|
|
||||||
@JsonProperty( "warning")
|
|
||||||
private Vector<QWeatherDisasterWarningItem> warning;
|
private Vector<QWeatherDisasterWarningItem> warning;
|
||||||
|
private QWeatherDisasterWarningRefer refer;
|
||||||
@JsonProperty( "refer")
|
|
||||||
private QWeatherDisasterWarningRefer refer;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +1,79 @@
|
||||||
package com.cpic.xim.notify.disaster;
|
package com.cpic.xim.notify.disaster;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
//import com.fasterxml.jackson.annotation.JsonIgnore;
|
//import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
public class QWeatherDisasterWarningItem
|
public class QWeatherDisasterWarningItem
|
||||||
{
|
{
|
||||||
public QWeatherDisasterWarningItem()
|
public QWeatherDisasterWarningItem() {}
|
||||||
{}
|
public QWeatherDisasterWarningItem( String id,
|
||||||
|
String sender,
|
||||||
public QWeatherDisasterWarningItem( String id, String sender, Date pubTime, String title,
|
String pubTime,
|
||||||
String status, String level, String type, String typeName, String text, String related,
|
String title,
|
||||||
String urgency, String certainty)
|
String status,
|
||||||
|
String level,
|
||||||
|
String type,
|
||||||
|
String typeName,
|
||||||
|
String text,
|
||||||
|
String related,
|
||||||
|
String urgency, String certainty )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.pubTime = pubTime;
|
this.pubTime = pubTime;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.related = related;
|
this.related = related;
|
||||||
this.urgency = urgency;
|
this.urgency = urgency;
|
||||||
this.certainty = certainty;
|
this.certainty = certainty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals( Object o )
|
public boolean equals( Object o )
|
||||||
{
|
{
|
||||||
if ( this == o)
|
if ( this == o )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( o == null || getClass() != o.getClass())
|
if ( o == null || getClass() != o.getClass() )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QWeatherDisasterWarningItem that = (QWeatherDisasterWarningItem) o;
|
QWeatherDisasterWarningItem that = (QWeatherDisasterWarningItem) o;
|
||||||
return id.equals( that.id ) && Objects.equals( sender, that.sender )
|
return id.equals( that.id ) && Objects.equals( sender, that.sender ) && Objects.equals( pubTime,
|
||||||
&& Objects.equals( pubTime, that.pubTime ) && Objects.equals( title, that.title )
|
that.pubTime ) && Objects.equals(
|
||||||
&& Objects.equals( status, that.status ) && Objects.equals( level, that.level )
|
title,
|
||||||
&& Objects.equals( type, that.type ) && Objects.equals( typeName, that.typeName )
|
that.title ) && Objects.equals( status, that.status ) && Objects.equals( level,
|
||||||
&& Objects.equals( text, that.text ) && Objects.equals( related, that.related )
|
that.level ) && Objects.equals(
|
||||||
&& Objects.equals( urgency, that.urgency )
|
type,
|
||||||
&& Objects.equals( certainty, that.certainty );
|
that.type ) && Objects.equals( typeName, that.typeName ) && Objects.equals( text,
|
||||||
|
that.text ) && Objects.equals(
|
||||||
|
related,
|
||||||
|
that.related ) && Objects.equals( urgency, that.urgency ) && Objects.equals( certainty,
|
||||||
|
that.certainty );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Objects.hash( id, sender, pubTime, title, status, level, type, typeName, text,
|
return Objects.hash( id,
|
||||||
related, urgency, certainty );
|
sender,
|
||||||
|
pubTime,
|
||||||
|
title,
|
||||||
|
status,
|
||||||
|
level,
|
||||||
|
type,
|
||||||
|
typeName,
|
||||||
|
text,
|
||||||
|
related,
|
||||||
|
urgency,
|
||||||
|
certainty );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
|
@ -78,12 +96,12 @@ public class QWeatherDisasterWarningItem
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getPubTime()
|
public String getPubTime()
|
||||||
{
|
{
|
||||||
return pubTime;
|
return pubTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPubTime( Date pubTime )
|
public void setPubTime( String pubTime )
|
||||||
{
|
{
|
||||||
this.pubTime = pubTime;
|
this.pubTime = pubTime;
|
||||||
}
|
}
|
||||||
|
@ -180,11 +198,8 @@ public class QWeatherDisasterWarningItem
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String sender;
|
private String sender;
|
||||||
|
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm")
|
||||||
@JsonProperty( "pubTime")
|
private String pubTime;
|
||||||
@JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX")
|
|
||||||
private Date pubTime;
|
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private String status;
|
private String status;
|
||||||
private String level;
|
private String level;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 10:53:49
|
* @Date: 2022-04-22 10:53:49
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-05-06 11:14:32
|
* @LastEditTime: 2022-04-23 23:46:54
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
|
||||||
* @Description: 用来推送公众号消息的程序库。
|
* @Description: 用来推送公众号消息的程序库。
|
||||||
*
|
*
|
||||||
|
@ -10,20 +10,13 @@
|
||||||
*/
|
*/
|
||||||
package com.cpic.xim.wechat.officalAccount;
|
package com.cpic.xim.wechat.officalAccount;
|
||||||
|
|
||||||
import com.cpic.xim.config.db.OracleConfigManager;
|
|
||||||
import com.cpic.xim.config.db.OracleConfig;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import com.cpic.xim.notify.disaster.*;
|
import com.cpic.xim.notify.disaster.*;
|
||||||
import com.cpic.xim.httpUtil.HttpUtils;
|
import com.cpic.xim.httpUtil.HttpUtils;
|
||||||
|
|
||||||
|
@ -38,7 +31,7 @@ public class sendMessage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》
|
* 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》
|
||||||
* 使用 post 方式,请求体内容以最基础的 post 格式。
|
*
|
||||||
* @param officalAccountURL 产险厦门分公司公众号接口网址
|
* @param officalAccountURL 产险厦门分公司公众号接口网址
|
||||||
* @param warning 灾害预警对象
|
* @param warning 灾害预警对象
|
||||||
*/
|
*/
|
||||||
|
@ -56,7 +49,7 @@ public class sendMessage
|
||||||
headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
|
headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
|
||||||
|
|
||||||
// 遍历消息,将消息推送出去。
|
// 遍历消息,将消息推送出去。
|
||||||
for ( QWeatherDisasterWarningItem item : warningItems )
|
for ( QWeatherDisasterWarningItem item : warningItems)
|
||||||
{
|
{
|
||||||
// 拼接消息内容
|
// 拼接消息内容
|
||||||
String title = item.getTitle();
|
String title = item.getTitle();
|
||||||
|
@ -64,6 +57,7 @@ public class sendMessage
|
||||||
String color = warningLevel.keySet().contains( item.getLevel() )
|
String color = warningLevel.keySet().contains( item.getLevel() )
|
||||||
? warningLevel.get( item.getLevel() )
|
? warningLevel.get( item.getLevel() )
|
||||||
: "#000000";
|
: "#000000";
|
||||||
|
|
||||||
requestBody = new StringBuilder();
|
requestBody = new StringBuilder();
|
||||||
|
|
||||||
requestBody.append( "tplid=57&groupid=1&first=尊敬的#realname#,您好!&" );
|
requestBody.append( "tplid=57&groupid=1&first=尊敬的#realname#,您好!&" );
|
||||||
|
@ -75,188 +69,13 @@ public class sendMessage
|
||||||
{
|
{
|
||||||
HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
|
HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
|
||||||
}
|
}
|
||||||
catch ( MalformedURLException error )
|
catch (MalformedURLException error)
|
||||||
{
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查预警是否已经推送过,通过 QWeatherDisasterWarningItem 对象的 id 属性。
|
|
||||||
* 查询 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表,
|
|
||||||
* 统计 warningID 的数量,如果不为0,说明该预警已经保存过,视为已经推送过。
|
|
||||||
* @param warningID 预警的id
|
|
||||||
* @return 如果推送过,返回false,否则返回 true。
|
|
||||||
*/
|
|
||||||
public static boolean checkWarningHasSended( String warningID )
|
|
||||||
throws ClassNotFoundException, SQLException, IOException
|
|
||||||
{
|
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
OracleConfig dbConfig = OracleConfigManager.getOracleConfig();;
|
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
|
|
||||||
String jdbcURL = dbConfig.getJdbcURL();
|
|
||||||
String userName = dbConfig.getUserName();
|
|
||||||
String password = dbConfig.getPassword();
|
|
||||||
String sql = "select count(*) from weather_disaster_notify where notify_id = ?";
|
|
||||||
|
|
||||||
// Logger logger = Logger.getLogger( "com.cpicxim.wechat.officalAccount.sendMessage" );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName( "oracle.jdbc.driver.OracleDriver" );
|
|
||||||
|
|
||||||
conn = DriverManager.getConnection( jdbcURL, userName, password );
|
|
||||||
stmt = conn.prepareStatement( sql );
|
|
||||||
stmt.setString( 1, warningID );
|
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
if ( rs.next() && rs.getInt( 1 ) == 0)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ( rs != null)
|
|
||||||
{
|
|
||||||
rs.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ( stmt != null)
|
|
||||||
{
|
|
||||||
stmt.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ( conn != null)
|
|
||||||
{
|
|
||||||
conn.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存天气预警警报数据。
|
|
||||||
* 保存至 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表。
|
|
||||||
* 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。
|
|
||||||
* @param city 城市名称
|
|
||||||
* @param warning 预警数据,为 QWeatherDisasterWarningItem 对象。
|
|
||||||
* @throws SQLException 执行sql时可能抛出的异常。出现sql异常,就回滚事务。
|
|
||||||
* @throws IOException 读取数据库配置文件时可能抛出的异常。
|
|
||||||
* @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。
|
|
||||||
*/
|
|
||||||
public static void saveWeatherDisasterWarning( String city, QWeatherDisasterWarning warnings )
|
|
||||||
throws SQLException, IOException, ClassNotFoundException
|
|
||||||
{
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
|
|
||||||
String sql = "insert into weather_disaster_notify(notify_id, sender, city,"
|
|
||||||
+ "warning_level, warning_type_code, warning_type_name, title,"
|
|
||||||
+ "text, pub_time) values( ?,?,?,?,?,?,?,?,?)";
|
|
||||||
|
|
||||||
OracleConfig dbConfig = OracleConfigManager.getOracleConfig();
|
|
||||||
|
|
||||||
String jdbcURL = dbConfig.getJdbcURL();
|
|
||||||
String userName = dbConfig.getUserName();
|
|
||||||
String password = dbConfig.getPassword();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName( "oracle.jdbc.driver.OracleDriver" );
|
|
||||||
|
|
||||||
conn = DriverManager.getConnection( jdbcURL, userName, password );
|
|
||||||
stmt = conn.prepareStatement( sql );
|
|
||||||
|
|
||||||
for ( QWeatherDisasterWarningItem warning : warnings.getWarning() )
|
|
||||||
{
|
|
||||||
java.sql.Timestamp pubTime =
|
|
||||||
new java.sql.Timestamp( warning.getPubTime().getTime() );
|
|
||||||
|
|
||||||
stmt.setString( 1, warning.getId() );
|
|
||||||
stmt.setString( 2, warning.getSender() );
|
|
||||||
stmt.setString( 3, city );
|
|
||||||
stmt.setString( 4, warning.getLevel() );
|
|
||||||
stmt.setString( 5, warning.getType() );
|
|
||||||
stmt.setString( 6, warning.getTypeName() );
|
|
||||||
stmt.setString( 7, warning.getTitle() );
|
|
||||||
stmt.setString( 8, warning.getText() );
|
|
||||||
stmt.setTimestamp( 9, pubTime );
|
|
||||||
|
|
||||||
stmt.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 没有问题就提交
|
|
||||||
conn.commit();
|
|
||||||
}
|
|
||||||
catch ( SQLException error )
|
|
||||||
{
|
|
||||||
// 出现sql错误,就回滚!
|
|
||||||
if ( conn != null)
|
|
||||||
{
|
|
||||||
conn.rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ( stmt != null)
|
|
||||||
{
|
|
||||||
stmt.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ( conn != null)
|
|
||||||
{
|
|
||||||
conn.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
// 预警级别色彩
|
// 预警级别色彩
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
|
||||||
|
|
||||||
.level = INFO
|
|
||||||
|
|
||||||
java.util.logging.FileHandler.pattern = ./logs/log_%u.log
|
|
||||||
java.util.logging.FileHandler.limit = 50000
|
|
||||||
java.util.logging.FileHandler.count = 10
|
|
||||||
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
|
|
||||||
java.util.logging.FileHandler.append = true;
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-22 10:53:49
|
* @Date: 2022-04-22 10:53:49
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-05-10 11:33:41
|
* @LastEditTime: 2022-04-23 23:44:54
|
||||||
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
|
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
|
@ -12,10 +12,10 @@ package com.cpic.xim.wechat.officalAccount;
|
||||||
|
|
||||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
|
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import com.cpic.xim.httpUtil.*;
|
import com.cpic.xim.httpUtil.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -32,7 +32,7 @@ public class sendMessageTest
|
||||||
{
|
{
|
||||||
// sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" );
|
// sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容!" );
|
||||||
}
|
}
|
||||||
catch ( Exception error )
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
fail( "测试失败!" );
|
fail( "测试失败!" );
|
||||||
}
|
}
|
||||||
|
@ -54,13 +54,13 @@ public class sendMessageTest
|
||||||
{
|
{
|
||||||
HttpUtils.postHttpRequest( url, headers, param );
|
HttpUtils.postHttpRequest( url, headers, param );
|
||||||
}
|
}
|
||||||
catch ( Exception error )
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void testSendWeatherDisasterWarning() throws IOException
|
public void testSendWeatherDisasterWarning() throws IOException
|
||||||
{
|
{
|
||||||
String warningJSON =
|
String warningJSON =
|
||||||
|
@ -72,29 +72,11 @@ public class sendMessageTest
|
||||||
QWeatherDisasterWarning warning =
|
QWeatherDisasterWarning warning =
|
||||||
mapper.readValue( warningJSON, QWeatherDisasterWarning.class );
|
mapper.readValue( warningJSON, QWeatherDisasterWarning.class );
|
||||||
|
|
||||||
String city = "东山县";
|
sendMessage.sendWeatherDisasterWarning( url, warning );
|
||||||
|
|
||||||
|
|
||||||
sendMessage.saveWeatherDisasterWarning( city, warning );
|
|
||||||
}
|
}
|
||||||
catch ( Exception error )
|
catch (Exception error)
|
||||||
{
|
{
|
||||||
fail( error.getMessage() );
|
fail( error.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testCheckWarningHasSended()
|
|
||||||
{
|
|
||||||
String warningID = "10123060820220422061200476313081";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sendMessage.checkWarningHasSended( warningID );
|
|
||||||
}
|
|
||||||
catch ( Exception error )
|
|
||||||
{
|
|
||||||
error.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"title": "天气灾害预警配置文件",
|
|
||||||
"key": "fe9fa8eeeb6f4301a92541eed565dd15",
|
|
||||||
"query_url": "https://devapi.qweather.com/v7/warning/now?",
|
|
||||||
"wechat_officalaccount_url": "https://cxxmwx.cpic.com.cn/app/index.php?i=2&c=entry&do=send_group_tpl_api&m=ok_tplmessage",
|
|
||||||
"query_interval": 10,
|
|
||||||
"cities": [
|
|
||||||
{
|
|
||||||
"city_name": "厦门",
|
|
||||||
"city_code": "101230201"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"notify_stuffs": [
|
|
||||||
{
|
|
||||||
"stuff_name": "王炜",
|
|
||||||
"mobile_phone": "15959215339"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"tns_name": "xmcx1",
|
|
||||||
"ip_addr": "10.39.0.86",
|
|
||||||
"jdbc_url": "jdbc:oracle:thin:@10.39.0.86:1521:xmcx1",
|
|
||||||
"table_space": "wechat",
|
|
||||||
"user_name": "wechat",
|
|
||||||
"password": "@rn7Q+t5zeyKIZ~s",
|
|
||||||
"tables": [
|
|
||||||
{
|
|
||||||
"table_name": "weather_disaster_notify",
|
|
||||||
"table_description": "天气预警消息表"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
|
|
||||||
|
|
||||||
.level = INFO
|
|
||||||
|
|
||||||
java.util.logging.FileHandler.pattern = ./logs/log_%u.log
|
|
||||||
java.util.logging.FileHandler.limit = 50000
|
|
||||||
java.util.logging.FileHandler.count = 1
|
|
||||||
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
|
|
||||||
java.util.logging.FileHandler.append = true;
|
|
Loading…
Reference in New Issue