完成发送记录保存功能。待完善……
This commit is contained in:
parent
0fb8b90509
commit
91c99ba8f9
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-26 22:33:14
|
||||
* @LastEditTime: 2022-05-05 16:51:11
|
||||
* @FilePath: \DisasterWarning\src\main\java\AppMain.java
|
||||
* @Description: 和风天气预警推送厦门太保公众号主程序!
|
||||
*
|
||||
@ -11,9 +11,11 @@
|
||||
import com.cpic.xim.config.City;
|
||||
import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;
|
||||
import com.cpic.xim.notify.disaster.WeatherDisasterWarningGrabber;
|
||||
import com.cpic.xim.wechat.officalAccount.sendMessage;
|
||||
import com.cpic.xim.config.WeatherDisasterNotifyConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.*;
|
||||
|
||||
@ -68,8 +70,6 @@ public class AppMain
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
json = WeatherDisasterWarningGrabber.getWeatherDisasterWarningJSON( queryURL,
|
||||
userKey, city.getCityCode() );
|
||||
warning = WeatherDisasterWarningGrabber.convertWeatherDisasterWarning( json );
|
||||
@ -86,8 +86,14 @@ public class AppMain
|
||||
logger.log( Level.INFO, "查询{0}天气预警,发送日志。", new Object[]
|
||||
{ city.getCityName()} );
|
||||
|
||||
// sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
|
||||
// warning );
|
||||
sendMessage.sendWeatherDisasterWarning( config.getWechatOfficalAccountURL(),
|
||||
warning );
|
||||
|
||||
logger.log( Level.INFO, "{0}天气预警,日志发送成功。", new Object[]
|
||||
{ city.getCityName()} );
|
||||
|
||||
sendMessage.saveWeatherDisasterWarning( city.getCityName(),
|
||||
warning.getWarning().get( 0 ) );
|
||||
}
|
||||
catch ( IOException error )
|
||||
{
|
||||
@ -96,8 +102,22 @@ public class AppMain
|
||||
|
||||
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()} );
|
||||
|
||||
continue;
|
||||
}
|
||||
catch ( Exception error )
|
||||
{
|
||||
logger.log( Level.SEVERE, "查询 {0} 出现未知错误:{1}。", new Object[]
|
||||
{ city.getCityName(), error.getMessage()} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-27 22:55:44
|
||||
* @LastEditTime: 2022-05-05 11:26:35
|
||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
|
||||
* @Description: 用来推送公众号消息的程序库。
|
||||
*
|
||||
@ -182,7 +182,9 @@ public class sendMessage
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
String sql = "";
|
||||
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();
|
||||
|
||||
@ -196,7 +198,21 @@ public class sendMessage
|
||||
|
||||
conn = DriverManager.getConnection( jdbcURL, userName, password );
|
||||
stmt = conn.prepareStatement( sql );
|
||||
|
||||
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();
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-04-22 10:53:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-04-27 17:29:11
|
||||
* @LastEditTime: 2022-05-05 11:21:54
|
||||
* @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
|
||||
* @Description:
|
||||
*
|
||||
@ -16,6 +16,7 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import com.cpic.xim.httpUtil.*;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
//import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@ -61,7 +62,7 @@ public class sendMessageTest
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void testSendWeatherDisasterWarning() throws IOException
|
||||
{
|
||||
String warningJSON =
|
||||
@ -73,10 +74,17 @@ public class sendMessageTest
|
||||
QWeatherDisasterWarning warning =
|
||||
mapper.readValue( warningJSON, QWeatherDisasterWarning.class );
|
||||
|
||||
String city = "东山县";
|
||||
|
||||
|
||||
sendMessage.saveWeatherDisasterWarning( city, warning.getWarning().get( 0 ) );
|
||||
|
||||
|
||||
|
||||
// SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );
|
||||
// String putTime = format.format( warning.getUpdateTime() );
|
||||
|
||||
sendMessage.sendWeatherDisasterWarning( url, warning );
|
||||
// sendMessage.sendWeatherDisasterWarning( url, warning );
|
||||
}
|
||||
catch ( Exception error )
|
||||
{
|
||||
@ -84,7 +92,7 @@ public class sendMessageTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void testCheckWarningHasSended()
|
||||
{
|
||||
String warningID = "10123060820220422061200476313081";
|
||||
|
Loading…
x
Reference in New Issue
Block a user