[测评系统]--测评系统核心代码库
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
104
105
106
107
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.CacheServiceFactory;
import com.ots.project.tool.report.MAQNEW.base.BaseCondition_V2;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
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_V2 extends BaseCondition_V2 {
    private String name = "KeyPointsCautions_V2";
    @Override
    public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
        try {
            Map<String, String> paramMap = new HashMap();
            paramMap.put("LIBMAQV21010,LIBMAQV21025", map.get("P_Flex01"));
            paramMap.put("LIBMAQV22010,LIBMAQV22025", map.get("P_Creat02"));
            paramMap.put("LIBMAQV23010,LIBMAQV23025", map.get("P_Analyt03"));
            paramMap.put("LIBMAQV210010,LIBMAQV210025", map.get("P_Plan10"));
            paramMap.put("LIBMAQV216010,LIBMAQV216025", map.get("P_Team16"));
            paramMap.put("LIBMAQV221010,LIBMAQV221025", map.get("P_Confid21"));
            paramMap.put("LIBMAQV215010,LIBMAQV215025", 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);
                }
            }
            if (calculateMap.isEmpty()) {
                calculateMap.put("LIBMAQV233054", 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("<YellowText>");
                    content.append(maqReportLibrary.getLangTypeContext(langType));
                    content.append("</YellowText>");
                    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);
        });
    }
}