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.InitialSwitchFanInfo;
import com.ruoyi.rocketmq.service.IInitialSwitchFanInfoService;
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("/switchFanInfo")
public class InitialSwitchFanInfoController extends BaseController
{
    @Autowired
    private IInitialSwitchFanInfoService initialSwitchFanInfoService;

    /**
     * 查询风扇信息列表
     */
    @RequiresPermissions("rocketmq:info:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchFanInfo initialSwitchFanInfo)
    {
        startPage();
        List<InitialSwitchFanInfo> list = initialSwitchFanInfoService.selectInitialSwitchFanInfoList(initialSwitchFanInfo);
        return getDataTable(list);
    }

    /**
     * 导出风扇信息列表
     */
    @RequiresPermissions("rocketmq:info:export")
    @Log(title = "风扇信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchFanInfo initialSwitchFanInfo)
    {
        List<InitialSwitchFanInfo> list = initialSwitchFanInfoService.selectInitialSwitchFanInfoList(initialSwitchFanInfo);
        ExcelUtil<InitialSwitchFanInfo> util = new ExcelUtil<InitialSwitchFanInfo>(InitialSwitchFanInfo.class);
        util.exportExcel(response, list, "风扇信息数据");
    }

    /**
     * 获取风扇信息详细信息
     */
    @RequiresPermissions("rocketmq:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchFanInfoService.selectInitialSwitchFanInfoById(id));
    }

    /**
     * 新增风扇信息
     */
    @RequiresPermissions("rocketmq:info:add")
    @Log(title = "风扇信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchFanInfo initialSwitchFanInfo)
    {
        return toAjax(initialSwitchFanInfoService.insertInitialSwitchFanInfo(initialSwitchFanInfo));
    }

    /**
     * 修改风扇信息
     */
    @RequiresPermissions("rocketmq:info:edit")
    @Log(title = "风扇信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchFanInfo initialSwitchFanInfo)
    {
        return toAjax(initialSwitchFanInfoService.updateInitialSwitchFanInfo(initialSwitchFanInfo));
    }

    /**
     * 删除风扇信息
     */
    @RequiresPermissions("rocketmq:info:remove")
    @Log(title = "风扇信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchFanInfoService.deleteInitialSwitchFanInfoByIds(ids));
    }

    /**
     * 获取指定交换机的风扇名称
     * @param initialSwitchFanInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getAllFanName")
    public AjaxResult getAllFanName(@RequestBody InitialSwitchFanInfo initialSwitchFanInfo){
        List<Map> list = initialSwitchFanInfoService.getAllFanName(initialSwitchFanInfo);
        return success(list);
    }
    /**
     * 获取风扇基础信息
     * @param initialSwitchFanInfo
     * @return
     */
    @RequiresPermissions("rocketmq:info:list")
    @PostMapping("/getFanMsg")
    public AjaxResult getFanMsg(@RequestBody InitialSwitchFanInfo initialSwitchFanInfo){
        List<InitialSwitchFanInfo> list = initialSwitchFanInfoService.getFanMsg(initialSwitchFanInfo);
        return success(list);
    }
}
