|
|
@@ -84,8 +84,10 @@ import com.zhongzheng.modules.user.bo.UserPhoneBo;
|
|
|
import com.zhongzheng.modules.user.bo.UserStudyRecordAddBo;
|
|
|
import com.zhongzheng.modules.user.domain.School;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
+import com.zhongzheng.modules.user.domain.UserExamRecord;
|
|
|
import com.zhongzheng.modules.user.domain.UserStudyRecord;
|
|
|
import com.zhongzheng.modules.user.service.ISchoolService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserExamRecordService;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import com.zhongzheng.modules.user.service.IUserStudyRecordService;
|
|
|
import com.zhongzheng.modules.user.vo.SubjectStudyRecordVo;
|
|
|
@@ -109,6 +111,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
import static java.math.RoundingMode.HALF_UP;
|
|
|
|
|
|
@@ -233,6 +236,8 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
private ICertificateTpService iCertificateTpService;
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
+ @Autowired
|
|
|
+ private IUserExamRecordService iUserExamRecordService;
|
|
|
|
|
|
@Autowired
|
|
|
private IUserStudyRecordService iUserStudyRecordService;
|
|
|
@@ -5782,6 +5787,108 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean disposeQuestion(Long goodsId) {
|
|
|
+ Goods goods = getById(goodsId);
|
|
|
+ if (Objects.isNull(goods)) {
|
|
|
+ throw new CustomException("商品ID有误");
|
|
|
+ }
|
|
|
+ if (goods.getGoodsType() != 2){
|
|
|
+ throw new CustomException("不是题库商品");
|
|
|
+ }
|
|
|
+ //获取所有试卷
|
|
|
+ List<GoodsAttached> list = iGoodsAttachedService.list(new LambdaQueryWrapper<GoodsAttached>().eq(GoodsAttached::getGoodsId, goods.getGoodsId()).eq(GoodsAttached::getType, 1));
|
|
|
+ //模块卷
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (GoodsAttached goodsAttached : list) {
|
|
|
+ List<QuestionModuleChapter> chapterList = iQuestionModuleChapterService.list(new LambdaQueryWrapper<QuestionModuleChapter>().eq(QuestionModuleChapter::getModuleExamId, goodsAttached.getMajorId()));
|
|
|
+ if (CollectionUtils.isEmpty(chapterList)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<Long> chapterIds = chapterList.stream().map(QuestionModuleChapter::getChapterExamId).collect(Collectors.toList());
|
|
|
+ List<QuestionChapterExam> chapterExams = iQuestionChapterExamService.list(new LambdaQueryWrapper<QuestionChapterExam>().in(QuestionChapterExam::getChapterExamId, chapterIds));
|
|
|
+ if (CollectionUtils.isEmpty(chapterExams)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (QuestionChapterExam chapterExam : chapterExams) {
|
|
|
+ List<ExamQuestion> examQuestions = iExamQuestionService.list(new LambdaQueryWrapper<ExamQuestion>().eq(ExamQuestion::getExamId, chapterExam.getExamId()));
|
|
|
+ if (CollectionUtils.isEmpty(examQuestions)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取所有题目id
|
|
|
+ List<Long> questionIds = examQuestions.stream().map(ExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ //根据数量分割 100题为一组
|
|
|
+ int total = questionIds.size();
|
|
|
+ List<List<Long>> colquestionList = IntStream.range(0, (total + 100 - 1) / 100)
|
|
|
+ .mapToObj(i -> questionIds.subList(
|
|
|
+ i * 100,
|
|
|
+ Math.min((i + 1) * 100, total)
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Exam exam = iExamService.getById(chapterExam.getExamId());
|
|
|
+ List<QuestionBusiness> businesses = iQuestionBusinessService.list(new LambdaQueryWrapper<QuestionBusiness>()
|
|
|
+ .eq(QuestionBusiness::getMajorId, exam.getExamId()).eq(QuestionBusiness::getType, 2));
|
|
|
+ //重新组装数据
|
|
|
+ for (int i = 0; i < colquestionList.size(); i++) {
|
|
|
+
|
|
|
+ Exam bean = BeanUtil.toBean(exam, Exam.class);
|
|
|
+ bean.setExamId(null);
|
|
|
+ bean.setCode(ServletUtils.getEncoded("SJ"));
|
|
|
+ bean.setExamName(String.format("%s(%s)",bean.getExamName(),i+1));
|
|
|
+ iExamService.save(bean);
|
|
|
+
|
|
|
+ List<QuestionBusiness> questionBusinesses = businesses.stream().map(y -> {
|
|
|
+ y.setMajorId(bean.getExamId());
|
|
|
+ y.setId(null);
|
|
|
+ return y;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iQuestionBusinessService.saveBatch(questionBusinesses);
|
|
|
+
|
|
|
+ List<Long> idList = colquestionList.get(i);
|
|
|
+ List<ExamQuestion> examQuestionList = IntStream.range(0, idList.size())
|
|
|
+ .mapToObj(index -> {
|
|
|
+ Long questionId = idList.get(index);
|
|
|
+ ExamQuestion examQuestion = new ExamQuestion();
|
|
|
+ examQuestion.setExamId(bean.getExamId());
|
|
|
+ examQuestion.setSort(index + 1);
|
|
|
+ examQuestion.setQuestionId(questionId);
|
|
|
+ examQuestion.setScore(BigDecimal.ZERO);
|
|
|
+ examQuestion.setPartScore(BigDecimal.ZERO);
|
|
|
+ return examQuestion;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iExamQuestionService.saveBatch(examQuestionList);
|
|
|
+
|
|
|
+ //试卷章
|
|
|
+ QuestionChapterExam questionChapterExam = new QuestionChapterExam();
|
|
|
+ questionChapterExam.setChapterExamId(chapterExam.getChapterExamId());
|
|
|
+ questionChapterExam.setExamId(bean.getExamId());
|
|
|
+ questionChapterExam.setSort(i+1L);
|
|
|
+ iQuestionChapterExamService.save(questionChapterExam);
|
|
|
+ }
|
|
|
+
|
|
|
+ //清除记录
|
|
|
+ List<UserExamRecord> records = iUserExamRecordService.list(new LambdaQueryWrapper<UserExamRecord>().eq(UserExamRecord::getExamId, exam.getExamId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(records)){
|
|
|
+ iUserExamRecordService.removeByIds(records.stream().map(UserExamRecord::getRecordId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除之前的试卷
|
|
|
+ iExamService.removeById(exam.getExamId());
|
|
|
+
|
|
|
+ //删除之前试卷和题的关联关系
|
|
|
+ iExamQuestionService.removeByIds(examQuestions.stream().map(ExamQuestion::getId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ }
|
|
|
+ //删除之前试卷和章的关联关系
|
|
|
+ iQuestionChapterExamService.removeByIds(chapterExams.stream().map(QuestionChapterExam::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void updateHandoutsId(Long goodsId, Long tenantId, Long handoutsId) {
|
|
|
baseMapper.updateHandoutsId(goodsId, tenantId, handoutsId);
|
|
|
}
|