package com.usky.system.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.system.controller.web.page.TableDataInfo;
import com.usky.system.domain.SysLogininfor;
import com.usky.system.service.ISysLogininforService;
import com.usky.system.service.vo.SysLoginExportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 系统访问记录
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/logininfor")
public class SysLogininforController extends BaseController
{
    @Autowired
    private ISysLogininforService logininforService;

//    @Log(title = "查询登录日志", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public ApiResult<TableDataInfo> list(SysLogininfor logininfor)
    {
        startPage();
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        return ApiResult.success(getDataTable(list));
    }

    @Log(title = "导出登录日志", businessType = BusinessType.EXPORT)
    @PostMapping("/listExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "exportTitle") String exportTitle,
                       SysLogininfor logininfor)throws IOException{
        List<SysLoginExportVO> list = logininforService.selectLogininforListExport(logininfor);
        ExcelUtil<SysLoginExportVO> util = new ExcelUtil<SysLoginExportVO>(SysLoginExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    @DeleteMapping("/{infoIds}")
    public ApiResult<Void> remove(@PathVariable Long[] infoIds)
    {
        return toAjax(logininforService.deleteLogininforByIds(infoIds));
    }

    @Log(title = "清空登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public ApiResult<Void> clean()
    {
        logininforService.cleanLogininfor();
        return ApiResult.success();
    }

    @PostMapping
    public ApiResult<Void> add(@RequestBody SysLogininfor logininfor)
    {
        logininforService.insertLogininfor(logininfor);
        return ApiResult.success();
    }
}
