|
@@ -1,10 +1,15 @@
|
|
package com.persagy.dmp.rwd.parser.service.impl;
|
|
package com.persagy.dmp.rwd.parser.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.BooleanUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
+import com.fasterxml.jackson.databind.node.JsonNodeType;
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
import com.persagy.dmp.rwd.parser.entity.ParserResult;
|
|
import com.persagy.dmp.rwd.parser.entity.ParserResult;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 布尔信息点 处理器
|
|
* 布尔信息点 处理器
|
|
@@ -13,6 +18,9 @@ import java.io.IOException;
|
|
*/
|
|
*/
|
|
public class BooleanInfoParser extends AbstractInfoDataParser {
|
|
public class BooleanInfoParser extends AbstractInfoDataParser {
|
|
|
|
|
|
|
|
+ /** 表示为真的字符串 */
|
|
|
|
+ private static final Set<String> FALSE_SET = CollUtil.newHashSet("false", "no", "0", "off", "否", "错", "假", "錯", "×");
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void validateDefine(ParserResult result) {
|
|
protected void validateDefine(ParserResult result) {
|
|
// 不支持区间格式
|
|
// 不支持区间格式
|
|
@@ -31,4 +39,21 @@ public class BooleanInfoParser extends AbstractInfoDataParser {
|
|
formatValue(result.getValueInfo(), Boolean.class);
|
|
formatValue(result.getValueInfo(), Boolean.class);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取数据
|
|
|
|
+ * @param value
|
|
|
|
+ * @param clazz
|
|
|
|
+ * @param <T>
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ protected <T> T formatValue(JsonNode value, Class<T> clazz) throws IOException {
|
|
|
|
+ if(value == null || JsonNodeType.NULL == value.getNodeType()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (!(FALSE_SET.contains(value.asText()) || BooleanUtil.toBoolean(value.asText()))){
|
|
|
|
+ throw new IOException(value.asText()+"格式有误");
|
|
|
|
+ }
|
|
|
|
+ return getObjectMapper().readValue(BooleanUtil.toStringTrueFalse(BooleanUtil.toBoolean(value.asText())), clazz);
|
|
|
|
+ }
|
|
}
|
|
}
|