|
|
|
@ -67,28 +67,19 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
@Value("${API_SECRET}")
|
|
|
|
|
private String apiSecret;
|
|
|
|
|
|
|
|
|
|
/*自助平台->UDI*/
|
|
|
|
|
private final String[] SPMS_TO_UDI_TABLES= {
|
|
|
|
|
"basic_udirel/updateTime//耗材字典","basic_products///耗材字典信息详情","company_product_relevance/updateTime//供应商关联信息",
|
|
|
|
|
"basic_corp/updateTime//往来单位","thr_bustype_origin/updateTime//第三方单据类型",
|
|
|
|
|
"thr_corp/updateTime//第三方往来单位","thr_dept/updateTime//第三方部门",
|
|
|
|
|
"thr_inv_products/updateTime//第三方库存","thr_inv_warehouse///第三方仓库",
|
|
|
|
|
"thr_order/updateTime//第三方单据","thr_order_detail/updateTime//第三方单据详情",
|
|
|
|
|
"thr_products/updateTime//第三方产品信息","sup_cert/updateTime/filePath/资质证书信息",
|
|
|
|
|
"sup_cert_set/updateTime//供应商资质证书设置","sup_company/updateTime//配送供应商资质信息",
|
|
|
|
|
"sup_manufacturer/updateTime//生产企业资质信息","sup_product/updateTime//产品资质信息"};
|
|
|
|
|
/*UDI->自助平台*/
|
|
|
|
|
private final String[] UDI_TO_SPMS_TABLES= {
|
|
|
|
|
"basic_udirel/updateTime//耗材字典","basic_products///耗材字典信息详情","company_product_relevance/updateTime//供应商关联信息",
|
|
|
|
|
"basic_corp/updateTime//往来单位","thr_bustype_origin/updateTime//第三方单据类型",
|
|
|
|
|
"thr_corp/updateTime//第三方往来单位","thr_dept/updateTime//第三方部门",
|
|
|
|
|
"thr_inv_products/updateTime//第三方库存","thr_inv_warehouse///第三方仓库",
|
|
|
|
|
"thr_order/updateTime//第三方单据","thr_order_detail/updateTime//第三方单据详情",
|
|
|
|
|
"thr_products/updateTime//第三方产品信息","sup_cert/updateTime/filePath/资质证书信息",
|
|
|
|
|
"sup_cert_set/updateTime//供应商资质证书设置","sup_company/updateTime//配送供应商资质信息",
|
|
|
|
|
"sup_manufacturer/updateTime//生产企业资质信息","sup_product/updateTime//产品资质信息",
|
|
|
|
|
"productinfo/updateTime//国家库UDI数据,udicompany/updateTime//国际库医疗器械注册人信息"};
|
|
|
|
|
|
|
|
|
|
/*同步表,格式:同步设置表列名/同步设置表列名(子表时设置,主表不设置)/主表关联列/子表关联列/数据库实际表/时间列/图片或文件列/数据条件/说明*/
|
|
|
|
|
private final String[] SYNC_TABLES= {
|
|
|
|
|
"entrustAction////////委托验收,basicProducts//basic_udirel///updateTime///耗材字典","/basicProducts/basic_products//////耗材字典信息详情",
|
|
|
|
|
"//company_product_relevance///updateTime///供应商关联信息",
|
|
|
|
|
"basicCorp//basic_corp///updateTime///往来单位","typeThird//thr_bustype_origin///updateTime///第三方单据类型",
|
|
|
|
|
"basicThirdCorp//thr_corp///updateTime///第三方往来单位","//thr_dept///updateTime///第三方部门",
|
|
|
|
|
"//thr_inv_products///updateTime///第三方库存","basicThirdInv//thr_inv_warehouse//////第三方仓库",
|
|
|
|
|
"basicThirdBusOrder//thr_order///updateTime///第三方业务单据","/basicThirdBusOrder/thr_order_detail///updateTime///第三方单据详情",
|
|
|
|
|
"basicThirdProducts//thr_products///updateTime///第三方产品信息","//sup_cert///updateTime/filePath//资质证书信息",
|
|
|
|
|
"//sup_cert_set///updateTime///供应商资质证书设置","companyCert//sup_company///updateTime///配送企业",
|
|
|
|
|
"manufacturerCert//sup_manufacturer///updateTime///生产企业","productCert//sup_product///updateTime///产品资质信息",
|
|
|
|
|
"dbDiProducts//productinfo///updateTime///DI产品信息,//udicompany///updateTime///国际库医疗器械注册人信息"};
|
|
|
|
|
|
|
|
|
|
private int orderNum=0;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@ -121,96 +112,117 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
return ResultVOUtils.success(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*UDI系统上传自助平台*/
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncUdiTask() {
|
|
|
|
|
asyncDataTask(true);
|
|
|
|
|
}
|
|
|
|
|
/*自助平台生成任务,不上传*/
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncSpsTask() {
|
|
|
|
|
asyncDataTask(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*拉取前一级中继服务数据*/
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
|
String[] directions = {"I","U"};
|
|
|
|
|
for(String dir:directions) {
|
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
|
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);
|
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
|
|
|
|
|
List<Map> list = JSON.parseArray(json.getString("data"), Map.class);
|
|
|
|
|
if(list!=null) {
|
|
|
|
|
for(Map map:list) {
|
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
|
params.put("taskId", map.get("taskId"));
|
|
|
|
|
fetchData(host+"/spssync/common/list",params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String,Object> query = new HashMap<String,Object>();
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
String result = post(host+"/spssync/common/list",query);
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
|
|
|
|
|
List<Map> list = JSON.parseArray(json.getString("data"), Map.class);
|
|
|
|
|
if(list!=null) {
|
|
|
|
|
for(Map map:list) {
|
|
|
|
|
Map<String,Object> params = new HashMap<String,Object>();
|
|
|
|
|
params.put("taskId", map.get("taskId"));
|
|
|
|
|
fetchData(host+"/spssync/common/list",params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncIdcTask() {
|
|
|
|
|
initTable();
|
|
|
|
|
String[] tNames= {};
|
|
|
|
|
String direction = getDirection();
|
|
|
|
|
|
|
|
|
|
if(direction.equals("I")) {
|
|
|
|
|
tNames = SPMS_TO_UDI_TABLES;
|
|
|
|
|
} else if (direction.equals("U")) {
|
|
|
|
|
tNames = UDI_TO_SPMS_TABLES;
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
|
if(map==null) {
|
|
|
|
|
dbDao.save("insert into idc_var (code,content) values ('system_type','IDC')");
|
|
|
|
|
}
|
|
|
|
|
/*为顶级或末级,以及下游或上游连通,可执行*/
|
|
|
|
|
Boolean isLastLevel = isLastLevel(direction);
|
|
|
|
|
Boolean isRelay = isRelay(direction);
|
|
|
|
|
logger.info("-----数据传输任务开始----"+direction+"\n");
|
|
|
|
|
logger.info("-----是否需要上传或下发数据:"+isLastLevel+",是否已配置接收地址:"+isRelay+"----\n");
|
|
|
|
|
if(isLastLevel&&isRelay) {
|
|
|
|
|
for(String t:tNames) {
|
|
|
|
|
uploadData(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void uploadData(String t) {
|
|
|
|
|
String[] tn = t.split("/");
|
|
|
|
|
String lastUpdateTime = getUpdateTime(tn[0]);
|
|
|
|
|
Date nowUpdateTime = new Date();
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tn[0]);
|
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where type='"+tn[0]+"' and fkId="+tn[0]+"."+keyColumn+")";
|
|
|
|
|
if(!StringUtils.isEmpty(tn[1])) {
|
|
|
|
|
sqlWhere+=" and "+tn[1]+">=cast('"+lastUpdateTime+"' as datetime)";
|
|
|
|
|
} else {
|
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
|
}
|
|
|
|
|
if(tn[0].equals("thr_order"))
|
|
|
|
|
logger.info("-------------------"+sqlWhere);
|
|
|
|
|
map.put("sqlWhere", sqlWhere);
|
|
|
|
|
map.put("tableName", tn[0]);
|
|
|
|
|
map.put("filePathColumn", tn[2]);
|
|
|
|
|
map.put("messageType", tn[3]);
|
|
|
|
|
map.put("messageName", tn[3]);
|
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
|
scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tn[0], new char[]{'_'}).replace("_", ""));
|
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
|
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "";
|
|
|
|
|
boolean send = true;
|
|
|
|
|
if(!StringUtils.isEmpty(cron)) {
|
|
|
|
|
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
|
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
|
send = nextTimePoint.before(nowUpdateTime);
|
|
|
|
|
private void asyncDataTask(boolean isUpload) {
|
|
|
|
|
initTable();
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from sync_data_set limit 1");
|
|
|
|
|
if(map!=null&&map.get("downstreamEnable")!=null&&map.get("downstreamEnable").toString().equals("1"))
|
|
|
|
|
for(int i=0;i<SYNC_TABLES.length;i++) {
|
|
|
|
|
String[] tnames = SYNC_TABLES[i].split("/");
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])&&map!=null&&map.get(tnames[0])!=null&&map.get(tnames[0]).toString().equals("1"))
|
|
|
|
|
syncData(SYNC_TABLES[i],isUpload);
|
|
|
|
|
}
|
|
|
|
|
if(send) {
|
|
|
|
|
BaseResponse result = send(map);
|
|
|
|
|
if(result.getCode()==20000) {
|
|
|
|
|
setUpdateTime(tn[0],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void syncData(String t,boolean isUpload) {
|
|
|
|
|
boolean sync = true;
|
|
|
|
|
String[] tnames = t.split("/");
|
|
|
|
|
String[] cnames = {};
|
|
|
|
|
String lastUpdateTime = getUpdateTime(tnames[0]);
|
|
|
|
|
Date nowUpdateTime = new Date();
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[0])) {
|
|
|
|
|
int n=-1;
|
|
|
|
|
for(int k=0;k<SYNC_TABLES.length;k++) {
|
|
|
|
|
if(SYNC_TABLES[k].contains("/"+tnames[0]+"/")) {
|
|
|
|
|
n++;
|
|
|
|
|
cnames[n] = SYNC_TABLES[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Map<String, String>> keyList = dbDao.listKeyMysql(tnames[2]);
|
|
|
|
|
String keyColumn = keyList!=null&&keyList.size()>0 ? keyList.get(0).get("columnName").toString() : "id";
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
String sqlWhere = "not exists (select fkId from idc_record where type='"+tnames[2]+"' and fkId="+tnames[2]+"."+keyColumn+")";
|
|
|
|
|
if(!StringUtils.isEmpty(tnames[2])) {
|
|
|
|
|
sqlWhere+=" and "+tnames[5]+">=cast('"+lastUpdateTime+"' as datetime)";
|
|
|
|
|
} else {
|
|
|
|
|
map.put("isEnd", "1");
|
|
|
|
|
}
|
|
|
|
|
map.put("sqlWhere", sqlWhere);
|
|
|
|
|
map.put("dataWhere", tnames[7]);
|
|
|
|
|
map.put("tableKey", tnames[0]);
|
|
|
|
|
map.put("tableName", tnames[2]);
|
|
|
|
|
map.put("masterLinkColumn", tnames[3]);
|
|
|
|
|
map.put("subLinkColumn", tnames[4]);
|
|
|
|
|
map.put("filePathColumn", tnames[6]);
|
|
|
|
|
map.put("messageType", tnames[8]);
|
|
|
|
|
map.put("messageName", tnames[8]);
|
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
|
scheduledRequest.setCronName("sync"+WordUtils.capitalizeFully(tnames[2], new char[]{'_'}).replace("_", ""));
|
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
|
String cron = scheduledEntity!=null ? scheduledEntity.getCron() : "";
|
|
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(cron)) {
|
|
|
|
|
CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);
|
|
|
|
|
Date nextTimePoint = cronSequenceGenerator.next(DateUtil.parseDate(lastUpdateTime));
|
|
|
|
|
sync = nextTimePoint.before(nowUpdateTime);
|
|
|
|
|
}
|
|
|
|
|
if(sync) {
|
|
|
|
|
if(syncMasterData(map,isUpload)) {
|
|
|
|
|
setUpdateTime(tnames[2],DateUtil.formatDate(nowUpdateTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String fetchData(String url,Map<String,Object> params) {
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
@ -263,9 +275,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
dbDao.update(sql);
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
/*direction方向 U 上传,I 下发,往自助平台为上传,往UDI管理系统为下发*/
|
|
|
|
|
/****/
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse receive(String direction,HttpServletRequest request,
|
|
|
|
|
public BaseResponse receive(HttpServletRequest request,
|
|
|
|
|
String content,MultipartFile[] files) {
|
|
|
|
|
/*授权检查,后续完善*/
|
|
|
|
|
String apiKey = request.getHeader("apiKey");
|
|
|
|
@ -303,12 +315,12 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName);
|
|
|
|
|
/*解析入库*/
|
|
|
|
|
if(isLastLevel(direction)) {
|
|
|
|
|
if(isLastLevel()) {
|
|
|
|
|
analyToDB(json,files);
|
|
|
|
|
} else {
|
|
|
|
|
//需要转发
|
|
|
|
|
if(isRelay(direction)) {
|
|
|
|
|
relay(direction,request.getHeader("reqNo"),content,saveFiles);
|
|
|
|
|
if(isRelay()) {
|
|
|
|
|
relay(request.getHeader("reqNo"),content,saveFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
@ -325,13 +337,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse send(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(sendOnPage(messageType,tableName,params))
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
logger.error(ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(9999, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -349,6 +355,20 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveExportStatus(String messageType,String taskId,String fileName) {
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("taskId", taskId);
|
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
|
map.put("status", "0");
|
|
|
|
|
map.put("type", messageType);
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
Map<String,Object> columns = getColumn("basic_export_status");
|
|
|
|
|
String sql = "insert into basic_export_status "+DBAUtils.parseInsert(map, columns);
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
private void saveDownloadStatus(String messageType,String taskId,String remark) {
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
@ -377,29 +397,44 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
private boolean sendOnPage(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean syncMasterData(Map<String,Object> params,boolean isUplaod) {
|
|
|
|
|
boolean success=false;
|
|
|
|
|
String tableName = params.get("tableName").toString();
|
|
|
|
|
String tableKey = params.get("tableKey").toString();
|
|
|
|
|
String[] childs = {};
|
|
|
|
|
int childNum = -1;
|
|
|
|
|
for(String str:SYNC_TABLES) {
|
|
|
|
|
if(str.contains("/"+tableKey+"/")) {
|
|
|
|
|
childNum++;
|
|
|
|
|
childs[childNum] = str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Map<String,String> table = dbDao.getMysql(tableName);
|
|
|
|
|
if(!(table!=null&&table.get("tableName")!=null))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
String sql = "select count(*) from "+tableName;
|
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
|
|
|
|
|
|
Map<String,Object> whMap = new HashMap<String,Object>();
|
|
|
|
|
whMap.put("sqlWhere", params.get("sqlWhere"));
|
|
|
|
|
whMap.put("dataWhere", params.get("dataWhere"));
|
|
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
String where = DBAUtils.convertWhere(column,params,"");
|
|
|
|
|
String where = DBAUtils.convertWhere(column,whMap,"");
|
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
|
map.put("sql", sql);
|
|
|
|
|
int total = dbDao.count(map);
|
|
|
|
|
String direction = getDirection();
|
|
|
|
|
|
|
|
|
|
String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0";
|
|
|
|
|
int limit = 50;
|
|
|
|
|
String[] files = new String[limit];
|
|
|
|
|
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
|
|
|
|
|
orderNum++;
|
|
|
|
|
String messageType = params.get("messageType").toString();
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+where,0,total);
|
|
|
|
|
if(tableName.equals("thr_order"))
|
|
|
|
|
logger.info("tableName-->"+tableName+"-->row-->"+total+"-->sqlWhere-->"+where);
|
|
|
|
|
|
|
|
|
|
if(total>0) {
|
|
|
|
|
success = true;
|
|
|
|
|
params.put("page", 0);
|
|
|
|
@ -423,31 +458,65 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
recordSql+=!StringUtils.isEmpty(recordSql) ? "," : "";
|
|
|
|
|
recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())";
|
|
|
|
|
if(childNum>-1&¶ms.get("masterLinkColumn")!=null&¶ms.get("subLinkColumn")!=null) {
|
|
|
|
|
for(int z=0;z<childNum+1;z++) {
|
|
|
|
|
String[] chidTnames = childs[z].split("/");
|
|
|
|
|
String keyValue = list.get(i).get(params.get("masterLinkColumn")).toString();
|
|
|
|
|
Map<String,Object> childMap = new HashMap<>();
|
|
|
|
|
childMap.put(params.get("subLinkColumn").toString(), keyValue);
|
|
|
|
|
List<Map<String,Object>> childList = getList(chidTnames[2],childMap);
|
|
|
|
|
list.get(m).put("tableName"+z, chidTnames[2]);
|
|
|
|
|
list.get(m).put("data"+z, childList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderNum++;
|
|
|
|
|
String result = relay(direction,"",JSON.toJSONString(data),files);
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
if(json.getInteger("code")==20000) {
|
|
|
|
|
if(!StringUtils.isEmpty(recordSql)) {
|
|
|
|
|
dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql);
|
|
|
|
|
if(isUplaod) {
|
|
|
|
|
String result = relay("",JSON.toJSONString(data),files);
|
|
|
|
|
if(IDCUtils.isJson(result)) {
|
|
|
|
|
JSONObject json = JSON.parseObject(result);
|
|
|
|
|
if(json.getInteger("code")==20000) {
|
|
|
|
|
if(!StringUtils.isEmpty(recordSql)) {
|
|
|
|
|
dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql);
|
|
|
|
|
}
|
|
|
|
|
saveDownloadStatus(messageType,json.getString("reqNo"),messageType+" 记录数:"+list.size()+"/"+total);
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">success",i *limit,total);
|
|
|
|
|
} else {
|
|
|
|
|
success = false;
|
|
|
|
|
logger.error(result);
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+result,i *limit,total);
|
|
|
|
|
}
|
|
|
|
|
saveDownloadStatus(messageType,json.getString("reqNo"),messageType+" 记录数:"+list.size()+"/"+total);
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">success",i *limit,total);
|
|
|
|
|
} else {
|
|
|
|
|
success = false;
|
|
|
|
|
logger.error(result);
|
|
|
|
|
saveIdcLog(messageType,"",tableName +">"+result,i *limit,total);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
syncAddTask(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*增加同步任务*/
|
|
|
|
|
private void syncAddTask(Map<String,Object> json) {
|
|
|
|
|
String content = JSON.toJSONString(json);
|
|
|
|
|
String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
FileUtils.makeDirectory(filePath +datePath+"/");
|
|
|
|
|
FileUtils.makeDirectory(backFilePath +datePath+"/");
|
|
|
|
|
String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
|
|
|
|
|
String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saveExportStatus(json.get("messageType").toString(),json.get("messageId").toString(),fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*解析到数据库*/
|
|
|
|
|
private void analyToDB(JSONObject jsonObject,MultipartFile[] files) {
|
|
|
|
@ -548,6 +617,18 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
sql+=")";
|
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int m=0;m<6;m++) {
|
|
|
|
|
if(list.get(i).get("tableName"+m)!=null&&list.get(i).get("data"+m)!=null) {
|
|
|
|
|
Object obj = list.get(i).get("data"+m);
|
|
|
|
|
List<Map<String,Object>> chList = new ArrayList<Map<String,Object>>();
|
|
|
|
|
for (Object o : (List<?>) obj) {
|
|
|
|
|
chList.add((Map<String,Object>)o);
|
|
|
|
|
}
|
|
|
|
|
analyData(list.get(i).get("tableName"+m).toString(),chList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(n>0)
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
@ -558,13 +639,13 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*转发下级或上级中继服务*/
|
|
|
|
|
private String relay(String direction,String reqNo,String content,String[] files) {
|
|
|
|
|
String host = getNextHost(direction);
|
|
|
|
|
private String relay(String reqNo,String content,String[] files) {
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
String result="";
|
|
|
|
|
if(StringUtils.isEmpty(reqNo))
|
|
|
|
|
reqNo = UUID.randomUUID().toString();
|
|
|
|
|
if(!StringUtils.isEmpty(host)) {
|
|
|
|
|
host+=direction.equals("U") ? "/spssync/common/upload" : "/spssync/common/issued";
|
|
|
|
|
host+="/spssync/common/upload" ;
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)//设置连接超时时间
|
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)//设置读取超时时间
|
|
|
|
@ -611,41 +692,38 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取转发服务地址,当前值允许单向,只使用参数upper_server_ip*/
|
|
|
|
|
private String getNextHost(String direction) {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity =
|
|
|
|
|
direction.equals("U") ? getSystemParamConfig("upper_server_host","自助平台数据接收服务地址" , "","接收由UDI系统上传的数据") :
|
|
|
|
|
direction.equals("I") ? getSystemParamConfig("lower_server_host","UDI系统数据接收服务地址" , "","接收由自助平台下发的数据") : null;
|
|
|
|
|
private String getNextHost() {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("upper_server_ip");
|
|
|
|
|
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) {
|
|
|
|
|
return direction.equals("I") || direction.equals("U") ? true : false ;
|
|
|
|
|
/*判断是否需要解析入库,中继服务只转发*/
|
|
|
|
|
private boolean isLastLevel() {
|
|
|
|
|
Map<String,Object> map = dbDao.get("select * from idc_var where code='system_type'");
|
|
|
|
|
return !(map!=null&&map.get("content")!=null&&map.get("content").toString().equals("IDC")) ;
|
|
|
|
|
}
|
|
|
|
|
/*检查当前系统为自助平台(下发)还是UDI系统(上传),返回传输方向,如果都未设置,默认返回下发*/
|
|
|
|
|
private String getDirection() {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = getSystemParamConfig("sync_system_type","系统类型" , "IDC","UDI(UDI管理系统,由UDI系统往自助平台上传数据),SPS(自助平台,由自助平台往UDI系统下发数据),IDC(中继服务,只接收,转发或暂存数据供下一级服务拉取数据)");
|
|
|
|
|
return systemParamConfigEntity.getParamValue().equals("UDI") ? "U" : systemParamConfigEntity.getParamValue().equals("SPS") ? "I" : "N";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*是否需要转发*/
|
|
|
|
|
private boolean isRelay(String direction) {
|
|
|
|
|
String relayHost = getNextHost(direction);
|
|
|
|
|
|
|
|
|
|
private boolean isRelay() {
|
|
|
|
|
String relayHost = getNextHost();
|
|
|
|
|
return !StringUtils.isEmpty(relayHost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*由表名获取数据*/
|
|
|
|
|
private Map<String,Object> getData(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
private List<Map<String,Object>> getList(String tableName,Map<String,Object> params) {
|
|
|
|
|
String sql = "select "+tableName+".*,'A' as operateMode from "+tableName;
|
|
|
|
|
Map<String,Object> column = getColumn(tableName);
|
|
|
|
|
String where = DBAUtils.convertWhere(column,params,"");
|
|
|
|
|
sql+=!StringUtils.isEmpty(where) ? " where "+where : "";
|
|
|
|
|
params.put("sql", sql);
|
|
|
|
|
List<Map<String,Object>> list = dbDao.list(params);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
/*由表名获取数据*/
|
|
|
|
|
private Map<String,Object> getData(String messageType,String tableName,Map<String,Object> params) {
|
|
|
|
|
List<Map<String,Object>> list = getList(tableName,params);
|
|
|
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
|
|
|
|
map.put("messageId", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
|
|
map.put("messageType", messageType);
|
|
|
|
@ -750,10 +828,17 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
return updateTime;
|
|
|
|
|
}
|
|
|
|
|
private void initTable() {
|
|
|
|
|
alterTable("idc_var","create table idc_var (code varchar(60),content varchar(200),PRIMARY KEY (code))");
|
|
|
|
|
alterTable("idc_status","create table idc_status (id varchar(36),statusTime datetime,PRIMARY KEY (id))");
|
|
|
|
|
alterTable("idc_record","create table idc_record (id varchar(36),type varchar(60),fkId varchar(36),isEnd char(1),createTime datetime,primary key (id),INDEX i_idc_record_fk_id (fkId),INDEX i_idc_record_create_time (createTime))");
|
|
|
|
|
alterTable("idc_log","create table idc_log (id varchar(36),orderNum int,taskId varchar(60),type varchar(60),content varchar(2000),offset int,total int,createTime datetime,PRIMARY KEY (id))");
|
|
|
|
|
dbDao.delete("delete from idc_record where createTime<date_sub(now(),interval 2 day) and isEnd='0'");
|
|
|
|
|
try {
|
|
|
|
|
jdbcTemplate.execute("alter table basic_export_status add column cacheFilePath varchar(255)");
|
|
|
|
|
jdbcTemplate.execute("alter table basic_upload_status add column cacheFilePath varchar(255)");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void alterTable(String tableName,String sql) {
|
|
|
|
|
Map<String,String> map = dbDao.getMysql(tableName);
|
|
|
|
@ -762,5 +847,4 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|