|
|
|
@ -138,6 +138,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
logger.info("UDI管理系统同步任务开始--------");
|
|
|
|
|
asyncDataTask(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*自助平台生成任务,不上传*/
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncSpsTask() {
|
|
|
|
@ -151,6 +152,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
public void asyncFetchUdiTask() {
|
|
|
|
|
fetchTask(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
@Override
|
|
|
|
|
public void asyncFetchTask() {
|
|
|
|
@ -274,7 +276,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String fetchData(String host, Map<String, Object> params) {
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.build();
|
|
|
|
@ -287,7 +288,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
.build();
|
|
|
|
|
String result = "";
|
|
|
|
|
MultipartFile[] files = {};
|
|
|
|
|
Date startTime = new Date();
|
|
|
|
|
try {
|
|
|
|
|
boolean success = true;
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
@ -302,11 +302,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
} else {
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"),3,success,startTime,true);
|
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"), 3, success);
|
|
|
|
|
} else {
|
|
|
|
|
if (json.get("code") != null && json.get("data") != null) {
|
|
|
|
|
//logger.info("res1-->"+JSON.toJSONString(json));
|
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"),0,success,startTime,true);
|
|
|
|
|
logger.info("res1-->" + JSON.toJSONString(json));
|
|
|
|
|
syncAddTaskStatus(json.getJSONObject("data"), 0, success);
|
|
|
|
|
analyMiddle(host, json.getJSONObject("data"), files, false, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -349,10 +349,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse downlaodSuccess(HttpServletRequest request, Map<String, Object> params) {
|
|
|
|
|
String sql = "update basic_export_status set receiveStatus='1',endTime=now() where id='"+params.get("taskId")+"'";
|
|
|
|
|
String sql = "update basic_export_status set receiveStatus='1' where id='" + params.get("taskId") + "'";
|
|
|
|
|
dbDao.update(sql);
|
|
|
|
|
return ResultVOUtils.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****/
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse receive(HttpServletRequest request,
|
|
|
|
@ -375,7 +376,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
FileUtils.SaveFileAs(content, fileName);
|
|
|
|
|
FileUtils.SaveFileAs(content, backFileName);
|
|
|
|
|
ArrayList<String> saveFiles = new ArrayList<>();
|
|
|
|
|
Date startTime = new Date();
|
|
|
|
|
|
|
|
|
|
if (files != null) {
|
|
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
@ -402,7 +403,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
boolean success = false;
|
|
|
|
|
if (isLastLevel()) {
|
|
|
|
|
success = analyMiddle("", json, files, true, true);
|
|
|
|
|
syncAddTaskStatus(json,2,success,startTime,true);
|
|
|
|
|
syncAddTaskStatus(json, 2, success);
|
|
|
|
|
if (!success) {
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.error(9000, "解析失败");
|
|
|
|
@ -413,11 +414,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
String host = getNextHost();
|
|
|
|
|
String result = relay(request.getHeader("reqNo"), content, saveFiles, host);
|
|
|
|
|
if (IDCUtils.isJson(result)) {
|
|
|
|
|
syncAddTaskStatus(json,1,true,startTime,true);
|
|
|
|
|
syncAddTaskStatus(json, 1, true);
|
|
|
|
|
BaseResponse object = JSON.parseObject(result, BaseResponse.class);
|
|
|
|
|
return object;
|
|
|
|
|
} else {
|
|
|
|
|
syncAddTaskStatus(json,1,false,startTime,false);
|
|
|
|
|
syncAddTaskStatus(json, 1, false);
|
|
|
|
|
return ResultVOUtils.error(9000, "转发失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -435,6 +436,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse send(String messageType, String tableName, Map<String, Object> params) {
|
|
|
|
|
|
|
|
|
@ -446,7 +448,9 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
public void downloadFile(String fileName, HttpServletResponse response) {
|
|
|
|
|
OutputStream os;
|
|
|
|
|
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : fileName.substring(0, 1).equals("/") ? "" : "/";
|
|
|
|
|
|
|
|
|
|
if (!FileUtils.isFileExist(filePath + filePathSlash + fileName))
|
|
|
|
|
fileName = "11.jpg";
|
|
|
|
|
logger.info(filePath + filePathSlash + fileName);
|
|
|
|
|
try {
|
|
|
|
|
if (FileUtils.isFileExist(filePath + filePathSlash + fileName)) {
|
|
|
|
|
byte[] bytes = FileUtils.readFileByBytes(filePath + filePathSlash + fileName);
|
|
|
|
@ -464,34 +468,39 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
private void saveUploadStatus(Map<String, Object> params) {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
map.putAll(params);
|
|
|
|
|
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
Map<String, Object> columns = getColumn("basic_upload_status");
|
|
|
|
|
String sql = "replace basic_upload_status "+DBAUtils.parseInsert(map, columns);
|
|
|
|
|
String sql = "insert into basic_upload_status " + DBAUtils.parseInsert(map, columns);
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveExportStatus(Map<String, Object> params) {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
|
|
map.putAll(params);
|
|
|
|
|
map.put("receiveStatus", "0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
Map<String, Object> columns = getColumn("basic_export_status");
|
|
|
|
|
String sql = "replace basic_export_status "+DBAUtils.parseInsert(map, columns);
|
|
|
|
|
String sql = "insert into basic_export_status " + DBAUtils.parseInsert(map, columns);
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveDownloadStatus(Map<String, Object> params) {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
map.put("receiveStatus", "0");
|
|
|
|
|
map.putAll(params);
|
|
|
|
|
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
Map<String, Object> columns = getColumn("basic_download_status");
|
|
|
|
|
String sql = "replace basic_download_status "+DBAUtils.parseInsert(map, columns);
|
|
|
|
|
String sql = "insert into basic_download_status " + DBAUtils.parseInsert(map, columns);
|
|
|
|
|
|
|
|
|
|
dbDao.save(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveIdcLog(String messageType, String taskId, String content, int offset, int total) {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
@ -559,7 +568,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
for (int i = 0; i < Math.ceil(total / limit) + 1; i++) {
|
|
|
|
|
whereParams.replace("page", i * limit);
|
|
|
|
|
whereParams.replace("limit", limit);
|
|
|
|
|
Date startTime = new Date();
|
|
|
|
|
Map<String, Object> data = getData(messageType, tableName, params, whereParams);
|
|
|
|
|
String recordSql = "";
|
|
|
|
|
orderNum++;
|
|
|
|
@ -580,7 +588,6 @@ 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) {
|
|
|
|
|
for (int z = 0; z < childNum + 1; z++) {
|
|
|
|
|
String[] chidTnames = childs[z].split("/");
|
|
|
|
@ -639,7 +646,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
saveIdcLog(messageType, "", tableName + ">success", i * limit, total);
|
|
|
|
|
}
|
|
|
|
|
syncAddTaskStatus(data,isUpload ? 1 : 0 ,success,startTime,isUpload);
|
|
|
|
|
syncAddTaskStatus(data, isUpload ? 1 : 0, success);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -650,9 +657,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*增加同步任务状态*/
|
|
|
|
|
private void syncAddTaskStatus(Map<String,Object> json,int scheduleType,boolean success,Date startTime,boolean isEnd) {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
private void syncAddTaskStatus(Map<String, Object> json, int scheduleType, boolean success) {
|
|
|
|
|
try {
|
|
|
|
|
String content = JSON.toJSONString(json);
|
|
|
|
|
String datePath = DateUtil.formatDate(new Date(), "yyyy-MM-dd");
|
|
|
|
|
String fileName = filePath + datePath + "/" + json.get("messageType") + "-" + json.get("messageId") + ".udi";
|
|
|
|
@ -668,18 +674,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
//type,transportType,superiorService,subordinateService,cacheFilePath
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("type", json.get("messageType"));
|
|
|
|
|
map.put("id", json.get("messageId"));
|
|
|
|
|
if(json.get("id")==null)
|
|
|
|
|
map.put("id", CustomUtil.getId());
|
|
|
|
|
map.put("transportType", scheduleType == 0 ? "1" : "2");
|
|
|
|
|
map.put("scheduleType", scheduleType);
|
|
|
|
|
map.put("taskId", json.get("messageId"));
|
|
|
|
|
map.put("cacheFilePath", fileName);
|
|
|
|
|
map.put("status", success ? "1" : "0");
|
|
|
|
|
map.put("startTime", startTime!=null ? startTime : new Date());
|
|
|
|
|
map.put("updateTime", new Date());
|
|
|
|
|
if(isEnd)
|
|
|
|
|
map.put("endTime", new Date());
|
|
|
|
|
if (scheduleType == 2) {
|
|
|
|
|
saveUploadStatus(map);
|
|
|
|
|
} else if (scheduleType == 3) {
|
|
|
|
@ -957,9 +956,11 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean signleDownloadFile(String syncIp, String fileName) {
|
|
|
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
|
|
.build();;
|
|
|
|
|
.build();
|
|
|
|
|
;
|
|
|
|
|
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
|
|
|
|
|
|
|
RequestBody body = RequestBody.create(mediaType, "fileName=" + fileName);
|
|
|
|
@ -992,7 +993,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1037,14 +1037,16 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
map.putAll(params);
|
|
|
|
|
map.put("sql", sql);
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = dbDao.list(map);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*由表名获取数据*/
|
|
|
|
|
private Map<String, Object> getData(String messageType, String tableName, Map<String, Object> params, Map<String, Object> whereParams) {
|
|
|
|
|
List<Map<String, Object>> list = getList(tableName, whereParams);
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
map.put("messageId", CustomUtil.getId());
|
|
|
|
|
map.put("messageId", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
|
|
map.put("messageType", messageType);
|
|
|
|
|
map.put("apiCode", "common");
|
|
|
|
|
map.put("tableName", DBAUtils.tableAliasName(tableName));
|
|
|
|
@ -1058,8 +1060,6 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SystemParamConfigEntity getSystemParamConfig(String paramKey, String paramName, String defaultValue, String paramExplain) {
|
|
|
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey(paramKey);
|
|
|
|
|
if (systemParamConfigEntity == null || (systemParamConfigEntity != null && StringUtils.isEmpty(systemParamConfigEntity.getParamKey()))) {
|
|
|
|
@ -1075,6 +1075,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
return systemParamConfigEntity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void writeFile(byte[] file, String filePath, String fileName) throws Exception {
|
|
|
|
|
File targetFile = new File(filePath);
|
|
|
|
|
if (!targetFile.exists()) {
|
|
|
|
@ -1099,7 +1100,8 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
for (int i = 0; i < columnList.size(); i++) {
|
|
|
|
|
Map<String, Object> column = new HashMap<String, Object>();
|
|
|
|
|
String dataType = columnList.get(i).get("dataType").toLowerCase().contains("char") || columnList.get(i).get("dataType").toLowerCase().contains("text") ?
|
|
|
|
|
"C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N" ;;
|
|
|
|
|
"C" : columnList.get(i).get("dataType").toLowerCase().contains("date") ? "D" : "N";
|
|
|
|
|
;
|
|
|
|
|
String attrName = columnList.get(i).get("columnName").toString();
|
|
|
|
|
if (map.get(attrName) == null) {
|
|
|
|
|
column.put("tableName", tname);
|
|
|
|
@ -1139,6 +1141,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
}
|
|
|
|
|
return updateTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String setUpdateTime(String id, String updateTime) {
|
|
|
|
|
String sql = "";
|
|
|
|
|
Map<String, Object> map = dbDao.get("select * from idc_status where id='" + id + "'");
|
|
|
|
@ -1151,6 +1154,7 @@ 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(100),statusTime datetime,PRIMARY KEY (id))");
|
|
|
|
@ -1166,6 +1170,7 @@ public class IdcServiceImpl implements IdcService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void alterTable(String tableName, String sql) {
|
|
|
|
|
Map<String, String> map = dbDao.getMysql(tableName);
|
|
|
|
|
if (!(map != null && map.get("tableName") != null)) {
|
|
|
|
|