自动化立体仓库 - WMS系统
whycq
2024-10-07 792ec31c45fbb4935821d55ab38765febbbb82c8
新增日志定时清除任务
2个文件已添加
1个文件已修改
106 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/task/LogClearScheduler.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/handler/LogClearHandler.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/apiLog/apiLog.html 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/task/LogClearScheduler.java
New file
@@ -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);
        }
    }
}
src/main/java/com/zy/asrs/task/handler/LogClearHandler.java
New file
@@ -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;
    }
}
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>