From 87deac1d6e56eaf4b6b1e3872d0c80d6af2b2855 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 2 Apr 2023 09:08:24 +0800 Subject: [PATCH] createDirectory --- .../idc/service/impl/IdcServiceImpl.java | 22 +++++++++++-------- .../glxp/sale/admin/idc/utils/IDCUtils.java | 21 ++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java index 44e3a8c..a0b74e5 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java @@ -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); - } + + saveExportStatus(map); + } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/IDCUtils.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/IDCUtils.java index 7fadaa7..ff3f781 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/IDCUtils.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/IDCUtils.java @@ -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 = ""; + } + } + } + + } }