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.TabSystemSpace;
import com.citygis.web.service.ITabSystemSpaceService;
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-system-space")
public class TabSystemSpaceController {

    @Resource
    ITabSystemSpaceService tabSystemSpaceService;

    @RequestMapping("/inserTabSystemSpace")
    public void inserTabSystemSpace() {
        tabSystemSpaceService.insertTabSystemSpace();
    }

    @Log(title = "库存容量监控", businessType = BusinessType.EXPORT)
    @ApiOperation("导出库存容量监控")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, @ModelAttribute TabSystemSpace tabSystemSpace) throws IOException {
        List<TabSystemSpace> list = tabSystemSpaceService.getSpace(tabSystemSpace);
        ExcelUtil<TabSystemSpace> util = new ExcelUtil<TabSystemSpace>(TabSystemSpace.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 TabSystemSpace tabSystemSpace) throws IOException {
        List<TabSystemSpace> list = tabSystemSpaceService.getSpaceDetailByFilepath(tabSystemSpace);
        ExcelUtil<TabSystemSpace> util = new ExcelUtil<TabSystemSpace>(TabSystemSpace.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(TabSystemSpace tabSystemSpace) {
        return tabSystemSpaceService.getLinkTitle(tabSystemSpace);
    }

}

