package jnpf.limsService.support;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.LinkedHashSet;
|
import java.util.List;
|
import java.util.Locale;
|
import java.util.Set;
|
|
public final class LimsWendingxingFenxiSupport {
|
|
private LimsWendingxingFenxiSupport() {
|
}
|
|
public static BigDecimal strictDecimal(String value) {
|
if (!hasText(value)
|
|| !value.trim().matches("[+-]?(?:\\d+(?:\\.\\d+)?|\\.\\d+)")) {
|
return null;
|
}
|
try {
|
return new BigDecimal(value.trim());
|
} catch (NumberFormatException ignored) {
|
return null;
|
}
|
}
|
|
public static List<String> normalizeIds(List<String> ids) {
|
Set<String> values = new LinkedHashSet<>();
|
if (ids != null) {
|
for (String id : ids) {
|
if (hasText(id)) {
|
values.add(id.trim());
|
}
|
}
|
}
|
return new ArrayList<>(values);
|
}
|
|
public static double periodOrder(BigDecimal period, String unit) {
|
if (period == null) {
|
return Double.MAX_VALUE;
|
}
|
String normalized = hasText(unit)
|
? unit.trim().toLowerCase(Locale.ROOT) : "";
|
double factor;
|
if (normalized.matches("天|日|day|days|d")) {
|
factor = 1D;
|
} else if (normalized.matches("周|星期|week|weeks|w")) {
|
factor = 7D;
|
} else if (normalized.matches("月|month|months|m")) {
|
factor = 30D;
|
} else if (normalized.matches("年|year|years|y")) {
|
factor = 365D;
|
} else if (normalized.matches("小时|时|hour|hours|h")) {
|
factor = 1D / 24D;
|
} else {
|
factor = 10000D;
|
}
|
return period.doubleValue() * factor;
|
}
|
|
public static String exceptionType(String investigation, String conclusion,
|
BigDecimal value, BigDecimal lower, BigDecimal upper) {
|
String type = investigation == null
|
? "" : investigation.trim().toLowerCase(Locale.ROOT);
|
if ("oos".equals(type) || "oot".equals(type)) {
|
return type;
|
}
|
if ("non_compliant".equalsIgnoreCase(conclusion)) {
|
return "non_compliant";
|
}
|
if (value != null && ((lower != null && value.compareTo(lower) < 0)
|
|| (upper != null && value.compareTo(upper) > 0))) {
|
return "out_of_limit";
|
}
|
if ("ad".equals(type)) {
|
return "ad";
|
}
|
return "";
|
}
|
|
private static boolean hasText(String value) {
|
return value != null && !value.trim().isEmpty();
|
}
|
}
|