优化交换机数据入库,修改bug,增加手动计算95值接口
This commit is contained in:
@@ -77,4 +77,8 @@ public class RmDeploymentPolicy extends BaseEntity
|
||||
/** 脚本类型 */
|
||||
@Excel(name = "脚本类型")
|
||||
private String scriptType;
|
||||
/** 资源组名称 */
|
||||
private String resourceGroupName;
|
||||
/** 资源组置空 */
|
||||
private Boolean resourceGroupIdNull;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.ruoyi.rocketmq.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class RspVo {
|
||||
/**
|
||||
* 状态码,0、失败;1、成功
|
||||
@@ -21,5 +25,5 @@ public class RspVo {
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long timestamp;
|
||||
private Long timestamp = Instant.now().getEpochSecond();
|
||||
}
|
||||
|
||||
+12
-1
@@ -13,6 +13,7 @@ import com.ruoyi.rocketmq.mapper.RmDeploymentPolicyMapper;
|
||||
import com.ruoyi.rocketmq.model.ProducerMode;
|
||||
import com.ruoyi.rocketmq.producer.MessageProducer;
|
||||
import com.ruoyi.rocketmq.service.IRmDeploymentPolicyService;
|
||||
import com.ruoyi.rocketmq.utils.DataProcessUtil;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import com.ruoyi.system.api.domain.RmResourceRegistrationRemote;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -38,6 +39,8 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
@Autowired
|
||||
private DataProcessUtil dataProcessUtil;
|
||||
@Autowired
|
||||
private ProducerMode producerMode;
|
||||
|
||||
/**
|
||||
@@ -99,6 +102,10 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
policy.setIncludedDevicesName(names);
|
||||
if(policy.getResourceGroupId() != null){
|
||||
String resourceGroupName = dataProcessUtil.getResourceGroupNameById(policy.getResourceGroupId());
|
||||
policy.setResourceGroupName(resourceGroupName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,6 +131,11 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
public int updateRmDeploymentPolicy(RmDeploymentPolicy rmDeploymentPolicy)
|
||||
{
|
||||
rmDeploymentPolicy.setUpdateTime(DateUtils.getNowDate());
|
||||
// 有修改就改为待下发状态
|
||||
rmDeploymentPolicy.setPolicyStatus("0");
|
||||
if(rmDeploymentPolicy.getResourceGroupId() == null){
|
||||
rmDeploymentPolicy.setResourceGroupIdNull(Boolean.TRUE);
|
||||
}
|
||||
return rmDeploymentPolicyMapper.updateRmDeploymentPolicy(rmDeploymentPolicy);
|
||||
}
|
||||
|
||||
@@ -165,7 +177,6 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
||||
policy.setIncludedDevicesName("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
String[] ids = policy.getIncludedDevicesId().split(",");
|
||||
R<List<RmResourceRegistrationRemote>> resourceNameList =
|
||||
remoteRevenueConfigService.getRegistrationByIds(ids, SecurityConstants.INNER);
|
||||
|
||||
+2
-2
@@ -119,10 +119,10 @@ public class RmResourceRemoteServiceImpl implements IRmResourceRemoteService
|
||||
JSONObject jsonObject = JSONObject.parseObject(resourceRemote.getDescription());
|
||||
String command = jsonObject.getString("command");
|
||||
String resOut = jsonObject.getString("resOut");
|
||||
String sucOrFail = (!"".equals(resOut) && !"脚本执行失败".equals(resOut)) ? "\n执行成功\n":"\n执行失败\n";
|
||||
String sucOrFail = (!"".equals(resOut) && !"脚本执行失败".equals(resOut)) ? "\n执行成功,\n":"\n执行失败,\n";
|
||||
StringBuilder resultSb = new StringBuilder();
|
||||
resultSb.append("【").append(resourceRemote.getResourceName()).append("】脚本执行命令:\n")
|
||||
.append(command).append(sucOrFail).append(",执行结果如下:\n").append(resOut);
|
||||
.append(command).append(sucOrFail).append("执行结果如下:\n").append(resOut);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
Date createTime = resourceRemote.getCreateTime();
|
||||
String createTimeStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime);
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.ruoyi.rocketmq.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SwitchJsonDataParser {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 通用JSON解析方法(兼容对象和数组)
|
||||
* @param jsonStr JSON字符串
|
||||
* @param valueType 目标实体类类型
|
||||
* @return 实体类List集合
|
||||
*/
|
||||
public static <T> List<T> parseJsonData(String jsonStr, Class<T> valueType) {
|
||||
if (!StringUtils.hasText(jsonStr)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
try {
|
||||
JsonNode rootNode = objectMapper.readTree(jsonStr);
|
||||
|
||||
if (rootNode.isArray()) {
|
||||
// 处理数组格式JSON
|
||||
if (isStringArrayContainingJsonObjects((ArrayNode) rootNode)) {
|
||||
// 处理包含JSON对象字符串的数组 - 转换为真正的对象数组
|
||||
ArrayNode processedArray = processStringJsonArrayToObjectArray((ArrayNode) rootNode);
|
||||
return convertJsonArrayToList(processedArray, valueType);
|
||||
} else {
|
||||
// 处理普通JSON数组
|
||||
processJsonArray((ArrayNode) rootNode);
|
||||
return convertJsonArrayToList((ArrayNode) rootNode, valueType);
|
||||
}
|
||||
} else {
|
||||
// 处理单个对象格式JSON
|
||||
if (rootNode.isObject()) {
|
||||
processJsonObject((ObjectNode) rootNode);
|
||||
}
|
||||
List<T> result = new ArrayList<>(1);
|
||||
result.add(objectMapper.treeToValue(rootNode, valueType));
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON解析失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将JsonArray转换为List<T>
|
||||
*/
|
||||
private static <T> List<T> convertJsonArrayToList(ArrayNode arrayNode, Class<T> valueType) throws Exception {
|
||||
List<T> result = new ArrayList<>();
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
result.add(objectMapper.treeToValue(element, valueType));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是包含JSON对象字符串的字符串数组
|
||||
*/
|
||||
private static boolean isStringArrayContainingJsonObjects(ArrayNode arrayNode) {
|
||||
if (arrayNode.size() == 0) return false;
|
||||
|
||||
JsonNode firstElement = arrayNode.get(0);
|
||||
if (firstElement.isTextual()) {
|
||||
try {
|
||||
String strValue = firstElement.textValue();
|
||||
// 检查是否是JSON对象格式的字符串
|
||||
if (strValue.startsWith("{") && strValue.endsWith("}")) {
|
||||
objectMapper.readTree(strValue);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理包含JSON对象字符串的字符串数组,转换为真正的对象数组
|
||||
*/
|
||||
private static ArrayNode processStringJsonArrayToObjectArray(ArrayNode arrayNode) {
|
||||
ArrayNode resultArray = objectMapper.createArrayNode();
|
||||
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
if (element.isTextual()) {
|
||||
try {
|
||||
String jsonString = element.textValue();
|
||||
JsonNode jsonNode = objectMapper.readTree(jsonString);
|
||||
|
||||
if (jsonNode.isObject()) {
|
||||
// 处理JSON对象中的 noSuchInstance
|
||||
processJsonObject((ObjectNode) jsonNode);
|
||||
resultArray.add(jsonNode);
|
||||
} else {
|
||||
resultArray.add(element);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,保持原样
|
||||
resultArray.add(element);
|
||||
}
|
||||
} else {
|
||||
resultArray.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理JSON数组
|
||||
*/
|
||||
private static void processJsonArray(ArrayNode arrayNode) {
|
||||
for (int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode element = arrayNode.get(i);
|
||||
if (element.isObject()) {
|
||||
processJsonObject((ObjectNode) element);
|
||||
} else if (element.isArray()) {
|
||||
processJsonArray((ArrayNode) element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理JSON对象
|
||||
*/
|
||||
private static void processJsonObject(ObjectNode objectNode) {
|
||||
objectNode.fields().forEachRemaining(entry -> {
|
||||
JsonNode value = entry.getValue();
|
||||
if (value.isTextual() && "noSuchInstance".equals(value.textValue())) {
|
||||
objectNode.putNull(entry.getKey());
|
||||
} else if (value.isObject()) {
|
||||
processJsonObject((ObjectNode) value);
|
||||
} else if (value.isArray()) {
|
||||
processJsonArray((ArrayNode) value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user