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 io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import com.xunmei.system.service.IOperLogService;
import com.xunmei.system.domain.OperLog;
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>
 * OperLogController 前端控制器
 * </p>
 *
 * @author gaoxiong
 * @since 2023-08-04
 */
@Api(tags = {"OperLogController"})
@RestController
@RequestMapping("/operLog")
public class OperLogController {

    private Logger log = LoggerFactory.getLogger(getClass());
    @Resource
    private IOperLogService operLogService;


    @ApiOperation(value = "新增操作日志记录")
    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody OperLog operLog){
        try {
            return operLogService.add(operLog);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "删除操作日志记录")
    @RequiresPermissions("system:operLog:delete")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            return operLogService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "更新操作日志记录")
    @RequiresPermissions("system:operLog:update")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody OperLog operLog){
        try {
            return operLogService.updateData(operLog);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "查询操作日志记录分页数据")
    @RequiresPermissions("system:operLog:findByPage")
    @GetMapping("/findByPage")
    public AjaxResult findListByPage(Page<OperLog> page,OperLog operLog){
        try {
            return operLogService.findListByPage(page, operLog);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

    @ApiOperation(value = "id查询操作日志记录")
    @RequiresPermissions("system:operLog:findById")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Long id){
        try {
            return operLogService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return error();
        }
    }

}
