[测评系统]--测评系统核心代码库
林致杰
2023-10-19 77f6cf1868777a27c033af7d6d4f2fe9d2afc30d
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
package com.ots.project.tool.report.MAQ.base;
import com.ots.common.enums.LangTypeEnum;
import com.ots.project.exam.domain.TLibraryCode;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.ots.common.enums.LangTypeEnum.Chinese;
import static com.ots.common.enums.LangTypeEnum.English;
@Setter
@Getter
@Slf4j
public class MAQSummaryCondition extends BaseCondition {
    private String name;
    private MAQConditionVO conditionVO;
    private Double conditionValue;
    public MAQSummaryCondition(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;
        }
    }
    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;
    }
}