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.InitialSwitchPowerSupply;
import com.ruoyi.rocketmq.service.IInitialSwitchPowerSupplyService;
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("/switchPowerSupply")
public class InitialSwitchPowerSupplyController extends BaseController
{
    @Autowired
    private IInitialSwitchPowerSupplyService initialSwitchPowerSupplyService;

    /**
     * 查询电源信息列表
     */
    @RequiresPermissions("rocketmq:supply:list")
    @GetMapping("/list")
    public TableDataInfo list(InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        startPage();
        List<InitialSwitchPowerSupply> list = initialSwitchPowerSupplyService.selectInitialSwitchPowerSupplyList(initialSwitchPowerSupply);
        return getDataTable(list);
    }

    /**
     * 导出电源信息列表
     */
    @RequiresPermissions("rocketmq:supply:export")
    @Log(title = "电源信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        List<InitialSwitchPowerSupply> list = initialSwitchPowerSupplyService.selectInitialSwitchPowerSupplyList(initialSwitchPowerSupply);
        ExcelUtil<InitialSwitchPowerSupply> util = new ExcelUtil<InitialSwitchPowerSupply>(InitialSwitchPowerSupply.class);
        util.exportExcel(response, list, "电源信息数据");
    }

    /**
     * 获取电源信息详细信息
     */
    @RequiresPermissions("rocketmq:supply:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(initialSwitchPowerSupplyService.selectInitialSwitchPowerSupplyById(id));
    }

    /**
     * 新增电源信息
     */
    @RequiresPermissions("rocketmq:supply:add")
    @Log(title = "电源信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        return toAjax(initialSwitchPowerSupplyService.insertInitialSwitchPowerSupply(initialSwitchPowerSupply));
    }

    /**
     * 修改电源信息
     */
    @RequiresPermissions("rocketmq:supply:edit")
    @Log(title = "电源信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        return toAjax(initialSwitchPowerSupplyService.updateInitialSwitchPowerSupply(initialSwitchPowerSupply));
    }

    /**
     * 删除电源信息
     */
    @RequiresPermissions("rocketmq:supply:remove")
    @Log(title = "电源信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(initialSwitchPowerSupplyService.deleteInitialSwitchPowerSupplyByIds(ids));
    }
    /**
     * 获取指定交换机所有电源名称
     * @param initialSwitchPowerSupply
     * @return
     */
    @RequiresPermissions("rocketmq:supply:list")
    @PostMapping("/getAllPwrName")
    public AjaxResult getAllPwrName(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply){
        List<Map> list = initialSwitchPowerSupplyService.getAllPwrName(initialSwitchPowerSupply);
        return success(list);
    }
    /**
     * 获取电源基础信息
     * @param initialSwitchPowerSupply
     * @return
     */
    @RequiresPermissions("rocketmq:supply:list")
    @PostMapping("/getPwrMsg")
    public AjaxResult getPwrMsg(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply){
        List<Map> list = initialSwitchPowerSupplyService.getPwrMsg(initialSwitchPowerSupply);
        return success(list);
    }
    /**
     * 获取电源电流
     * @param initialSwitchPowerSupply
     * @return
     */
    @RequiresPermissions("rocketmq:supply:list")
    @PostMapping("/getPwrCurrent")
    public AjaxResult getPwrCurrent(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply){
        Map<String, Object> echartsData = initialSwitchPowerSupplyService.getPwrCurrent(initialSwitchPowerSupply);
        return success(echartsData);
    }
    /**
     * 获取电源电压
     * @param initialSwitchPowerSupply
     * @return
     */
    @RequiresPermissions("rocketmq:supply:list")
    @PostMapping("/getPwrVoltage")
    public AjaxResult getPwrVoltage(@RequestBody InitialSwitchPowerSupply initialSwitchPowerSupply){
        Map<String, Object> echartsData = initialSwitchPowerSupplyService.getPwrVoltage(initialSwitchPowerSupply);
        return success(echartsData);
    }
}
