package com.citygis.web.controller;


import com.citygis.common.annotation.Log;
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.TabDatalog;
import com.citygis.web.service.ITabDatalogService;
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-17
 */
@Api(tags = "作业监控")
@RestController
@RequestMapping("/web/tab-datalog")
public class TabDatalogController {

    @Resource
    ITabDatalogService tabDatalogService;

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

    @Log(title = "作业监控", businessType = BusinessType.EXPORT)
    @ApiOperation("导出作业监控详情")
    @PostMapping("/exportDetaile")
    @ResponseBody
    public void exportDetaile(HttpServletResponse response, @ModelAttribute TabDatalog tabDatalog) throws IOException {
        List<TabDatalog> list = tabDatalogService.getDatalogDetailByTableEnglishName(tabDatalog);
        ExcelUtil<TabDatalog> util = new ExcelUtil<TabDatalog>(TabDatalog.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("作业监控详情数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "作业监控详情数据","作业监控详情数据信息");
    }


    @Log(title = "作业监控", businessType = BusinessType.SELECT)
    @ApiOperation("详情左上角小标题")
    @GetMapping("/getLinkTitle")
    public AjaxResult getLinkTitle(TabDatalog tabDatalog) {
        return tabDatalogService.getLinkTitle(tabDatalog);
    }
}

