[测评系统]--测评系统核心代码库
林致杰
2021-12-03 ce080c08f08c01695ddc9d9510b77eb6d2c7a38d
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
package com.ots.project.tool.exam;
import com.ots.common.utils.StringUtils;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
public class ExamUtil {
    public static Map<String, String> productTypeMap = new HashMap<>();
    public static Map<String, String> waterDropPictureMap = new HashMap<>();
    public static Map<String, String> barPictureMap = new HashMap<>();
    static {
        setProductTypeMap();
        setWaterDropAndBar();
    }
    private static void setProductTypeMap() {
        productTypeMap.put("personality", "MAQ");
        productTypeMap.put("job", "JAQ");
        productTypeMap.put("RuiLin","RuiLin");
        productTypeMap.put("MAQ", "MAQ");
        productTypeMap.put("MAQV2", "MAQV2");
        productTypeMap.put("MAQIAR", "MAQIAR");
        productTypeMap.put("SAQ", "SAQ");
        productTypeMap.put("JAQ", "JAQ");
    }
 
    /**
     * 设置水滴背景对应图片
     */
    private static void setWaterDropAndBar() {
        //水滴图片
        waterDropPictureMap.put("ResponseFidelityDiagnosis", "waterDropDarkBlue.png");
        waterDropPictureMap.put("ResponseFidelityDiagnosis_V2", "waterDropDarkBlue_V2.png");
        //SAQ简易版
        waterDropPictureMap.put("ResponseFidelityDiagnosisSAQGs", "waterDropDarkBlue_V2.png");
        
        waterDropPictureMap.put("ResponseFidelityDiagnosisSAQ", "waterDropDarkBlue.png");
        
        waterDropPictureMap.put("RuilinTestResultValidityDiagnosisContext", "waterDropDarkBlue.png");
        waterDropPictureMap.put("PersonalEnergy", "waterDropRed.png");
        waterDropPictureMap.put("SociallyOpen", "waterDropRed.png");
        waterDropPictureMap.put("LeadingOthers", "waterDropRed.png");
        waterDropPictureMap.put("Influencing", "waterDropRed.png");
        waterDropPictureMap.put("AchievementOrientation", "waterDropGreed.png");
        waterDropPictureMap.put("Dependability", "waterDropGreed.png");
        waterDropPictureMap.put("Thoroughness", "waterDropGreed.png");
        waterDropPictureMap.put("Persistence", "waterDropGreed.png");
        waterDropPictureMap.put("Initiative", "waterDropGreed.png");
        waterDropPictureMap.put("PlanningandOrganizing", "waterDropGreed.png");
        waterDropPictureMap.put("TrustandIntegrity", "waterDropGreed.png");
        waterDropPictureMap.put("Flexibility", "waterDropOrange.png");
        waterDropPictureMap.put("Creativity", "waterDropOrange.png");
        waterDropPictureMap.put("AnalyticalApproach", "waterDropOrange.png");
        waterDropPictureMap.put("Independence", "waterDropOrange.png");
        waterDropPictureMap.put("Self", "waterDropLilac.png");
        waterDropPictureMap.put("ManagingStress", "waterDropLilac.png");
        waterDropPictureMap.put("Mindfulness", "waterDropLilac.png");
        waterDropPictureMap.put("CooperationTeamwork", "waterDropLightBlue.png");
        waterDropPictureMap.put("Empathetic", "waterDropLightBlue.png");
        waterDropPictureMap.put("PoliteTactful", "waterDropLightBlue.png");
        //背景导航条
        barPictureMap.put("ResponseFidelityDiagnosis_waterDrops1", "Bar1.png");
        barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops1", "Bar1_V2.png");
        barPictureMap.put("ResponseFidelityDiagnosis_waterDrops2", "Bar1.png");
        barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops2", "Bar1_V2.png");
        barPictureMap.put("ResponseFidelityDiagnosis_waterDrops3", "Bar2.png");
        barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops3", "Bar2_V2.png");
        
        barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops1", "Bar1.png");
        barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops2", "Bar1.png");
        barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops3", "Bar2.png");
        //增加SAQ简易版
        barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops1", "Bar1_V2.png");
        barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops2", "Bar1_V2.png");
        barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops3", "Bar2_V2.png");
        
        barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops1", "RuiLin1.png");
        barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops2", "RuiLin1.png");
        barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops3", "RuiLin2.png");
        
        barPictureMap.put("Flexibility_1_waterDrops", "Bar3.png");
        barPictureMap.put("Creativity_2_waterDrops", "Bar3.png");
        barPictureMap.put("AnalyticalApproach_3_waterDrops", "Bar3.png");
        barPictureMap.put("Independence_4_waterDrops", "Bar3.png");
        
        barPictureMap.put("AchievementOrientation_5_waterDrops","Bar4.png");
        barPictureMap.put("Initiative_6_waterDrops","Bar4.png");
        barPictureMap.put("Persistence_7_waterDrops","Bar4.png");
        barPictureMap.put("Thoroughness_8_waterDrops","Bar4.png");
        barPictureMap.put("Dependability_9_waterDrops","Bar4.png");
        barPictureMap.put("PlanningandOrganizing_10_waterDrops","Bar4.png");
        barPictureMap.put("TrustandIntegrity_11_waterDrops","Bar4.png");
        
        barPictureMap.put("PersonalEnergy_12_waterDrops", "Bar5.png");
        barPictureMap.put("SociallyOpen_13_waterDrops", "Bar5.png");
        barPictureMap.put("LeadingOthers_14_waterDrops", "Bar5.png");
        barPictureMap.put("Influencing_15_waterDrops", "Bar5.png");
        
        barPictureMap.put("CooperationTeamwork_16_waterDrops", "Bar6.png");
        barPictureMap.put("Empathetic_17_waterDrops", "Bar6.png");
        barPictureMap.put("PoliteTactful_18_waterDrops", "Bar6.png");
        
        barPictureMap.put("Self_Regulation_19_waterDrops", "Bar7.png");
        barPictureMap.put("ManagingStress_20_waterDrops", "Bar7.png");
        barPictureMap.put("Self_Confidence_21_waterDrops", "Bar7.png");
        barPictureMap.put("Mindfulness_22_waterDrops", "Bar7.png");
        
        barPictureMap.put("Combined_waterDrops", "CAQBar1.png");
        barPictureMap.put("P_Abstract_context_waterDrops", "CAQBar1.png");
        barPictureMap.put("P_Numeric_context_waterDrops", "CAQBar1.png");
        waterDropPictureMap.put("Combined_waterDrops", "waterDropOrange.png");
        waterDropPictureMap.put("P_Abstract_context_waterDrops", "waterDropOrange.png");
        waterDropPictureMap.put("P_Numeric_context_waterDrops", "waterDropOrange.png");
    }
    public static String scoreToVM(Integer score) {
        if (score % 10 == 0) {
            return String.valueOf(score / 10);
        } else {
            return String.format("%.1f", score / 10.0);
        }
    }
    public static String originalScoreToVM(Integer score) {
        return String.valueOf(score);
    }
    public static Integer scoreFromVM(String score) {
        if (score == null) {
            return null;
        } else {
            return (int) (Float.parseFloat(score) * 10);
        }
    }
    public static String secondToVM(Integer second) {
        String dateTimes;
        long days = second / (60 * 60 * 24);
        long hours = (second % (60 * 60 * 24)) / (60 * 60);
        long minutes = (second % (60 * 60)) / 60;
        long seconds = second % 60;
        if (days > 0) {
            dateTimes = days + "天 " + hours + "时 " + minutes + "分 " + seconds + "秒";
        } else if (hours > 0) {
            dateTimes = hours + "时 " + minutes + "分 " + seconds + "秒";
        } else if (minutes > 0) {
            dateTimes = minutes + "分 " + seconds + "秒";
        } else {
            dateTimes = seconds + " 秒";
        }
        return dateTimes;
    }
    private static final String ANSWER_SPLIT = ",";
    public static String contentToString(List<String> contentArray) {
        return contentArray.stream().sorted().collect(Collectors.joining(ANSWER_SPLIT));
    }
    public static List<String> contentToArray(String contentArray) {
        return Arrays.asList(contentArray.split(ANSWER_SPLIT));
    }
    private static final String FORM_ANSWER_SPLIT = "_";
    public static Integer lastNum(String str) {
        Integer start = str.lastIndexOf(FORM_ANSWER_SPLIT);
        return Integer.parseInt(str.substring(start + 1));
    }
    
    public static String html2Text(String inputString) {
        String htmlStr = inputString; 
        String textStr = "";
        java.util.regex.Pattern p_script;
        java.util.regex.Matcher m_script;
        java.util.regex.Pattern p_xml;
        java.util.regex.Matcher m_xml;
        java.util.regex.Pattern p_style;
        java.util.regex.Matcher m_style;
        java.util.regex.Pattern p_html;
        java.util.regex.Matcher m_html;
        try {
            String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; 
            String regEx_xml = "<[\\s]*?xml[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?xml[\\s]*?>";
            String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; 
            String regEx_html = "<[^>]+>"; 
            p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
            m_script = p_script.matcher(htmlStr);
            htmlStr = m_script.replaceAll(""); 
            
            p_xml = Pattern.compile(regEx_xml, Pattern.CASE_INSENSITIVE);
            m_xml = p_xml.matcher(htmlStr);
            htmlStr = m_xml.replaceAll(""); 
            p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
            m_style = p_style.matcher(htmlStr);
            htmlStr = m_style.replaceAll(""); 
            p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
            m_html = p_html.matcher(htmlStr);
            htmlStr = m_html.replaceAll(""); 
            textStr = htmlStr;
        } catch (Exception e) {
            System.err.println("Html2Text: " + e.getMessage());
        }
        
        textStr = textStr.replaceAll("[ ]+", " ");
        textStr = textStr.replaceAll("(?m)^\\s*$(\\n|\\r\\n)", "");
        return textStr;
    }
    
    public static String getStringMapJson(String langType, String content, Map<String, String> map) {
        if (StringUtils.isEmpty(content)) {
            return JsonUtil.toJSONString(map);
        }
        if (Objects.isNull(map)) {
            map = new HashMap<>();
        }
        map.put(langType, content);
        return JsonUtil.toJSONString(map);
    }
    public static String getStringMapJson(String langType, String content, String srcContent) {
        if (StringUtils.isEmpty(langType)) {
            return "";
        }
        if (StringUtils.isEmpty(content) && StringUtils.isEmpty(srcContent)) {
            return "";
        }
        Map<String, String> map = null;
        if (StringUtils.isEmpty(srcContent)) {
            map = new HashMap<>();
        } else {
            map = JsonUtil.parseObject(srcContent, HashMap.class);
        }
        if (Objects.isNull(map)) {
            map = new HashMap<>();
        }
        Map<String, String> mapNew = null;
        if (StringUtils.isEmpty(content)) {
            return JsonUtil.toJSONString(map);
        } else {
            mapNew = JsonUtil.parseObject(content, HashMap.class);
        }
        if (Objects.isNull(map) && Objects.isNull(mapNew)) {
            return srcContent;
        }
        
        if (Objects.isNull(mapNew)) {
            map.put(langType, content);
        } else if (StringUtils.equals(langType, "ALL") || StringUtils.isEmpty(langType)) {
            map.putAll(mapNew);
        } else if (Objects.nonNull(mapNew) && StringUtils.isNotEmpty(mapNew.get(langType))) {
            map.put(langType, mapNew.get(langType));
        } else {
            map.put(langType, content);
        }
        return JsonUtil.toJSONString(map);
    }
 
    /**
     * 获取提示语
     * @param langType 语言
     * @param contentMapJson 提示语内容
     * @return
     */
    public static String getLangString(String langType, String contentMapJson) {
        if (StringUtils.isEmpty(contentMapJson)) {
            return "";
        }
        if (StringUtils.isEmpty(langType)) {
            return contentMapJson;
        }
        /**
         * json 转为 map 方便根据key获取对应语言提示语
         */
        Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
        if (Objects.isNull(contentMap)) {
            return contentMapJson;
        }
 
        //对应语言提示语为空
        if (StringUtils.isNotEmpty(contentMap.get(langType))) {
            return contentMap.get(langType);
        } /*else if (StringUtils.isNotEmpty(contentMap.get("English"))) {
            contentMap.get("English");
        }*/
        if (contentMap.isEmpty()) {
            return "";
        }
        
        return contentMap.values().stream().findFirst().get();
    }
 
    /**
     * 判断对应语言的提示语是否存在
     * @param langType 语言
     * @param contentMapJson 提示语内容
     * @return
     */
    public static boolean isLangType(String langType, String contentMapJson) {
        if (StringUtils.isEmpty(contentMapJson)) {
            return false;
        }
        if (StringUtils.isEmpty(langType)) {
            return false;
        }
        /**
         * json 转为 map 方便根据key获取对应语言提示语
         */
        Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
        if (Objects.isNull(contentMap)) {
            return false;
        }
 
        //对应语言提示语为空
        if (StringUtils.isNotEmpty(contentMap.get(langType))) {
            return StringUtils.isNotEmpty(contentMap.get(langType));
        } /*else if (StringUtils.isNotEmpty(contentMap.get("English"))) {
            contentMap.get("English");
        }*/
        if (contentMap.isEmpty()) {
            return false;
        }
 
        return false;
    }
    
    public static String getStringByLang(String langType, String contentMapJson) {
        if (StringUtils.isEmpty(contentMapJson)) {
            return "";
        }
        if (StringUtils.isEmpty(langType)) {
            return contentMapJson;
        }
        Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
        if (Objects.isNull(contentMap)) {
            return contentMapJson;
        }
        
        if (StringUtils.isNotEmpty(contentMap.get(langType))) {
            return contentMap.get(langType);
        } else {
            return "";
        }
    }
    
    public static String deleteLangString(String langType, String contentMapJson) {
        if (StringUtils.isEmpty(contentMapJson)) {
            return "";
        }
        Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
        if (Objects.isNull(contentMap)) {
            return contentMapJson;
        }
        if (StringUtils.isEmpty(langType)) {
            return contentMapJson;
        }
        contentMap.remove(langType);
        return JsonUtil.toJSONString(contentMap);
    }
    
    public static boolean isListEmpty(List<?> objList) {
        if (Objects.isNull(objList)) {
            return true;
        }
        return objList.isEmpty();
    }
    public static boolean isListNotEmpty(List<?> objList) {
        return !isListEmpty(objList);
    }
    public static long timeSpent(Date startDate, Date endDate) {
        if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
            return 0L;
        }
        long startTime = startDate.getTime();
        long endTime = endDate.getTime();    
        long timeDifference = endTime - startTime;
        long second = timeDifference / 1000;  
        return second;
    }
    public static Map<String, String> getProudctTypeMap() {
        return productTypeMap;
    }
    public static String getWaterDropPictureMap(String key) {
        if (StringUtils.isEmpty(key)) {
            return "";
        }
        String value = waterDropPictureMap.get(key);
        if (StringUtils.isNotEmpty(value)) {
            return value;
        }
        return "";
    }
    public static String getBarPictureMap(String key) {
        if (StringUtils.isEmpty(key)) {
            return "";
        }
        String value = barPictureMap.get(key);
        if (StringUtils.isNotEmpty(value)) {
            return value;
        }
        return "";
    }
}