package com.fastbee.data.controller.gis;

import java.util.List;

import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.ggroup.domain.dto.GGroupSiteDto;
import com.fastbee.ggroup.domain.dto.GGroupSiteRelateDto;
import com.fastbee.ggroup.domain.dto.GSitesEditDto;
import com.fastbee.ggroup.domain.dto.GSitesSelectDto;
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.GSites;
import com.fastbee.ggroup.service.IGSitesService;
import com.fastbee.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 站点Controller
 *
 * @author kerwincui
 * &#064;date  2024-09-29
 */
@RestController
@RequestMapping("/gis/sites")
@Api(tags = "站点")
//@PreAuthorize("@ss.hasPermi('ggroup:groups')")
public class GSitesController extends BaseController
{

    private final IGSitesService gSitesService;

    public GSitesController(IGSitesService gSitesService) {
        this.gSitesService = gSitesService;
    }


    /**
     * 查询/搜索站点列表
     */
    @GetMapping("/list")
    @ApiOperation("查询站点列表")
    public TableDataInfo list(GSitesSelectDto gSites)
    {
        startPage();
        List<GSites> list = gSitesService.selectGSitesList(gSites);
        return getDataTable(list);
    }

    /**
     * 站点关联组
     */
    @PostMapping("/relate")
    @ApiOperation("站点关联组")
    public AjaxResult relate(@RequestBody GGroupSiteRelateDto gGroupSiteRelateDto){
        return toAjax(gSitesService.relateGroup(gGroupSiteRelateDto));
    }

    /**
     * 导出站点列表
     */
    @ApiOperation("导出站点列表")
//    @PreAuthorize("@ss.hasPermi('ggroup:sites:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GSitesSelectDto gSites)
    {
        List<GSites> list = gSitesService.selectGSitesList(gSites);
        ExcelUtil<GSites> util = new ExcelUtil<>(GSites.class);
        util.exportExcel(response, list, "站点数据");
    }

    /**
     * 获取站点详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取站点详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gSitesService.selectGSitesById(id));
    }

    /**
     * 新增站点
     */
    @PostMapping
    @ApiOperation("新增站点")
    public AjaxResult add(@RequestBody GGroupSiteDto gGroupSiteDto)
    {
        return toAjax(gSitesService.insertGSites(gGroupSiteDto));
    }

    /**
     * 修改站点
     */
    @PutMapping
    @ApiOperation("修改站点")
    public AjaxResult edit(@RequestBody GSitesEditDto gSitesEditDto)
    {
        return toAjax(gSitesService.updateGSites(gSitesEditDto));
    }

    /**
     * 根据id删除站点
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除站点")
    public AjaxResult remove(@PathVariable Long id){
        return toAjax(gSitesService.deleteGSitesById(id));
    }


    /**
     * 批量删除站点
     */
    @DeleteMapping("/batch/{ids}")
    @ApiOperation("删除站点")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gSitesService.deleteGSitesByIds(ids));
    }

    /**
     * 搜索站点
     */
    @GetMapping("/search")
    @ApiOperation("搜索站点")
    public TableDataInfo search(GSites gSites){
        startPage();
        List<GSites> list = gSitesService.searchGSitesList(gSites);
        return getDataTable(list);

    }

    /**
     * 查询站点已设备关联列表
     */
    @GetMapping("/device-linked")
    @ApiOperation("已关联设备")
    public AjaxResult deviceLinked(){

        return AjaxResult.success();
    }

}
