package com.citygis.web.controller;


import com.citygis.common.annotation.Log;
import com.citygis.common.core.controller.BaseController;
import com.citygis.common.core.domain.AjaxResult;
import com.citygis.common.enums.BusinessType;
import com.citygis.common.utils.poi.ExcelUtil;
import com.citygis.web.domain.TabLog2;
import com.citygis.web.service.ITabLog2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author citygis
 * @since 2025-01-14
 */
@Api(tags = "Api监控")
@RestController
@RequestMapping("/web/tab-log2")
public class TabLog2Controller extends BaseController {

    @Resource
    ITabLog2Service tlLog2Service;

    @Log(title = "Api监控", businessType = BusinessType.EXPORT)
    @ApiOperation("导出Api监控")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, @ModelAttribute TabLog2 tabLog2) throws IOException {
        List<TabLog2> list = tlLog2Service.getTabLog2List(tabLog2);
        ExcelUtil<TabLog2> util = new ExcelUtil<TabLog2>(TabLog2.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("接口监控数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "接口监控数据", "接口监控数据信息");
    }

    @Log(title = "Api监控", businessType = BusinessType.EXPORT)
    @ApiOperation("导出Api监控详情")
    @PostMapping("/exportDetail")
    @ResponseBody
    public void exportDetail(HttpServletResponse response, @ModelAttribute TabLog2 tabLog2) throws IOException {
        List<TabLog2> list = tlLog2Service.getTabLog2DetailListByUrl(tabLog2);
        ExcelUtil<TabLog2> util = new ExcelUtil<TabLog2>(TabLog2.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("接口监控详情数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "接口监控详情", "接口监控详情信息");
    }

    @Log(title = "Api监控", businessType = BusinessType.SELECT)
    @ApiOperation("详情左上角小标题")
    @GetMapping("/getTabLinkTitle")
    public AjaxResult getTabLinkTitle(TabLog2 tabLog2) {
        return tlLog2Service.getTabLinkTitle(tabLog2);
    }
}

