diff --git a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/AppMain.java b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/AppMain.java index 9eb5296..6efa140 100644 --- a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/AppMain.java +++ b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/AppMain.java @@ -13,59 +13,43 @@ */ package com.cpic.xim.huixiabao; -import com.alibaba.fastjson.JSONObject; -import com.cpic.xim.huixiabao.data.config.HuixiabaoConfig; +import java.util.Vector; -import cn.hsa.zephyr.apisdk.DefaultZephyrClient; -import cn.hsa.zephyr.apisdk.internal.exception.ZephyrApiException; -import cn.hsa.zephyr.apisdk.internal.util.encrypt.EncryptionModeEnum; -import cn.hsa.zephyr.apisdk.internal.util.encrypt.SignTypeEnum; -import cn.hsa.zephyr.apisdk.request.DefaultZephyrRequest; -import cn.hsa.zephyr.apisdk.response.DefaultZephyrResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.cpic.xim.huixiabao.data.config.HuixiabaoConfig; +import com.cpic.xim.huixiabao.data.pojo.HmbXyxInfo; +import com.cpic.xim.huixiabao.nhs.CpicximToXMNHS; public class AppMain { + private static Logger logger = LoggerFactory.getLogger( AppMain.class ); + public static void main( String[] args ) { - String url = HuixiabaoConfig.getUrl(); - String appId = HuixiabaoConfig.getAppid(); - String appSecret = HuixiabaoConfig.getAppSecret(); - String funId = "xxx"; - String encKey = HuixiabaoConfig.getEncKey(); - String signKey = HuixiabaoConfig.getSignKey(); - - EncryptionModeEnum encType = EncryptionModeEnum.SM4; - SignTypeEnum signType = SignTypeEnum.SM3; - - try - { - DefaultZephyrClient client = new DefaultZephyrClient( url, - funId, - appId, - appSecret, - signType, - signKey, - encType, - encKey ); - - DefaultZephyrRequest req = new DefaultZephyrRequest(); - JSONObject jsonObject1 = new JSONObject(); - DefaultZephyrResponse resp = null; - - jsonObject1.put( "code", "XXXXXXXXXXXXXXXXXX" ); - jsonObject1.put( "scene_code", "XXX" ); - - req.setData( jsonObject1 ); - // resp = client.execute( req ); - - System.out.println( req.toString() ); - } - catch ( Exception e ) - { - System.out.println( "Fuck World!" ); - e.printStackTrace(); - } + doPostXyxInfo(); System.out.println( "Hello World!" ); } + + private static void doPostXyxInfo() + { + while ( true ) + { + Vector xyxInfo = CpicximToXMNHS.getNeverTransHmbList(); + + // 发送 + CpicximToXMNHS.postHmbList( xyxInfo ); + + try + { + Thread.sleep( HuixiabaoConfig.getSleepSeconds() * 1000 ); + } + catch ( InterruptedException error ) + { + logger.error( "sleep时出错:" + error.getMessage() ); + } + } + } } diff --git a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/data/config/HuixiabaoConfig.java b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/data/config/HuixiabaoConfig.java index 6ea2c2b..7936c58 100644 --- a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/data/config/HuixiabaoConfig.java +++ b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/data/config/HuixiabaoConfig.java @@ -46,7 +46,13 @@ public class HuixiabaoConfig return url; } + public static int getSleepSeconds() + { + return SLEEP_SECONDS; + } + private static final int MAX_COUNT_PER_REQUEST = 500; + private static final int SLEEP_SECONDS = 10; private static final String url = "https://172.18.1.150:9040"; private static final String appid = "hxb-tb"; diff --git a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/nhs/CpicximToXMNHS.java b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/nhs/CpicximToXMNHS.java index 4ed7cbf..fdbce8b 100644 --- a/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/nhs/CpicximToXMNHS.java +++ b/code/cpicxim-XMNHSA-repeater/src/main/java/com/cpic/xim/huixiabao/nhs/CpicximToXMNHS.java @@ -1,7 +1,7 @@ /* * @Author: Kane * - * @Date: 2025-03-11 11:10:09 + * @Date: 2025-03-12 09:01:59 * * @LastEditors: Kane * @@ -11,10 +11,12 @@ * * Copyright (c) ${2023} by Kane, All Rights Reserved. */ + package com.cpic.xim.huixiabao.nhs; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.sql.SQLException; @@ -32,7 +34,9 @@ import cn.hsa.zephyr.apisdk.request.DefaultZephyrRequest; import cn.hsa.zephyr.apisdk.response.DefaultZephyrResponse; import com.cpic.xim.huixiabao.data.config.HuixiabaoConfig; -@SuppressWarnings("unused") +@SuppressWarnings( + "unused" +) public class CpicximToXMNHS { private static Logger logger = LoggerFactory.getLogger( CpicximToXMNHS.class ); @@ -61,10 +65,10 @@ public class CpicximToXMNHS { Class.forName( "com.mysql.cj.jdbc.Driver" ); - String url = CpicximToXMNHS.url; - String userName = CpicximToXMNHS.userName; - String password = CpicximToXMNHS.password; - String sql = """ + String url = CpicximToXMNHS.url; + String userName = CpicximToXMNHS.userName; + String password = CpicximToXMNHS.password; + String sql = """ select info.psnName, info.certNo, info.serviceId, info.status, info.xyxNo from HmbXyxInfo info, HmbXyxInfo_Update u @@ -91,19 +95,44 @@ public class CpicximToXMNHS } catch ( ClassNotFoundException error ) { - + logger.error( "加载sql驱动错误:" + error.getMessage() ); } finally { - try - { - result.close(); - statement.close(); - connection.close(); - } - catch ( SQLException error ) + if ( result != null ) { + try + { + result.close(); + } + catch ( SQLException error ) + { + } + } + + if ( statement != null ) + { + try + { + statement.close(); + } + catch ( SQLException error ) + { + + } + } + + if ( connection != null ) + { + try + { + connection.close(); + } + catch ( SQLException error ) + { + + } } } @@ -115,27 +144,30 @@ public class CpicximToXMNHS Vector items = new Vector(); HmbXyxInfo item = null; - Connection connection = null; - Statement statement = null; - ResultSet result = null; + Connection connection = null; + PreparedStatement statement = null; + ResultSet result = null; try { Class.forName( "com.mysql.cj.jdbc.Driver" ); - String url = CpicximToXMNHS.url; - String userName = CpicximToXMNHS.userName; - String password = CpicximToXMNHS.password; - String sql = """ + String url = CpicximToXMNHS.url; + String userName = CpicximToXMNHS.userName; + String password = CpicximToXMNHS.password; + String sql = """ delete from HmbXyxInfo_Update where xyxNo = ?"""; connection = DriverManager.getConnection( url, userName, password ); - statement = connection.prepareStatement(sql.trim()); + statement = connection.prepareStatement( sql.trim() ); - for ( HmbXyxInfo info : postedItems) + for ( HmbXyxInfo info : postedItems ) { - + statement.setString( 1, info.getXyxNo() ); + statement.execute(); } + + connection.commit(); } catch ( SQLException error ) { @@ -147,8 +179,8 @@ public class CpicximToXMNHS { } - - error.printStackTrace(); + + logger.error( "清理已发送数据失败:" + error.getMessage() ); } catch ( ClassNotFoundException error ) { @@ -156,15 +188,40 @@ public class CpicximToXMNHS } finally { - try - { - - statement.close(); - connection.close(); - } - catch ( SQLException error ) + if ( result != null ) { + try + { + result.close(); + } + catch ( SQLException error ) + { + } + } + + if ( statement != null ) + { + try + { + statement.close(); + } + catch ( SQLException error ) + { + logger.error( "加载sql驱动错误:" + error.getMessage() ); + } + } + + if ( connection != null ) + { + try + { + connection.close(); + } + catch ( SQLException error ) + { + + } } } } @@ -194,9 +251,10 @@ public class CpicximToXMNHS DefaultZephyrResponse resp = null; // 数据 - JSONObject requestObject = new JSONObject(); - JSONObject xyxInfo = null; - JSONArray xyxInfoList = new JSONArray(); + JSONObject requestObject = new JSONObject(); + JSONObject xyxInfo = null; + JSONArray xyxInfoList = new JSONArray(); + Vector postedInfo = new Vector(); // 存放已经送出的数据 requestObject.put( "topic", "hmbXyxInfo" ); @@ -214,6 +272,7 @@ public class CpicximToXMNHS xyxInfo.put( "xyxNo", info.getXyxNo() ); xyxInfoList.add( xyxInfo ); + postedInfo.add( info ); request_count++; total_count++; @@ -234,6 +293,7 @@ public class CpicximToXMNHS logger.info( "发送成功,返回消息:" + resp.getData() ); // 将已发送的数据从update表中清理掉 + removePostedHmbXyxInfo( postedInfo ); } catch ( ZephyrApiException error ) { @@ -241,10 +301,15 @@ public class CpicximToXMNHS // 失败的数据就留在update表中,待以后重新发送 logger.error( error.getMessage() ); } + finally + { + // 清理清单,重置计数 + // 如果发送失败,在HmbXyxInfo_update表中保留发送失败的记录,待下次发送 + xyxInfoList.clear(); + postedInfo.clear(); - // 清理清单,重置计数 - xyxInfoList.clear(); - request_count = 0; + request_count = 0; + } } } } diff --git a/code/sql/触发器.txt b/code/sql/触发器.txt index 2fd7eb9..d6ef6cc 100644 --- a/code/sql/触发器.txt +++ b/code/sql/触发器.txt @@ -1,5 +1,5 @@ -drop TRIGGER xyxinfo_update; -CREATE TRIGGER xyxinfo_update BEFORE INSERT ON huixiabao.HmbXyxInfo FOR EACH ROW +drop TRIGGER xyxinfo_insert; +CREATE TRIGGER xyxinfo_insert after INSERT ON huixiabao.HmbXyxInfo FOR EACH ROW BEGIN delete from huixiabao.HmbXyxInfo_Update u where u.xyxNo = NEW.xyxNo; INSERT INTO huixiabao.HmbXyxInfo_Update ( xyxNo, update_time ) @@ -8,4 +8,17 @@ BEGIN new.xyxNo, SYSDATE()); -END \ No newline at end of file +END; + + +drop trigger xyxinfo_update; +create trigger xyxinfo_update after update on huixiabao.HmbXyxInfo FOR EACH ROW +BEGIN + delete from huixiabao.HmbXyxInfo_Update u where u.xyxNo = NEW.xyxNo; + INSERT INTO huixiabao.HmbXyxInfo_Update ( xyxNo, update_time ) + VALUES + ( + new.xyxNo, + SYSDATE()); + +END; \ No newline at end of file