package com.lantone.message.web;

import com.lantone.common.api.CommonResult;
import com.lantone.common.dto.AbnormalLogDTO;
import com.lantone.common.dto.LoginLogDTO;
import com.lantone.common.dto.OperationLogDTO;
import com.lantone.message.component.MessageSender;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Description: 系统相关日志处理API
 * @author: rengb
 * @time: 2021/1/5 18:27
 */
@ApiIgnore
@RestController
@Api(value = "系统相关日志处理API", tags = { "系统相关日志处理API" })
public class SyslogHandleController {

    @Autowired
    private MessageSender messageSender;

    @ApiOperation(value = "用户登录成功后记录日志处理")
    @PostMapping("/loginLogHandle")
    public CommonResult loginLogHandle(@RequestBody LoginLogDTO loginLog) {
        messageSender.sendLogSuccessRecordMessage(loginLog);
        return CommonResult.success(null);
    }

    @ApiOperation(value = "用户操作后记录日志处理")
    @PostMapping("/operationLogHandle")
    public CommonResult operationLogHandle(@RequestBody OperationLogDTO operationLog) {
        messageSender.sendOperLogRecordMessage(operationLog);
        return CommonResult.success(null);
    }

    @ApiOperation(value = "用户操作异常记录日志处理")
    @PostMapping("/abnormalLogHandle")
    public CommonResult abnormalLogHandle(@RequestBody AbnormalLogDTO abnormalLogDTO) {
        messageSender.operErrorLogRecordMessage(abnormalLogDTO);
        return CommonResult.success(null);
    }

}