From 1eafa4de4abae5aafe470d1f301f3060a83ab0f8 Mon Sep 17 00:00:00 2001
From: zhaowenxuan <chacca165@163.com>
Date: 星期一, 01 七月 2024 14:10:24 +0800
Subject: [PATCH] his同步字典实体类

---
 src/main/java/com/example/controller/TestController.java |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/example/controller/TestController.java b/src/main/java/com/example/controller/TestController.java
index 54e00ae..498359e 100644
--- a/src/main/java/com/example/controller/TestController.java
+++ b/src/main/java/com/example/controller/TestController.java
@@ -1,20 +1,69 @@
 package com.example.controller;
 
 import com.example.utils.DictionaryUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
+
+import java.io.*;
 
 /**
  * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃
  * @Author: zhaowenxuan
  * @Date: 2024/6/3 15:25
  */
+@Slf4j
 @RestController
 public class TestController {
-    @GetMapping("test")
-    public String test(){
-        DictionaryUtil util = new DictionaryUtil();
-        util.exec1();
-        return "123";
+    private static final String LOG_PATH = "src/main/resources/log.log";
+    @Autowired
+    private DictionaryUtil dictionaryUtil;
+    @GetMapping("exec")
+    public String exce(){
+        // 灏嗘枃浠跺唴瀹硅缃负绌�
+        FileWriter fileWriter = null;
+        try {
+            fileWriter = new FileWriter(LOG_PATH);
+            fileWriter.write("");
+            fileWriter.close();
+        } catch (IOException ignored) {}
+        new Thread(()->{
+            try {
+                dictionaryUtil.exec1();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }).start();
+        return "宸叉彁浜ゆ墽琛�";
+    }
+
+    @GetMapping("/show")
+    public String showLog() {
+        StringBuilder logContent = new StringBuilder();
+        try (BufferedReader reader = new BufferedReader(new FileReader(LOG_PATH))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                logContent.append(line).append("<br>");
+            }
+            return logContent.toString();
+        } catch (IOException e) {
+            log.error("Error reading log file", e);
+            return e.getMessage();
+        }
+    }
+
+    @GetMapping("/clear")
+    public String cleanLog() {
+        try {
+            // 灏嗘枃浠跺唴瀹硅缃负绌�
+            FileWriter fileWriter = new FileWriter(LOG_PATH);
+            fileWriter.write("");
+            fileWriter.close();
+            return "Log content cleared successfully.";
+        } catch (IOException e) {
+            e.printStackTrace();
+            return "Failed to clear log content.";
+        }
     }
 }

--
Gitblit v1.8.0