package com.fastbee.data.controller.gis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.ggroup.enums.SiteTypeCategoryEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.ggroup.domain.GLegend;
import com.fastbee.ggroup.service.IGLegendService;
import com.fastbee.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 图例Controller
 *
 * @author kerwincui
 * &#064;date  2024-10-08
 */
@RestController
@RequestMapping("/gis/legend")
@Api(tags = "图例")
//@PreAuthorize("@ss.hasPermi('ggroup:legend')")
public class GLegendController extends BaseController
{

    private final IGLegendService gLegendService;

    public GLegendController(IGLegendService gLegendService) {
        this.gLegendService = gLegendService;
    }

    /**
     * 查询/搜索图例列表
     */
    @GetMapping("/list")
    @ApiOperation("查询图例列表")
    public TableDataInfo list(GLegend gLegend)
    {
        startPage();
        List<GLegend> list = gLegendService.selectGLegendList(gLegend);
        return getDataTable(list);
    }

    /**
     * 导出图例列表
     */
    @ApiOperation("导出图例列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GLegend gLegend)
    {
        List<GLegend> list = gLegendService.selectGLegendList(gLegend);
        ExcelUtil<GLegend> util = new ExcelUtil<>(GLegend.class);
        util.exportExcel(response, list, "图例数据");
    }

    /**
     * 获取图例详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取图例详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gLegendService.selectGLegendById(id));
    }

    /**
     * 新增图例
     */
    @PostMapping
    @ApiOperation("新增图例")
    public AjaxResult add(@RequestBody GLegend gLegend)
    {
        return toAjax(gLegendService.insertGLegend(gLegend));
    }

    /**
     * 修改图例
     */
    @PutMapping
    @ApiOperation("修改图例")
    public AjaxResult edit(@RequestBody GLegend gLegend)
    {
        return toAjax(gLegendService.updateGLegend(gLegend));
    }

    /**
     * 删除图例
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除图例")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(gLegendService.deleteGLegendById(id));
    }

    /**
     * 获取图例按照类别划分列表
     */
    @GetMapping("/category-list")
    @ApiOperation("获取图例按照类别划分列表")
    public AjaxResult listByCategory(){
        return success(gLegendService.getLegendListByCategory());
    }

    /**
     * 获取图例的类别列表
     */
    @GetMapping(value = "/category/list")
    @ApiOperation("获取图例的类别列表")
    public AjaxResult typeList()
    {
        List<Map<String, Object>> labelList = new ArrayList<>();
        for (SiteTypeCategoryEnum categoryEnum : SiteTypeCategoryEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", categoryEnum.getName());
            labelList.add(map);
        }
        return AjaxResult.success(labelList);
    }

}
