package com.xinda.data.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.iot.domain.Bridge;
import com.xinda.iot.service.IBridgeService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 数据桥接Controller
 *
 * @author zhuangpeng.li
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/iot/bridge")
@Api(tags = "数据桥接管理")
public class BridgeController extends BaseController
{
    @Autowired
    private IBridgeService bridgeService;

    /**
     * 查询数据桥接列表
     */
    @ApiOperation("查询数据桥接列表")
    @PreAuthorize("@ss.hasPermi('iot:bridge:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bridge bridge)
    {
        startPage();
        List<Bridge> list = bridgeService.selectBridgeList(bridge);
        return getDataTable(list);
    }

    /**
     * 导出数据桥接列表
     */
    @ApiOperation("导出数据桥接列表")
    @PreAuthorize("@ss.hasPermi('iot:bridge:export')")
    @Log(title = "数据桥接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bridge bridge)
    {
        List<Bridge> list = bridgeService.selectBridgeList(bridge);
        ExcelUtil<Bridge> util = new ExcelUtil<Bridge>(Bridge.class);
        util.exportExcel(response, list, "数据桥接数据");
    }

    /**
     * 获取数据桥接详细信息
     */
    @ApiOperation("获取数据桥接详细信息")
    @PreAuthorize("@ss.hasPermi('iot:bridge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bridgeService.selectBridgeById(id));
    }

    /**
     * 新增数据桥接
     */
    @ApiOperation("新增数据桥接")
    @PreAuthorize("@ss.hasPermi('iot:bridge:add')")
    @Log(title = "数据桥接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bridge bridge)
    {
        return toAjax(bridgeService.insertBridge(bridge));
    }

    /**
     * 修改数据桥接
     */
    @ApiOperation("修改数据桥接")
    @PreAuthorize("@ss.hasPermi('iot:bridge:edit')")
    @Log(title = "数据桥接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bridge bridge)
    {
        return toAjax(bridgeService.updateBridge(bridge));
    }

    @ApiOperation("连接数据桥接")
    @PreAuthorize("@ss.hasPermi('iot:bridge:edit')")
    @Log(title = "数据桥接", businessType = BusinessType.UPDATE)
    @PostMapping("/connect")
    public AjaxResult connect(@RequestBody Bridge bridge)
    {
        return toAjax(bridgeService.connect(bridge));
    }

    /**
     * 删除数据桥接
     */
    @ApiOperation("删除数据桥接")
    @PreAuthorize("@ss.hasPermi('iot:bridge:remove')")
    @Log(title = "数据桥接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bridgeService.deleteBridgeByIds(ids));
    }
}
