From 792ec31c45fbb4935821d55ab38765febbbb82c8 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期一, 07 十月 2024 16:52:31 +0800
Subject: [PATCH] 新增日志定时清除任务

---
 src/main/java/com/zy/asrs/task/handler/LogClearHandler.java |   53 ++++++++++++++++++++++++++
 src/main/webapp/views/apiLog/apiLog.html                    |    5 ++
 src/main/java/com/zy/asrs/task/LogClearScheduler.java       |   48 ++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/asrs/task/LogClearScheduler.java b/src/main/java/com/zy/asrs/task/LogClearScheduler.java
new file mode 100644
index 0000000..9b46e4a
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/LogClearScheduler.java
@@ -0,0 +1,48 @@
+package com.zy.asrs.task;
+
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.zy.asrs.entity.ApiLog;
+import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.ApiLogService;
+import com.zy.asrs.task.core.ReturnT;
+import com.zy.asrs.task.handler.LogClearHandler;
+import com.zy.system.entity.OperateLog;
+import com.zy.system.service.OperateLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class LogClearScheduler {
+
+    @Autowired
+    private ApiLogService apiLogService;
+    @Autowired
+    private OperateLogService operateLogService;
+    @Autowired
+    private LogClearHandler logClearHandler;
+//    姣忓ぉ0鐐瑰紑濮�
+//    @Scheduled(cron = "0/1 * * * * ? ")
+    @Scheduled(cron = "* * 0 * * ? ")
+    private void apiLogExecute(){
+        LocalDateTime oneMonthAgo = LocalDateTime.now().minus(1, ChronoUnit.MONTHS);
+        List<ApiLog> apiLogs = apiLogService.selectList(new EntityWrapper<ApiLog>().lt("create_time", oneMonthAgo));
+        for(ApiLog apiLog : apiLogs){
+            ReturnT<String> returnT = logClearHandler.startClearApiLog(apiLog);
+        }
+    }
+
+    @Scheduled(cron = "* * 0 * * ? ")
+    private void sysOperateLogExecute(){
+        LocalDateTime oneMonthAgo = LocalDateTime.now().minus(2, ChronoUnit.MONTHS);
+        List<OperateLog> operateLogs = operateLogService.selectList(new EntityWrapper<OperateLog>().lt("create_time", oneMonthAgo));
+        for(OperateLog operateLog : operateLogs){
+            ReturnT<String> returnT = logClearHandler.startClearOperateLog(operateLog);
+        }
+    }
+}
diff --git a/src/main/java/com/zy/asrs/task/handler/LogClearHandler.java b/src/main/java/com/zy/asrs/task/handler/LogClearHandler.java
new file mode 100644
index 0000000..7102806
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/handler/LogClearHandler.java
@@ -0,0 +1,53 @@
+package com.zy.asrs.task.handler;
+
+import com.zy.asrs.entity.AgvWrkMast;
+import com.zy.asrs.entity.ApiLog;
+import com.zy.asrs.entity.WrkMastExecute;
+import com.zy.asrs.service.ApiLogService;
+import com.zy.asrs.task.AbstractHandler;
+import com.zy.asrs.task.core.ReturnT;
+import com.zy.system.entity.OperateLog;
+import com.zy.system.service.OperateLogService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+
+@Slf4j
+@Service
+@Transactional
+public class LogClearHandler extends AbstractHandler<String> {
+
+    @Autowired
+    private ApiLogService apiLogService;
+    @Autowired
+    private OperateLogService operateLogService;
+
+    public ReturnT<String> startClearApiLog(ApiLog apiLog) {//1-4
+        try{
+            if (apiLogService.deleteById(apiLog)) {
+                return SUCCESS;
+            } else {
+                return FAIL;
+            }
+        }catch (Exception e){
+            log.error("apiLog娓呴櫎===銆嬪紓甯革細"+e.getMessage());
+        }
+        return SUCCESS;
+    }
+
+    public ReturnT<String> startClearOperateLog(OperateLog operateLog) {//1-4
+        try{
+            if (operateLogService.deleteById(operateLog)) {
+                return SUCCESS;
+            } else {
+                return FAIL;
+            }
+        }catch (Exception e){
+            log.error("apiLog娓呴櫎===銆嬪紓甯革細"+e.getMessage());
+        }
+        return SUCCESS;
+    }
+}
diff --git a/src/main/webapp/views/apiLog/apiLog.html b/src/main/webapp/views/apiLog/apiLog.html
index 800a016..84ddf3c 100644
--- a/src/main/webapp/views/apiLog/apiLog.html
+++ b/src/main/webapp/views/apiLog/apiLog.html
@@ -29,6 +29,11 @@
                     </div>
                     <div class="layui-inline">
                         <div class="layui-input-inline">
+                            <input class="layui-input" type="text" name="request" placeholder="璇锋眰鍐呭" autocomplete="off">
+                        </div>
+                    </div>
+                    <div class="layui-inline">
+                        <div class="layui-input-inline">
                             <input class="layui-input" type="text" name="condition" placeholder="璇疯緭鍏�" autocomplete="off">
                         </div>
                     </div>

--
Gitblit v1.9.1