图片下载

version1
admin 2 years ago
parent d471bf0894
commit 4d9ecbabc2

@ -293,9 +293,12 @@ public class IdcServiceImpl implements IdcService {
logger.info("fetchData-->解析失败");
} else {
if(json.get("code")!=null) {
syncAddTaskStatus(json.getJSONObject("data"),false,success);
analyMiddle(host,json.getJSONObject("data"),files,false,false);
} else {
syncAddTaskStatus(json,false,success);
analyMiddle(host,json,files,false,false);
}
}
@ -362,14 +365,16 @@ public class IdcServiceImpl implements IdcService {
FileUtils.SaveFileAs(content, fileName);
FileUtils.SaveFileAs(content, backFileName);
String[] saveFiles= {};
ArrayList<String> saveFiles = new ArrayList<>();
if(files!=null) {
saveFiles = new String[files.length];
int n=0;
try {
for(MultipartFile file:files) {
String imageName = filePath +filePathSlash+"register/file/image2/"+file.getOriginalFilename();
saveFiles[n] = imageName;
saveFiles.add(imageName);
writeFile(file.getBytes(), filePath +filePathSlash+"register/file/image2/", file.getOriginalFilename());
writeFile(file.getBytes(), backFilePath +backFileSlash+datePath+"register/file/image2/", file.getOriginalFilename());
n++;
@ -425,11 +430,13 @@ public class IdcServiceImpl implements IdcService {
OutputStream os;
String filePathSlash = filePath.substring(filePath.length() -1).equals("/") ? "" : fileName.substring(0,1).equals("/") ? "" : "/";
try {
byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName);
os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
if(FileUtils.isFileExist(filePath+filePathSlash+fileName)) {
byte[] bytes = FileUtils.readFileByBytes(filePath+filePathSlash+fileName);
os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -519,7 +526,8 @@ public class IdcServiceImpl implements IdcService {
String isEnd = params.get("isEnd")!=null ? params.get("isEnd").toString() : "0";
int limit = 50;
String[] files = new String[limit];
ArrayList<String> files = new ArrayList<>();
String filePathColumn = params.get("filePathColumn")!=null ? params.get("filePathColumn").toString() : "";
orderNum++;
String messageType = params.get("messageType").toString();
@ -547,7 +555,7 @@ public class IdcServiceImpl implements IdcService {
if(list!=null&&list.size()>0) {
for(int m=0;m<list.size();m++) {
if(!StringUtils.isEmpty(filePathColumn)&&list.get(m).get(filePathColumn)!=null) {
files[m] = filePath+filePathSlash+"register/file/image2/"+list.get(m).get(filePathColumn).toString();
files.add(filePath+filePathSlash+"register/file/image2/"+list.get(m).get(filePathColumn).toString());
}
recordSql+=!StringUtils.isEmpty(recordSql) ? "," : "";
recordSql+="('"+UUID.randomUUID().toString().replaceAll("-", "")+"','"+tableName+"','"+list.get(m).get(keyColumn)+"','"+isEnd+"',now())";
@ -560,7 +568,15 @@ public class IdcServiceImpl implements IdcService {
childMap.put(chidTnames[5], keyValue);
List<Map<String,Object>> childList = getList(chidTnames[2],childMap);
list.get(m).put("tableName"+z, chidTnames[2]);
list.get(m).put("filePathColumn"+z, chidTnames[7]);
list.get(m).put("data"+z, childList);
if(!StringUtils.isEmpty(chidTnames[7])&&childList.size()>0) {
for(int x=0;x<childList.size();x++) {
if(childList.get(i).get(chidTnames[7])!=null) {
files.add(filePath+filePathSlash+"register/file/image2/"+childList.get(i).get(chidTnames[7]));
}
}
}
}
}
}
@ -682,7 +698,7 @@ public class IdcServiceImpl implements IdcService {
for(int z=0;z<30;z++) {
if(list.get(i).get("data"+z)!=null) {
if(list.get(i).get("filePathColumn"+z)!=null) {
List<Map<String,Object>> childList = (ArrayList<Map<String,Object>>)list.get(i).get("data"+z);
List<Map<String,Object>> childList = (List<Map<String,Object>>)list.get(i).get("data"+z);
analyToFile(host,list.get(i).get("filePathColumn"+z).toString(),childList);
}
} else {
@ -821,18 +837,14 @@ public class IdcServiceImpl implements IdcService {
if(!result)
logger.error(tableName+"-->fetchSave Fail");
}
if(!isUpload&&!StringUtils.isEmpty(filePathColumn)) {
logger.info("downloadFile-->"+files.toString());
batchDownloadFile(host,files);
}
batchDownloadFile(host,files);
}
return result;
}
/*转发下级或上级中继服务*/
private String relay(String reqNo,String content,String[] files,String ip) {
private String relay(String reqNo,String content,ArrayList<String> files,String ip) {
String host = ip;
String result="";
if(StringUtils.isEmpty(reqNo))
@ -848,11 +860,13 @@ public class IdcServiceImpl implements IdcService {
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
String fileType = "application/octet-stream";
for (int i = 0; i < files.length; i++) {
if(!StringUtils.isEmpty(files[i])) {
File file = new File(files[i]);
builder.addFormDataPart("files",files[i],
RequestBody.create(MediaType.parse(fileType), file));
if(files!=null&&files.size()>0) {
for (int i = 0; i < files.size(); i++) {
if(!StringUtils.isEmpty(files.get(i))) {
File file = new File(files.get(i));
builder.addFormDataPart("files",files.get(i),
RequestBody.create(MediaType.parse(fileType), file));
}
}
}
builder.addFormDataPart("content", content);
@ -1092,13 +1106,15 @@ public class IdcServiceImpl implements IdcService {
}
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_status","create table idc_status (id varchar(100),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)");
jdbcTemplate.execute("alter table idc_status modify column id varchar(100)");
jdbcTemplate.execute("delete from idc_log where createTime<date_sub(now(),interval 3 day)");
} catch (Exception e) {
}

Loading…
Cancel
Save