linzhijie
2021-03-11 e1801037f0d65bcd61f9a7dc0970bea09bb048a0
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
package com.ots.project.tool.report.JAQ;
import com.alibaba.fastjson.JSONObject;
import com.ots.common.enums.LangTypeEnum;
import com.ots.common.utils.StringUtils;
import com.ots.project.exam.domain.TLibraryCode;
import com.ots.project.exam.domain.TQuestion;
import com.ots.project.exam.dto.QuestionObject;
import com.ots.project.exam.service.impl.TQuestionServiceImpl;
import com.ots.project.tool.AppUtil;
import com.ots.project.tool.CacheServiceFactory;
import com.ots.project.tool.exam.JsonUtil;
import com.ots.project.tool.report.JAQ.condition.Table1;
import com.ots.project.tool.report.JAQ.condition.Table2;
import com.ots.project.tool.report.JAQ.condition.Table3;
import com.ots.project.tool.report.JAQ.condition.Table4;
import com.ots.project.tool.report.reportCalculation.response.ReportAPIResult;
import lombok.Getter;
import lombok.Setter;
import java.util.*;
@Getter
@Setter
public class JAQReport {
    TQuestionServiceImpl tQuestionService = AppUtil.getObject("examQuestion", TQuestionServiceImpl.class);
    
    private String postName;
    
    private String reportGenerationDate;
    
    private String reportNumber;
    
    public List<Map<String, Object>> getTemplateParameters(ReportAPIResult result, LangTypeEnum langType) {
        Map<String, Object> infoMap = new HashMap();
        infoMap.put("postName", postName);
        infoMap.put("reportNumber", reportNumber);
        infoMap.put("reportGenerationDate", reportGenerationDate);
        Map<String, Object> tableList = new HashMap();
        tableList.put("table1", getTable1(result, langType));
        tableList.put("table2", getTable2(result, langType));
        tableList.put("table3", getTable3(result, langType));
        tableList.put("table4", getTable4(result, langType));
        return Arrays.asList(infoMap, tableList);
    }
    List<Table4> getTable4(ReportAPIResult result, LangTypeEnum langType) {
        List<Table4> table4 = result.getTable4();
        table4.stream().forEach(item -> {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item.getCompetency());
            if (Objects.nonNull(maqReportLibrary)) {
                item.setCompetency(maqReportLibrary.getLangTypeContext(langType));
            }
            StringBuilder stringBuilder = new StringBuilder();
            List<String> listOfTopicNumbers = item.getListOfTopicNumbers();
            
            listOfTopicNumbers.stream().forEach(p -> {
                String topic = queryTopic(langType, p);
                if (StringUtils.isBlank(topic)) {
                    topic = "NONE N/A";
                }
                stringBuilder.append(topic + "\n");
            });
            item.setExamplesOfHighPerformancePerformers(stringBuilder.toString());
        });
        return table4;
    }
    List<Table3> getTable3(ReportAPIResult result, LangTypeEnum langType) {
        List<Table3> table3 = result.getTable3();
        table3.stream().forEach(item -> {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item.getCompetency());
            if (Objects.nonNull(maqReportLibrary)) {
                item.setCompetency(maqReportLibrary.getLangTypeContext(langType));
            }
        });
        return table3;
    }
    List<Table2> getTable2(ReportAPIResult result, LangTypeEnum langType) {
        List<Table2> table2 = result.getTable2();
        table2.stream().forEach(item -> {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item.getCompetency());
            if (Objects.nonNull(maqReportLibrary)) {
                item.setCompetency(maqReportLibrary.getLangTypeContext(langType));
            }
        });
        return table2;
    }
    List<Table1> getTable1(ReportAPIResult result, LangTypeEnum langType) {
        List<Table1> table1 = result.getTable1();
        table1.stream().forEach(item -> {
            TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item.getCompetency());
            if (Objects.nonNull(maqReportLibrary)) {
                item.setCompetency(maqReportLibrary.getLangTypeContext(langType));
            }
        });
        return table1;
    }
    
    private String queryTopic(LangTypeEnum langType, String permanentId) {
        List<TQuestion> tQuestionList = tQuestionService.selectTQuestionByPermanentId(permanentId);
        if (Objects.isNull(tQuestionList) || tQuestionList.size() == 0) {
            return null;
        }
        String content = tQuestionList.get(0).getContent();
        QuestionObject questionObject = JSONObject.parseObject(content, QuestionObject.class);
        Map<String, String> titleMap = JsonUtil.toJsonObject(questionObject.getTitleContent(), HashMap.class);
        return titleMap.get(langType.getMessage());
    }
}