package com.simuwang.manage.api.system;

import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.pojo.dto.sys.LogQuery;
import com.simuwang.base.pojo.vo.sys.SysLogVO;
import com.simuwang.logging.SystemLog;
import com.simuwang.manage.service.system.SysLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志管理接口
 */
@SystemLog(value = "日志管理")
@RestController
@RequestMapping("/v1/sys/log")
public class SysLogController {
    private final SysLogService service;

    public SysLogController(SysLogService service) {
        this.service = service;
    }

    /**
     * 分页接口
     *
     * @param query 日志分页参数
     * @return /
     */
    @GetMapping("page")
    public MybatisPage<SysLogVO> page(LogQuery query) {
        return this.service.findPage(query);
    }

    /**
     * 清空日志，要有权限才能清空
     *
     * @return /
     */
    @SystemLog(value = "清空日志", type = SystemLog.Type.DELETE)
    @RequiresPermissions("SYS:LOG:TRUNCATE")
    @DeleteMapping
    public boolean truncate() {
        return this.service.truncate();
    }
}
