完成发送代码,开始编写查询和清理已发送数据的代码。
This commit is contained in:
@@ -41,6 +41,8 @@ public class CpicximToXMNHS
|
||||
|
||||
Vector<HmbXyxInfo> items = new Vector<HmbXyxInfo>();
|
||||
|
||||
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -70,20 +72,56 @@ public class CpicximToXMNHS
|
||||
|
||||
// 数据
|
||||
JSONObject requestObject = new JSONObject();
|
||||
JSONObject xyxInfo = new JSONObject();
|
||||
JSONObject xyxInfo = null;
|
||||
JSONArray xyxInfoList = new JSONArray();
|
||||
|
||||
requestObject.put( "topic", "hmbXyxInfo" );
|
||||
requestObject.put( "hmbList", xyxInfoList );
|
||||
|
||||
int count = 0; // 计数,每个请求不能超过500条
|
||||
int request_count = 0; // 计数,每个请求不能超过500条
|
||||
int total_count = 0;
|
||||
|
||||
for ( HmbXyxInfo info : items )
|
||||
{
|
||||
if ( count >= HuixiabaoConfig.getMAX_COUNT_PER_REQUEST() - 1 )
|
||||
{
|
||||
// 达到上限,将当前数据送出
|
||||
xyxInfo = new JSONObject();
|
||||
|
||||
xyxInfo.put( "psnName", info.getPsnName() );
|
||||
xyxInfo.put( "cerno", info.getCertNo() );
|
||||
xyxInfo.put( "serviceId", info.getServiceId() );
|
||||
xyxInfo.put( "status", info.getStatus() );
|
||||
xyxInfo.put( "xyxNo", info.getXyxNo() );
|
||||
|
||||
xyxInfoList.add( xyxInfo );
|
||||
|
||||
request_count++;
|
||||
total_count++;
|
||||
|
||||
logger.info( "准备数据:" + xyxInfo.toJSONString() );
|
||||
|
||||
if ( request_count >= HuixiabaoConfig.getMAX_COUNT_PER_REQUEST() - 1 || total_count == items.size() )
|
||||
{
|
||||
// 达到上限,或者记录已经全部处理,将当前生成的数据送出
|
||||
requestObject.remove( "hmbList" );
|
||||
requestObject.put( "hmbList", xyxInfoList );
|
||||
|
||||
try
|
||||
{
|
||||
req.setData( requestObject );
|
||||
resp = client.execute( req );
|
||||
|
||||
logger.info( "发送成功,返回消息:" + resp.getData() );
|
||||
|
||||
// 将已发送的数据从update表中清理掉
|
||||
}
|
||||
catch ( ZephyrApiException error )
|
||||
{
|
||||
// 发送不成功,记录日志
|
||||
// 失败的数据就留在update表中,待以后重新发送
|
||||
logger.error( error.getMessage() );
|
||||
}
|
||||
|
||||
// 清理清单,重置计数
|
||||
xyxInfoList.clear();
|
||||
request_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user