|
@@ -1,8 +1,8 @@
|
|
|
package com.persagy.dc.parser.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.persagy.dc.common.exception.BusinessException;
|
|
|
import com.persagy.dc.common.model.data.RegionValue;
|
|
|
import com.persagy.dc.common.utils.RegionUtil;
|
|
|
import com.persagy.dc.parser.entity.ParserResult;
|
|
@@ -18,106 +18,75 @@ import java.util.List;
|
|
|
public class DateInfoParser extends AbstractInfoDataParser {
|
|
|
|
|
|
@Override
|
|
|
- protected boolean validateDefine(ParserResult result) {
|
|
|
+ protected void validateDefine(ParserResult result) throws IOException {
|
|
|
// 格式默认为yyyyMMddHHmmss
|
|
|
if(StrUtil.isBlank(result.getInfoDefine().getFormatter())) {
|
|
|
result.getInfoDefine().setFormatter("yyyyMMddHHmmss");
|
|
|
}
|
|
|
String formatter = result.getInfoDefine().getFormatter();
|
|
|
// 数据源 - 应为区间列表格式
|
|
|
- try {
|
|
|
- List<RegionValue<String>> dataSource = formatRegionListValue(result.getInfoDefine().getDataSource(), String.class);
|
|
|
- // 区间格式校验
|
|
|
- if(!matchRegionDataFormat(formatter, dataSource)) {
|
|
|
- result.addErrorMsg("信息点[{}]定义有误,数据源格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- result.addErrorMsg("信息点[{}]定义有误,数据源格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
+ List<RegionValue<String>> dataSource = formatRegionListValue(result.getInfoDefine().getDataSource(), String.class);
|
|
|
+ // 区间格式校验
|
|
|
+ if(!matchRegionDataFormat(formatter, dataSource)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]定义有误,数据源格式有误!", result.getInfoDefine().getCode()));
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected boolean validateValue(ParserResult result) {
|
|
|
- boolean multiFlag = BooleanUtil.isTrue(result.getInfoDefine().getMultipleFlag());
|
|
|
- boolean regionFlag = BooleanUtil.isTrue(result.getInfoDefine().getRegionFlag());
|
|
|
+ protected void validateValue(ParserResult result) throws IOException {
|
|
|
String formatter = result.getInfoDefine().getFormatter();
|
|
|
- try {
|
|
|
- // 数据源定义信息
|
|
|
- List<RegionValue<String>> dataSource = formatRegionListValue(result.getInfoDefine().getDataSource(), String.class);
|
|
|
- // 复数
|
|
|
- if(multiFlag) {
|
|
|
- // 复数区间
|
|
|
- if(regionFlag) {
|
|
|
- List<RegionValue<String>> valueList = formatRegionListValue(result.getValueInfo(), String.class);
|
|
|
- // 区间格式校验
|
|
|
- if (!matchRegionDataFormat(formatter, valueList)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 区间范围校验
|
|
|
- if (CollUtil.isNotEmpty(dataSource)) {
|
|
|
- if (!RegionUtil.allContains(dataSource, valueList)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 复数非区间
|
|
|
- List<String> valueList = formatListValue(result.getValueInfo(), String.class);
|
|
|
- // 区间格式校验
|
|
|
- if (!matchDataFormat(formatter, valueList)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 区间范围校验
|
|
|
- if (CollUtil.isNotEmpty(dataSource)) {
|
|
|
- if (!RegionUtil.allContain(dataSource, valueList)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 数据源定义信息
|
|
|
+ List<RegionValue<String>> dataSource = formatRegionListValue(result.getInfoDefine().getDataSource(), String.class);
|
|
|
+ // 复数
|
|
|
+ if(result.isMulti()) {
|
|
|
+ // 复数区间
|
|
|
+ if(result.isRegion()) {
|
|
|
+ List<RegionValue<String>> valueList = formatRegionListValue(result.getValueInfo(), String.class);
|
|
|
+ // 区间格式校验
|
|
|
+ if (!matchRegionDataFormat(formatter, valueList)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据格式有误!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ // 区间范围校验
|
|
|
+ if (!RegionUtil.allContains(dataSource, valueList)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
}
|
|
|
} else {
|
|
|
- // 单数区间
|
|
|
- if(regionFlag) {
|
|
|
- RegionValue<String> value = formatRegionValue(result.getValueInfo(), String.class);
|
|
|
- // 日期格式校验
|
|
|
- if (!matchRegionDataFormat(formatter, CollUtil.newArrayList(value))) {
|
|
|
- result.addErrorMsg("信息点[{}]数据格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(dataSource)) {
|
|
|
- // 区间范围校验
|
|
|
- if (!RegionUtil.anyContains(dataSource, value)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 单数非区间
|
|
|
- String value = formatValue(result.getValueInfo(), String.class);
|
|
|
- // 日期格式校验
|
|
|
- if (!matchDataFormat(formatter, value)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(dataSource)) {
|
|
|
- // 区间范围校验
|
|
|
- if (!RegionUtil.anyContain(dataSource, value)) {
|
|
|
- result.addErrorMsg("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 复数非区间
|
|
|
+ List<String> valueList = formatListValue(result.getValueInfo(), String.class);
|
|
|
+ // 区间格式校验
|
|
|
+ if (!matchDataFormat(formatter, valueList)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据格式有误!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ // 区间范围校验
|
|
|
+ if (!RegionUtil.allContain(dataSource, valueList)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 单数区间
|
|
|
+ if(result.isRegion()) {
|
|
|
+ RegionValue<String> value = formatRegionValue(result.getValueInfo(), String.class);
|
|
|
+ // 日期格式校验
|
|
|
+ if (!matchRegionDataFormat(formatter, CollUtil.newArrayList(value))) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据格式有误!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ // 区间范围校验
|
|
|
+ if (!RegionUtil.anyContains(dataSource, value)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 单数非区间
|
|
|
+ String value = formatValue(result.getValueInfo(), String.class);
|
|
|
+ // 日期格式校验
|
|
|
+ if (!matchDataFormat(formatter, value)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据格式有误!", result.getInfoDefine().getCode()));
|
|
|
+ }
|
|
|
+ // 区间范围校验
|
|
|
+ if (!RegionUtil.anyContain(dataSource, value)) {
|
|
|
+ throw new BusinessException(StrUtil.format("信息点[{}]数据有误,超出区间范围!", result.getInfoDefine().getCode()));
|
|
|
}
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- result.addErrorMsg("信息点[{}]数据格式有误!", result.getInfoDefine().getCode());
|
|
|
- return false;
|
|
|
}
|
|
|
- return true;
|
|
|
}
|
|
|
|
|
|
/**
|