package com.ebts.web.controller.monitor;

import com.ebts.common.annotation.Log;
import com.ebts.common.core.controller.BaseController;
import com.ebts.common.core.entity.Result;
import com.ebts.common.enums.BusinessType;
import com.ebts.common.utils.poi.ExcelUtil;
import com.ebts.system.entity.Logininfor;
import com.ebts.system.service.LogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 系统访问记录
 *
 * @author binlin
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class LogininforController extends BaseController {

    @Autowired
    private LogininforService logininforService;

    @PreAuthorize("@ebts.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public Serializable list(Logininfor logininfor) {
        startPage();
        List<Logininfor> list = logininforService.selectLogininforList(logininfor);
        return getDataTable(list);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ebts.hasPermi('monitor:logininfor:export')")
    @GetMapping("/export")
    public Result<Logininfor> export(Logininfor logininfor) {
        List<Logininfor> list = logininforService.selectLogininforList(logininfor);
        ExcelUtil<Logininfor> util = new ExcelUtil<Logininfor>(Logininfor.class);
        return util.exportExcel(list, "登录日志");
    }

    @PreAuthorize("@ebts.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public Result<Integer> remove(@PathVariable Long[] infoIds) {
        return toResult(logininforService.deleteLogininforByIds(infoIds));
    }

    @PreAuthorize("@ebts.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public Result<Object> clean() {
        logininforService.cleanLogininfor();
        return Result.ok();
    }
}
