package com.enterprise.manage.modules.system.controller;

import com.enterprise.manage.common.base.BaseController;
import com.enterprise.manage.common.constant.ControllerConstant;
import com.enterprise.manage.common.web.request.PageDomain;
import com.enterprise.manage.common.web.response.Result;
import com.enterprise.manage.common.web.response.module.ResultTable;
import com.enterprise.manage.modules.system.domain.po.Log;
import com.enterprise.manage.modules.system.service.ILogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * system log Controller
 *
 * @author PeiZhi Guo
 * 2021-04-25 11:01
 */
@RestController
@RequestMapping(ControllerConstant.SYSTEM + "log/v1")
public class LogController extends BaseController {

    private ILogService logService;

    @Autowired
    public LogController(ILogService logService) {
        this.logService = logService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','sys:log:main')")
    public ResultTable main(PageDomain page, Log log, String beginTime, String endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put("beginTime", beginTime);
        params.put("endTime", endTime);
        log.setParams(params);
        PageInfo<Log> logPage = logService.page(page, log);
        return pageTable(logPage.getList(), logPage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','sys:menu:main')")
    public Result get(@PathVariable Long id) {
        return success(logService.queryById(id));
    }

}
