|
@@ -0,0 +1,111 @@
|
|
|
|
+package com.persagy.ibms.data.sdk.util;
|
|
|
|
+
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+public class LogOfRun {
|
|
|
|
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+
|
|
|
|
+ public Date startTime;
|
|
|
|
+ public Date endTime;
|
|
|
|
+ public Map<String, String> contentTime = new ConcurrentHashMap<String, String>();
|
|
|
|
+ public Map<String, String> contentTimeLast = new ConcurrentHashMap<String, String>();
|
|
|
|
+ public int step_count;
|
|
|
|
+ public List<JSONObject> stepList = new CopyOnWriteArrayList<JSONObject>();
|
|
|
|
+ public List<JSONObject> errorList = new CopyOnWriteArrayList<JSONObject>();
|
|
|
|
+ public String status;// running,success,failure
|
|
|
|
+
|
|
|
|
+ public LogOfRun() {
|
|
|
|
+ this.startTime = new Date();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized void setTime(String name, String oldTime, String newTime) {
|
|
|
|
+ log.warn(name + ": " + (oldTime == null ? "" : oldTime + " -> ") + newTime);
|
|
|
|
+ if (oldTime != null) {
|
|
|
|
+ this.contentTimeLast.put(name, oldTime);
|
|
|
|
+ }
|
|
|
|
+ this.contentTime.put(name, newTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized void error(String path, String message) {
|
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
|
+ item.put("path", path);
|
|
|
|
+ item.put("message", message);
|
|
|
|
+ if (this.errorList.size() <= 1024) {
|
|
|
|
+ this.errorList.add(item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized JSONObject toJSON() {
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ if (startTime != null) {
|
|
|
|
+ result.put("startTime", sdf.format(startTime));
|
|
|
|
+ }
|
|
|
|
+ String[] keys = contentTime.keySet().toArray(new String[0]);
|
|
|
|
+ Arrays.sort(keys);
|
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
|
+ for (String key : keys) {
|
|
|
|
+ String time = (contentTimeLast.containsKey(key) ? contentTimeLast.get(key) + " -> " : "") + contentTime.get(key);
|
|
|
|
+ content.put(key, time);
|
|
|
|
+ }
|
|
|
|
+ result.put("content", content);
|
|
|
|
+ if (this.step_count > 0) {
|
|
|
|
+ result.put("step_count", step_count);
|
|
|
|
+ }
|
|
|
|
+ {
|
|
|
|
+ JSONArray stepArray = new JSONArray();
|
|
|
|
+ for (JSONObject step : stepList) {
|
|
|
|
+ stepArray.add(step);
|
|
|
|
+ }
|
|
|
|
+ result.put("stepArray", stepArray);
|
|
|
|
+ }
|
|
|
|
+ {
|
|
|
|
+ JSONArray errorArray = new JSONArray();
|
|
|
|
+ for (JSONObject error : errorList) {
|
|
|
|
+ errorArray.add(error);
|
|
|
|
+ }
|
|
|
|
+ result.put("errorArray", errorArray);
|
|
|
|
+ }
|
|
|
|
+ if (endTime != null) {
|
|
|
|
+ result.put("endTime", sdf.format(endTime));
|
|
|
|
+ }
|
|
|
|
+ if (status != null) {
|
|
|
|
+ result.put("status", status);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public synchronized String toString() {
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ if (startTime != null) {
|
|
|
|
+ sb.append("startTime: " + sdf.format(startTime));
|
|
|
|
+ }
|
|
|
|
+ String[] keys = contentTime.keySet().toArray(new String[0]);
|
|
|
|
+ Arrays.sort(keys);
|
|
|
|
+ for (String key : keys) {
|
|
|
|
+ sb.append("<BR>");
|
|
|
|
+ sb.append(key + ": " + (contentTimeLast.containsKey(key) ? contentTimeLast.get(key) + " -> " : "") + contentTime.get(key));
|
|
|
|
+ }
|
|
|
|
+ if (endTime != null) {
|
|
|
|
+ sb.append("<BR>");
|
|
|
|
+ sb.append("endTime: " + sdf.format(endTime));
|
|
|
|
+ }
|
|
|
|
+ if (status != null) {
|
|
|
|
+ sb.append("<BR>");
|
|
|
|
+ sb.append("status: " + status);
|
|
|
|
+ }
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+}
|