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.core.page.TableDataInfo;
import com.citygis.common.enums.BusinessType;
import com.citygis.common.utils.poi.ExcelUtil;
import com.citygis.web.domain.TabAccess;
import com.citygis.web.service.ITabAccessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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-03
 */
@Api(tags = "接入方管理")
@RestController
@RequestMapping("/web/tab-access")
public class TabAccessController extends BaseController {

    @Resource
    ITabAccessService tabAccessService;

    @Log(title = "接入方管理", businessType = BusinessType.SELECT)
    @ApiOperation("接入方管理列表")
    @GetMapping("getTabAccessList")
    public TableDataInfo getTabAccessList(TabAccess tabAccess) {
        startPage();
        return getDataTable(tabAccessService.getTabAccessList(tabAccess));
    }

    @Log(title = "接入方管理", businessType = BusinessType.SELECT)
    @ApiOperation("接入方管理详情")
    @GetMapping("getTabAccessById/{id}")
    public AjaxResult getTabAccessById(@PathVariable Long id) {
        return tabAccessService.getTabAccessById(id);
    }

    @Log(title = "接入方管理", businessType = BusinessType.INSERT)
    @ApiOperation("添加接入方管理")
    @PostMapping("insertTabAccess")
    public AjaxResult insertTabAccess(@Validated @RequestBody TabAccess tabAccess) {
        return tabAccessService.insertTabAccess(tabAccess);
    }


    @Log(title = "接入方管理", businessType = BusinessType.UPDATE)
    @ApiOperation("修改接入方管理")
    @PutMapping("updateTabAccessById")
    public AjaxResult updateTabAccessById(@RequestBody TabAccess tabAccess) {
        return tabAccessService.updateTabAccessById(tabAccess);
    }

    @Log(title = "接入方管理", businessType = BusinessType.DELETE)
    @ApiOperation("逻辑删除接入方管理")
    @PutMapping("falseDeleteTabAccessById")
    public AjaxResult falseDeleteTabAccessById(@RequestBody TabAccess tabAccess) {
        return tabAccessService.falseDeleteTabAccessById(tabAccess);
    }

    @Log(title = "接入方管理", businessType = BusinessType.EXPORT)
    @ApiOperation("导出接入方管理")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, @ModelAttribute TabAccess tabAccess) throws IOException {
        List<TabAccess> list = tabAccessService.getTabAccessList(tabAccess);
        ExcelUtil<TabAccess> util = new ExcelUtil<TabAccess>(TabAccess.class);
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("接入方数据.xlsx", "UTF-8"));
        util.exportExcel(response, list, "接入方数据", "接入方数据信息");
    }


    @Log(title = "接入方管理", businessType = BusinessType.IMPORT)
    @ApiOperation("导入接入方管理")
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws Exception {
        ExcelUtil<TabAccess> util = new ExcelUtil<TabAccess>(TabAccess.class);
        List<TabAccess> tabAccessList = util.importExcel(file.getInputStream(),1);
        return tabAccessService.importData(tabAccessList);
    }


}

