[测评系统]--测评系统核心代码库
linzhijie
2021-04-12 ccbe40edcd772214ac3df40be1f582b6acea63f4
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
package com.ots.project.tool.report.MAQ.base;
import com.ots.common.enums.LangTypeEnum;
import com.ots.project.exam.domain.TLibraryCode;
import com.ots.project.tool.CacheServiceFactory;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
@Slf4j
public abstract class BaseCondition {
    public static final String IMAGE_PREFIX = "_waterDrops";
    public abstract String getName();
    
    public abstract TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType);
    
    public abstract Map<String, String> getMAQwaterDropsImages();
    protected String selectTrueObject(Map<Boolean, String> calculateMap) {
        for (Map.Entry<Boolean, String> entry : calculateMap.entrySet()) {
            Boolean mapKey = entry.getKey();
            if (mapKey) {
                return entry.getValue();
            }
        }
        return null;
    }
    protected boolean checkParamsNonNull(String... value) {
        return !checkParamsIsNull(value);
    }
    protected boolean checkParamsIsNull(String... value) {
        for (int i = 0; i < value.length; i++) {
            if (Objects.isNull(value[i])) {
                return true;
            }
        }
        return false;
    }
 
    /**
     * 获取报告字典
     * @param map
     * @param codeId
     * @param langType
     * @return
     */
    public TLibraryCode getMaqReportLibrary(Map<String, String> map, String codeId, LangTypeEnum langType) {
        if (Objects.isNull(codeId)) {
            return null;
        }
        StringBuilder content = new StringBuilder();
        String[] split = codeId.split(",");
        TLibraryCode result = new TLibraryCode();
        /**
         * 根据字典CODE获取对应的字典详情
         */
        Arrays.stream(split).forEach(item -> {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item);
            if (Objects.isNull(maqReportLibrary)) {
                log.warn("**************  LibraryCode 没有配置 code = {} ***********", item);
            } else {
                content.append(maqReportLibrary.getLangTypeContext(langType));
                result.setDictType(maqReportLibrary.getDictType());
                result.setIcon(maqReportLibrary.getIcon());
                result.setLibraryCode(maqReportLibrary.getLibraryCode());
            }
        });
        //设置对应语言的文字内容
        result.setLangTypeContext(content.toString(), langType);
        //替换报告字典内容的变量
        dynamicParameterSubstitution(map, result, langType);
        return result;
    }
 
    /**
     * 替换报告字典内容的变量
     * @param map
     * @param maqReportLibrary
     * @param langType
     */
    public void dynamicParameterSubstitution(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, "<BoldText>" + value + "</BoldText>"), langType);
        });
    }
}