package com.nantian.sc.cloud.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.sc.cloud.admin.api.entity.OperationLog;
import com.nantian.sc.cloud.admin.service.OperationLogService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 操作日志
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/operationLog")
@Api(value = "operationLog", tags = "操作日志")
public class OperationLogController {
    private final OperationLogService operationLogService;

    @PostMapping("/save")
    public R save(@RequestBody OperationLog operationLog) {
        ScUser u= SecurityUtils.getUser();
        operationLog.setUserId(u.getId().toString());
        operationLog.setUserName(u.getUsername());
        operationLog.setUserRealName(u.getUserRealName());
        operationLog.setDeptId(u.getDeptId());
        return R.ok(operationLogService.save(operationLog));
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页获取操作日志", notes = "分页获取操作日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页对象", required = false, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "OperationLog", value = "操作日志对象", required = false, dataType = "json", paramType = "path")
    })
    public R getOperationLogPage(Page page, OperationLog operationLog) {
        //根据用户归属、区域，查询操作日志
        return R.ok(operationLogService.getPageScope(page,operationLog));
    }

}
