package org.xyzh.system.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xyzh.api.system.dto.TbSysLogDTO;
import org.xyzh.api.system.service.LogService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.core.page.PageRequest;

/**
 * @description    系统日志控制器
 * @filename    LogController.java
 * @author    yslg
 * @copyright yslg
 * @since 2026-01-01
 */
@RestController
@RequestMapping("/system/log")
public class LogController {

    private static final Logger logger = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private LogService logService;

    // ================= 系统日志相关接口 =================

    /**
     * 添加系统日志
     */
    @PostMapping
    @PreAuthorize("hasAuthority('log:log:add')")
    public ResultDomain<TbSysLogDTO> addSysLog(@RequestBody TbSysLogDTO sysLog) {
        return logService.addSysLog(sysLog);
    }

    /**
     * 统计日志数量
     */
    @PostMapping("/count")
    @PreAuthorize("hasAuthority('log:log:view')")
    public ResultDomain<Integer> countSysLog(@RequestBody TbSysLogDTO filter) {
        return logService.countSysLog(filter);
    }

    /**
     * 获取日志列表
     */
    @PostMapping("/list")
    @PreAuthorize("hasAuthority('log:log:view')")
    public ResultDomain<TbSysLogDTO> getSysLogList(@RequestBody TbSysLogDTO filter) {
        return logService.getSysLogList(filter);
    }

    /**
     * 分页查询日志
     */
    @PostMapping("/page")
    @PreAuthorize("hasAuthority('log:log:view')")
    public ResultDomain<TbSysLogDTO> getSysLogPage(@RequestBody PageRequest<TbSysLogDTO> pageRequest) {
        return logService.getSysLogPage(pageRequest);
    }
}
