package com.mindskip.xzs.service.impl;
import com.mindskip.xzs.domain.*;
import com.mindskip.xzs.domain.enums.ExamPaperAnswerStatusEnum;
import com.mindskip.xzs.domain.enums.ExamPaperTypeEnum;
import com.mindskip.xzs.domain.enums.QuestionTypeEnum;
import com.mindskip.xzs.domain.exam.ExamPaperTitleItemObject;
import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.domain.other.ExamPaperAnswerUpdate;
import com.mindskip.xzs.domain.task.TaskItemAnswerObject;
import com.mindskip.xzs.repository.*;
import com.mindskip.xzs.repository.ExamPaperAnswerMapper;
import com.mindskip.xzs.repository.ExamPaperMapper;
import com.mindskip.xzs.repository.QuestionMapper;
import com.mindskip.xzs.repository.TaskExamCustomerAnswerMapper;
import com.mindskip.xzs.service.ExamPaperAnswerService;
import com.mindskip.xzs.service.ExamPaperQuestionCustomerAnswerService;
import com.mindskip.xzs.service.TextContentService;
import com.mindskip.xzs.utility.DateTimeUtil;
import com.mindskip.xzs.utility.ExamUtil;
import com.mindskip.xzs.utility.JsonUtil;
import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitItemVM;
import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitVM;
import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ExamPaperAnswerServiceImpl extends BaseServiceImpl<ExamPaperAnswer> implements ExamPaperAnswerService {
private final ExamPaperAnswerMapper examPaperAnswerMapper;
private final ExamPaperMapper examPaperMapper;
private final TextContentService textContentService;
private final QuestionMapper questionMapper;
private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;
private final TaskExamCustomerAnswerMapper taskExamCustomerAnswerMapper;
@Autowired
public ExamPaperAnswerServiceImpl(ExamPaperAnswerMapper examPaperAnswerMapper, ExamPaperMapper examPaperMapper, TextContentService textContentService, QuestionMapper questionMapper, ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService, TaskExamCustomerAnswerMapper taskExamCustomerAnswerMapper) {
super(examPaperAnswerMapper);
this.examPaperAnswerMapper = examPaperAnswerMapper;
this.examPaperMapper = examPaperMapper;
this.textContentService = textContentService;
this.questionMapper = questionMapper;
this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService;
this.taskExamCustomerAnswerMapper = taskExamCustomerAnswerMapper;
}
@Override
public PageInfo<ExamPaperAnswer> studentPage(ExamPaperAnswerPageVM requestVM) {
return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
examPaperAnswerMapper.studentPage(requestVM));
}
@Override
public ExamPaperAnswerInfo calculateExamPaperAnswer(ExamPaperSubmitVM examPaperSubmitVM, User user) {
ExamPaperAnswerInfo examPaperAnswerInfo = new ExamPaperAnswerInfo();
Date now = new Date();
ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(examPaperSubmitVM.getId());
ExamPaperTypeEnum paperTypeEnum = ExamPaperTypeEnum.fromCode(examPaper.getPaperType());
//任务试卷只能做一次
if (paperTypeEnum == ExamPaperTypeEnum.Task) {
ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.getByPidUid(examPaperSubmitVM.getId(), user.getId());
if (null != examPaperAnswer)
return null;
}
String frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId()).getContent();
List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent, ExamPaperTitleItemObject.class);
List<Integer> questionIds = examPaperTitleItemObjects.stream().flatMap(t -> t.getQuestionItems().stream().map(q -> q.getId())).collect(Collectors.toList());
List<Question> questions = questionMapper.selectByIds(questionIds);
//将题目结构的转化为题目答案
List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers = examPaperTitleItemObjects.stream()
.flatMap(t -> t.getQuestionItems().stream()
.map(q -> {
Question question = questions.stream().filter(tq -> tq.getId().equals(q.getId())).findFirst().get();
ExamPaperSubmitItemVM customerQuestionAnswer = examPaperSubmitVM.getAnswerItems().stream()
.filter(tq -> tq.getQuestionId().equals(q.getId()))
.findFirst()
.orElse(null);
return ExamPaperQuestionCustomerAnswerFromVM(question, customerQuestionAnswer, examPaper, q.getItemOrder(), user, now);
})
).collect(Collectors.toList());
ExamPaperAnswer examPaperAnswer = ExamPaperAnswerFromVM(examPaperSubmitVM, examPaper, examPaperQuestionCustomerAnswers, user, now);
examPaperAnswerInfo.setExamPaper(examPaper);
examPaperAnswerInfo.setExamPaperAnswer(examPaperAnswer);
examPaperAnswerInfo.setExamPaperQuestionCustomerAnswers(examPaperQuestionCustomerAnswers);
return examPaperAnswerInfo;
}
@Override
@Transactional
public String judge(ExamPaperSubmitVM examPaperSubmitVM) {
ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.selectByPrimaryKey(examPaperSubmitVM.getId());
List<ExamPaperSubmitItemVM> judgeItems = examPaperSubmitVM.getAnswerItems().stream().filter(d -> d.getDoRight() == null).collect(Collectors.toList());
List<ExamPaperAnswerUpdate> examPaperAnswerUpdates = new ArrayList<>(judgeItems.size());
Integer customerScore = examPaperAnswer.getUserScore();
Integer questionCorrect = examPaperAnswer.getQuestionCorrect();
for (ExamPaperSubmitItemVM d : judgeItems) {
ExamPaperAnswerUpdate examPaperAnswerUpdate = new ExamPaperAnswerUpdate();
examPaperAnswerUpdate.setId(d.getId());
examPaperAnswerUpdate.setCustomerScore(ExamUtil.scoreFromVM(d.getScore()));
boolean doRight = examPaperAnswerUpdate.getCustomerScore().equals(ExamUtil.scoreFromVM(d.getQuestionScore()));
examPaperAnswerUpdate.setDoRight(doRight);
examPaperAnswerUpdates.add(examPaperAnswerUpdate);
customerScore += examPaperAnswerUpdate.getCustomerScore();
if (examPaperAnswerUpdate.getDoRight()) {
++questionCorrect;
}
}
examPaperAnswer.setUserScore(customerScore);
examPaperAnswer.setQuestionCorrect(questionCorrect);
examPaperAnswer.setStatus(ExamPaperAnswerStatusEnum.Complete.getCode());
examPaperAnswerMapper.updateByPrimaryKeySelective(examPaperAnswer);
examPaperQuestionCustomerAnswerService.updateScore(examPaperAnswerUpdates);
ExamPaperTypeEnum examPaperTypeEnum = ExamPaperTypeEnum.fromCode(examPaperAnswer.getPaperType());
switch (examPaperTypeEnum) {
case Task:
//任务试卷批改完成后,需要更新任务的状态
ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(examPaperAnswer.getExamPaperId());
Integer taskId = examPaper.getTaskExamId();
Integer userId = examPaperAnswer.getCreateUser();
TaskExamCustomerAnswer taskExamCustomerAnswer = taskExamCustomerAnswerMapper.getB
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
校园二手交易平台:基于Java开发,包含296个文件,包括200个Java类文件、19个JavaScript文件、16个XML配置文件、13个CSS样式文件、12个PNG图像文件、5个YAML配置文件、4个字节码文件、4个JPG图像文件、2个JSON配置文件和1个类路径文件。该项目是一个校园二手交易平台,旨在为用户提供一个便捷、高效的校园内二手物品交易平台,包括商品发布、商品搜索、订单管理等功能。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的校园二手交易平台设计与实现源码 (298个子文件)
.browserslistrc 21B
index.class 2KB
indexService.class 425B
indexAction.class 420B
indexServiceImpl.class 329B
.classpath 818B
org.eclipse.wst.common.component 486B
org.eclipse.wst.jsdt.ui.superType.container 49B
chunk-vendors.4bd9a591.css 231KB
chunk-7e275898.4fbbf1ef.css 6KB
chunk-26bf5f94.eec97ea9.css 6KB
index.f1742efb.css 5KB
chunk-099b9c43.1951fa25.css 5KB
chunk-1b8c8b54.b56209ba.css 712B
chunk-604488bc.f72e8178.css 260B
chunk-69a4052e.54efd6ce.css 260B
chunk-31aa2150.ad364b97.css 260B
chunk-1d601c29.dd8c5d56.css 114B
chunk-122e80b5.dd8c5d56.css 114B
chunk-66bf5956.dd8c5d56.css 114B
chunk-912d804c.dd8c5d56.css 114B
.env.dev 25B
.editorconfig 121B
.env 11B
.eslintignore 70B
.gitignore 223B
index.html 0B
ExamPaperAnswerServiceImpl.java 16KB
ExamPaperServiceImpl.java 10KB
QuestionServiceImpl.java 8KB
ExamPaperAnswerController.java 7KB
UserController.java 7KB
UserController.java 6KB
ExamPaperAnswerController.java 6KB
DashboardController.java 6KB
DashboardController.java 6KB
UserController.java 6KB
SecurityConfigurer.java 6KB
ExamPaperQuestionCustomerAnswerServiceImpl.java 6KB
TaskExamServiceImpl.java 6KB
UserServiceImpl.java 5KB
QuestionController.java 5KB
UploadController.java 4KB
QuestionAnswerController.java 4KB
MessageController.java 4KB
User.java 4KB
UserTokenServiceImpl.java 3KB
AuthController.java 3KB
DateTimeUtil.java 3KB
CalculateExamPaperAnswerListener.java 3KB
ExamPaperQuestionCustomerAnswer.java 3KB
TaskExamCustomerAnswerImpl.java 3KB
ExamPaperAnswer.java 3KB
ExamPaper.java 3KB
ExamPaperController.java 3KB
RestAuthenticationProvider.java 3KB
Question.java 3KB
MessageServiceImpl.java 3KB
RsaUtil.java 3KB
EducationController.java 3KB
RestLoginAuthenticationFilter.java 3KB
DashboardController.java 3KB
UserMapper.java 3KB
TextContentServiceImpl.java 3KB
TokenHandlerInterceptor.java 2KB
TaskController.java 2KB
ExamPaperController.java 2KB
CacheConfig.java 2KB
ExamPaperController.java 2KB
UserService.java 2KB
RestAuthenticationSuccessHandler.java 2KB
WebMvcConfiguration.java 2KB
Message.java 2KB
ExceptionHandle.java 2KB
UserEventLogServiceImpl.java 2KB
RestLogoutSuccessHandler.java 2KB
UploadController.java 2KB
SubjectServiceImpl.java 2KB
JsonUtil.java 2KB
MessageUser.java 2KB
ExamUtil.java 2KB
TaskExam.java 2KB
EducationController.java 2KB
AuthenticationServiceImpl.java 2KB
FileUploadImpl.java 2KB
RestDetailsServiceImpl.java 2KB
UserEventLog.java 2KB
WebContext.java 2KB
UserToken.java 1KB
WxUtil.java 1KB
ErrorController.java 1KB
PageInfoHelper.java 1KB
ExamPaperMapper.java 1KB
ExamPaperQuestionCustomerAnswerMapper.java 1KB
RestResponse.java 1KB
index.java 1KB
QuestionTypeEnum.java 1KB
ExamPaperAnswerService.java 1KB
ExamPaperQuestionCustomerAnswerService.java 1KB
Subject.java 1KB
共 298 条
- 1
- 2
- 3
资源评论
沐知全栈开发
- 粉丝: 4747
- 资源: 3373
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- TCG Opal标准核心文档
- low_side_current_sense_circuit_design_an-c.pdf
- 新工程.pdsprj
- 上海大学大学生创新创业训练计划申请书(创新训练项目).doc
- matplotlib-3.8.4-cp39-cp39-macosx-10-12-x86-64.whl
- Spire.Presentation for Java 9.2.8 全功能无限制资源
- 基于51单片机和APP的电子广告牌设计.docx
- PDF Gallery_20240506_145613.pdf
- 2006高教社杯全国大学生数学建模竞赛A、B题评阅要点.doc
- fonttools-4.51.0-cp39-cp39-macosx-10-9-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功