package com.microservices.system.api;

import com.microservices.common.core.constant.SecurityConstants;
import com.microservices.common.core.constant.ServiceNameConstants;
import com.microservices.common.core.domain.R;
import com.microservices.system.api.domain.SysLogininfor;
import com.microservices.system.api.domain.SysOperLog;
import com.microservices.system.api.factory.RemoteLogFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日志服务
 *
 * @author microservices
 */
@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
public interface RemoteLogService
{
    /**
     * 保存系统日志
     *
     * @param sysOperLog 日志实体
     * @param source 请求来源
     * @return 结果
     */
    @PostMapping("/operlog")
    public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 保存访问记录
     *
     * @param sysLogininfor 访问实体
     * @param source 请求来源
     * @return 结果
     */
    @PostMapping("/logininfor")
    public R<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 获取操作日志列表
     *
     * @param title 日志标题
     * @param operUrl 操作地址
     * @param status 操作状态
     * @param topN 获取最新N条
     * @return 操作日志列表
     */
    @GetMapping("/operlog/latest")
    R<List<SysOperLog>> getLatestOperLogList(@RequestParam(value = "title", required = false) String title,
                                             @RequestParam(value = "operUrl", required = false) String operUrl,
                                             @RequestParam(value = "status", required = false) Integer status,
                                             @RequestParam(value = "topN") Integer topN,
                                             @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
