|
|
@ -122,18 +122,27 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
|
|
|
|
@Async
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void pull() {
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
|
|
|
|
String[] directions = {"I","U"};
|
|
|
|
|
|
|
|
for(String dir:directions) {
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
String result = post(getNextHost("U")+"/spssync/common/list",query);
|
|
|
|
String host = getNextHost(dir);
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
|
|
|
String result = post(host+"/spssync/common/list",query);
|
|
|
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
if(json.getInteger("code")==20000&&json.getString("data")!=null) {
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
|
|
|
|
List<Map> list = JSON.parseArray(json.getString("data"), Map.class);
|
|
|
|
List<Map> list = JSON.parseArray(json.getString("data"), Map.class);
|
|
|
|
if(list!=null) {
|
|
|
|
if(list!=null) {
|
|
|
|
for(Map map:list) {
|
|
|
|
for(Map map:list) {
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
params.put("taskId", map.get("taskId"));
|
|
|
|
params.put("taskId", map.get("taskId"));
|
|
|
|
pullData(getNextHost("U")+"/spssync/common/list",params);
|
|
|
|
fetchData(host+"/spssync/common/list",params);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -154,8 +163,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
/*为顶级或末级,以及下游或上游连通,可执行*/
|
|
|
|
/*为顶级或末级,以及下游或上游连通,可执行*/
|
|
|
|
Boolean isLastLevel = isLastLevel(direction);
|
|
|
|
Boolean isLastLevel = isLastLevel(direction);
|
|
|
|
Boolean isRelay = isRelay(direction);
|
|
|
|
Boolean isRelay = isRelay(direction);
|
|
|
|
System.out.print("-----数据传输任务开始----"+direction+"\n");
|
|
|
|
logger.info("-----数据传输任务开始----"+direction+"\n");
|
|
|
|
System.out.print("-----是否顶级或末级服务:"+isLastLevel+",是否转发数据:"+isRelay+"----\n");
|
|
|
|
logger.info("-----是否顶级或末级服务:"+isLastLevel+",是否转发数据:"+isRelay+"----\n");
|
|
|
|
if(isLastLevel&&isRelay) {
|
|
|
|
if(isLastLevel&&isRelay) {
|
|
|
|
for(String t:tNames) {
|
|
|
|
for(String t:tNames) {
|
|
|
|
uploadData(t);
|
|
|
|
uploadData(t);
|
|
|
@ -163,6 +172,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void uploadData(String t) {
|
|
|
|
private void uploadData(String t) {
|
|
|
|
String[] tn = t.split("/");
|
|
|
|
String[] tn = t.split("/");
|
|
|
|
String lastUpdateTime = getUpdateTime(tn[0]);
|
|
|
|
String lastUpdateTime = getUpdateTime(tn[0]);
|
|
|
@ -170,7 +181,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where fkId="+tn[0]+".id)";
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where fkId="+tn[0]+".id)";
|
|
|
|
if(!StringUtils.isEmpty(tn[1])) {
|
|
|
|
if(!StringUtils.isEmpty(tn[1])) {
|
|
|
|
sqlWhere+=" and ifnull("+tn[1]+",now())>=cast('"+lastUpdateTime+"' as datetime)";
|
|
|
|
sqlWhere+=" and "+tn[1]+">=cast('"+lastUpdateTime+"' as datetime)";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -189,15 +200,15 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
send = nextTimePoint.before(nowUpdateTime);
|
|
|
|
send = nextTimePoint.before(nowUpdateTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if(send) {
|
|
|
|
if(send) {
|
|
|
|
BaseResponse result = send(map);
|
|
|
|
BaseResponse result = send(map);
|
|
|
|
if(result.getCode()==20000) {
|
|
|
|
if(result.getCode()==20000) {
|
|
|
|
setUpdateTime(tn[0],DateUtil.formatDate(nowUpdateTime));
|
|
|
|
setUpdateTime(tn[0],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String pullData(String url,Map<String,Object> params) {
|
|
|
|
private String fetchData(String url,Map<String,Object> params) {
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
@ -590,43 +601,29 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
private String getNextHost(String direction) {
|
|
|
|
private String getNextHost(String direction) {
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("upper_server_ip","中继上传服务地址" , "","");
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity =
|
|
|
|
//direction.equals("U") ? getSystemParamConfig("upper_server_ip","中继上传服务地址" , "",""):
|
|
|
|
direction.equals("U") ? getSystemParamConfig("upper_server_host","自助平台数据接收服务地址" , "","") :
|
|
|
|
//getSystemParamConfig("sync_idc_lower_host","下级(下发)中继服务地址" , "","") ;
|
|
|
|
direction.equals("I") ? getSystemParamConfig("lower_server_host","UDI系统数据接收服务地址" , "","") : null;
|
|
|
|
return systemParamConfigEntity.getParamValue();
|
|
|
|
String host = systemParamConfigEntity!=null ? systemParamConfigEntity.getParamValue() : "";
|
|
|
|
|
|
|
|
host = !StringUtils.isEmpty(host)&&host.substring(host.length() -1).equals("/") ? host.substring(0,host.length() -1) : host;
|
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*判断是否最后一级*/
|
|
|
|
/*判断是否上传或下发数据*/
|
|
|
|
private boolean isLastLevel(String direction) {
|
|
|
|
private boolean isLastLevel(String direction) {
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity =
|
|
|
|
return direction.equals("I") || direction.equals("U") ? true : false ;
|
|
|
|
direction.equals("I") ? getSystemParamConfig("sync_idc_top","是否顶级中继服务(连接自助平台)" , "0","0:否;1:是(是,接收下级上传数据后解析入库)"):
|
|
|
|
|
|
|
|
getSystemParamConfig("sync_idc_final","是否末级中继服务(连接UDI管理系统)" , "0","0:否;1:是(是,接收上级下发数据后解析入库)") ;
|
|
|
|
|
|
|
|
return systemParamConfigEntity.getParamValue().equals("0") ? false : true ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/
|
|
|
|
/*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/
|
|
|
|
private String getDirection() {
|
|
|
|
private String getDirection() {
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_idc_top","是否顶级中继服务(连接自助平台)" , "0","0:否;1:是(是,接收下级上传数据后解析入库)");
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_system_type","系统类型" , "IDC","UDI(UDI管理系统),SPS(自助平台),IDC(中继服务)");
|
|
|
|
System.out.print(">>>>>>>>>>"+JSON.toJSONString(systemParamConfigEntity)+"\n");
|
|
|
|
return systemParamConfigEntity.getParamValue().equals("UDI") ? "U" : systemParamConfigEntity.getParamValue().equals("SPS") ? "I" : "N";
|
|
|
|
if(systemParamConfigEntity.getParamValue().equals("0")) {
|
|
|
|
|
|
|
|
systemParamConfigEntity = getSystemParamConfig("sync_idc_final","是否末级中继服务(连接UDI管理系统)" , "0","0:否;1:是(是,接收上级下发数据后解析入库)");
|
|
|
|
|
|
|
|
if(systemParamConfigEntity.getParamValue().equals("1"))
|
|
|
|
|
|
|
|
return "U";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "I";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*是否需要转发*/
|
|
|
|
/*是否需要转发*/
|
|
|
|
private boolean isRelay(String direction) {
|
|
|
|
private boolean isRelay(String direction) {
|
|
|
|
String relayStr = direction.equals("U") ? "sync_upstream_enable" : "sync_downstream_enable";
|
|
|
|
String relayHost = getNextHost(direction);
|
|
|
|
|
|
|
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(relayStr);
|
|
|
|
return !StringUtils.isEmpty(relayHost);
|
|
|
|
if (systemParamConfigEntity!=null&&systemParamConfigEntity.getParamValue()!=null&&
|
|
|
|
|
|
|
|
systemParamConfigEntity.getParamValue().equals("0")) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|