|
@@ -0,0 +1,57 @@
|
|
|
|
+package com.persagy.dmp.rwd.parser.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
|
+import com.persagy.dmp.rwd.parser.entity.EnumVO;
|
|
|
|
+import com.persagy.dmp.rwd.parser.entity.ParserResult;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 多选枚举信息点 处理器
|
|
|
|
+ * @author Charlie Yu
|
|
|
|
+ * @date 2021-08-11
|
|
|
|
+ */
|
|
|
|
+public class MEnumInfoParser extends AbstractInfoDataParser {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void validateDefine(ParserResult result) throws IOException {
|
|
|
|
+ // 字符串类型不支持区间格式
|
|
|
|
+ if(result.isRegion()) {
|
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]定义有误,MENUM类型不允许定义区间!", result.getInfoDefine().getCode()));
|
|
|
|
+ }
|
|
|
|
+ // 数据源 - 应为枚举列表格式
|
|
|
|
+ formatListValue(result.getInfoDefine().getDataSource(), EnumVO.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected void validateValue(ParserResult result) throws IOException {
|
|
|
|
+ // 数据源定义信息
|
|
|
|
+ List<EnumVO> dataSource = formatListValue(result.getInfoDefine().getDataSource(), EnumVO.class);
|
|
|
|
+ Set<String> codeSet = new HashSet<>();
|
|
|
|
+ for(EnumVO enumVO:dataSource) {
|
|
|
|
+ codeSet.add(enumVO.getCode());
|
|
|
|
+ }
|
|
|
|
+ // 复数
|
|
|
|
+ if(result.isMulti()) {
|
|
|
|
+ List<ArrayNode> enumList = formatListValue(result.getValueInfo(), ArrayNode.class);
|
|
|
|
+ for(int i = 0,j = CollUtil.size(enumList);i < j;i++) {
|
|
|
|
+ List<String> valueList = formatListValue(enumList.get(i), String.class);
|
|
|
|
+ if (!CollUtil.containsAll(codeSet, valueList)) {
|
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 单数
|
|
|
|
+ List<String> valueList = formatListValue(result.getValueInfo(), String.class);
|
|
|
|
+ if (!CollUtil.containsAll(codeSet, valueList)) {
|
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|