完善转发

version1
admin 2 years ago
parent a712980a99
commit ac7a1ca8c2

@ -78,7 +78,8 @@ public class IdcServiceImpl implements IdcService {
"basicThirdProducts//thr_products/id///updateTime///第三方产品信息","//sup_cert/id///updateTime/filePath//资质证书信息",
"//sup_cert_set/id///updateTime///供应商资质证书设置","companyCert//sup_company/customerId///updateTime///配送企业",
"manufacturerCert//sup_manufacturer/id///updateTime///生产企业","productCert//sup_product/id///updateTime///产品资质信息",
"dbDiProducts//productinfo/id///updateTime///DI产品信息","//udicompany/id///updateTime///国际库医疗器械注册人信息"};
"//udicompany/id///updateTime///国际库医疗器械注册人信息"};
//"dbDiProducts//productinfo/id///updateTime///DI产品信息",
private int orderNum=0;
@ -286,11 +287,11 @@ public class IdcServiceImpl implements IdcService {
JSONObject json = JSONObject.parseObject(content);
String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
FileUtils.makeDirectory(filePath +datePath+"/");
FileUtils.makeDirectory(backFilePath +datePath+"/");
String fileName = filePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi";
String backFileName = backFilePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi";
FileUtils.makeDirectory(fileName);
FileUtils.makeDirectory(backFileName);
FileUtils.SaveFileAs(content, fileName);
FileUtils.SaveFileAs(content, backFileName);
String[] saveFiles= {};
@ -316,11 +317,18 @@ public class IdcServiceImpl implements IdcService {
saveUploadStatus(json.getString("messageType"),json.getString("messageId"),fileName);
/*解析入库*/
if(isLastLevel()) {
analyToDB(json,files);
if(!analyToDB(json,files))
return ResultVOUtils.error(9000, "解析失败");
} else {
//需要转发
if(isRelay()) {
relay(request.getHeader("reqNo"),content,saveFiles);
String result = relay(request.getHeader("reqNo"),content,saveFiles);
if(IDCUtils.isJson(result)) {
JSONObject object = JSON.parseObject(result);
if(object.getInteger("code")!=20000)
return ResultVOUtils.error(9000, "转发失败");
}
}
}
return ResultVOUtils.success();
@ -356,13 +364,11 @@ public class IdcServiceImpl implements IdcService {
dbDao.save(sql);
}
private void saveExportStatus(String messageType,String taskId,String fileName) {
private void saveExportStatus(Map<String,Object> params) {
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.putAll(params);
map.put("id", CustomUtil.getId());
map.put("updateTime", new Date());
Map<String,Object> columns = getColumn("basic_export_status");
String sql = "insert into basic_export_status "+DBAUtils.parseInsert(map, columns);
@ -503,12 +509,12 @@ public class IdcServiceImpl implements IdcService {
saveIdcLog(messageType,"",tableName +">fail:上传地址未连通",i *limit,total);
}
} else {
syncAddTask(data);
if(!StringUtils.isEmpty(recordSql)) {
dbDao.save("insert into idc_record (id,type,fkId,isEnd,createTime) values "+recordSql);
}
saveIdcLog(messageType,"",tableName +">success",i *limit,total);
}
syncAddTask(data,isUplaod);
}
}
}
@ -519,34 +525,41 @@ public class IdcServiceImpl implements IdcService {
}
/*增加同步任务*/
private void syncAddTask(Map<String,Object> json) {
private void syncAddTask(Map<String,Object> json,boolean isUpload) {
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.makeDirectory(fileName);
FileUtils.makeDirectory(backFileName);
FileUtils.SaveFileAs(content, fileName);
FileUtils.SaveFileAs(content, backFileName);
saveExportStatus(json.get("messageType").toString(),json.get("messageId").toString(),fileName);
//type,transportType,superiorService,subordinateService,cacheFilePath
Map<String,Object> map = new HashMap<>();
map.put("type", json.get("messageType"));
map.put("transportType", isUpload ? "1" : "2");
map.put("scheduleType", isUpload ? "1" : "0");
map.put("taskId", json.get("messageId"));
map.put("cacheFilePath", fileName);
saveExportStatus(map);
}
/*解析到数据库*/
private void analyToDB(JSONObject jsonObject,MultipartFile[] files) {
private boolean analyToDB(JSONObject jsonObject,MultipartFile[] files) {
if(!StringUtils.isEmpty(jsonObject.getString("tableName"))) {
List<Map<String,Object>> list = jsonObject.getObject("data", List.class);
analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list);
return analyData(jsonObject.getString("tableName"),jsonObject.getString("uniqueColumn"),list);
//图片处理
}
return false;
}
/*按表名解析数据到数据库,子表暂未处理*/
private void analyData(String tableName,String uniqueColumn,List<Map<String,Object>> list) {
private boolean analyData(String tableName,String uniqueColumn,List<Map<String,Object>> list) {
String tName = DBAUtils.tableRealName(tableName);
String sql="replace "+tName +"(";
@ -555,6 +568,7 @@ public class IdcServiceImpl implements IdcService {
String[] keyColumn=new String[30];
String[] keyDataType=new String[30];
List<Map<String,String>> columnList = dbDao.listColumnsMysql(tName);
boolean result = false;
int key=0;
int col=0;
for(int i=0;i<columnList.size();i++) {
@ -658,11 +672,12 @@ public class IdcServiceImpl implements IdcService {
}
}
if(n>0)
dbDao.save(sql);
if(n>0) {
result = (dbDao.save(sql)>0);
}
}
return result;
}
@ -761,6 +776,7 @@ public class IdcServiceImpl implements IdcService {
map.put("apiCode", "common");
map.put("tableName", DBAUtils.tableAliasName(tableName));
map.put("uniqueColumn", params.get("uniqueColumn"));
map.put("filePathColumn", params.get("filePathColumn"));
map.put("sendTime", new Date());
map.put("version", "1.0");
map.put("total", list.size());
@ -879,4 +895,6 @@ public class IdcServiceImpl implements IdcService {
}
}
}

Loading…
Cancel
Save