package com.ruoyi.web.controller.dxp.system.quality;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.dxp.domain.CallLog;
import com.ruoyi.dxp.domain.CallLogParam;
import com.ruoyi.dxp.dto.CalllogAdd;
import com.ruoyi.dxp.service.ICallLogParamService;
import com.ruoyi.dxp.service.ICallLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口监控Controller
 *
 * @author jy
 * @date 2022-11-06
 */
@Api("用户接口调用日志")
@RestController
@RequestMapping("/system/quantity/calllog")
public class CallLogController extends BaseController
{
    @Autowired
    private ICallLogService dxpCallLogService;

    @Autowired
    private ICallLogParamService dxpCallLogParamService;

    /**
     * 查询接口监控列表
     */
    @PreAuthorize("@ss.hasPermi('system/quality:calllog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CallLog callLog)
    {
        startPage();
        List<CallLog> list = dxpCallLogService.selectCallLogList(callLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system/quality:calllog:detail')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") String uuid)
    {
        CallLogParam callLogParam = new CallLogParam();
        callLogParam.setUuid(uuid);
        List<CallLogParam> callLogParams = dxpCallLogParamService.selectCallLogParamList(callLogParam);
        return success(callLogParams);
    }

    /**
     * 新增接口监控
     */
    @ApiOperation("新增用户接口调用日志")
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody CalllogAdd dxpCallLog)
    {
        return dxpCallLogService.insertCallLog(dxpCallLog);
    }
}
