1.0完成。
This commit is contained in:
parent
f77272ff29
commit
45fb965496
@ -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<HmbXyxInfo> xyxInfo = CpicximToXMNHS.getNeverTransHmbList();
|
||||
|
||||
// 发送
|
||||
CpicximToXMNHS.postHmbList( xyxInfo );
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep( HuixiabaoConfig.getSleepSeconds() * 1000 );
|
||||
}
|
||||
catch ( InterruptedException error )
|
||||
{
|
||||
logger.error( "sleep时出错:" + error.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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 );
|
||||
@ -91,14 +95,38 @@ public class CpicximToXMNHS
|
||||
}
|
||||
catch ( ClassNotFoundException error )
|
||||
{
|
||||
|
||||
logger.error( "加载sql驱动错误:" + error.getMessage() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
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 )
|
||||
@ -106,6 +134,7 @@ public class CpicximToXMNHS
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
@ -116,7 +145,7 @@ public class CpicximToXMNHS
|
||||
HmbXyxInfo item = null;
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet result = null;
|
||||
|
||||
try
|
||||
@ -130,12 +159,15 @@ public class CpicximToXMNHS
|
||||
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 )
|
||||
{
|
||||
@ -148,18 +180,42 @@ public class CpicximToXMNHS
|
||||
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
logger.error( "清理已发送数据失败:" + error.getMessage() );
|
||||
}
|
||||
catch ( ClassNotFoundException error )
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
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 )
|
||||
@ -168,6 +224,7 @@ public class CpicximToXMNHS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void postHmbList( Vector<HmbXyxInfo> items )
|
||||
{
|
||||
@ -197,6 +254,7 @@ public class CpicximToXMNHS
|
||||
JSONObject requestObject = new JSONObject();
|
||||
JSONObject xyxInfo = null;
|
||||
JSONArray xyxInfoList = new JSONArray();
|
||||
Vector<HmbXyxInfo> postedInfo = new Vector<HmbXyxInfo>(); // 存放已经送出的数据
|
||||
|
||||
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,11 +301,16 @@ public class CpicximToXMNHS
|
||||
// 失败的数据就留在update表中,待以后重新发送
|
||||
logger.error( error.getMessage() );
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
// 清理清单,重置计数
|
||||
// 如果发送失败,在HmbXyxInfo_update表中保留发送失败的记录,待下次发送
|
||||
xyxInfoList.clear();
|
||||
postedInfo.clear();
|
||||
|
||||
request_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
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;
|
Loading…
x
Reference in New Issue
Block a user