fix: 添加判断条件处理svalue,rvalue异常问题

This commit is contained in:
wht
2025-05-20 11:25:37 +08:00
parent 62682dcb5b
commit 8e44840c88

View File

@ -1,4 +1,5 @@
package com.centricsoftware.enhancement.controller.c8; package com.centricsoftware.enhancement.controller.c8;
import com.centricsoftware.enhancement.modules.c8.dto.ExpResultEntity; import com.centricsoftware.enhancement.modules.c8.dto.ExpResultEntity;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
@ -321,7 +322,8 @@ public class C8TestController {
public ResEntity searchByUrl(@RequestParam Map<String, ?> map) { public ResEntity searchByUrl(@RequestParam Map<String, ?> map) {
String url = (String) map.get("url"); String url = (String) map.get("url");
JSONObject jsonObject = nodeInfoByUrl(url); JSONObject jsonObject = nodeInfoByUrl(url);
return WebResponse.success(ResCode.SUCCESS, jsonObject); String nodeStr = JsonUtil.toJSONString(jsonObject);
return WebResponse.success(ResCode.SUCCESS, JsonUtil.parseObject(nodeStr, Object.class));
} }
public JSONObject nodeInfoByUrl(String url) { public JSONObject nodeInfoByUrl(String url) {
@ -537,37 +539,66 @@ public class C8TestController {
String modifiedTimeStart = (String) map.get("modifiedTimeStart"); String modifiedTimeStart = (String) map.get("modifiedTimeStart");
String modifiedTimeEnd = (String) map.get("modifiedTimeEnd"); String modifiedTimeEnd = (String) map.get("modifiedTimeEnd");
// 如果是10位时间戳补为13位时间戳
if (modifiedTimeStart != null && modifiedTimeStart.length() == 10) {
modifiedTimeStart = modifiedTimeStart + "000";
}
if (modifiedTimeEnd != null && modifiedTimeEnd.length() == 10) {
modifiedTimeEnd = modifiedTimeEnd + "000";
}
int page = Convert.toInt(map.get("page"), 1); int page = Convert.toInt(map.get("page"), 1);
int pageSize = Convert.toInt(map.get("pageSize"), 10); int pageSize = Convert.toInt(map.get("pageSize"), 10);
String sequence = Convert.toStr(map.get("sequence"), "DESC"); String sequence = Convert.toStr(map.get("sequence"), "DESC");
String nodeName = (String) map.get("nodeName"); String nodeName = (String) map.get("nodeName");
String parent = (String) map.get("parent"); String parent = (String) map.get("parent");
String URL = (String) map.get("URL");
String sValue = (String) map.get("sValue"); String sValue = (String) map.get("sValue");
String rValue = (String) map.get("rValue"); String rValue = (String) map.get("rValue");
String value = (String) map.get("value");
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
Map<String, Object> sValueMap = mapper.readValue(sValue, new TypeReference<Map<String, Object>>() {}); if (sValue != null) {
Map<String, Object> sValueMap = mapper.readValue(sValue, new TypeReference<Map<String, Object>>() {
for (Map.Entry<String, Object> entry : sValueMap.entrySet()) { });
xmlBuilder.append(String.format( for (Map.Entry<String, Object> entry : sValueMap.entrySet()) {
"<Attribute Id=\"%s\" Op=\"EQ\" SValue=\"%s\"/>", xmlBuilder.append(String.format(
entry.getKey(), "<Attribute Id=\"%s\" Op=\"EQ\" SValue=\"%s\"/>",
entry.getValue() entry.getKey(),
)); entry.getValue()
));
}
} }
Map<String, Object> rValueMap = mapper.readValue(rValue, new TypeReference<Map<String, Object>>() {}); if (rValue != null) {
for (Map.Entry<String, Object> entry : rValueMap.entrySet()) { Map<String, Object> rValueMap = mapper.readValue(rValue, new TypeReference<Map<String, Object>>() {
xmlBuilder.append(String.format( });
"<Attribute Id=\"%s\" Op=\"EQ\" RValue=\"%s\"/>", for (Map.Entry<String, Object> entry : rValueMap.entrySet()) {
entry.getKey(), xmlBuilder.append(String.format(
entry.getValue() "<Attribute Id=\"%s\" Op=\"EQ\" RValue=\"%s\"/>",
)); entry.getKey(),
entry.getValue()
));
}
} }
if (value != null) {
Map<String, Object> valueMap = mapper.readValue(value, new TypeReference<Map<String, Object>>() {
});
for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
xmlBuilder.append(String.format(
"<Attribute Id=\"%s\" Op=\"EQ\" Value=\"%s\"/>",
entry.getKey(),
entry.getValue()
));
}
}
} catch (Exception e) { } catch (Exception e) {
log.error("Error parsing JSON: {}", e.getMessage()); log.error("Error parsing JSON: {}", e.getMessage());
} }
@ -579,13 +610,13 @@ public class C8TestController {
if (!StrUtil.isBlank(modifiedTimeStart)) { if (!StrUtil.isBlank(modifiedTimeStart)) {
xmlBuilder.append(String.format( xmlBuilder.append(String.format(
"<Attribute Id=\"ModifiedAt\" Op=\"GE\" SValue=\"%s\"/>", "<Node Parameter=\"PublishedTime\" Op=\"GE\" Value=\"%s\"/>",
modifiedTimeStart modifiedTimeStart
)); ));
} }
if (!StrUtil.isBlank(modifiedTimeEnd)) { if (!StrUtil.isBlank(modifiedTimeEnd)) {
xmlBuilder.append(String.format( xmlBuilder.append(String.format(
"<Attribute Id=\"ModifiedAt\" Op=\"LE\" SValue=\"%s\"/>", "<Node Parameter=\"PublishedTime\" Op=\"LE\" Value=\"%s\"/>",
modifiedTimeEnd modifiedTimeEnd
)); ));
} }
@ -604,7 +635,13 @@ public class C8TestController {
)); ));
} }
System.out.println("xmlBuilder: " + xmlBuilder.toString()); if (!StrUtil.isBlank(URL)) {
xmlBuilder.append(String.format(
"<Node Parameter=\"URL\" Op=\"EQ\" Value=\"%s\"/>",
URL
));
}
log.info("xmlBuilder: {}", xmlBuilder);
DepPath depPath = DepPath.builderXml() DepPath depPath = DepPath.builderXml()
.xml(xmlBuilder.toString()) .xml(xmlBuilder.toString())