@RequestMapping("/import_data")
public HttpResult importData(@RequestParam("file") MultipartFile file,HttpServletRequest request) {
Map<String,Object> importParam = new HashMap<>();
importParam.put("file",file);
return dwdbBasicDsService.importData(importParam);
}
HttpResult importData(Map<String, Object> importParam);
//导入信息
@Override
public HttpResult importData(Map<String, Object> importParam) {
//获取传输参数
MultipartFile file = (MultipartFile) importParam.get("file");
Date now = new Date();
int iType = "".equals(type) ? 0 : Integer.parseInt(type);
List<String> keys = HeartHelper.getInstance().getKeys();
HttpResult<String> router = ExecutorRouteStrategyEnum.ROUND.getRouter().router(keys);
String clientId = router.getData();
String ip = redisService.mapGet(clientId, "ip");
String port = redisService.mapGet(clientId, "port");
String prefix = redisService.mapGet(clientId, "prefix");
String importUrl = "";
if (StrUtil.isNotEmpty(ip) && StrUtil.isNotEmpty(port)) {
if (StrUtil.isNotEmpty(prefix)) {
prefix = "/" + prefix;
}
importUrl = StrUtil.format("http://{}:{}{}/import_client/import", ip, port, prefix);
} else {
return HttpResult.error("获取信息错误");
}
try {
//新增记录
CurrUserInfo currUserInfo = UserUtils.getCurrUserInfo();
RwkUploadRecord rwkUploadRecord = new RwkUploadRecord();
rwkUploadRecord.setUserid(currUserInfo.getUserID());
rwkUploadRecord.setRequestId(createRequestId(currUserInfo.getUserID(), iType, now));
rwkUploadRecord.setStartTime(now);
rwkUploadRecord.setServerIp(IpUtil.getUniqueFlag());
rwkUploadRecord.setResult(-1);
rwkUploadRecord.setMsg(StrUtil.format("{} 开始等待导入", yyyyMMddHHmmss(now)));
rwkUploadRecord.setType(iType);
iRwkUploadRecordService.save(rwkUploadRecord);
System.out.println("导入服务地址:" + importUrl);
HttpResponse response = HttpUtil.createPost(importUrl)
.form("file", file.getBytes(), file.getName())
.form("currUser", JSON.toJSONString(UserUtils.getCurrUserInfo()))
.form("type", type)
.form("wwrwk", isWwrwk)
.form("recordId", rwkUploadRecord.getId())
.form("isDs", "1")
.form("isUpdateHeadImage", String.valueOf(isUpdateHeadImage))
.execute();
String body = response.body();
System.out.println("访问导入服务器接受到结果:" + body);
HttpResult res = JSON.parseObject(body, HttpResult.class);
return res;
} catch (Exception e) {
e.printStackTrace();
return HttpResult.error(e.getMessage());
}
}