123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- package com.qxgmat.service.extend;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.nuliji.tools.Transform;
- import com.nuliji.tools.exception.ParameterException;
- import com.qxgmat.data.constants.enums.QuestionType;
- import com.qxgmat.data.constants.enums.user.AskTarget;
- import com.qxgmat.data.constants.enums.user.ExportType;
- import com.qxgmat.data.dao.entity.*;
- import com.qxgmat.data.inline.ExportCourseNote;
- import com.qxgmat.data.inline.ExportQuestion;
- import com.qxgmat.data.relation.entity.QuestionNoRelation;
- import com.qxgmat.data.relation.entity.UserNoteCourseRelation;
- import com.qxgmat.data.relation.entity.UserQuestionRelation;
- import com.qxgmat.service.UserNoteCourseService;
- import com.qxgmat.service.UserNoteQuestionService;
- import com.qxgmat.service.UserQuestionService;
- import com.qxgmat.service.inline.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.*;
- @Service
- public class ExportService {
- @Autowired
- private UserNoteQuestionService userNoteQuestionService;
- @Autowired
- private UserNoteCourseService userNoteCourseService;
- @Autowired
- private CourseNoService courseNoService;
- @Autowired
- private QuestionService questionService;
- @Autowired
- private QuestionNoService questionNoService;
- @Autowired
- private UserAskQuestionService userAskQuestionService;
- @Autowired
- private UserQuestionService userQuestionService;
- @Resource
- private UserExportService userExportService;
- public UserExport addQuestionCollect(Integer userId, JSONObject setting){
- JSONArray questionNoIds = setting.getJSONArray("questionNoIds");
- if (questionNoIds.size() ==0){
- throw new ParameterException("不可小于1题,请重新选择");
- }
- if (questionNoIds.size() >100){
- throw new ParameterException("不可多余100题,请重新选择");
- }
- JSONArray include = setting.getJSONArray("include");
- List<UserQuestionRelation> relationList = this.listByQuestionNoIds(userId, questionNoIds.toJavaList(Integer.class), false);
- JSONObject content = new JSONObject();
- JSONArray list = new JSONArray();
- for(UserQuestionRelation relation : relationList){
- if (!include.contains(AskTarget.QUESTION.key)){
- relation.getQuestion().setStem(null);
- if (relation.getNote() != null) relation.getNote().setQuestionContent(null);
- }
- if (!include.contains(AskTarget.QX.key)){
- relation.getQuestion().setQxContent(null);
- if (relation.getNote() != null) relation.getNote().setQxContent(null);
- }
- if (!include.contains(AskTarget.OFFICIAL.key)){
- relation.getQuestion().setOfficialContent(null);
- if (relation.getNote() != null) relation.getNote().setOfficialContent(null);
- }
- if (!include.contains(AskTarget.ASSOCIATION.key)){
- relation.setAssociations(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setAssociationContent(null);
- }
- if (!include.contains(AskTarget.QA.key)){
- relation.setAsks(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setQaContent(null);
- }
- if (!include.contains("note")){
- relation.setNote(null);
- }
- list.add(Transform.convert(relation, ExportQuestion.class));
- }
- content.put("list", list);
- int count = userExportService.countByUser(userId, ExportType.QUESTION_COLLECT);
- UserExport export = UserExport.builder()
- .userId(userId)
- .type(ExportType.QUESTION_COLLECT.key)
- .setting(setting)
- .content(content)
- .no(count+1)
- .build();
- return userExportService.add(export);
- }
- public UserExport addQuestionError(Integer userId, JSONObject setting){
- JSONArray questionNoIds = setting.getJSONArray("questionNoIds");
- if (questionNoIds.size() ==0){
- throw new ParameterException("不可小于1题,请重新选择");
- }
- if (questionNoIds.size() >100){
- throw new ParameterException("不可多余100题,请重新选择");
- }
- JSONArray include = setting.getJSONArray("include");
- List<UserQuestionRelation> relationList = this.listByQuestionNoIds(userId, questionNoIds.toJavaList(Integer.class), true);
- JSONObject content = new JSONObject();
- JSONArray list = new JSONArray();
- for(UserQuestionRelation relation : relationList){
- if (!include.contains(AskTarget.QUESTION.key)){
- relation.getQuestion().setStem(null);
- if (relation.getNote() != null) relation.getNote().setQuestionContent(null);
- }
- if (!include.contains(AskTarget.QX.key)){
- relation.getQuestion().setQxContent(null);
- if (relation.getNote() != null) relation.getNote().setQxContent(null);
- }
- if (!include.contains(AskTarget.OFFICIAL.key)){
- relation.getQuestion().setOfficialContent(null);
- if (relation.getNote() != null) relation.getNote().setOfficialContent(null);
- }
- if (!include.contains(AskTarget.ASSOCIATION.key)){
- relation.setAssociations(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setAssociationContent(null);
- }
- if (!include.contains(AskTarget.QA.key)){
- relation.setAsks(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setQaContent(null);
- }
- if (!include.contains("note")){
- relation.setNote(null);
- }
- list.add(Transform.convert(relation, ExportQuestion.class));
- }
- content.put("list", list);
- int count = userExportService.countByUser(userId, ExportType.QUESTION_ERROR);
- UserExport export = UserExport.builder()
- .userId(userId)
- .type(ExportType.QUESTION_ERROR.key)
- .setting(setting)
- .content(content)
- .no(count + 1)
- .build();
- return userExportService.add(export);
- }
- public UserExport addQuestionNote(Integer userId, JSONObject setting){
- JSONArray questionNoIds = setting.getJSONArray("questionNoIds");
- if (questionNoIds.size() ==0){
- throw new ParameterException("不可小于1题,请重新选择");
- }
- if (questionNoIds.size() >100){
- throw new ParameterException("不可多余100题,请重新选择");
- }
- JSONArray include = setting.getJSONArray("include");
- List<UserQuestionRelation> relationList = this.listByQuestionNoIds(userId, questionNoIds.toJavaList(Integer.class), true);
- JSONObject content = new JSONObject();
- JSONArray list = new JSONArray();
- for(UserQuestionRelation relation : relationList){
- if (!include.contains(AskTarget.QUESTION.key)){
- relation.getQuestion().setStem(null);
- if (relation.getNote() != null) relation.getNote().setQuestionContent(null);
- }
- if (!include.contains(AskTarget.QX.key)){
- relation.getQuestion().setQxContent(null);
- if (relation.getNote() != null) relation.getNote().setQxContent(null);
- }
- if (!include.contains(AskTarget.OFFICIAL.key)){
- relation.getQuestion().setOfficialContent(null);
- if (relation.getNote() != null) relation.getNote().setOfficialContent(null);
- }
- if (!include.contains(AskTarget.ASSOCIATION.key)){
- relation.setAssociations(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setAssociationContent(null);
- }
- if (!include.contains(AskTarget.QA.key)){
- relation.setAsks(new ArrayList<>());
- if (relation.getNote() != null) relation.getNote().setQaContent(null);
- }
- if (!include.contains("note")){
- relation.setNote(null);
- }
- list.add(Transform.convert(relation, ExportQuestion.class));
- }
- content.put("list", list);
- int count = userExportService.countByUser(userId, ExportType.NOTE_QUESTION);
- UserExport export = UserExport.builder()
- .userId(userId)
- .type(ExportType.NOTE_QUESTION.key)
- .setting(setting)
- .content(content)
- .no(count + 1)
- .build();
- return userExportService.add(export);
- }
- public UserExport addCourseNote(Integer userId, JSONObject setting){
- JSONArray courseNoIds = setting.getJSONArray("courseNoIds");
- if (courseNoIds.size() ==0){
- throw new ParameterException("不可小于1题,请重新选择");
- }
- if (courseNoIds.size() >100){
- throw new ParameterException("不可多余100题,请重新选择");
- }
- List<UserNoteCourse> noteList = userNoteCourseService.listByCourseNo(userId, courseNoIds.toJavaList(Integer.class));
- List<CourseNo> courseNoList = courseNoService.select(courseNoIds.toJavaList(Integer.class));
- Map courseNoMap = Transform.getMap(courseNoList, CourseNo.class, "id");
- JSONObject content = new JSONObject();
- JSONArray list = new JSONArray();
- for(UserNoteCourse note : noteList){
- UserNoteCourseRelation relation = Transform.convert(note, UserNoteCourseRelation.class);
- relation.setCourseNo((CourseNo)courseNoMap.get(note.getCourseNoId()));
- list.add(Transform.convert(relation, ExportCourseNote.class));
- }
- content.put("list", list);
- int count = userExportService.countByUser(userId, ExportType.NOTE_COURSE);
- UserExport export = UserExport.builder()
- .userId(userId)
- .type(ExportType.NOTE_COURSE.key)
- .setting(setting)
- .content(content)
- .no(count + 1)
- .build();
- return userExportService.add(export);
- }
- private List<UserQuestionRelation> listByQuestionNoIds(Integer userId, Collection questionNoIds, boolean needAnswer){
- List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
- Collection questionIds = Transform.getIds(questionNoList, QuestionNo.class, "questionId");
- List<UserQuestion> userQuestionList = null;
- if (needAnswer){
- // 查询所有id的最后一次做题记录
- userQuestionList = userQuestionService.listWithLast(userId, questionNoIds);
- }else{
- userQuestionList = new ArrayList<>();
- for(Object questionNoId : questionNoIds){
- userQuestionList.add(UserQuestion.builder()
- .questionNoId((Integer)questionNoId)
- .build());
- }
- }
- List<UserQuestionRelation> relationList = Transform.convert(userQuestionList, UserQuestionRelation.class);
- Transform.combine(relationList, questionNoList, UserQuestionRelation.class, "questionNoId", "questionNo", QuestionNo.class, "id");
- // Map questionNoMap = Transform.getMap(questionNoList, QuestionNo.class, "id", "questionId");
- // Transform.combine(relationList, questionNoMap, UserQuestionRelation.class, "questionNoId", "questionId");
- List<Question> questionList = questionService.select(questionIds);
- for(Question question : questionList){
- if (QuestionType.ValueOf(question.getQuestionType()) == QuestionType.IR){
- throw new ParameterException("“综合推理IR”暂时无法导出。");
- }
- }
- Transform.combine(relationList, questionList, UserQuestionRelation.class, "questionId", "question", Question.class, "id");
- // 题源联想
- Map<Integer, Integer[]> questionIdsMap = new HashMap<>();
- for(Question q : questionList){
- questionIdsMap.put(q.getId(), q.getAssociationContent());
- }
- Map questionMap = questionService.groupByMap(questionIdsMap);
- Transform.combine(relationList, questionMap, UserQuestionRelation.class, "questionId", "associations");
- // 相关问答
- Map<Object, Collection<UserAskQuestion>> userAskMap = userAskQuestionService.groupByQuestionNo(questionIds);
- Transform.combine(relationList, userAskMap, UserQuestionRelation.class, "questionId", "asks");
- // 笔记
- List<UserNoteQuestion> userNoteQuestionList = userNoteQuestionService.listByUserAndQuestions(userId, questionIds);
- Transform.combine(relationList, userNoteQuestionList, UserQuestionRelation.class, "questionId", "note", UserNoteQuestion.class, "questionId");
- return relationList;
- }
- }
|