刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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();
    }
}