package com.inspect.system.controller;

import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.InnerAuth;
import com.inspect.common.security.annotation.RequiresPermissions;
import com.inspect.system.base.domain.SysLoginFor;
import com.inspect.system.service.ISysLoginForService;

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

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

@RestController
@RequestMapping({"/logininfor"})
public class SysLoginForController extends BaseController {
    private final ISysLoginForService loginForService;

    public SysLoginForController(ISysLoginForService loginForService) {
        this.loginForService = loginForService;
    }

    @RequiresPermissions({"system:logininfor:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(SysLoginFor loginFor) {
        this.startPage();
        List<SysLoginFor> list = this.loginForService.selectLoginForList(loginFor);
        return this.getDataTable(list);
    }

    @Log(
            title = "登录日志",
            businessType = BizType.EXPORT
    )
    @RequiresPermissions({"system:logininfor:export"})
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, SysLoginFor loginFor) {
        List<SysLoginFor> list = this.loginForService.selectLoginForList(loginFor);
        ExcelUtil<SysLoginFor> util = new ExcelUtil<>(SysLoginFor.class);
        util.exportExcel(response, list, "登录日志");
    }

    @RequiresPermissions({"system:logininfor:remove"})
    @Log(
            title = "登录日志",
            businessType = BizType.DELETE
    )
    @PostMapping({"/remove/{infoIds}"})
    public AjaxResult remove(@PathVariable Long[] infoIds) {
        return this.toAjax(this.loginForService.deleteLoginForByIds(infoIds));
    }

    @RequiresPermissions({"system:logininfor:remove"})
    @Log(
            title = "登录日志",
            businessType = BizType.DELETE
    )
    @PostMapping({"/clean"})
    public AjaxResult clean() {
        this.loginForService.cleanLoginFor();
        return AjaxResult.success();
    }

    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody SysLoginFor loginFor) {
        return this.toAjax(this.loginForService.insertLoginFor(loginFor));
    }
}
