[测评系统]--测评系统核心代码库
linzhijie
2021-04-26 9843a613b41db35b05e048d3eacaf99253b57ce6
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.ots.project.tool.report.MAQNEW.base;
import com.ots.common.enums.LangTypeEnum;
import com.ots.project.exam.domain.TLibraryCode;
import com.ots.project.tool.report.MAQ.base.MAQConditionVO;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.*;
import static com.ots.common.enums.LangTypeEnum.*;
@Setter
@Getter
@Slf4j
public class MAQSummaryCondition_V2 extends BaseCondition_V2 {
    private String name;
    private MAQConditionVO conditionVO;
    private Double conditionValue;
    public MAQSummaryCondition_V2(MAQConditionVO conditionVO) {
        this.name = conditionVO.getName();
        this.conditionVO = conditionVO;
    }
    @Override
    public Map<String, String> getMAQwaterDropsImages() {
        HashMap<String, String> map = new HashMap<>();
        map.put(name + IMAGE_PREFIX, Objects.isNull(conditionValue) ? "0" : String.valueOf(conditionValue));
        return map;
    }
    @Override
    public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
        try {
            String conditionKey = conditionVO.getConditionKey();
            String conValue = map.get(conditionKey);
            if (checkParamsIsNull(conValue)) {
                return null;
            }
            conditionValue = Double.valueOf(conValue);
            List<String> conditionTarget = conditionVO.getConditionTarget();
            boolean jianjian = conditionValue <= 5; 
            boolean jian = 5 < conditionValue && conditionValue <= 30;
            boolean jia = 70 <= conditionValue && conditionValue < 95;
            boolean jiajia = conditionValue >= 95; 
            String prefix = getPrefix(jianjian, jian, jia, jiajia);
            if (Objects.isNull(prefix)) {
                return null;
            }
            Map calculateMap = new HashMap();
            calculateMap.put(jianjian, conditionTarget.get(0));
            calculateMap.put(jian, conditionTarget.get(1));
            calculateMap.put(jia, conditionTarget.get(4));
            calculateMap.put(jiajia, conditionTarget.get(5));
            String codeId = selectTrueObject(calculateMap);
            
            TLibraryCode library = getMaqReportLibrary(map, codeId, langType);
            
            String split = getTitleByLang(conditionVO.getTitle(), langType);
            String context = "<BoldText>" + prefix + split + "</BoldText> " + library.getLangTypeContext(langType);
            library.setLangTypeContext(context, langType);
            return library;
        } catch (Exception ex) {
            log.error("MAQCondition error name={},conditionKey={},conditionTarget={} error:{}", name, conditionVO.getConditionKey(), conditionVO.getConditionTarget(), ex.getMessage(), ex);
            return null;
        }
    }
    @Override
    public List<TLibraryCode> calculateList(Map<String, String> map, LangTypeEnum langType) {
        try {
            String conditionKey = conditionVO.getConditionKey();
            String conValue = map.get(conditionKey);
            if (checkParamsIsNull(conValue)) {
                return null;
            }
            conditionValue = Double.valueOf(conValue);
            List<String> conditionTarget = conditionVO.getConditionTarget();
            boolean jianjian = conditionValue <= 5; 
            boolean jian = 5 < conditionValue && conditionValue <= 30;
            boolean jia = 70 <= conditionValue && conditionValue < 95;
            boolean jiajia = conditionValue >= 95; 
            String prefix = getPrefix(jianjian, jian, jia, jiajia);
            if (Objects.isNull(prefix)) {
                return null;
            }
            Map calculateMap = new HashMap();
            calculateMap.put(jianjian, conditionTarget.get(0));
            calculateMap.put(jian, conditionTarget.get(1));
            calculateMap.put(jia, conditionTarget.get(4));
            calculateMap.put(jiajia, conditionTarget.get(5));
            String codeId = selectTrueObject(calculateMap);
            String[] codes = codeId.split(",");
            List<TLibraryCode> libcodes = new ArrayList<>();
            Arrays.stream(codes).forEach(item -> {
                libcodes.add(getMaqReportLibrary(map, item, langType));
            });
            TLibraryCode headLib = new TLibraryCode();
            
            String split = getTitleByLang(conditionVO.getTitle(), langType);
            String context = "<BoldText>" + prefix + split + "</BoldText> ";
            headLib.setLibraryCode("0");
            headLib.setLangTypeContext(context, langType);
            headLib.setScore(conValue);
            libcodes.add(headLib);
            libcodes.sort(new Comparator<TLibraryCode>() {
                @Override
                public int compare(TLibraryCode o1, TLibraryCode o2) {
                    return o1.getLibraryCode().compareTo(o2.getLibraryCode());
                }
            });
            return libcodes;
        } catch (Exception ex) {
            log.error("MAQCondition error name={},conditionKey={},conditionTarget={} error:{}", name, conditionVO.getConditionKey(), conditionVO.getConditionTarget(), ex.getMessage(), ex);
            return null;
        }
    }
    private String getTitleByLang(String title, LangTypeEnum langType) {
        String[] split = title.split(",");
        if (langType == English) {
            return split[0];
        } else if (langType == Chinese) {
            return split[1];
        }
        return "noConfiguration";
    }
    private String getPrefix(boolean jianjian, boolean jian, boolean jia, boolean jiajia) {
        String prefix = "";
        if (jianjian) {
            prefix = "--";
        } else if (jian) {
            prefix = "-";
        } else if (jia) {
            prefix = "+";
        } else if (jiajia) {
            prefix = "++";
        } else {
            prefix = null;
        }
        return prefix;
    }
}