package com.tofly.base.controller;

import com.tofly.base.api.entity.SysLog;
import com.tofly.base.service.SysLogService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.log.event.SysLogListener;
import com.tofly.common.oauth.auth.innerCall;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Administrator
 * @date 2019/9/4  16:07
 */
@RestController
@AllArgsConstructor
@Slf4j
public class SysLogController {

    private SysLogService sysLogService;
    private SysLogListener sysLogListener;


    @innerCall
    @PostMapping("/applog")
    public ResultRespone save(@Valid @RequestBody SysLog sysLog){
        log.info("到这来了没..................."+sysLog.toString());
        try {
            sysLogService.save(sysLog);
        }catch(Exception e) {
            log.info("报错。。。。。。。。:"+e.getMessage());
        }
        return ResultRespone.success(true);
    }

    @ToFlyAppLog(title="标题")
    @RequestMapping("/test")
    public ResultRespone test(){
        log.info("sysLogListener",sysLogListener);
        return ResultRespone.success(true);
    }
}
