浏览代码

进度条

xiaochan 1 年之前
父节点
当前提交
6e75dcd2a3
共有 1 个文件被更改,包括 47 次插入0 次删除
  1. 47 0
      src/main/java/thyyxxk/webserver/utils/ProgressBar.java

+ 47 - 0
src/main/java/thyyxxk/webserver/utils/ProgressBar.java

@@ -0,0 +1,47 @@
+package thyyxxk.webserver.utils;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+@Slf4j
+public class ProgressBar {
+    public Map<Integer, String> map = new TreeMap<>();
+
+    public void show() {
+        StringBuilder a = new StringBuilder();
+        for (Map.Entry<Integer, String> item : map.entrySet()) {
+            a.append("任务")
+                    .append(item.getKey())
+                    .append(":")
+                    .append(item.getValue())
+                    .append("\n");
+        }
+        log.info("\n{}", a);
+    }
+
+    public void drawProgressBar(int name, int total, int current) {
+        int progress = (int) (((double) current / total) * 100); // 计算进度百分比
+        StringBuilder progressBar = new StringBuilder("["); // 进度条字符串
+
+        for (int i = 0; i < 100; i += 5) { // 遍历 0 到 100
+            if (i < progress) {
+                progressBar.append("="); // 表示已完成的进度
+            } else if (i == progress) {
+                progressBar.append(">"); // 表示当前进度
+            } else {
+                progressBar.append(" "); // 表示未完成的进度
+            }
+        }
+        progressBar.append("] ")
+                .append(progress)
+                .append("%")
+                .append("当前:【").append(current).append("】")
+                .append("总:【").append(total).append("】");
+
+        map.put(name, progressBar.toString());
+        show();
+    }
+
+}