createDirectory

version1
admin 2 years ago
parent 8c1076fcaf
commit 87deac1d6e

@ -136,6 +136,7 @@ public class IdcServiceImpl implements IdcService {
String host = getNextHost();
if(!StringUtils.isEmpty(host)) {
String result = post(host+"/spssync/common/list",query);
logger.info("fetchTask--->"+result);
if(IDCUtils.isJson(result)) {
JSONObject json = JSON.parseObject(result);
if(json!=null&&json.getInteger("code")==20000&&json.getString("data")!=null) {
@ -249,6 +250,7 @@ public class IdcServiceImpl implements IdcService {
boolean success=true;
Response response = client.newCall(request).execute();
result = response.body().toString();
logger.info("fetchData-->"+result);
JSONObject json = JSONObject.parseObject(result);
if(isLastLevel()) {
success = analyToDB(json,files);
@ -309,8 +311,10 @@ public class IdcServiceImpl implements IdcService {
String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
String fileName = filePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi";
String backFileName = backFilePath +datePath+"/"+json.getString("messageType")+"-"+json.getString("messageId")+".udi";
FileUtils.makeDirectory( filePath +datePath+"/");
FileUtils.makeDirectory(backFilePath +datePath+"/");
if(!FileUtils.makeDirectory( filePath +datePath))
IDCUtils.createDirectory(filePath +datePath+"/");
if(!FileUtils.makeDirectory(backFilePath +datePath))
IDCUtils.createDirectory(filePath +datePath+"/");
FileUtils.SaveFileAs(content, fileName);
FileUtils.SaveFileAs(content, backFileName);
@ -549,8 +553,10 @@ public class IdcServiceImpl implements IdcService {
String datePath = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
String fileName = filePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
String backFileName = backFilePath +datePath+"/"+json.get("messageType")+"-"+json.get("messageId")+".udi";
FileUtils.makeDirectory(filePath +datePath+"/");
FileUtils.makeDirectory(backFilePath +datePath+"/");
if(!FileUtils.makeDirectory( filePath +datePath))
IDCUtils.createDirectory(filePath +datePath+"/");
if(!FileUtils.makeDirectory(backFilePath +datePath))
IDCUtils.createDirectory(filePath +datePath+"/");
FileUtils.SaveFileAs(content, fileName);
FileUtils.SaveFileAs(content, backFileName);
@ -563,11 +569,9 @@ public class IdcServiceImpl implements IdcService {
map.put("taskId", json.get("messageId"));
map.put("cacheFilePath", fileName);
map.put("status", success ? "1" : "0");
if(isUpload) {
saveUploadStatus(map);
} else {
saveExportStatus(map);
}
}

@ -1,5 +1,6 @@
package com.glxp.sale.admin.idc.utils;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -109,4 +110,24 @@ public class IDCUtils {
return date;
}
public static void createDirectory(String directory) {
String dir = directory;
String path ="";
String[] breakChar ={"\\","/"};
for(String bk:breakChar) {
while(dir.indexOf(bk)>-1) {
path+=dir.substring(0,dir.indexOf(bk))+"\\";
File file = new File(path);
if (!(new File(path)).exists()) {
(new File(path)).mkdir();
}
if (dir.length()>dir.indexOf(bk)) {
dir = dir.substring(dir.indexOf(bk) +1);
} else {
dir = "";
}
}
}
}
}

Loading…
Cancel
Save