package com.citygis.web.controller;


import com.citygis.common.annotation.Log;
import com.citygis.common.core.controller.BaseController;
import com.citygis.common.enums.BusinessType;
import com.citygis.common.utils.poi.ExcelUtil;
import com.citygis.web.domain.TabIpResult;
import com.citygis.web.service.ITabIpResultService;
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>
 * ip监测结果表 前端控制器
 * </p>
 *
 * @author citygis
 * @since 2025-01-17
 */
@Api(tags = "心跳监测")
@RestController
@RequestMapping("/web/tab-ip-result")
public class TabIpResultController extends BaseController {

    @Resource
    ITabIpResultService tabIpResultService;

    @RequestMapping("/insertTabIpResult")
    public void insertTabIpResult() {
        tabIpResultService.insertTabIpResult();
    }

    @Log(title = "心跳监测", businessType = BusinessType.EXPORT)
    @ApiOperation("导出心跳监测")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, @ModelAttribute TabIpResult tabIpResult) throws IOException {
        List<TabIpResult> list = tabIpResultService.getTabIpResultList(tabIpResult);
        ExcelUtil<TabIpResult> util = new ExcelUtil<TabIpResult>(TabIpResult.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("心跳监测数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "心跳监测数据","心跳监测数据信息");
    }

    @Log(title = "心跳监测", businessType = BusinessType.EXPORT)
    @ApiOperation("导出心跳监测详情")
    @PostMapping("/exportDetail")
    @ResponseBody
    public void exportDetail(HttpServletResponse response, @ModelAttribute TabIpResult tabIpResult) throws IOException {
        List<TabIpResult> list = tabIpResultService.getTabIpResultDetailByIpAndPort(tabIpResult);
        ExcelUtil<TabIpResult> util = new ExcelUtil<TabIpResult>(TabIpResult.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("心跳监测详情数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "心跳监测详情数据","心跳监测详情数据信息");
    }

}

