[测评系统]--测评系统核心代码库
zhijie
2021-06-08 56c8bc18def3992259da50948119259f571d04ee
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
package com.ots.project.tool.report.MAQ.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.CacheServiceFactory;
import com.ots.project.tool.report.MAQ.base.BaseCondition;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static com.ots.common.enums.LangTypeEnum.*;
 
@Getter
@Setter
@Slf4j
public class KeyPointsCautions extends BaseCondition {
    private String name = "KeyPointsCautions";
    @Override
    public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
        try {
            Map<String, String> paramMap = new HashMap();
            paramMap.put("LIBMAQ1010,LIBMAQ1025", map.get("P_Flex01"));
            paramMap.put("LIBMAQ2010,LIBMAQ2025", map.get("P_Creat02"));
            paramMap.put("LIBMAQ3010,LIBMAQ3025", map.get("P_Analyt03"));
            paramMap.put("LIBMAQ10010,LIBMAQ10025", map.get("P_Plan10"));
            paramMap.put("LIBMAQ16010,LIBMAQ16025", map.get("P_Team16"));
            paramMap.put("LIBMAQ21010,LIBMAQ21025", map.get("P_Confid21"));
            paramMap.put("LIBMAQ15010,LIBMAQ15025", map.get("P_Influ15"));
            Map<String, Boolean> calculateMap = new HashMap();
            for (Map.Entry<String, String> entry : paramMap.entrySet()) {
                if (checkParamsNonNull(entry.getValue()) && Double.valueOf(entry.getValue()) <= 30) {
                    calculateMap.put(entry.getKey(), true);
                }
            }
            TLibraryCode maqReportLibrary = spliceTrueObject(calculateMap, map, langType);
            return maqReportLibrary;
        } catch (Exception ex) {
            log.error("KeyPointsCautions error:{}", ex.getMessage(), ex);
            return null;
        }
    }
    @Override
    public Map<String, String> getMAQwaterDropsImages() {
        return null;
    }
    protected TLibraryCode spliceTrueObject(Map<String, Boolean> calculateMap, Map<String, String> map, LangTypeEnum langType) {
        TLibraryCode result = new TLibraryCode();
        StringBuilder context = new StringBuilder();
        for (Map.Entry<String, Boolean> entry : calculateMap.entrySet()) {
            Boolean value = entry.getValue();
            if (value) {
                String key = entry.getKey();
                TLibraryCode ret = getMaqReportLibrary2(map, key, langType);
                context.append(ret.getLangTypeContext(langType));
                context.append("%line-feed%");
            }
        }
        result.setLangTypeContext(context.toString(), langType);
        if (StringUtils.isBlank(context)) {
            if (langType== English) {
                context.append("No caution was found.");
            } else if (langType== Chinese) {
                context.append("没有发现短版项。");
            } else if (langType== Thai) {
                context.append("No caution was found.");
            }
            result.setLangTypeContext(context.toString(), langType);
        }
        return result;
    }
    public TLibraryCode getMaqReportLibrary2(Map<String, String> map, String codeId, LangTypeEnum langType) {
        StringBuilder content = new StringBuilder();
        String[] split = codeId.split(",");
        for (int i = 0;i<split.length;i++) {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(split[i]);
            if (Objects.isNull(maqReportLibrary)) {
                log.error("**************  LibraryCode 没有配置 code = {} ***********", split[i]);
            } else {
                if (i==0) {
                    content.append("<BoldText>");
                    content.append(maqReportLibrary.getLangTypeContext(langType));
                    content.append("</BoldText>");
                } else {
                    content.append(maqReportLibrary.getLangTypeContext(langType));
                }
            }
        }
        TLibraryCode result = new TLibraryCode();
        result.setLangTypeContext(content.toString(), langType);
        dynamicParameterSubstitution2(map, result, langType);
        return result;
    }
    public void dynamicParameterSubstitution2(Map<String, String> map, TLibraryCode maqReportLibrary, LangTypeEnum langType) {
        map.forEach((key, value) -> {
            String content = maqReportLibrary.getLangTypeContext(langType);
            String replaceStr = "%" + key + "%";
            maqReportLibrary.setLangTypeContext(content.replace(replaceStr, value), langType);
        });
    }
}