package com.ruoyi.rocketmq.controller;

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.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rocketmq.domain.InitialSwitchOpticalModule;
import com.ruoyi.rocketmq.service.IInitialSwitchOpticalModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 光模块信息Controller
 * 
 * @author gyt
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/switchOpticalModule")
public class InitialSwitchOpticalModuleController extends BaseController
{
    @Autowired
    private IInitialSwitchOpticalModuleService initialSwitchOpticalModuleService;

    /**
     * 查询光模块信息列表
     */
    @RequiresPermissions("rocketmq:module:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchOpticalModule initialSwitchOpticalModule)
    {
        startPage();
        List<InitialSwitchOpticalModule> list = initialSwitchOpticalModuleService.selectInitialSwitchOpticalModuleList(initialSwitchOpticalModule);
        return getDataTable(list);
    }

    /**
     * 导出光模块信息列表
     */
    @RequiresPermissions("rocketmq:module:export")
    @Log(title = "光模块信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchOpticalModule initialSwitchOpticalModule)
    {
        List<InitialSwitchOpticalModule> list = initialSwitchOpticalModuleService.selectInitialSwitchOpticalModuleList(initialSwitchOpticalModule);
        ExcelUtil<InitialSwitchOpticalModule> util = new ExcelUtil<InitialSwitchOpticalModule>(InitialSwitchOpticalModule.class);
        util.exportExcel(response, list, "光模块信息数据");
    }

    /**
     * 获取光模块信息详细信息
     */
    @RequiresPermissions("rocketmq:module:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchOpticalModuleService.selectInitialSwitchOpticalModuleById(id));
    }

    /**
     * 新增光模块信息
     */
    @RequiresPermissions("rocketmq:module:add")
    @Log(title = "光模块信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule)
    {
        return toAjax(initialSwitchOpticalModuleService.insertInitialSwitchOpticalModule(initialSwitchOpticalModule));
    }

    /**
     * 修改光模块信息
     */
    @RequiresPermissions("rocketmq:module:edit")
    @Log(title = "光模块信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule)
    {
        return toAjax(initialSwitchOpticalModuleService.updateInitialSwitchOpticalModule(initialSwitchOpticalModule));
    }

    /**
     * 删除光模块信息
     */
    @RequiresPermissions("rocketmq:module:remove")
    @Log(title = "光模块信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchOpticalModuleService.deleteInitialSwitchOpticalModuleByIds(ids));
    }

    /**
     * 获取该交换机的所有光模块名称
     * @return
     */
    @RequiresPermissions("rocketmq:module:list")
    @PostMapping("/getAllModuleName")
    public AjaxResult getAllModuleName(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule){
        List<Map> list = initialSwitchOpticalModuleService.getAllModuleName(initialSwitchOpticalModule);
        return success(list);
    }
    /**
     * 获取光模块基础信息
     * @param initialSwitchOpticalModule
     * @return
     */
    @RequiresPermissions("rocketmq:module:list")
    @PostMapping("/switchOpticalModuleMsg")
    public AjaxResult switchOpticalModuleMsg(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule){

        List<InitialSwitchOpticalModule> list = initialSwitchOpticalModuleService.switchOpticalModuleMsg(initialSwitchOpticalModule);
        return success(list);
    }
    /**
     * 获取光模块的光衰阈值
     * @param initialSwitchOpticalModule
     * @return
     */
    @RequiresPermissions("rocketmq:module:list")
    @PostMapping("/opticalModuleLowThreshold")
    public AjaxResult opticalModuleLowThreshold(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule){
        Map<String, Object> echartsData = initialSwitchOpticalModuleService.opticalModuleLowThreshold(initialSwitchOpticalModule);
        return success(echartsData);
    }
    /**
     * 获取光模块的功率
     * @param initialSwitchOpticalModule
     * @return
     */
    @RequiresPermissions("rocketmq:module:list")
    @PostMapping("/opticalModulePower")
    public AjaxResult opticalModulePower(@RequestBody InitialSwitchOpticalModule initialSwitchOpticalModule){
        Map<String, Object> echartsData = initialSwitchOpticalModuleService.opticalModulePower(initialSwitchOpticalModule);
        return success(echartsData);
    }
}
