package com.ruoyi.web.controller.monitor;

import com.easy.mongodb.core.biz.PageInfo;
import com.easy.mongodb.core.toolkit.Wraps;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysLogininfor;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.service.ISysLogininforService;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * ProjectName: RuoYi-Vue-MongoDB
 * Description: 系统访问记录
 * Author: 86631561@163.coom
 * Date: 2022/7/20 17:03:46
 * UpdateUser: 86631561@163.coom
 * UpdateDate: 2022/7/20 17:03:46
 * UpdateRemark: The modified content
 * Version: 1.0
 * <p>
 * Copyright © 2022 86631561@163.coom Technologies Inc. All Rights Reserved
 **/
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController {
    @Autowired
    private ISysLogininforService logininforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLogininfor logininfor, Integer pageNum, Integer pageSize) {
        startPage();
//        List<SysLogininfor> list = this.logininforService.selectLogininforList(logininfor);
        PageInfo<SysLogininfor> pageInfo = this.logininforService.page(Wraps.lbQ(logininfor), pageNum, pageSize);
        return getDataTable(pageInfo);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLogininfor logininfor) {
        List<SysLogininfor> list = this.logininforService.selectLogininforList(logininfor);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        util.exportExcel(response, list, "登录日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable String[] infoIds) {
        return toAjax(this.logininforService.deleteLogininforByIds(infoIds));
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean() {
        this.logininforService.cleanLogininfor();
        return AjaxResult.success();
    }
}
