完成check函数!修正jdbc url的错误!
This commit is contained in:
		@@ -1,13 +1,14 @@
 | 
			
		||||
{
 | 
			
		||||
    "tns_name": "xmcx1",
 | 
			
		||||
    "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",
 | 
			
		||||
    "password": "@rn7Q+t5zeyKIZ~s",
 | 
			
		||||
    "tables": [
 | 
			
		||||
        {
 | 
			
		||||
            "table_name": "",
 | 
			
		||||
            "table_description": ""
 | 
			
		||||
            "table_name": "weather_disaster_notify",
 | 
			
		||||
            "table_description": "天气预警消息表"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,13 @@
 | 
			
		||||
    <artifactId>disaster_warning</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    <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>
 | 
			
		||||
            <groupId>org.apache.httpcomponents</groupId>
 | 
			
		||||
            <artifactId>httpclient</artifactId>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 17:33:30
 | 
			
		||||
 * @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
 | 
			
		||||
 * @Description: 
 | 
			
		||||
 * 
 | 
			
		||||
@@ -12,6 +12,8 @@ package com.cpic.xim.config.db;
 | 
			
		||||
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
 | 
			
		||||
public class DBTable
 | 
			
		||||
{
 | 
			
		||||
    public DBTable()
 | 
			
		||||
@@ -59,6 +61,9 @@ public class DBTable
 | 
			
		||||
        return Objects.hash( tableName, tableDescription );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "table_name")
 | 
			
		||||
    private String tableName;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "table_description")
 | 
			
		||||
    private String tableDescription;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,17 @@ public class OracleConfig
 | 
			
		||||
        this.jdbcURL = jdbcURL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public String getTableSpace()
 | 
			
		||||
    {
 | 
			
		||||
        return tableSpace;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTableSpace( String tableSpace )
 | 
			
		||||
    {
 | 
			
		||||
        this.tableSpace = tableSpace;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getUserName()
 | 
			
		||||
    {
 | 
			
		||||
        return userName;
 | 
			
		||||
@@ -88,6 +99,9 @@ public class OracleConfig
 | 
			
		||||
    @JsonProperty( "jdbc_url")
 | 
			
		||||
    private String jdbcURL;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "table_space")
 | 
			
		||||
    private String tableSpace;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "user_name")
 | 
			
		||||
    private String userName;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-25 21:45:12
 | 
			
		||||
 * @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
 | 
			
		||||
 * @Description: oracle数据库配置文件加载类
 | 
			
		||||
 * 
 | 
			
		||||
@@ -24,7 +24,7 @@ public class OracleConfigLoader
 | 
			
		||||
    private OracleConfigLoader()
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    public OracleConfig getOracleConfig() throws IOException
 | 
			
		||||
    public static OracleConfig getOracleConfig() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        FileInputStream file = null;
 | 
			
		||||
        InputStreamReader in = null;
 | 
			
		||||
@@ -39,10 +39,9 @@ public class OracleConfigLoader
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            file = new FileInputStream( CONFIG_FILE_PATH );
 | 
			
		||||
            in = new InputStreamReader( file, CONFIG_FILE_CHARSET);
 | 
			
		||||
            in = new InputStreamReader( file, CONFIG_FILE_CHARSET );
 | 
			
		||||
            json = new StringBuffer();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            int count = in.read( buffer );
 | 
			
		||||
 | 
			
		||||
            while (count != -1)
 | 
			
		||||
@@ -56,7 +55,7 @@ public class OracleConfigLoader
 | 
			
		||||
 | 
			
		||||
            dbConfig = mapper.readValue( json.toString(), OracleConfig.class );
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException error)
 | 
			
		||||
        catch ( IOException error )
 | 
			
		||||
        {
 | 
			
		||||
            throw error;
 | 
			
		||||
        }
 | 
			
		||||
@@ -66,7 +65,7 @@ public class OracleConfigLoader
 | 
			
		||||
            {
 | 
			
		||||
                file.close();
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception error)
 | 
			
		||||
            catch ( Exception error )
 | 
			
		||||
            {
 | 
			
		||||
                error.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @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
 | 
			
		||||
 * @Description: 用来推送公众号消息的程序库。
 | 
			
		||||
 *
 | 
			
		||||
@@ -10,9 +10,11 @@
 | 
			
		||||
 */
 | 
			
		||||
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 java.io.IOException;
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
@@ -86,21 +88,22 @@ public class sendMessage
 | 
			
		||||
     * @param warningID
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public boolean checkWarningHasSended( String warningID )
 | 
			
		||||
            throws ClassNotFoundException, SQLException
 | 
			
		||||
    public static boolean checkWarningHasSended( String warningID )
 | 
			
		||||
            throws ClassNotFoundException, SQLException, IOException
 | 
			
		||||
    {
 | 
			
		||||
        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 = ?";
 | 
			
		||||
        OracleConfig dbConfig = OracleConfigLoader.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
 | 
			
		||||
@@ -111,9 +114,9 @@ public class sendMessage
 | 
			
		||||
            stmt = conn.prepareStatement( sql );
 | 
			
		||||
            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;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @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
 | 
			
		||||
 * @Description:
 | 
			
		||||
 *
 | 
			
		||||
@@ -61,7 +61,7 @@ public class sendMessageTest
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    // @Test
 | 
			
		||||
    public void testSendWeatherDisasterWarning() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        String warningJSON =
 | 
			
		||||
@@ -83,4 +83,19 @@ public class sendMessageTest
 | 
			
		||||
            fail( error.getMessage() );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testCheckWarningHasSended()
 | 
			
		||||
    {
 | 
			
		||||
        String warningID = "10123060820220422061200476313081";
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            sendMessage.checkWarningHasSended( warningID );
 | 
			
		||||
        }
 | 
			
		||||
        catch ( Exception error )
 | 
			
		||||
        {
 | 
			
		||||
            error.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user