保存进度!
This commit is contained in:
		@@ -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-05 11:26:35
 | 
					 * @LastEditTime: 2022-05-05 17:42:33
 | 
				
			||||||
 * @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: 用来推送公众号消息的程序库。
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -171,12 +171,11 @@ public class sendMessage
 | 
				
			|||||||
     * 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。
 | 
					     * 保存的数据用来判断预警是否已经推送过,以防止反复推送数据。
 | 
				
			||||||
     * @param city 城市名称
 | 
					     * @param city 城市名称
 | 
				
			||||||
     * @param warning 预警数据,为 QWeatherDisasterWarningItem 对象。
 | 
					     * @param warning 预警数据,为 QWeatherDisasterWarningItem 对象。
 | 
				
			||||||
     * @throws SQLException 执行sql时可能抛出的异常。
 | 
					     * @throws SQLException 执行sql时可能抛出的异常。出现sql异常,就回滚事务。
 | 
				
			||||||
     * @throws IOException 读取数据库配置文件时可能抛出的异常。
 | 
					     * @throws IOException 读取数据库配置文件时可能抛出的异常。
 | 
				
			||||||
     * @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。
 | 
					     * @throws ClassNotFoundException 加载oracle jdbc驱动时可能抛出的异常。
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static void saveWeatherDisasterWarning( String city,
 | 
					    public static void saveWeatherDisasterWarning( String city, QWeatherDisasterWarning warnings )
 | 
				
			||||||
            QWeatherDisasterWarningItem warning )
 | 
					 | 
				
			||||||
            throws SQLException, IOException, ClassNotFoundException
 | 
					            throws SQLException, IOException, ClassNotFoundException
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Connection conn = null;
 | 
					        Connection conn = null;
 | 
				
			||||||
@@ -199,21 +198,37 @@ public class sendMessage
 | 
				
			|||||||
            conn = DriverManager.getConnection( jdbcURL, userName, password );
 | 
					            conn = DriverManager.getConnection( jdbcURL, userName, password );
 | 
				
			||||||
            stmt = conn.prepareStatement( sql );
 | 
					            stmt = conn.prepareStatement( sql );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            java.sql.Timestamp pubTime = new java.sql.Timestamp( warning.getPubTime().getTime() );
 | 
					            for ( QWeatherDisasterWarningItem warning : warnings.getWarning() )
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                java.sql.Timestamp pubTime =
 | 
				
			||||||
 | 
					                        new java.sql.Timestamp( warning.getPubTime().getTime() );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            stmt.setString( 1, warning.getId() );
 | 
					                stmt.setString( 1, warning.getId() );
 | 
				
			||||||
            stmt.setString( 2, warning.getSender() );
 | 
					                stmt.setString( 2, warning.getSender() );
 | 
				
			||||||
            stmt.setString( 3, city );
 | 
					                stmt.setString( 3, city );
 | 
				
			||||||
            stmt.setString( 4, warning.getLevel() );
 | 
					                stmt.setString( 4, warning.getLevel() );
 | 
				
			||||||
            stmt.setString( 5, warning.getType() );
 | 
					                stmt.setString( 5, warning.getType() );
 | 
				
			||||||
            stmt.setString( 6, warning.getTypeName() );
 | 
					                stmt.setString( 6, warning.getTypeName() );
 | 
				
			||||||
            stmt.setString( 7, warning.getTitle() );
 | 
					                stmt.setString( 7, warning.getTitle() );
 | 
				
			||||||
            stmt.setString( 8, warning.getText() );
 | 
					                stmt.setString( 8, warning.getText() );
 | 
				
			||||||
            stmt.setTimestamp( 9, pubTime );
 | 
					                stmt.setTimestamp( 9, pubTime );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            stmt.execute();
 | 
					                stmt.execute();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 没有问题就提交
 | 
				
			||||||
            conn.commit();
 | 
					            conn.commit();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        catch ( SQLException error )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // 出现sql错误,就回滚!
 | 
				
			||||||
 | 
					            if ( conn != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                conn.rollback();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            throw error;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        finally
 | 
					        finally
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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-05 11:21:54
 | 
					 * @LastEditTime: 2022-05-05 17:53:10
 | 
				
			||||||
 * @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:
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@@ -77,7 +77,7 @@ public class sendMessageTest
 | 
				
			|||||||
            String city = "东山县";
 | 
					            String city = "东山县";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sendMessage.saveWeatherDisasterWarning( city, warning.getWarning().get( 0 ) );
 | 
					            sendMessage.saveWeatherDisasterWarning( city, warning );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user