完成check函数!修正jdbc url的错误!
This commit is contained in:
parent
5da53f02ea
commit
24cdc66b7d
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"tns_name": "xmcx1",
|
"tns_name": "xmcx1",
|
||||||
"ip_addr": "10.39.0.86",
|
"ip_addr": "10.39.0.86",
|
||||||
"jdbc_url": "",
|
"jdbc_url": "jdbc:oracle:thin:@10.39.0.86:1521:xmcx1",
|
||||||
|
"table_space": "wechat",
|
||||||
"user_name": "wechat",
|
"user_name": "wechat",
|
||||||
"password": "@rn7Q+t5zeyKIZ~s",
|
"password": "@rn7Q+t5zeyKIZ~s",
|
||||||
"tables": [
|
"tables": [
|
||||||
{
|
{
|
||||||
"table_name": "",
|
"table_name": "weather_disaster_notify",
|
||||||
"table_description": ""
|
"table_description": "天气预警消息表"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,13 @@
|
|||||||
<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>
|
||||||
|
@ -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-23 23:50:20
|
* @LastEditTime: 2022-04-27 16:53:13
|
||||||
* @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,6 +12,8 @@ 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()
|
||||||
@ -59,6 +61,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,17 @@ 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;
|
||||||
@ -88,6 +99,9 @@ public class OracleConfig
|
|||||||
@JsonProperty( "jdbc_url")
|
@JsonProperty( "jdbc_url")
|
||||||
private String jdbcURL;
|
private String jdbcURL;
|
||||||
|
|
||||||
|
@JsonProperty( "table_space")
|
||||||
|
private String tableSpace;
|
||||||
|
|
||||||
@JsonProperty( "user_name")
|
@JsonProperty( "user_name")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-25 21:45:12
|
* @Date: 2022-04-25 21:45:12
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-04-25 22:58:47
|
* @LastEditTime: 2022-04-27 17:10:57
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigLoader.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigLoader.java
|
||||||
* @Description: oracle数据库配置文件加载类
|
* @Description: oracle数据库配置文件加载类
|
||||||
*
|
*
|
||||||
@ -24,7 +24,7 @@ public class OracleConfigLoader
|
|||||||
private OracleConfigLoader()
|
private OracleConfigLoader()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public OracleConfig getOracleConfig() throws IOException
|
public static OracleConfig getOracleConfig() throws IOException
|
||||||
{
|
{
|
||||||
FileInputStream file = null;
|
FileInputStream file = null;
|
||||||
InputStreamReader in = null;
|
InputStreamReader in = null;
|
||||||
@ -39,10 +39,9 @@ public class OracleConfigLoader
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
file = new FileInputStream( CONFIG_FILE_PATH );
|
file = new FileInputStream( CONFIG_FILE_PATH );
|
||||||
in = new InputStreamReader( file, CONFIG_FILE_CHARSET);
|
in = new InputStreamReader( file, CONFIG_FILE_CHARSET );
|
||||||
json = new StringBuffer();
|
json = new StringBuffer();
|
||||||
|
|
||||||
|
|
||||||
int count = in.read( buffer );
|
int count = in.read( buffer );
|
||||||
|
|
||||||
while (count != -1)
|
while (count != -1)
|
||||||
@ -56,7 +55,7 @@ public class OracleConfigLoader
|
|||||||
|
|
||||||
dbConfig = mapper.readValue( json.toString(), OracleConfig.class );
|
dbConfig = mapper.readValue( json.toString(), OracleConfig.class );
|
||||||
}
|
}
|
||||||
catch (IOException error)
|
catch ( IOException error )
|
||||||
{
|
{
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@ -66,7 +65,7 @@ public class OracleConfigLoader
|
|||||||
{
|
{
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
catch (Exception error)
|
catch ( Exception error )
|
||||||
{
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -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-04-27 16:09:17
|
* @LastEditTime: 2022-04-27 17:35:06
|
||||||
* @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,9 +10,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.cpic.xim.wechat.officalAccount;
|
package com.cpic.xim.wechat.officalAccount;
|
||||||
|
|
||||||
|
import com.cpic.xim.config.db.OracleConfigLoader;
|
||||||
|
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;
|
||||||
@ -86,21 +88,22 @@ public class sendMessage
|
|||||||
* @param warningID
|
* @param warningID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean checkWarningHasSended( String warningID )
|
public static boolean checkWarningHasSended( String warningID )
|
||||||
throws ClassNotFoundException, SQLException
|
throws ClassNotFoundException, SQLException, IOException
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
// 暂时写死,以后改成读取配置方式
|
OracleConfig dbConfig = OracleConfigLoader.getOracleConfig();;
|
||||||
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;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = 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" );
|
// Logger logger = Logger.getLogger( "com.cpicxim.wechat.officalAccount.sendMessage" );
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -111,9 +114,9 @@ public class sendMessage
|
|||||||
stmt = conn.prepareStatement( sql );
|
stmt = conn.prepareStatement( sql );
|
||||||
stmt.setString( 1, warningID );
|
stmt.setString( 1, warningID );
|
||||||
|
|
||||||
rs = stmt.executeQuery( sql );
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
if ( rs.next() && rs.getInt( 0 ) == 0)
|
if ( rs.next() && rs.getInt( 1 ) == 0)
|
||||||
{
|
{
|
||||||
result = true;
|
result = 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-04-26 23:16:46
|
* @LastEditTime: 2022-04-27 17:29:11
|
||||||
* @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:
|
||||||
*
|
*
|
||||||
@ -61,7 +61,7 @@ public class sendMessageTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testSendWeatherDisasterWarning() throws IOException
|
public void testSendWeatherDisasterWarning() throws IOException
|
||||||
{
|
{
|
||||||
String warningJSON =
|
String warningJSON =
|
||||||
@ -83,4 +83,19 @@ public class sendMessageTest
|
|||||||
fail( error.getMessage() );
|
fail( error.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCheckWarningHasSended()
|
||||||
|
{
|
||||||
|
String warningID = "10123060820220422061200476313081";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sendMessage.checkWarningHasSended( warningID );
|
||||||
|
}
|
||||||
|
catch ( Exception error )
|
||||||
|
{
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user