Browse Source

构建问题详情

master
luoweijian 2 weeks ago
parent
commit
8e7226ae6a
  1. 2
      src/main/java/com/project/exam/application/ExamRecordApplicationService.java
  2. 7
      src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java
  3. 6
      src/main/java/com/project/exam/controller/ExamRecordController.java
  4. 4
      src/main/java/com/project/exam/domain/dto/ExamRecordDTO.java
  5. 9
      src/main/java/com/project/exam/domain/service/GetDetailExamRecordDomainService.java
  6. 18
      src/main/java/com/project/exam/domain/service/impl/AssemblePaperDomainServiceImpl.java
  7. 37
      src/main/java/com/project/exam/domain/service/impl/BuildExamRecordDomainServiceImpl.java
  8. 24
      src/main/java/com/project/exam/domain/service/impl/GetDetailExamRecordDomainServiceImpl.java

2
src/main/java/com/project/exam/application/ExamRecordApplicationService.java

@ -21,4 +21,6 @@ public interface ExamRecordApplicationService {
Result<PageResult<ExamRecordDTO>> adminSearch(ExamRecordParam param) throws Exception; Result<PageResult<ExamRecordDTO>> adminSearch(ExamRecordParam param) throws Exception;
void export(ExamRecordParam appealParam, HttpServletResponse response) throws Exception; void export(ExamRecordParam appealParam, HttpServletResponse response) throws Exception;
Result<ExamRecordDTO> getDetail(Long id) throws Exception;
} }

7
src/main/java/com/project/exam/application/impl/ExamRecordApplicationServiceImpl.java

@ -33,6 +33,8 @@ public class ExamRecordApplicationServiceImpl implements ExamRecordApplicationSe
@Autowired @Autowired
private AdminExportExamRecordDomainService adminExportExamRecordDomainService; private AdminExportExamRecordDomainService adminExportExamRecordDomainService;
@Autowired
private GetDetailExamRecordDomainService getDetailExamRecordDomainService;
@Override @Override
public Result<PageResult<ExamRecordDTO>> adminSearch(ExamRecordParam param) throws Exception { public Result<PageResult<ExamRecordDTO>> adminSearch(ExamRecordParam param) throws Exception {
@ -44,6 +46,11 @@ public class ExamRecordApplicationServiceImpl implements ExamRecordApplicationSe
adminExportExamRecordDomainService.export(examRecordParam , response); adminExportExamRecordDomainService.export(examRecordParam , response);
} }
@Override
public Result<ExamRecordDTO> getDetail(Long id) throws Exception {
return getDetailExamRecordDomainService.getDetail(id);
}
@Override @Override
public Result<ExamRecordDTO> assemblePaper(Long taskId) throws Exception { public Result<ExamRecordDTO> assemblePaper(Long taskId) throws Exception {
return Result.success(assemblePaperDomainService.assemblePaper(taskId , SecurityUtils.getUserId())); return Result.success(assemblePaperDomainService.assemblePaper(taskId , SecurityUtils.getUserId()));

6
src/main/java/com/project/exam/controller/ExamRecordController.java

@ -6,6 +6,7 @@ import com.project.exam.application.ExamRecordApplicationService;
import com.project.exam.domain.dto.ExamRecordDTO; import com.project.exam.domain.dto.ExamRecordDTO;
import com.project.exam.domain.dto.ExamRecordPictureDTO; import com.project.exam.domain.dto.ExamRecordPictureDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -38,5 +39,10 @@ public class ExamRecordController {
return examRecordApplicationService.savePicture(file , recordId); return examRecordApplicationService.savePicture(file , recordId);
} }
@GetMapping("/getDetail")
public Result<ExamRecordDTO> getDetail(Long id) throws Exception {
return examRecordApplicationService.getDetail(id);
}
} }

4
src/main/java/com/project/exam/domain/dto/ExamRecordDTO.java

@ -46,11 +46,15 @@ public class ExamRecordDTO extends BaseDTO {
@Data @Data
public static class QuestionSnapshotDTO { public static class QuestionSnapshotDTO {
// 序号
private Integer index;
private Long questionId; private Long questionId;
// 题干原文 // 题干原文
private String questionContent; private String questionContent;
// 题型 // 题型
private Integer type; private Integer type;
// 题型中文
private String typeText;
// 用户看的选项:{"A":"xxx", "B":"yyy"} // 用户看的选项:{"A":"xxx", "B":"yyy"}
private Map<String, String> options; private Map<String, String> options;
// 正确项 // 正确项

9
src/main/java/com/project/exam/domain/service/GetDetailExamRecordDomainService.java

@ -0,0 +1,9 @@
package com.project.exam.domain.service;
import com.project.base.domain.result.Result;
import com.project.exam.domain.dto.ExamRecordDTO;
public interface GetDetailExamRecordDomainService {
Result<ExamRecordDTO> getDetail(Long id) throws Exception;
}

18
src/main/java/com/project/exam/domain/service/impl/AssemblePaperDomainServiceImpl.java

@ -83,11 +83,6 @@ public class AssemblePaperDomainServiceImpl implements AssemblePaperDomainServic
@Autowired @Autowired
private QuestionInventoryDomainService questionInventoryDomainService; private QuestionInventoryDomainService questionInventoryDomainService;
private final static String X_DEBUG_MODE_HEADER = "X-Debug-Mode";
private final static String X_DEBUG_MODE_VALUE = "true";
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -160,8 +155,9 @@ public class AssemblePaperDomainServiceImpl implements AssemblePaperDomainServic
recordDTO.setSubLineId(taskDTO.getSubLineId()); recordDTO.setSubLineId(taskDTO.getSubLineId());
recordDTO.setTaskName(taskDTO.getName()); recordDTO.setTaskName(taskDTO.getName());
recordDTO.setAnswerSnapshotDTOList(buildPaperSnapshot(selectedQuestionList)); recordDTO.setAnswerSnapshotDTOList(buildPaperSnapshot(selectedQuestionList));
ExamRecordDTO examRecordDTO = examRecordBaseService.saveDTO(recordDTO, ExamRecordEntity::new, ExamRecordDTO::new);
return buildExamRecordDomainService.buildDTO(examRecordDTO); recordDTO = examRecordBaseService.saveDTO(recordDTO, ExamRecordEntity::new, ExamRecordDTO::new);
return buildExamRecordDomainService.buildDTO(recordDTO);
} }
private List<ExamRecordDTO.QuestionSnapshotDTO> buildPaperSnapshot(List<QuestionDTO> questionDTOList) { private List<ExamRecordDTO.QuestionSnapshotDTO> buildPaperSnapshot(List<QuestionDTO> questionDTOList) {
@ -169,13 +165,7 @@ public class AssemblePaperDomainServiceImpl implements AssemblePaperDomainServic
QuestionDTO.QuestionDetailDTO detail = questionDTO.getQuestionDetailDTO(); QuestionDTO.QuestionDetailDTO detail = questionDTO.getQuestionDetailDTO();
ExamRecordDTO.QuestionSnapshotDTO snapshot = new ExamRecordDTO.QuestionSnapshotDTO(); ExamRecordDTO.QuestionSnapshotDTO snapshot = new ExamRecordDTO.QuestionSnapshotDTO();
BeanUtils.copyProperties(detail , snapshot); BeanUtils.copyProperties(detail , snapshot);
// 拥有admin权限且请求头有特殊标识才在此接口返回答案和解析 snapshot.setQuestionId(questionDTO.getId());
boolean isDebugMode = SecurityUtils.hasRole(UserRoleEnum.ROLE_ADMIN.name())
&& StrUtil.equals(X_DEBUG_MODE_VALUE , ServletUtils.getHeader(X_DEBUG_MODE_HEADER));
if (!isDebugMode) {
detail.setRightAnswer(null);
detail.setAnalysis(null);
}
return snapshot; return snapshot;
}).toList(); }).toList();
} }

37
src/main/java/com/project/exam/domain/service/impl/BuildExamRecordDomainServiceImpl.java

@ -1,25 +1,44 @@
package com.project.exam.domain.service.impl; package com.project.exam.domain.service.impl;
import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import com.project.base.domain.utils.ServletUtils;
import com.project.ding.domain.enums.UserRoleEnum;
import com.project.ding.utils.SecurityUtils;
import com.project.exam.domain.dto.ExamRecordDTO; import com.project.exam.domain.dto.ExamRecordDTO;
import com.project.exam.domain.service.BuildExamRecordDomainService; import com.project.exam.domain.service.BuildExamRecordDomainService;
import com.project.task.domain.enums.QuestionTypeEnum; import com.project.task.domain.enums.QuestionTypeEnum;
import com.project.task.domain.service.TaskBaseService; import io.vavr.control.Try;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
@Service @Service
public class BuildExamRecordDomainServiceImpl implements BuildExamRecordDomainService { public class BuildExamRecordDomainServiceImpl implements BuildExamRecordDomainService {
@Autowired
private TaskBaseService taskBaseService;
private final static String X_DEBUG_MODE_HEADER = "X-Debug-Mode";
private final static String X_DEBUG_MODE_VALUE = "true";
@Override @Override
public ExamRecordDTO buildDTO(ExamRecordDTO dto) throws Exception { public ExamRecordDTO buildDTO(ExamRecordDTO dto) throws Exception {
// 补全题目分数 // 补全题目分数
if (Objects.nonNull(dto.getTaskDTO())) { if (Objects.nonNull(dto.getTaskDTO())) {
dto.getAnswerSnapshotDTOList().stream().map(answerSnapshotDTO -> { dto.getAnswerSnapshotDTOList().forEach(answerSnapshotDTO -> {
// 拥有admin权限且请求头有特殊标识才在此接口返回答案和解析
boolean isDebugMode = SecurityUtils.hasRole(UserRoleEnum.ROLE_ADMIN.name())
&& StrUtil.equals(X_DEBUG_MODE_VALUE , ServletUtils.getHeader(X_DEBUG_MODE_HEADER));
boolean isSubmitted = Objects.nonNull(dto.getSubmitTime());
boolean canShowDetails = isDebugMode || isSubmitted;
if (!canShowDetails) {
answerSnapshotDTO.setRightAnswer(null);
answerSnapshotDTO.setAnalysis(null);
}
if (QuestionTypeEnum.SINGLE_CHOICE.getValue().equals(answerSnapshotDTO.getType())) { if (QuestionTypeEnum.SINGLE_CHOICE.getValue().equals(answerSnapshotDTO.getType())) {
answerSnapshotDTO.setScore(dto.getTaskDTO().getSingleChoiceScore()); answerSnapshotDTO.setScore(dto.getTaskDTO().getSingleChoiceScore());
answerSnapshotDTO.setUserScore(BooleanUtil.isTrue(answerSnapshotDTO.getIsRight()) ? answerSnapshotDTO.setUserScore(BooleanUtil.isTrue(answerSnapshotDTO.getIsRight()) ?
@ -33,9 +52,15 @@ public class BuildExamRecordDomainServiceImpl implements BuildExamRecordDomainSe
answerSnapshotDTO.setUserScore(BooleanUtil.isTrue(answerSnapshotDTO.getIsRight()) ? answerSnapshotDTO.setUserScore(BooleanUtil.isTrue(answerSnapshotDTO.getIsRight()) ?
dto.getTaskDTO().getMultipleChoiceScore() : 0); dto.getTaskDTO().getMultipleChoiceScore() : 0);
} }
return answerSnapshotDTO; answerSnapshotDTO.setTypeText(Try.of(() ->
QuestionTypeEnum.findByValue(answerSnapshotDTO.getType()).getDescription())
.getOrElse(""));
}); });
} }
AtomicInteger index = new AtomicInteger(0);
dto.getAnswerSnapshotDTOList().forEach(answerSnapshotDTO -> {
answerSnapshotDTO.setIndex(index.incrementAndGet());
});
return dto; return dto;
} }
} }

24
src/main/java/com/project/exam/domain/service/impl/GetDetailExamRecordDomainServiceImpl.java

@ -0,0 +1,24 @@
package com.project.exam.domain.service.impl;
import com.project.base.domain.result.Result;
import com.project.exam.domain.dto.ExamRecordDTO;
import com.project.exam.domain.service.BuildExamRecordDomainService;
import com.project.exam.domain.service.GetDetailExamRecordDomainService;
import com.project.exam.mapper.ExamRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GetDetailExamRecordDomainServiceImpl implements GetDetailExamRecordDomainService {
@Autowired
private BuildExamRecordDomainService buildExamRecordDomainService;
@Autowired
private ExamRecordMapper examRecordMapper;
@Override
public Result<ExamRecordDTO> getDetail(Long id) throws Exception {
ExamRecordDTO dto = examRecordMapper.selectById(id).toDTO(ExamRecordDTO::new);
return Result.success(buildExamRecordDomainService.buildDTO(dto));
}
}
Loading…
Cancel
Save