|
|
@@ -1,6 +1,7 @@
|
|
|
package com.shkpr.service.alambizplugin.apiparam;
|
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.shkpr.service.alambizplugin.constants.DataType;
|
|
|
import com.shkpr.service.alambizplugin.constants.DmaAnalySettingType;
|
|
|
@@ -9,6 +10,7 @@ import com.shkpr.service.alambizplugin.dto.DmaAnalySettingDefine;
|
|
|
import lombok.Data;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
@@ -59,8 +61,20 @@ public class DmaAnalySettingParams {
|
|
|
DmaAnalySettingParams.Setting setting = settings.stream()
|
|
|
.filter(it -> define.getKey().equals(it.getKey())).findFirst().orElse(null);
|
|
|
if (setting == null) continue;
|
|
|
- //验证数据
|
|
|
- if (!DataType.valueOf(define.getDataType().toUpperCase()).valida(setting.getValue())) return false;
|
|
|
+ System.out.println(setting.getValue().toString());
|
|
|
+ //获取数据类型
|
|
|
+ DataType dataType = DataType.valueOf(define.getDataType().toUpperCase());
|
|
|
+ //获取值
|
|
|
+ String value = setting.getValue().isTextual() ? StringUtils.removeAll(setting.getValue().toString(), "\"") :
|
|
|
+ setting.getValue().toString();
|
|
|
+ //验证值
|
|
|
+ if (!dataType.valida(value)) return false;
|
|
|
+ //验证百分数
|
|
|
+ if ("%".equals(define.getUnit())) {
|
|
|
+ if (!NumberUtils.isParsable(value)) return false;
|
|
|
+ double v = Double.parseDouble(value);
|
|
|
+ if (v < -3d || 3d < v) return false;
|
|
|
+ }
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -77,7 +91,7 @@ public class DmaAnalySettingParams {
|
|
|
/**
|
|
|
* 值
|
|
|
*/
|
|
|
- private String value;
|
|
|
+ private JsonNode value;
|
|
|
|
|
|
/**
|
|
|
* 转dto
|
|
|
@@ -85,24 +99,16 @@ public class DmaAnalySettingParams {
|
|
|
* @param zoneId 分区id
|
|
|
* @param settingType 设置类型
|
|
|
* @param kind 种类
|
|
|
- * @param define 定义
|
|
|
* @return dto
|
|
|
*/
|
|
|
- public DmaAnalySetting toDto(String zoneId, Short settingType, String kind, DmaAnalySettingDefine define) throws IOException {
|
|
|
+ public DmaAnalySetting toDto(String zoneId, Short settingType, String kind) throws IOException {
|
|
|
//构建dto
|
|
|
DmaAnalySetting dmaAnalySetting = new DmaAnalySetting();
|
|
|
dmaAnalySetting.setZoneId(zoneId);
|
|
|
dmaAnalySetting.setSettingType(settingType);
|
|
|
dmaAnalySetting.setKind(kind);
|
|
|
dmaAnalySetting.setKey(key);
|
|
|
-
|
|
|
- //json不兼容处理
|
|
|
- DataType dataType = DataType.valueOf(define.getDataType().toUpperCase());
|
|
|
- if (dataType == DataType.STRING || dataType == DataType.TIME || dataType == DataType.DATE || dataType == DataType.DATETIME) {
|
|
|
- dmaAnalySetting.setValue(objectMapper.readTree("\"" + value + "\""));
|
|
|
- } else {
|
|
|
- dmaAnalySetting.setValue(objectMapper.readTree(value));
|
|
|
- }
|
|
|
+ dmaAnalySetting.setValue(value);
|
|
|
return dmaAnalySetting;
|
|
|
}
|
|
|
}
|