Browse Source

读取计算结果upload.json

dengsixing 3 years ago
parent
commit
180e8038ff

+ 29 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/ComputerUtil.java

@@ -1,5 +1,8 @@
 package com.fdkankan.common.util;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ConstantFileName;
@@ -635,4 +638,30 @@ public class ComputerUtil {
 
         return exist;
     }
+
+    /**
+     * 获取计算完需要上传的文件数组
+     * @param uploadJsonPath uploadjson路径
+     * @param maxCheckTimes 校验upload.json文件是否存在循环次数
+     * @param waitTime 每次检测间隔时间,毫秒
+     * @return boolean
+     * @throws Exception
+     */
+    public static JSONArray getUploadArray(String uploadJsonPath, int maxCheckTimes, long waitTime) throws Exception{
+        boolean buildCompeleted = ComputerUtil.checkComputeCompleted(uploadJsonPath, maxCheckTimes, waitTime);
+        if(!buildCompeleted){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
+        }
+        String uploadData = FileUtil.readUtf8String(uploadJsonPath);
+        JSONObject uploadJson;
+        JSONArray array = null;
+        if(StrUtil.isNotEmpty(uploadData)) {
+            uploadJson = JSONObject.parseObject(uploadData);
+            array = uploadJson.getJSONArray("upload");
+        }
+        if(CollUtil.isEmpty(array)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
+        }
+        return array;
+    }
 }