rocktmqjson串减少转义次数,数据类型与接收数据适配
This commit is contained in:
@@ -11,6 +11,7 @@ import com.ruoyi.rocketmq.domain.vo.CollectDataVo;
|
||||
import com.ruoyi.rocketmq.domain.vo.RspVo;
|
||||
import com.ruoyi.rocketmq.service.*;
|
||||
import com.ruoyi.rocketmq.utils.JsonDataParser;
|
||||
import com.ruoyi.rocketmq.utils.SwitchJsonDataParser;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.EpsInitialTrafficDataRemote;
|
||||
import com.ruoyi.system.api.domain.InitialSwitchInfoDetailsRemote;
|
||||
@@ -87,6 +88,8 @@ public class DeviceMessageHandler {
|
||||
private IInitialSystemOtherCollectDataService iInitialSystemOtherCollectDataService;
|
||||
@Autowired
|
||||
private IRmResourceRemoteService rmResourceRemoteService;
|
||||
@Autowired
|
||||
private IRmAgentManagementService rmAgentManagementService;
|
||||
// 在类中添加
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@@ -105,7 +108,7 @@ public class DeviceMessageHandler {
|
||||
registerHandler(MsgEnum.关闭交换机采集应答.getValue(), this::handleResponseMessage);
|
||||
registerHandler(MsgEnum.告警设置应答.getValue(), this::handleResponseMessage);
|
||||
registerHandler(MsgEnum.执行脚本策略应答.getValue(), this::handleScriptRspMessage);
|
||||
registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleResponseMessage);
|
||||
registerHandler(MsgEnum.Agent版本更新应答.getValue(), this::handleAgentUpdateRspMessage);
|
||||
|
||||
// 其他类型消息可以单独注册处理器
|
||||
registerHandler(MsgEnum.CPU上报.getValue(), this::handleCpuMessage);
|
||||
@@ -119,6 +122,28 @@ public class DeviceMessageHandler {
|
||||
registerHandler(MsgEnum.心跳上报.getValue(), this::handleHeartbeatMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* agent更新响应
|
||||
* @param message
|
||||
*/
|
||||
private void handleAgentUpdateRspMessage(DeviceMessage message) {
|
||||
List<RspVo> rspVoList = JsonDataParser.parseJsonData(message.getData(), RspVo.class);
|
||||
if (!rspVoList.isEmpty()) {
|
||||
RspVo rsp = rspVoList.get(0);
|
||||
if(rsp.getResCode() == 1){
|
||||
RmAgentManagement rmAgentManagement = new RmAgentManagement();
|
||||
rmAgentManagement.setHardwareSn(message.getClientId());
|
||||
rmAgentManagement.setLastUpdateResult("1");
|
||||
rmAgentManagementService.updateRmAgentManagementByHardwareSn(rmAgentManagement);
|
||||
}else{
|
||||
RmAgentManagement rmAgentManagement = new RmAgentManagement();
|
||||
rmAgentManagement.setHardwareSn(message.getClientId());
|
||||
rmAgentManagement.setLastUpdateResult("0");
|
||||
rmAgentManagementService.updateRmAgentManagementByHardwareSn(rmAgentManagement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册消息处理器
|
||||
*/
|
||||
@@ -285,10 +310,9 @@ public class DeviceMessageHandler {
|
||||
List<CollectDataVo> switchData = JsonDataParser.parseJsonData(message.getData(), CollectDataVo.class);
|
||||
if(!switchData.isEmpty()){
|
||||
CollectDataVo switchDataVo = switchData.get(0);
|
||||
switchDataVo.setValue(switchDataVo.getValue().replaceAll("\"noSuchInstance\"", "null"));
|
||||
switch(switchDataVo.getType()){
|
||||
case "switchNetCollect":
|
||||
handleSwitchMessage(switchDataVo, message.getClientId());
|
||||
handleSwitchNetMessage(switchDataVo, message.getClientId());
|
||||
break;
|
||||
case "switchPwrCollect":
|
||||
handleSwitchPwrMessage(switchDataVo, message.getClientId());
|
||||
@@ -316,7 +340,7 @@ public class DeviceMessageHandler {
|
||||
* @param switchDataVo
|
||||
*/
|
||||
private void handleSwitchPwrMessage(CollectDataVo switchDataVo, String clientId){
|
||||
List<InitialSwitchPowerSupply> powerSupplyList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchPowerSupply.class);
|
||||
List<InitialSwitchPowerSupply> powerSupplyList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchPowerSupply.class);
|
||||
if (!powerSupplyList.isEmpty()){
|
||||
InitialSwitchPowerSupply insertData = powerSupplyList.get(0);
|
||||
// 时间戳转换
|
||||
@@ -333,7 +357,7 @@ public class DeviceMessageHandler {
|
||||
* @param switchDataVo
|
||||
*/
|
||||
private void handleSwitchModuleMessage(CollectDataVo switchDataVo, String clientId){
|
||||
List<InitialSwitchOpticalModule> moduleList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchOpticalModule.class);
|
||||
List<InitialSwitchOpticalModule> moduleList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchOpticalModule.class);
|
||||
if (!moduleList.isEmpty()){
|
||||
InitialSwitchOpticalModule insertData = moduleList.get(0);
|
||||
// 时间戳转换
|
||||
@@ -351,7 +375,7 @@ public class DeviceMessageHandler {
|
||||
* @param switchDataVo
|
||||
*/
|
||||
private void handleSwitchMpuMessage(CollectDataVo switchDataVo, String clientId){
|
||||
List<InitialSwitchMpuInfo> mpuList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchMpuInfo.class);
|
||||
List<InitialSwitchMpuInfo> mpuList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchMpuInfo.class);
|
||||
if (!mpuList.isEmpty()){
|
||||
InitialSwitchMpuInfo insertData = mpuList.get(0);
|
||||
// 时间戳转换
|
||||
@@ -369,7 +393,7 @@ public class DeviceMessageHandler {
|
||||
* @param switchDataVo
|
||||
*/
|
||||
private void handleSwitchFanMessage(CollectDataVo switchDataVo, String clientId){
|
||||
List<InitialSwitchFanInfo> fanList = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchFanInfo.class);
|
||||
List<InitialSwitchFanInfo> fanList = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchFanInfo.class);
|
||||
if (!fanList.isEmpty()){
|
||||
InitialSwitchFanInfo insertData = fanList.get(0);
|
||||
// 时间戳转换
|
||||
@@ -438,11 +462,11 @@ public class DeviceMessageHandler {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 交换机数据入库
|
||||
* 交换机网卡信息数据入库
|
||||
* @param switchDataVo
|
||||
*/
|
||||
private void handleSwitchMessage(CollectDataVo switchDataVo, String clientId) {
|
||||
List<InitialSwitchInfo> switchInfos = JsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class);
|
||||
private void handleSwitchNetMessage(CollectDataVo switchDataVo, String clientId) {
|
||||
List<InitialSwitchInfo> switchInfos = SwitchJsonDataParser.parseJsonData(switchDataVo.getValue(), InitialSwitchInfo.class);
|
||||
if(!switchInfos.isEmpty()){
|
||||
// 时间戳转换
|
||||
long timestamp = switchDataVo.getTimestamp();
|
||||
|
||||
Reference in New Issue
Block a user