| | |
| | | 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 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); |
| | | } |
| | | |
| | | |
| | | // Job 工作分析文具的大题目去取question表 |
| | | @Override |
| | | public void setTitleName(TExamPaper tExamPaper, List<ExamPaperTitleItemObject> examPaperTitleItemObjectList) { |
| | | |
| | | // 工作分析问卷的大题,大题里面如果有questionId,就取questionId的题目 |
| | | 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; |
| | | } |
| | | |
| | | |
| | | // 如果有questionid就是工作分析问卷,要取question表的 |
| | | 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) { |
| | | |
| | | // name就是段的题目 |
| | | examPaperTitleItemObject.setName(questionIdMap.get(examPaperTitleItemObject.getQuestionId().longValue())); |
| | | } |
| | | |
| | | } |
| | | } |