Junjie
8 小时以前 8bfe1168a42d4e3750a15b0c0fb0a7629d6cf91c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.zy.system.controller;
 
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.common.web.BaseController;
import com.zy.system.domain.param.LogCleanupConfigParam;
import com.zy.system.domain.param.LogCleanupRunParam;
import com.zy.system.model.LogCleanupExecutionResult;
import com.zy.system.service.HighPrivilegeGrantService;
import com.zy.system.service.LogCleanupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.LinkedHashMap;
import java.util.Map;
 
@RestController
public class LogCleanupController extends BaseController {
 
    @Autowired
    private LogCleanupService logCleanupService;
    @Autowired
    private HighPrivilegeGrantService highPrivilegeGrantService;
 
    @GetMapping("/logCleanup/config/auth")
    @ManagerAuth
    public R getConfig() {
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("expireDays", logCleanupService.getExpireDays());
        result.put("autoTime", "每日 23:00");
        result.put("tables", logCleanupService.getSupportedTables());
        return R.ok().add(result);
    }
 
    @PostMapping("/logCleanup/config/save/auth")
    @ManagerAuth(memo = "保存日志清理配置")
    public R saveConfig(@RequestBody LogCleanupConfigParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        logCleanupService.saveExpireDays(param.getExpireDays());
        return R.ok();
    }
 
    @PostMapping("/logCleanup/run/auth")
    @ManagerAuth(memo = "手动清理日志")
    public R run(@RequestBody LogCleanupRunParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        highPrivilegeGrantService.assertGranted(request.getHeader("token"), "手动清理日志");
        LogCleanupExecutionResult result;
        if ("selected".equals(param.getMode())) {
            result = logCleanupService.cleanupSelected(logCleanupService.getExpireDays(), param.getTables());
        } else {
            result = logCleanupService.cleanupAll(logCleanupService.getExpireDays());
        }
        return R.ok().add(result);
    }
}