package com.citygis.web.controller;


import com.citygis.common.core.controller.BaseController;
import com.citygis.common.core.domain.AjaxResult;
import com.citygis.common.core.page.TableDataInfo;
import com.citygis.common.utils.poi.ExcelUtil;
import com.citygis.web.domain.TabAccessConfig;
import com.citygis.web.service.ITabAccessConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
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-02
 */
@Api(tags = "接入配置")
@RestController
@RequestMapping("/web/tab-access-config")
public class TabAccessConfigController extends BaseController {

    @Resource
    ITabAccessConfigService tabAccessConfigService;

    @ApiOperation("接入配置列表")
    @GetMapping("getTabAccessConfigList")
    public TableDataInfo getTabAccessConfigList(TabAccessConfig tabAccessConfig) {
        startPage();
        return getDataTable(tabAccessConfigService.getTabAccessConfigList(tabAccessConfig));
    }

    @ApiOperation("接入配置详情")
    @GetMapping("getTabAccessConfigById/{id}")
    public AjaxResult getTabAccessConfigById(@PathVariable String id) {
        return tabAccessConfigService.getTabAccessConfigById(id);
    }

    @ApiOperation("添加接入配置")
    @PostMapping("insertTabAccessConfig")
    public AjaxResult insertTabAccessConfig(@Validated @RequestBody TabAccessConfig tabAccessConfig) {
        return tabAccessConfigService.insertTabAccessConfig(tabAccessConfig);
    }

    @ApiOperation("修改接入配置")
    @PutMapping("updateTabAccessConfigById")
    public AjaxResult updateTabAccessConfigById(@RequestBody TabAccessConfig tabAccessConfig) {
        return tabAccessConfigService.updateTabAccessConfigById(tabAccessConfig);
    }

    @ApiOperation("逻辑删除接入配置")
    @PutMapping("falseDeleteTabAccessConfigById/{id}")
    public AjaxResult falseDeleteTabAccessConfigById(@PathVariable Long id) {
        return tabAccessConfigService.falseDeleteTabAccessConfigById(id);
    }

    @ApiOperation("导出接入配置")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TabAccessConfig tabAccessConfig) throws IOException {
        List<TabAccessConfig> list = tabAccessConfigService.getTabAccessConfigList(tabAccessConfig);
        ExcelUtil<TabAccessConfig> util = new ExcelUtil<TabAccessConfig>(TabAccessConfig.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("接入配置数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "接入配置数据","接入配置数据信息");
    }

}

