package com.mosty.common.core.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.base.entity.log.SysOperLog;
import com.mosty.common.config.Excel.ExcelUtil;
import com.mosty.common.core.business.entity.SysLogininfor;
import com.mosty.common.core.business.entity.request.LoginLogPage;
import com.mosty.common.core.business.entity.vo.DeleteListVO;
import com.mosty.common.core.business.service.SysLogininforService;
import com.mosty.common.token.JwtSysUser;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@SuppressWarnings("unused")
@RestController
@AllArgsConstructor
@RequestMapping("/sysLoginLog")
@Api(tags = "登录日志")
public class SysLogininforController {

    private final SysLogininforService sysLogininforService;

    @PostMapping("/list")
    @JwtSysUser
    @Log(title = "查询登录日志列表", businessType = BusinessType.DELETE)
    public ResponseResult<IPage<SysLogininfor>> list(@RequestBody LoginLogPage loginLogPage) {
        IPage<SysLogininfor> sysOperLogPage = sysLogininforService.selectByPage(loginLogPage);
        return ResponseResult.success(sysOperLogPage);
    }

    @Log(title = "登录日志删除", businessType = BusinessType.OTHER)
    @PostMapping("/remove")
    public ResponseResult<Boolean> remove(@RequestBody  DeleteListVO vo) {
        sysLogininforService.deleteOperLogByIds(vo.getIds());
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("/detail/{id}")
    public ResponseResult<SysLogininfor> detail(@PathVariable("id") Long id) {
        SysLogininfor log = sysLogininforService.getOne(new LambdaQueryWrapper<SysLogininfor>()
                .eq(SysLogininfor::getInfoId,id));
        return ResponseResult.success(log);
    }

    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @PostMapping("/clean")
    @ResponseBody
    public ResponseResult<Boolean> clean() {
        sysLogininforService.cleanOperLog();
        return ResponseResult.success(Boolean.TRUE);
    }


//    @Log(title = "导出巡防力量", businessType = BusinessType.EXPORT)
//    @PostMapping("/exportZY")
//    @JwtSysUser
//    public void export(HttpServletResponse response) {
//        List<SysLogininfor> list = sysLogininforService.export();
//        ExcelUtil<SysLogininfor> util = new ExcelUtil<
//                >(SysLogininfor.class);
//        util.exportExcel(response, list, "登录日志");
//    }


}
