linzhijie
2021-04-12 3a8e1524dcf0eeb610d38123d5f0a3ef838379cd
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
package com.ots.project.tool.gen.service;
import com.alibaba.fastjson.JSONObject;
import com.ots.common.utils.StringUtils;
import com.ots.framework.web.service.DictService;
import com.ots.project.exam.domain.TExamPaper;
import com.ots.project.exam.domain.TQuestion;
import com.ots.project.exam.dto.ExamPaperTitleItemObject;
import com.ots.project.exam.dto.QuestionObject;
import com.ots.project.exam.mapper.TQuestionMapper;
import com.ots.project.tool.exam.ExamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class IExamUtilServiceImpl implements IExamUtilService {
    @Autowired
    private DictService dictService;
    @Autowired
    private TQuestionMapper questionMapper;
    @Override
    public String getLocalLangType(String langType) {
        
        if (StringUtils.equals(langType, "ALL") || StringUtils.isEmpty(langType)) {
            return dictService.getLangType(LocaleContextHolder.getLocale().toString());
        }
        return langType;
    }
    @Override
    public String getLangOrLocalLangString(String langType, String contentMapJson) {
        langType = getLocalLangType(langType);
        return ExamUtil.getLangString(langType, contentMapJson);
    }
    
    @Override
    public void setTitleName(TExamPaper tExamPaper, List<ExamPaperTitleItemObject> examPaperTitleItemObjectList) {
        
        Map<Long, String> questionIdMap = new HashMap<>();
        for (ExamPaperTitleItemObject examPaperTitleItemObject : examPaperTitleItemObjectList) {
            if (Objects.isNull(examPaperTitleItemObject.getQuestionId())) {
                continue;
            }
            questionIdMap.put(examPaperTitleItemObject.getQuestionId().longValue(), "");
        }
        if (questionIdMap.size() == 0) {
            return;
        }
        
        List<TQuestion> questionList = questionMapper.selectTQuestionByIds(new ArrayList<Long>(questionIdMap.keySet()));
        if (ExamUtil.isListEmpty(questionList)) {
            return;
        }
        questionList.stream().forEach(question -> {
            QuestionObject questionObject = JSONObject.parseObject(question.getContent(), QuestionObject.class);
            questionIdMap.put(question.getId(), getLangOrLocalLangString(tExamPaper.getLangType(), questionObject.getTitleContent()));
        });
        
        for (ExamPaperTitleItemObject examPaperTitleItemObject : examPaperTitleItemObjectList) {
            
            examPaperTitleItemObject.setName(questionIdMap.get(examPaperTitleItemObject.getQuestionId().longValue()));
        }
    }
}