Browse Source

增加MENUM和PIC两种数据类型信息点校验处理

yucheng 3 years ago
parent
commit
e12af51739

+ 2 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/parser/service/InfoDataFactory.java

@@ -47,6 +47,8 @@ public class InfoDataFactory {
             parserMap.put(DigitalDataType.ENUM.getIndex(), new EnumInfoParser());
             parserMap.put(DigitalDataType.INTEGER.getIndex(), new IntegerInfoParser());
             parserMap.put(DigitalDataType.STRING.getIndex(), new StringInfoParser());
+            parserMap.put(DigitalDataType.PIC.getIndex(), new PicInfoParser());
+            parserMap.put(DigitalDataType.MENUM.getIndex(), new MEnumInfoParser());
         }
         // 校验类型传值
         if(!parserMap.containsKey(dataType)) {

+ 1 - 1
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/parser/service/impl/EnumInfoParser.java

@@ -24,7 +24,7 @@ public class EnumInfoParser extends AbstractInfoDataParser {
         if(result.isRegion()) {
             throw new BusinessException(StrUtil.format("信息点[{}]定义有误,ENUM类型不允许定义区间!", result.getInfoDefine().getCode()));
         }
-        // 数据源 - 应为区间列表格式
+        // 数据源 - 应为枚举列表格式
         formatListValue(result.getInfoDefine().getDataSource(), EnumVO.class);
     }
 

+ 57 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/parser/service/impl/MEnumInfoParser.java

@@ -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()));
+            }
+        }
+    }
+}

+ 36 - 0
dmp-business/dmp-rwd/src/main/java/com/persagy/dmp/rwd/parser/service/impl/PicInfoParser.java

@@ -0,0 +1,36 @@
+package com.persagy.dmp.rwd.parser.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.common.exception.BusinessException;
+import com.persagy.dmp.rwd.parser.entity.ParserResult;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * 图片信息点 处理器
+ * @author Charlie Yu
+ * @date 2021-07-12
+ */
+public class PicInfoParser extends AbstractInfoDataParser {
+
+    @Override
+    protected void validateDefine(ParserResult result) throws IOException {
+        // 不支持区间格式
+        if(result.isRegion()) {
+            throw new BusinessException(StrUtil.format("信息点[{}]定义有误,Pic类型不允许定义区间!", result.getInfoDefine().getCode()));
+        }
+    }
+
+    @Override
+    protected void validateValue(ParserResult result) throws IOException {
+        // 复数
+        if(result.isMulti()) {
+            List<ObjectNode> valueList = formatListValue(result.getValueInfo(), ObjectNode.class);
+        } else {
+            // 单数
+            ObjectNode value = formatValue(result.getValueInfo(), ObjectNode.class);
+        }
+    }
+}