105 lines
4.3 KiB
Java
105 lines
4.3 KiB
Java
package com.ruoyi.rocketmq.utils;
|
|||
|
|
|
||
|
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||
|
|
import com.ruoyi.common.core.domain.R;
|
||
|
|
import com.ruoyi.rocketmq.domain.RmTemplateLinux;
|
||
|
|
import com.ruoyi.rocketmq.domain.RmTemplateSwitch;
|
||
|
|
import com.ruoyi.rocketmq.mapper.RmMonitorTemplateMapper;
|
||
|
|
import com.ruoyi.rocketmq.mapper.RmTemplateLinuxMapper;
|
||
|
|
import com.ruoyi.rocketmq.mapper.RmTemplateSwitchMapper;
|
||
|
|
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||
|
|
import com.ruoyi.system.api.domain.RmResourceGroupRemote;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
|
||
|
|
import java.lang.reflect.Field;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
import java.util.stream.Collectors;
|
||
|
|
@Slf4j
|
||
|
|
public class DataProcessUtil {
|
||
|
|
@Autowired
|
||
|
|
private RmMonitorTemplateMapper rmMonitorTemplateMapper;
|
||
|
|
@Autowired
|
||
|
|
private static RmTemplateLinuxMapper rmTemplateLinuxMapper;
|
||
|
|
@Autowired
|
||
|
|
private static RmTemplateSwitchMapper rmTemplateSwitchMapper;
|
||
|
|
@Autowired
|
||
|
|
private static RemoteRevenueConfigService remoteRevenueConfigService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 补充资源组信息
|
||
|
|
*/
|
||
|
|
public static String getResourceGroupNameById(Long resourceGroupId) {
|
||
|
|
try {
|
||
|
|
R<RmResourceGroupRemote> resourceGroupResponse = remoteRevenueConfigService
|
||
|
|
.getResourceGroupMsgById(resourceGroupId, SecurityConstants.INNER);
|
||
|
|
|
||
|
|
if (resourceGroupResponse != null && resourceGroupResponse.getData() != null) {
|
||
|
|
return resourceGroupResponse.getData().getGroupName();
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
log.error("获取资源组信息失败,resourceGroupId: {}", resourceGroupId, e);
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 处理Linux模板数据
|
||
|
|
*/
|
||
|
|
public static void processLinuxTemplateData(Long templateId, Map<String, Object> result) {
|
||
|
|
RmTemplateLinux query = new RmTemplateLinux();
|
||
|
|
query.setTemplateId(templateId);
|
||
|
|
List<RmTemplateLinux> linuxItems = rmTemplateLinuxMapper.selectRmTemplateLinuxList(query);
|
||
|
|
|
||
|
|
if (!linuxItems.isEmpty()) {
|
||
|
|
Map<String, List<RmTemplateLinux>> linuxData = new HashMap<>();
|
||
|
|
linuxData.put("cpu", filterItemsByDataType(linuxItems, "CPU"));
|
||
|
|
linuxData.put("other", filterItemsByDataType(linuxItems, "OTHER"));
|
||
|
|
linuxData.put("point", filterItemsByDataType(linuxItems, "POINT"));
|
||
|
|
linuxData.put("net", filterItemsByDataType(linuxItems, "NET"));
|
||
|
|
linuxData.put("disk", filterItemsByDataType(linuxItems, "DISK"));
|
||
|
|
linuxData.put("docker", filterItemsByDataType(linuxItems, "DOCKER"));
|
||
|
|
|
||
|
|
result.put("linux", linuxData);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 处理Switch模板数据
|
||
|
|
*/
|
||
|
|
public static void processSwitchTemplateData(Long templateId, Map<String, Object> result) {
|
||
|
|
RmTemplateSwitch query = new RmTemplateSwitch();
|
||
|
|
query.setTemplateId(templateId);
|
||
|
|
List<RmTemplateSwitch> switchItems = rmTemplateSwitchMapper.selectRmTemplateSwitchList(query);
|
||
|
|
|
||
|
|
if (!switchItems.isEmpty()) {
|
||
|
|
Map<String, List<RmTemplateSwitch>> switchData = new HashMap<>();
|
||
|
|
switchData.put("system", filterItemsByDataType(switchItems, "SYSTEM"));
|
||
|
|
switchData.put("mpu", filterItemsByDataType(switchItems, "MPU"));
|
||
|
|
switchData.put("power", filterItemsByDataType(switchItems, "POWERSOURCE"));
|
||
|
|
switchData.put("netport", filterItemsByDataType(switchItems, "NETPORT"));
|
||
|
|
switchData.put("lightmodule", filterItemsByDataType(switchItems, "LIGHTMODULE"));
|
||
|
|
switchData.put("fan", filterItemsByDataType(switchItems, "FAN"));
|
||
|
|
|
||
|
|
result.put("switch", switchData);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 通用过滤方法
|
||
|
|
*/
|
||
|
|
public static <T> List<T> filterItemsByDataType(List<T> items, String dataType) {
|
||
|
|
return items.stream()
|
||
|
|
.filter(item -> {
|
||
|
|
try {
|
||
|
|
Field dataTypeField = item.getClass().getDeclaredField("dataType");
|
||
|
|
dataTypeField.setAccessible(true);
|
||
|
|
return dataType.equals(dataTypeField.get(item));
|
||
|
|
} catch (Exception e) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.collect(Collectors.toList());
|
||
|
|
}
|
||
|
|
}
|