完成判断消息是否已发送功能!

This commit is contained in:
2022-04-27 16:09:58 +08:00
parent 0587001de0
commit 5da53f02ea
2 changed files with 56 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-04-22 10:53:49
* @LastEditors: Kane
* @LastEditTime: 2022-04-25 19:20:32
* @LastEditTime: 2022-04-27 16:09:17
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
* @Description: 用来推送公众号消息的程序库。
*
@@ -16,7 +16,13 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Vector;
import java.util.logging.*;
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.httpUtil.HttpUtils;
@@ -49,7 +55,7 @@ public class sendMessage
headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );
// 遍历消息,将消息推送出去。
for ( QWeatherDisasterWarningItem item : warningItems)
for ( QWeatherDisasterWarningItem item : warningItems )
{
// 拼接消息内容
String title = item.getTitle();
@@ -68,7 +74,7 @@ public class sendMessage
{
HttpUtils.postHttpRequest( officalAccountURL, headers, requestBody.toString() );
}
catch (MalformedURLException error)
catch ( MalformedURLException error )
{
error.printStackTrace();
}
@@ -80,11 +86,55 @@ public class sendMessage
* @param warningID
* @return
*/
private boolean checkWarningHasSended( String warningID )
public boolean checkWarningHasSended( String warningID )
throws ClassNotFoundException, SQLException
{
boolean result = false;
// 暂时写死,以后改成读取配置方式
String jdbcURL = "jdbc:oracle:thin@10.39.0.86:1521:wechat";
String userName = "wechat";
String password = "@rn7Q+t5zeyKIZ~s";
String sql = "select count(*) from weather_disaster_notify where notify_id = ?";
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
// 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( sql );
if ( rs.next() && rs.getInt( 0 ) == 0)
{
result = true;
}
}
finally
{
if ( rs != null)
{
rs.close();
}
if ( stmt != null)
{
stmt.close();
}
if ( conn != null)
{
conn.close();
}
}
return result;
}