|
|
@@ -43,10 +43,14 @@ import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerDetailVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerStudentPageVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerStudentVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentPlanAnswerTeacherPageVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.AssessmentQuestionOptionResultVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentQuestionResultVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentQuestionVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanPageVo;
|
|
|
import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanQuestionVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.AssessmentTemplatePlanResultVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.OneQuestionVo;
|
|
|
+import com.xjrsoft.module.assessment.vo.TwoQuestionVo;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
import com.xjrsoft.module.base.mapper.BaseClassMapper;
|
|
|
import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
@@ -58,6 +62,8 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -74,7 +80,8 @@ import java.util.Random;
|
|
|
*/
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<AssessmentTemplatePlanMapper, AssessmentTemplatePlan> implements IAssessmentTemplatePlanService {
|
|
|
+public
|
|
|
+class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<AssessmentTemplatePlanMapper, AssessmentTemplatePlan> implements IAssessmentTemplatePlanService {
|
|
|
private final AssessmentTemplatePlanMapper templatePlanMapper;
|
|
|
|
|
|
private final AssessmentPlanQuestionMapper planQuestionMapper;
|
|
|
@@ -209,7 +216,6 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
int nextInt = random.nextInt(classList.size());
|
|
|
if(!randomList.contains(nextInt) && nextInt >= 0){
|
|
|
randomList.add(nextInt);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
for (Integer i : randomList) {
|
|
|
@@ -343,17 +349,42 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
public Boolean saveAnswer(AssessmentPlanSubmitDto dto) {
|
|
|
long studentUserId = StpUtil.getLoginIdAsLong();
|
|
|
Date date = new Date();
|
|
|
+
|
|
|
+ List<Long> questionIds = new ArrayList<>();
|
|
|
+ for (AssessmentPlanAnswerSubmitDto answerSubmitDto : dto.getAnswerList()) {
|
|
|
+ questionIds.add(answerSubmitDto.getQuestionId());
|
|
|
+ }
|
|
|
+ Map<Long, String> questionTypeMaps = new HashMap<>();
|
|
|
+ planQuestionMapper.selectList(
|
|
|
+ new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
+ .in(AssessmentPlanQuestion::getId, questionIds)
|
|
|
+ ).forEach(question ->{
|
|
|
+ questionTypeMaps.put(question.getId(), question.getType());
|
|
|
+ });
|
|
|
+
|
|
|
// 学生提交
|
|
|
studentMapper.submitAnswer(dto.getAssessmentTemplatePlanId(), studentUserId);
|
|
|
for (AssessmentPlanAnswerSubmitDto answerSubmitDto : dto.getAnswerList()) {
|
|
|
- AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
- answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
- answerStudent.setStudentUserId(studentUserId);
|
|
|
- answerStudent.setCreateDate(date);
|
|
|
- answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
- answerStudent.setAnswerId(answerSubmitDto.getAnswerId());
|
|
|
- resultMapper.insert(answerStudent);
|
|
|
-
|
|
|
+ if("multi_question".equals(questionTypeMaps.get(answerSubmitDto.getQuestionId()))){
|
|
|
+ String[] split = answerSubmitDto.getAnswerId().split(",");
|
|
|
+ for (String answerId : split) {
|
|
|
+ AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
+ answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
+ answerStudent.setStudentUserId(studentUserId);
|
|
|
+ answerStudent.setCreateDate(date);
|
|
|
+ answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
+ answerStudent.setAnswerId(answerId);
|
|
|
+ resultMapper.insert(answerStudent);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ AssessmentPlanAnswerResult answerStudent = new AssessmentPlanAnswerResult();
|
|
|
+ answerStudent.setAssessmentTemplatePlanId(dto.getAssessmentTemplatePlanId());
|
|
|
+ answerStudent.setStudentUserId(studentUserId);
|
|
|
+ answerStudent.setCreateDate(date);
|
|
|
+ answerStudent.setQuestionId(answerSubmitDto.getQuestionId());
|
|
|
+ answerStudent.setAnswerId(answerSubmitDto.getAnswerId());
|
|
|
+ resultMapper.insert(answerStudent);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -384,65 +415,96 @@ public class AssessmentTemplatePlanServiceImpl extends MPJBaseServiceImpl<Assess
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AssessmentTemplatePlanQuestionVo getQuestionResult(Long id) {
|
|
|
+ public AssessmentTemplatePlanResultVo getQuestionResult(Long id) {
|
|
|
AssessmentTemplatePlan templatePlan = templatePlanMapper.selectById(id);
|
|
|
- AssessmentTemplatePlanQuestionVo vo = BeanUtil.toBean(templatePlan, AssessmentTemplatePlanQuestionVo.class);
|
|
|
+ AssessmentTemplatePlanResultVo vo = BeanUtil.toBean(templatePlan, AssessmentTemplatePlanResultVo.class);
|
|
|
vo.setStudentCount(studentMapper.getStudentCount(id));
|
|
|
List<AssessmentPlanQuestion> questionList = planQuestionMapper.selectList(
|
|
|
new QueryWrapper<AssessmentPlanQuestion>().lambda()
|
|
|
.eq(AssessmentPlanQuestion::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
.eq(AssessmentPlanQuestion::getAssessmentTemplatePlanId, id)
|
|
|
);
|
|
|
- List<AssessmentPlanAnswerDetailVo> questionResult = resultMapper.getQuestionResult(id);
|
|
|
- Map<String, Integer> answerCountMap = new HashMap<>();
|
|
|
- for (AssessmentPlanAnswerDetailVo countVo : questionResult) {
|
|
|
- answerCountMap.put(countVo.getQuestionId().toString() + countVo.getAnswerId(), countVo.getChooseCount());
|
|
|
- }
|
|
|
+
|
|
|
//循环大题
|
|
|
- List<AssessmentQuestionVo> oneList = new ArrayList<>();
|
|
|
+ List<OneQuestionVo> oneList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 1){
|
|
|
- oneList.add(BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class));
|
|
|
+ oneList.add(BeanUtil.toBean(assessmentQuestion, OneQuestionVo.class));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//循环小题
|
|
|
- for (AssessmentQuestionVo oneQuestion : oneList) {
|
|
|
- List<AssessmentQuestionVo> twoList = new ArrayList<>();
|
|
|
+ for (OneQuestionVo oneQuestion : oneList) {
|
|
|
+ List<TwoQuestionVo> twoList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 2 && assessmentQuestion.getParentId().equals(oneQuestion.getId())){
|
|
|
- AssessmentQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class);
|
|
|
+ TwoQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, TwoQuestionVo.class);
|
|
|
twoList.add(questionVo);
|
|
|
}
|
|
|
}
|
|
|
oneQuestion.setChildren(twoList);
|
|
|
}
|
|
|
+ List<AssessmentPlanAnswerDetailVo> questionResult = resultMapper.getQuestionResult(id);
|
|
|
+ Map<String, Integer> answerCountMap = new HashMap<>();
|
|
|
+ for (AssessmentPlanAnswerDetailVo countVo : questionResult) {
|
|
|
+ answerCountMap.put(countVo.getQuestionId().toString() + countVo.getAnswerId(), countVo.getChooseCount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //量表
|
|
|
+ List<AssessmentPlanAnswerDetailVo> scaleQuestionResult = resultMapper.getScaleQuestionResult(id);
|
|
|
|
|
|
//循环选项
|
|
|
- for (AssessmentQuestionVo oneQuestion : oneList) {
|
|
|
- for (AssessmentQuestionVo twoQuestion : oneQuestion.getChildren()) {
|
|
|
- List<AssessmentQuestionVo> optionList = new ArrayList<>();
|
|
|
+ for (OneQuestionVo oneQuestion : oneList) {
|
|
|
+ for (TwoQuestionVo twoQuestion : oneQuestion.getChildren()) {
|
|
|
+ List<AssessmentQuestionOptionResultVo> optionList = new ArrayList<>();
|
|
|
for (AssessmentPlanQuestion assessmentQuestion : questionList) {
|
|
|
if(assessmentQuestion.getCategory() == 3 && assessmentQuestion.getParentId().equals(twoQuestion.getId())){
|
|
|
- AssessmentQuestionVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionVo.class);
|
|
|
- questionVo.setChooseCount(answerCountMap.get(assessmentQuestion.getParentId().toString() + assessmentQuestion.getId().toString()));
|
|
|
+ AssessmentQuestionOptionResultVo questionVo = BeanUtil.toBean(assessmentQuestion, AssessmentQuestionOptionResultVo.class);
|
|
|
+ questionVo.setCount(answerCountMap.get(assessmentQuestion.getParentId().toString() + assessmentQuestion.getId().toString()));
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(questionVo.getCount())
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ questionVo.setPercentage(bigDecimal.floatValue());
|
|
|
optionList.add(questionVo);
|
|
|
}
|
|
|
if(assessmentQuestion.getCategory() == 2 && "judge_question".equals(assessmentQuestion.getType())){
|
|
|
- optionList.add(new AssessmentQuestionVo(){{
|
|
|
- setId(1L);
|
|
|
- setChooseCount(answerCountMap.get(assessmentQuestion.getId().toString() + "1"));
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName("是");
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(answerCountMap.get(assessmentQuestion.getId().toString() + "1"))
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(answerCountMap.get(assessmentQuestion.getId().toString() + "1"));
|
|
|
}});
|
|
|
- optionList.add(new AssessmentQuestionVo(){{
|
|
|
- setId(2L);
|
|
|
- setChooseCount(answerCountMap.get(assessmentQuestion.getId().toString() + "2"));
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName("否");
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(answerCountMap.get(assessmentQuestion.getId().toString() + "2"))
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount()))
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(answerCountMap.get(assessmentQuestion.getId().toString() + "2"));
|
|
|
}});
|
|
|
}
|
|
|
}
|
|
|
- twoQuestion.setOptions(optionList);
|
|
|
+ if("scale_question".equals(twoQuestion.getType())) {
|
|
|
+ for (AssessmentPlanAnswerDetailVo detailVo : scaleQuestionResult) {
|
|
|
+ if(detailVo.getQuestionId().equals(twoQuestion.getId())){
|
|
|
+ optionList.add(new AssessmentQuestionOptionResultVo(){{
|
|
|
+ setName(detailVo.getAnswerId());
|
|
|
+ BigDecimal bigDecimal = BigDecimal.valueOf(detailVo.getChooseCount())
|
|
|
+ .divide(BigDecimal.valueOf(vo.getStudentCount())).multiply(BigDecimal.valueOf(100))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ setPercentage(bigDecimal.floatValue());
|
|
|
+ setCount(detailVo.getChooseCount());
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ twoQuestion.setResultList(optionList);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
vo.setChildren(oneList);
|
|
|
return vo;
|
|
|
}
|