package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.RmSwitchManagement;
import com.ruoyi.system.service.IRmSwitchManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 交换机管理Controller
 * 
 * @author gyt
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/switchManagement")
public class RmSwitchManagementController extends BaseController
{
    @Autowired
    private IRmSwitchManagementService rmSwitchManagementService;

    /**
     * 查询交换机管理列表
     */
    @RequiresPermissions("system:switchManagement:list")
    @PostMapping("/list")
    public TableDataInfo list(RmSwitchManagement rmSwitchManagement)
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(rmSwitchManagement.getPageNum());
        pageDomain.setPageSize(rmSwitchManagement.getPageSize());
        startPage(pageDomain);
        List<RmSwitchManagement> list = rmSwitchManagementService.selectRmSwitchManagementList(rmSwitchManagement);
        return getDataTable(list);
    }

    /**
     * 导出交换机管理列表
     */
    @RequiresPermissions("system:switchManagement:export")
    @Log(title = "交换机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RmSwitchManagement rmSwitchManagement)
    {
        List<RmSwitchManagement> list = rmSwitchManagementService.selectRmSwitchManagementList(rmSwitchManagement);
        ExcelUtil<RmSwitchManagement> util = new ExcelUtil<RmSwitchManagement>(RmSwitchManagement.class);
        util.showColumn(rmSwitchManagement.getProperties());
        util.exportExcel(response, list, "交换机管理数据");
    }

    /**
     * 获取交换机管理详细信息
     */
    @RequiresPermissions("system:switchManagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rmSwitchManagementService.selectRmSwitchManagementById(id));
    }

    /**
     * 新增交换机管理
     */
    @RequiresPermissions("system:switchManagement:add")
    @Log(title = "交换机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RmSwitchManagement rmSwitchManagement)
    {
        return toAjax(rmSwitchManagementService.insertRmSwitchManagement(rmSwitchManagement));
    }

    /**
     * 修改交换机管理
     */
    @RequiresPermissions("system:switchManagement:edit")
    @Log(title = "交换机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RmSwitchManagement rmSwitchManagement)
    {
        return toAjax(rmSwitchManagementService.updateRmSwitchManagement(rmSwitchManagement));
    }

    /**
     * 删除交换机管理
     */
    @RequiresPermissions("system:switchManagement:remove")
    @Log(title = "交换机管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rmSwitchManagementService.deleteRmSwitchManagementByIds(ids));
    }
    /**
     * 查询交换机管理列表
     */
    @RequiresPermissions("system:switchManagement:list")
    @PostMapping("/getAllSwitchName")
    public AjaxResult getAllSwitchName(@RequestBody RmSwitchManagement rmSwitchManagement)
    {
        List<RmSwitchManagement> list = rmSwitchManagementService.selectRmSwitchManagementList(rmSwitchManagement);
        return success(list);
    }
    /**
     * 查询交换机管理列表
     */
    @InnerAuth
    @PostMapping("/getSwitchNameByClientId")
    public R<List<RmSwitchManagement>> getSwitchNameByClientId(@RequestBody RmSwitchManagement rmSwitchManagement)
    {
        List<RmSwitchManagement> list = rmSwitchManagementService.selectRmSwitchManagementList(rmSwitchManagement);
        return R.ok(list);
    }
    /**
     * 查询交换机信息树形接口
     */
    @RequiresPermissions("system:switchManagement:list")
    @GetMapping("/getAllSwitchNameTree")
    public AjaxResult getAllSwitchNameTree()
    {
        List<RmSwitchManagement> list = rmSwitchManagementService.getAllSwitchNameTree();
        return success(list);
    }
    /**
     * 修改交换机管理
     */
    @PostMapping("/updateSwitchMsgByClientId")
    @InnerAuth
    public R<Integer> updateSwitchMsgByClientId(@RequestBody RmSwitchManagement rmSwitchManagement)
    {
        return R.ok(rmSwitchManagementService.updateRmSwitchManagement(rmSwitchManagement));
    }
}
