2 Commits

Author SHA1 Message Date
b993638e5b 提交小修改! 2022-05-11 23:10:01 +08:00
6671cb69c9 问题已修正! 2022-05-10 19:37:52 +08:00
5 changed files with 103 additions and 160 deletions

View File

@@ -21,17 +21,13 @@
<SOURCES /> <SOURCES />
</library> </library>
</orderEntry> </orderEntry>
<orderEntry type="library" name="Maven: com.oracle:ojdbc8:19.3.0.0.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.13" level="project" /> <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.13" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" /> <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" /> <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13.2" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" />
<orderEntry type="library" name="Maven: commons-collections:commons-collections:20040616" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" />
<orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.8" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.8" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.8" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.8" level="project" />

View File

@@ -267,15 +267,15 @@
<root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.8/jackson-databind-2.9.8-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.9.8/jackson-databind-2.9.8-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
<library name="Maven: commons-beanutils:commons-beanutils:1.9.4"> <library name="Maven: com.oracle:ojdbc8:19.3.0.0.0">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/oracle/ojdbc8/19.3.0.0.0/ojdbc8-19.3.0.0.0.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/oracle/ojdbc8/19.3.0.0.0/ojdbc8-19.3.0.0.0-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-beanutils/commons-beanutils/1.9.4/commons-beanutils-1.9.4-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/oracle/ojdbc8/19.3.0.0.0/ojdbc8-19.3.0.0.0-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
<library name="Maven: commons-codec:commons-codec:1.11"> <library name="Maven: commons-codec:commons-codec:1.11">
@@ -289,37 +289,15 @@
<root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.11/commons-codec-1.11-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/commons-codec/commons-codec/1.11/commons-codec-1.11-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
<library name="Maven: commons-collections:commons-collections:20040616"> <library name="Maven: commons-logging:commons-logging:1.2">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/20040616/commons-collections-20040616.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/20040616/commons-collections-20040616-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-collections/commons-collections/20040616/commons-collections-20040616-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.2/commons-logging-1.2-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: commons-lang:commons-lang:2.6">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.6/commons-lang-2.6.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.6/commons-lang-2.6-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-lang/commons-lang/2.6/commons-lang-2.6-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: commons-logging:commons-logging:1.1.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
<library name="Maven: junit:junit:4.13.2"> <library name="Maven: junit:junit:4.13.2">
@@ -333,28 +311,6 @@
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.2/junit-4.13.2-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.2/junit-4.13.2-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
<library name="Maven: net.sf.ezmorph:ezmorph:1.0.6">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.6/ezmorph-1.0.6.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.6/ezmorph-1.0.6-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/ezmorph/ezmorph/1.0.6/ezmorph-1.0.6-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: net.sf.json-lib:json-lib:jdk15:2.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-sources.jar!/" />
</SOURCES>
</library>
<library name="Maven: org.apache.httpcomponents:httpclient:4.5.13"> <library name="Maven: org.apache.httpcomponents:httpclient:4.5.13">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar!/" />

View File

@@ -8,9 +8,7 @@
<dependency> <dependency>
<groupId>com.oracle</groupId> <groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId> <artifactId>ojdbc8</artifactId>
<version>1.0</version> <version>19.3.0.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ojdbc8.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
@@ -23,37 +21,6 @@
<version>4.13.2</version> <version>4.13.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- <dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>20040616</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.sf.ezmorph</groupId>
<artifactId>ezmorph</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency> -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>

View File

@@ -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 16:28:07 * @LastEditTime: 2022-05-10 19:03:56
* @FilePath: \DisasterWarning\src\main\java\AppMain.java * @FilePath: \DisasterWarning\src\main\java\AppMain.java
* @Description: 和风天气预警推送厦门太保公众号主程序! * @Description: 和风天气预警推送厦门太保公众号主程序!
* *
@@ -11,6 +11,7 @@
import com.cpic.xim.config.AppConfigManager; 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.QWeatherDisasterWarningItem;
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.wechat.officalAccount.sendMessage;
import com.cpic.xim.config.WeatherDisasterNotifyConfig; import com.cpic.xim.config.WeatherDisasterNotifyConfig;
@@ -79,23 +80,40 @@ public class AppMain
logger.log( Level.INFO, "查询{0}天气预警,结果:{1}。", new Object[] logger.log( Level.INFO, "查询{0}天气预警,结果:{1}。", new Object[]
{ city.getCityName(), json} ); { city.getCityName(), json} );
// 判断是否有警报 Vector<QWeatherDisasterWarningItem> warningItems = warning.getWarning();
if ( warning.getWarning().isEmpty() == true)
// 判断是否有警报,没有警报就结束当前城市的处理
if ( warningItems.isEmpty() == true)
{ {
logger.log( Level.INFO, "查询{0}天气预警,无警报!。", new Object[] logger.log( Level.INFO, "查询{0}天气预警,无警报!。", new Object[]
{ city.getCityName()} ); { city.getCityName()} );
continue; continue;
} }
// 有警报,就遍历警报数组
for ( QWeatherDisasterWarningItem item : warningItems )
{
// 先检查是否已经发送过
if ( sendMessage.checkWarningHasSended( item.getId() ) == false)
{
logger.log( Level.INFO, "查询{0}天气预警ID:{1},已有发送记录,跳过。", new Object[]
{ city.getCityName(), item.getId()} );
continue;
}
// 没有发送过
logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[] logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[]
{ city.getCityName()} ); { city.getCityName()} );
sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(), sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
warning ); item );
logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[] logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[]
{ city.getCityName()} ); { city.getCityName()} );
}
// 将发送的警报,保存起来
sendMessage.saveWeatherDisasterWarning( city.getCityName(), warning ); sendMessage.saveWeatherDisasterWarning( city.getCityName(), warning );
} }
catch ( IOException error ) catch ( IOException error )

View File

@@ -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-05-10 19:02:32
* @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: 用来推送公众号消息的程序库。
* *
@@ -14,16 +14,17 @@ import com.cpic.xim.config.db.OracleConfigManager;
import com.cpic.xim.config.db.OracleConfig; 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.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Vector;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; 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;
@@ -39,13 +40,14 @@ public class sendMessage
/** /**
* 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》 * 推送天气灾害预警!接口文档参考 彭奕洁 编写《消息发送接口调用文档》
* 使用 post 方式,请求体内容以最基础的 post 格式。 * 使用 post 方式,请求体内容以最基础的 post 格式。
*
* @param officalAccountURL 产险厦门分公司公众号接口网址 * @param officalAccountURL 产险厦门分公司公众号接口网址
* @param warning 灾害预警对象 * @param warningItem 灾害预警对象
*/ */
public static void sendWeatherDisasterWarning( String officalAccountURL, public static void sendWeatherDisasterWarning( String officalAccountURL,
QWeatherDisasterWarning warning ) QWeatherDisasterWarningItem warningItem )
{ {
Vector<QWeatherDisasterWarningItem> warningItems = warning.getWarning(); // Vector<QWeatherDisasterWarningItem> warningItems = warningItem.getWarning();
StringBuilder requestBody = null; StringBuilder requestBody = null;
// 设置请求头参数 // 设置请求头参数
@@ -56,13 +58,12 @@ 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 )
{
// 拼接消息内容 // 拼接消息内容
String title = item.getTitle(); String title = warningItem.getTitle();
String text = item.getText(); String text = warningItem.getText();
String color = warningLevel.keySet().contains( item.getLevel() ) String color = warningLevel.keySet().contains( warningItem.getLevel() )
? warningLevel.get( item.getLevel() ) ? warningLevel.get( warningItem.getLevel() )
: "#000000"; : "#000000";
requestBody = new StringBuilder(); requestBody = new StringBuilder();
@@ -79,13 +80,14 @@ public class sendMessage
{ {
error.printStackTrace(); error.printStackTrace();
} }
}
} }
/** /**
* 检查预警是否已经推送过,通过 QWeatherDisasterWarningItem 对象的 id 属性。 * 检查预警是否已经推送过,通过 QWeatherDisasterWarningItem 对象的 id 属性。
* 查询 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表, * 查询 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表,
* 统计 warningID 的数量如果不为0,说明该预警已经保存过,视为已经推送过。 * 统计 warningID 的数量如果不为0,说明该预警已经保存过,视为已经推送过。
*
* @param warningID 预警的id * @param warningID 预警的id
* @return 如果推送过返回false否则返回 true。 * @return 如果推送过返回false否则返回 true。
*/ */
@@ -94,7 +96,8 @@ public class sendMessage
{ {
boolean result = false; boolean result = false;
OracleConfig dbConfig = OracleConfigManager.getOracleConfig();; OracleConfig dbConfig = OracleConfigManager.getOracleConfig();
;
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@@ -168,8 +171,9 @@ public class sendMessage
* 保存天气预警警报数据。 * 保存天气预警警报数据。
* 保存至 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表。 * 保存至 oracle xmcx1 数据库 wechat 表空间下 weather_disaster_notify 表。
* 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。 * 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。
*
* @param city 城市名称 * @param city 城市名称
* @param warning 预警数据,为 QWeatherDisasterWarningItem 对象。 * @param warnings 预警数据,为 QWeatherDisasterWarningItem 对象。
* @throws SQLException 执行sql时可能抛出的异常。出现sql异常就回滚事务。 * @throws SQLException 执行sql时可能抛出的异常。出现sql异常就回滚事务。
* @throws IOException 读取数据库配置文件时可能抛出的异常。 * @throws IOException 读取数据库配置文件时可能抛出的异常。
* @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。 * @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。
@@ -197,6 +201,8 @@ public class sendMessage
conn = DriverManager.getConnection( jdbcURL, userName, password ); conn = DriverManager.getConnection( jdbcURL, userName, password );
stmt = conn.prepareStatement( sql ); stmt = conn.prepareStatement( sql );
conn.setAutoCommit( false );
for ( QWeatherDisasterWarningItem warning : warnings.getWarning() ) for ( QWeatherDisasterWarningItem warning : warnings.getWarning() )
{ {
java.sql.Timestamp pubTime = java.sql.Timestamp pubTime =