/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.dc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.dc.entity.InterfaceLog;
import com.tofly.dc.entity.dto.PerformanceMonitoringDto;
import com.tofly.dc.entity.vo.InterfaceLogVo;
import com.tofly.dc.entity.vo.SysMonitoringVo;
import com.tofly.dc.mapper.InterfaceLogMapper;
import com.tofly.dc.service.InterfaceLogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

/**
 * 接口访问日志表
 *
 * @author zev
 * @date Wed Jan 05 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/interfacelog")
@Api(tags="接口访问日志表接口")
public class InterfaceLogController {

    private final  InterfaceLogService interfaceLogService;
    private final InterfaceLogMapper interfaceLogMapper;
    /**
    * 分页查询
    * @param page 分页对象
    * @param interfaceLog 接口访问日志表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getInterfaceLogPage(Page page, @ModelAttribute InterfaceLogVo interfaceLog) {
      return ResultRespone.success(interfaceLogMapper.getInterfaceLogVoList(page, interfaceLog));
    }


    /**
     * 通过id查询接口访问日志表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(interfaceLogService.getById(id));
    }

    /**
     * 新增接口访问日志表
     * @param interfaceLog 接口访问日志表
     * @return ResultRespone
     */
    @ApiOperation(value = "新增接口访问日志表")
    @PostMapping
    public ResultRespone save(@RequestBody InterfaceLog interfaceLog) {
      return ResultRespone.success(interfaceLogService.save(interfaceLog));
    }


    @GetMapping("/getPerformanceMonitoring" )
    @ApiOperation(value = "性能监控查询")
    public ResultRespone getPerformanceMonitoring(@ModelAttribute PerformanceMonitoringDto dto) {
        String filter = dto.getFilter();
        ResultRespone respone = new ResultRespone();
        if("1".equals(filter)){
            respone.setResult(interfaceLogService.getSysMonitoringVo(dto));
        }else if("2".equals(filter)){
            respone.setResult(interfaceLogService.getBusinessMonitoringVo(dto));
        }else {
            respone.setResult(interfaceLogService.getInterfaceMonitoringVo(dto));
        }
        return respone;
    }


}
