package com.xunmei.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunmei.common.core.web.domain.AjaxResult;
import com.xunmei.common.security.annotation.InnerAuth;
import com.xunmei.system.api.domain.SysLogininfor;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import com.xunmei.system.service.ILogininforService;
import com.xunmei.system.domain.Logininfor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.xunmei.common.core.web.domain.AjaxResult.success;
import static com.xunmei.common.core.web.domain.AjaxResult.error;
import javax.annotation.Resource;
import com.xunmei.common.security.annotation.RequiresPermissions;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * LogininforController 前端控制器
 * </p>
 *
 * @author gaoxiong
 * @since 2023-08-04
 */
@Api(tags = {"LogininforController"})
@RestController
@RequestMapping("/logininfor")
public class LogininforController {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private ILogininforService logininforService;


    @ApiOperation(value = "新增系统访问记录")
    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody Logininfor logininfor){
        try {
            logininforService.add(logininfor);
            return success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "删除系统访问记录")
    @RequiresPermissions("system:logininfor:delete")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            return logininforService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "更新系统访问记录")
    @RequiresPermissions("system:logininfor:update")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Logininfor logininfor){
        try {
            return logininforService.updateData(logininfor);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "查询系统访问记录分页数据")
    @RequiresPermissions("system:logininfor:findByPage")
    @GetMapping("/findByPage")
    public AjaxResult findListByPage(Page<Logininfor> page,Logininfor logininfor){
        try {
            return logininforService.findListByPage(page, logininfor);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "id查询系统访问记录")
    @RequiresPermissions("system:logininfor:findById")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Long id){
        try {
            return logininforService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }


}
