[测评系统]--测评系统核心代码库
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
package com.ots.project.tool.report.MAQNEW.condition;
import com.ots.common.enums.LangTypeEnum;
import com.ots.common.utils.StringUtils;
import com.ots.project.exam.domain.TLibraryCode;
import com.ots.project.tool.report.MAQNEW.base.BaseCondition_V2;
import com.ots.project.tool.report.MAQNEW.base.MAQSummaryCondition_V2;
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 MAQSummary_V2 extends BaseCondition_V2 {
    private final List<MAQSummaryCondition_V2> paramList;
    private String name;
    public MAQSummary_V2(String name, List<MAQSummaryCondition_V2> paramList) {
        this.name = name;
        this.paramList = paramList;
    }
    @Override
    public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
        if (Objects.isNull(paramList) || paramList.isEmpty()) {
            return null;
        }
        StringBuffer context = new StringBuffer();
        paramList.stream().forEach(item -> {
            TLibraryCode calculate = item.calculate(map, langType);
            if (Objects.nonNull(calculate)) {
                context.append(calculate.getLangTypeContext(langType));
                context.append("%line-feed%");
            }
        });
        TLibraryCode maqReportLibrary = new TLibraryCode();
        if (StringUtils.isBlank(context)) {
            if (langType == English) {
                context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
            } else if (langType == Chinese) {
                context.append("所有维度的分数都在中等范围,没有高分和低分项。");
            } else if (langType == Thai) {
                context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
            }
        }
        maqReportLibrary.setLangTypeContext(context.toString(), langType);
        return maqReportLibrary;
    }
    @Override
    public List<TLibraryCode> calculateList(Map<String, String> map, LangTypeEnum langType) {
        if (Objects.isNull(paramList) || paramList.isEmpty()) {
            return null;
        }
        StringBuffer context = new StringBuffer();
        List<TLibraryCode> libcodes = new ArrayList<>();
        List<Map<Integer, List<TLibraryCode>>> sortList = new ArrayList<>();
        for (MAQSummaryCondition_V2 maqSummaryCondition_v2 : paramList) {
            List<TLibraryCode> tLibraryCodes = maqSummaryCondition_v2.calculateList(map, langType);
            if (tLibraryCodes != null && tLibraryCodes.size() > 0) {
                Integer sortLevel = getSortLevel(tLibraryCodes, langType);
                Map<Integer, List<TLibraryCode>> sortMap = new HashMap<>();
                sortMap.put(sortLevel, tLibraryCodes);
                sortList.add(sortMap);
            }
        }
        sortList.sort(new Comparator<Map<Integer, List<TLibraryCode>>>() {
            @Override
            public int compare(Map<Integer, List<TLibraryCode>> o1, Map<Integer, List<TLibraryCode>> o2) {
                Integer o1_level = new ArrayList<>(o1.keySet()).get(0);
                Integer o2_level = new ArrayList<>(o2.keySet()).get(0);
                if(o1_level.intValue() !=  o2_level.intValue()){
                    return o2_level - o1_level;
                }else{
                    List<TLibraryCode> o1_tLibraryCodes = o1.get(o1_level);
                    List<TLibraryCode> o2_tLibraryCodes = o2.get(o2_level);
                    return Integer.parseInt(o2_tLibraryCodes.get(0).getScore()) - Integer.parseInt(o1_tLibraryCodes.get(0).getScore());
                }
            }
        });
        for (Map<Integer, List<TLibraryCode>> integerListMap : sortList) {
            for (Integer integer : integerListMap.keySet()) {
                libcodes.addAll(integerListMap.get(integer));
            }
        }
        TLibraryCode maqReportLibrary = new TLibraryCode();
        if (libcodes.size() < 1) {
            if (langType == English) {
                context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
            } else if (langType == Chinese) {
                context.append("所有维度的分数都在中等范围,没有高分和低分项。");
            } else if (langType == Thai) {
                context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
            }
            maqReportLibrary.setLangTypeContext(context.toString(), langType);
            libcodes.add(maqReportLibrary);
        } else {
            libcodes.add(getMaqReportLibrary(map, "LIBMAQV233063", langType));
        }
        return libcodes;
    }
    private Integer getSortLevel(List<TLibraryCode> tLibraryCodes, LangTypeEnum langType) {
        TLibraryCode tLibraryCode = tLibraryCodes.get(0);
        String context = getContext(tLibraryCode, langType);
        int index = 1;
        while (context.indexOf("-") > 0 || context.indexOf("+") > 0) {
            if (context.indexOf("-") > 0) {
                context = context.replaceFirst("-", "");
                index = index * 10;
            } else if (context.indexOf("+") > 0) {
                context = context.replaceFirst("\\+", "");
                index = index * 1000;
            }
        }
        return index;
    }
    private String getContext(TLibraryCode tLibraryCode, LangTypeEnum langType) {
        String context = "";
        if (langType == English) {
            context = tLibraryCode.getEnglistContent();
        } else if (langType == Chinese) {
            context = tLibraryCode.getChineseContent();
        } else if (langType == Thai) {
            context = tLibraryCode.getThaiContent();
        }
        return context;
    }
    @Override
    public Map<String, String> getMAQwaterDropsImages() {
        return null;
    }
}