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);
|
}
|
}
|