123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package com.qxgmat.task;
- import com.alibaba.fastjson.JSONObject;
- import com.nuliji.tools.Transform;
- import com.qxgmat.data.constants.enums.QuestionDifficult;
- import com.qxgmat.data.constants.enums.QuestionType;
- import com.qxgmat.data.constants.enums.SettingKey;
- import com.qxgmat.data.constants.enums.logic.ExerciseLogic;
- import com.qxgmat.data.constants.enums.logic.SentenceLogic;
- import com.qxgmat.data.constants.enums.module.StructModule;
- import com.qxgmat.data.dao.entity.*;
- import com.qxgmat.data.relation.entity.QuestionNoRelation;
- import com.qxgmat.service.extend.ExerciseService;
- import com.qxgmat.service.extend.SentenceService;
- import com.qxgmat.service.inline.ExerciseStructService;
- import com.qxgmat.service.inline.QuestionNoService;
- import com.qxgmat.service.inline.SentenceQuestionService;
- import com.qxgmat.service.inline.SettingService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Component;
- import java.util.*;
- import java.util.stream.Collectors;
- @Component
- public class AsyncTask {
- private static final Logger logger = LoggerFactory.getLogger(AsyncTask.class);
- @Autowired
- private SentenceQuestionService sentenceQuestionService;
- @Autowired
- private SentenceService sentenceService;
- @Autowired
- private ExerciseService exerciseService;
- @Autowired
- private QuestionNoService questionNoService;
- @Autowired
- private ExerciseStructService exerciseStructService;
- @Autowired
- private SettingService settingService;
- @Async
- public void autoExercisePaper() {
- logger.info("自动练习组卷:顺序,考点,难易度");
- long start = System.currentTimeMillis();
- Setting setting = settingService.getByKey(SettingKey.EXERCISE_PAPER_STATUS);
- JSONObject status = setting.getValue();
- if (status == null) {
- status = new JSONObject();
- }
- int progress = 0;
- status.put("progress", 10);
- settingService.edit(setting);
- // 按所有4级结构
- List<ExerciseStruct> p = exerciseStructService.all();
- for(ExerciseStruct struct : p){
- if (struct.getLevel()!=4){
- continue;
- }
- progress += 70 / p.size();
- status.put("progress", progress);
- settingService.edit(setting);
- String prefixTitle = String.format("%s%s", struct.getTitleEn(), struct.getTitleZh());
- QuestionType questionType = QuestionType.ValueOf(struct.getExtend());
- List<QuestionNoRelation> list = questionNoService.listWithRelationByStruct(StructModule.EXERCISE, struct.getId());
- // 按顺序组卷
- List<ExercisePaper> noPapers = exerciseService.createPaper(prefixTitle, questionType, struct.getParentId(), struct.getId(), exerciseService.paperLength, ExerciseLogic.NO, null, list);
- Collection noIds = Transform.getIds(noPapers, SentencePaper.class, "id");
- exerciseService.switchPaper(struct.getParentId(), struct.getId(), ExerciseLogic.NO, noIds);
- // 按难度组卷
- List<Integer> allDifficultIds = new ArrayList<>();
- for(QuestionDifficult difficult : QuestionDifficult.all()){
- List<QuestionNoRelation> difficultList = list.stream().filter((question)-> question.getQuestion().getDifficult().equals(difficult.key)).collect(Collectors.toList());
- List<ExercisePaper> difficultPapers = exerciseService.createPaper(String.format("%s %s", prefixTitle, difficult.key), questionType, struct.getParentId(), struct.getId(), exerciseService.paperLength, ExerciseLogic.DIFFICULT, difficult.key, difficultList);
- Collection difficultIds = Transform.getIds(difficultPapers, ExercisePaper.class, "id");
- allDifficultIds.addAll(difficultIds);
- }
- exerciseService.switchPaper(struct.getParentId(), struct.getId(), ExerciseLogic.DIFFICULT, allDifficultIds);
- // 按考点组卷
- Map<String, List<QuestionNoRelation>> placeMap = new HashMap<>();
- for(QuestionNoRelation relation:list){
- String place = relation.getQuestion().getPlace();
- if (!placeMap.containsKey(place)){
- placeMap.put(place, new ArrayList<>());
- }
- List<QuestionNoRelation> placeList = placeMap.get(place);
- placeList.add(relation);
- }
- List<Integer> allPlaceIds = new ArrayList<>();
- for(String place: placeMap.keySet()){
- List<QuestionNoRelation> placeList = placeMap.get(place);
- List<ExercisePaper> difficultPapers = exerciseService.createPaper(String.format("%s %s", prefixTitle, place), questionType, struct.getParentId(), struct.getId(), exerciseService.paperLength, ExerciseLogic.PLACE, place, placeList);
- Collection placeIds = Transform.getIds(difficultPapers, ExercisePaper.class, "id");
- allPlaceIds.addAll(placeIds);
- }
- exerciseService.switchPaper(struct.getParentId(), struct.getId(), ExerciseLogic.PLACE, allPlaceIds);
- // 按难易度组卷:保持和下方难易度组卷一致
- list.sort((x, y)-> {
- // 难度从高到低
- Integer xScore = x.getTotalCorrect() * 100/ x.getTotalNumber();
- Integer yScore = y.getTotalCorrect() * 100/ y.getTotalNumber();
- return yScore.compareTo(xScore);
- });
- List<ExercisePaper> errorPapers = exerciseService.createPaper(prefixTitle, questionType, struct.getParentId(), struct.getId(), exerciseService.paperLength, ExerciseLogic.ERROR, null, list);
- Collection errorIds = Transform.getIds(errorPapers, SentencePaper.class, "id");
- exerciseService.switchPaper(struct.getParentId(), struct.getId(), ExerciseLogic.ERROR, errorIds);
- }
- status.put("progress", 80);
- settingService.edit(setting);
- // 作文组卷
- for(ExerciseStruct struct : p){
- if (struct.getLevel()!=3 || !struct.getExtend().equals(QuestionType.AWA.key)){
- continue;
- }
- String prefixTitle = String.format("%s%s", struct.getTitleEn(), struct.getTitleZh());
- QuestionType questionType = QuestionType.ValueOf(struct.getExtend());
- List<QuestionNoRelation> list = questionNoService.listWithRelationByStruct(StructModule.EXERCISE, struct.getId());
- // 按顺序组卷
- List<ExercisePaper> noPapers = exerciseService.createPaper(prefixTitle, questionType, struct.getId(), 0, exerciseService.awaLength, ExerciseLogic.NO, null, list);
- Collection noIds = Transform.getIds(noPapers, SentencePaper.class, "id");
- exerciseService.switchPaper(struct.getId(), 0, ExerciseLogic.NO, noIds);
- }
- status.put("progress", 80);
- settingService.edit(setting);
- // 逻辑组卷
- for(ExerciseStruct struct : p){
- if (struct.getLevel()!=3 || !struct.getExtend().equals(QuestionType.IR.key)){
- continue;
- }
- String prefixTitle = String.format("%s%s", struct.getTitleEn(), struct.getTitleZh());
- QuestionType questionType = QuestionType.ValueOf(struct.getExtend());
- List<QuestionNoRelation> list = questionNoService.listWithRelationByStruct(StructModule.EXERCISE, struct.getId());
- // 按顺序组卷
- List<ExercisePaper> noPapers = exerciseService.createPaper(prefixTitle, questionType, struct.getId(), 0, exerciseService.irLength, ExerciseLogic.NO, null, list);
- Collection noIds = Transform.getIds(noPapers, SentencePaper.class, "id");
- exerciseService.switchPaper(struct.getId(), 0, ExerciseLogic.NO, noIds);
- }
- status.put("progress", 100);
- settingService.edit(setting);
- long end = System.currentTimeMillis();
- logger.info("自动练习组卷,耗时:" + (end - start) + "毫秒");
- }
- @Async
- public void autoExercisePaperError() {
- logger.info("自动练习:难易度组卷,全局难易度判断");
- long start = System.currentTimeMillis();
- // 按所有4级结构
- List<ExerciseStruct> p = exerciseStructService.all();
- for(ExerciseStruct struct : p){
- if (struct.getLevel()!=4){
- continue;
- }
- String prefixTitle = String.format("%s%s", struct.getTitleEn(), struct.getTitleZh());
- QuestionType questionType = QuestionType.ValueOf(struct.getExtend());
- List<QuestionNoRelation> list = questionNoService.listWithRelationByStruct(StructModule.EXERCISE, struct.getId());
- // 按难易度组卷:保持和上方难易度组卷一致
- list.sort((x, y)-> {
- // 难度从高到低
- Integer xScore = x.getTotalCorrect() * 100/ x.getTotalNumber();
- Integer yScore = y.getTotalCorrect() * 100/ y.getTotalNumber();
- return yScore.compareTo(xScore);
- });
- List<ExercisePaper> errorPapers = exerciseService.createPaper(prefixTitle, questionType, struct.getParentId(), struct.getId(), exerciseService.paperLength, ExerciseLogic.ERROR, null, list);
- Collection errorIds = Transform.getIds(errorPapers, SentencePaper.class, "id");
- exerciseService.switchPaper(struct.getParentId(), struct.getId(), ExerciseLogic.ERROR, errorIds);
- }
- long end = System.currentTimeMillis();
- logger.info("自动练习难易度组卷,耗时:" + (end - start) + "毫秒");
- }
- @Async
- public void autoSentencePaper() {
- logger.info("自动长难句:对于试用卷进行自动生成");
- long start = System.currentTimeMillis();
- Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS);
- JSONObject status = setting.getValue();
- if (status == null) {
- status = new JSONObject();
- }
- status.put("progress", 10);
- settingService.edit(setting);
- // 获取所有组卷长难句题目
- List<SentenceQuestion> list = sentenceQuestionService.allPaper();
- status.put("progress", 20);
- settingService.edit(setting);
- // 组正常卷
- List<SentencePaper> noPapers = sentenceService.createPaper("长难句", SentenceLogic.NO, list);
- status.put("progress", 30);
- settingService.edit(setting);
- Collection noIds = Transform.getIds(noPapers, SentencePaper.class, "id");
- status.put("progress", 40);
- settingService.edit(setting);
- sentenceService.switchPaper(SentenceLogic.NO, noIds);
- status.put("progress", 60);
- settingService.edit(setting);
- // 组试用卷
- List<SentenceQuestion> trailList = list.stream().filter((question)-> question.getIsTrail() > 0).collect(Collectors.toList());
- List<SentencePaper> trailPapers = sentenceService.createPaper("长难句试用", SentenceLogic.TRAIL, trailList);
- status.put("progress", 70);
- settingService.edit(setting);
- Collection trailIds = Transform.getIds(trailPapers, SentencePaper.class, "id");
- status.put("progress", 80);
- settingService.edit(setting);
- sentenceService.switchPaper(SentenceLogic.TRAIL, trailIds);
- status.put("progress", 100);
- settingService.edit(setting);
- long end = System.currentTimeMillis();
- logger.info("自动长难句组卷,耗时:" + (end - start) + "毫秒");
- }
- @Async
- public void postTextbookToEmail(){
- logger.info("发布机经:发送到订阅用户邮箱");
- long start = System.currentTimeMillis();
- // 获取订阅用户及其邮箱
- long end = System.currentTimeMillis();
- logger.info("发布机经,耗时:" + (end - start) + "毫秒");
- }
- }
|