package com.ruoyi.rocketmq.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.EchartsDataUtils;
import com.ruoyi.rocketmq.domain.InitialSwitchPowerSupply;
import com.ruoyi.rocketmq.mapper.InitialSwitchPowerSupplyMapper;
import com.ruoyi.rocketmq.service.IInitialSwitchPowerSupplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * 电源信息Service业务层处理
 * 
 * @author gyt
 * @date 2025-09-22
 */
@Service
public class InitialSwitchPowerSupplyServiceImpl implements IInitialSwitchPowerSupplyService 
{
    @Autowired
    private InitialSwitchPowerSupplyMapper initialSwitchPowerSupplyMapper;

    /**
     * 查询电源信息
     * 
     * @param id 电源信息主键
     * @return 电源信息
     */
    @Override
    public InitialSwitchPowerSupply selectInitialSwitchPowerSupplyById(Long id)
    {
        return initialSwitchPowerSupplyMapper.selectInitialSwitchPowerSupplyById(id);
    }

    /**
     * 查询电源信息列表
     * 
     * @param initialSwitchPowerSupply 电源信息
     * @return 电源信息
     */
    @Override
    public List<InitialSwitchPowerSupply> selectInitialSwitchPowerSupplyList(InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        return initialSwitchPowerSupplyMapper.selectInitialSwitchPowerSupplyList(initialSwitchPowerSupply);
    }

    /**
     * 新增电源信息
     * 
     * @param initialSwitchPowerSupply 电源信息
     * @return 结果
     */
    @Override
    public int insertInitialSwitchPowerSupply(InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        return initialSwitchPowerSupplyMapper.insertInitialSwitchPowerSupply(initialSwitchPowerSupply);
    }

    /**
     * 修改电源信息
     * 
     * @param initialSwitchPowerSupply 电源信息
     * @return 结果
     */
    @Override
    public int updateInitialSwitchPowerSupply(InitialSwitchPowerSupply initialSwitchPowerSupply)
    {
        initialSwitchPowerSupply.setUpdateTime(DateUtils.getNowDate());
        return initialSwitchPowerSupplyMapper.updateInitialSwitchPowerSupply(initialSwitchPowerSupply);
    }

    /**
     * 批量删除电源信息
     * 
     * @param ids 需要删除的电源信息主键
     * @return 结果
     */
    @Override
    public int deleteInitialSwitchPowerSupplyByIds(Long[] ids)
    {
        return initialSwitchPowerSupplyMapper.deleteInitialSwitchPowerSupplyByIds(ids);
    }

    /**
     * 删除电源信息信息
     * 
     * @param id 电源信息主键
     * @return 结果
     */
    @Override
    public int deleteInitialSwitchPowerSupplyById(Long id)
    {
        return initialSwitchPowerSupplyMapper.deleteInitialSwitchPowerSupplyById(id);
    }
    /**
     * 批量新增电源信息
     * @param list
     * @return
     */
    @Override
    public int insertBatchInitialSwitchPowerSupply(List<InitialSwitchPowerSupply> list){
        return initialSwitchPowerSupplyMapper.insertBatchInitialSwitchPowerSupply(list);
    }

    /**
     * 获取指定交换机的电源名称
     * @param initialSwitchPowerSupply
     * @return
     */
    @Override
    public List<Map> getAllPwrName(InitialSwitchPowerSupply initialSwitchPowerSupply) {
        return initialSwitchPowerSupplyMapper.getAllPwrName(initialSwitchPowerSupply);
    }

    /**
     * 获取电源基础信息
     * @param initialSwitchPowerSupply
     * @return
     */
    @Override
    public List<Map> getPwrMsg(InitialSwitchPowerSupply initialSwitchPowerSupply) {
        return initialSwitchPowerSupplyMapper.getPwrMsg(initialSwitchPowerSupply);
    }

    /**
     * 获取电源电流
     * @param initialSwitchPowerSupply
     * @return
     */
    @Override
    public Map<String, Object> getPwrCurrent(InitialSwitchPowerSupply initialSwitchPowerSupply) {
        List<InitialSwitchPowerSupply> list = initialSwitchPowerSupplyMapper.selectInitialSwitchPowerSupplyList(initialSwitchPowerSupply);
        Map<String, Function<InitialSwitchPowerSupply, ?>> extractors = new LinkedHashMap<>();
        extractors.put("pwrCurrent", info -> info.getPwrEntityPwrCurrent());
        return EchartsDataUtils.buildEchartsData(list, InitialSwitchPowerSupply::getCreateTime, extractors);
    }

    /**
     * 获取电源电压
     * @param initialSwitchPowerSupply
     * @return
     */
    @Override
    public Map<String, Object> getPwrVoltage(InitialSwitchPowerSupply initialSwitchPowerSupply) {
        List<InitialSwitchPowerSupply> list = initialSwitchPowerSupplyMapper.selectInitialSwitchPowerSupplyList(initialSwitchPowerSupply);
        Map<String, Function<InitialSwitchPowerSupply, ?>> extractors = new LinkedHashMap<>();
        extractors.put("pwrVoltage", info -> info.getPwrEntityPwrVoltage());
        return EchartsDataUtils.buildEchartsData(list, InitialSwitchPowerSupply::getCreateTime, extractors);
    }
}
