Commit 01bd69f5 by wqc

多选题答题计算

parent 7df2ecf5
...@@ -34,7 +34,7 @@ public class QuestionApi { ...@@ -34,7 +34,7 @@ public class QuestionApi {
@ApiOperation("答题") @ApiOperation("答题")
@PostMapping(value = "/answer") @PostMapping(value = "/answer")
public ResultVo answer(@RequestBody AnswerRec vo) { public ResultVo answer(@RequestBody AnswerRec vo) {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID"); // AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getAnswerList(), "缺少答案"); AssertUtils.hasText(vo.getAnswerList(), "缺少答案");
return ResultVo.success(questionService.answer(vo)); return ResultVo.success(questionService.answer(vo));
} }
......
...@@ -45,7 +45,7 @@ public class AddressService { ...@@ -45,7 +45,7 @@ public class AddressService {
} }
if (vo.getIsDefault()) { if (vo.getIsDefault()) {
addressDao.update(Address.builder().isDefault(false).updateTime(DateUtil.date()).build(), addressDao.update(Address.builder().isDefault(true).updateTime(DateUtil.date()).build(),
Wrappers.lambdaUpdate(Address.class) Wrappers.lambdaUpdate(Address.class)
.eq(Address::getUserId, vo.getUserId()) .eq(Address::getUserId, vo.getUserId())
.notIn(Address::getId, vo.getId())); .notIn(Address::getId, vo.getId()));
......
...@@ -25,11 +25,13 @@ import com.zq.user.vo.AnswerRecVo; ...@@ -25,11 +25,13 @@ import com.zq.user.vo.AnswerRecVo;
import com.zq.user.vo.QuestionFindVo; import com.zq.user.vo.QuestionFindVo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author wilmiam * @author wilmiam
...@@ -135,30 +137,47 @@ public class QuestionService { ...@@ -135,30 +137,47 @@ public class QuestionService {
String questionId = obj.getStr("questionId"); String questionId = obj.getStr("questionId");
// 用户所选答案 // 用户所选答案
JSONArray answerArr = obj.getJSONArray("answer"); JSONArray answerArr = obj.getJSONArray("answer");
Question question = questionDao.selectById(questionId); Question question = questionDao.selectById(questionId);
String answer = question.getAnswer(); String answer = question.getAnswer();
// 正确答案 // 正确答案
List<String> answerList = StrUtil.split(answer, ','); List<String> answerList = StrUtil.split(answer, ',');
if(answerArr.size()>1){
for (Object o : answerArr) { String[] split = StringUtils.strip(answerArr.toString(), "[]").split(",");
String s = Convert.toStr(o, ""); List<String> list = new ArrayList<>();
// 删除所选答案,正确答案中还有答案就说明答错了 for (String s : split) {
boolean remove = answerList.remove(s); String str= s.replace("\"", "");
if (!remove) { list.add(str);
}
String collect = list.stream().collect(Collectors.joining(","));
if (!collect.equals(answer)){
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("subject", question.getSubject()); map.put("subject", question.getSubject());
map.put("answer", question.getAnswer()); map.put("answer", question.getAnswer());
map.put("analysis", question.getAnalysis()); map.put("analysis", question.getAnalysis());
map.put("content", question.getContent()); map.put("content", question.getContent());
map.put("choiceAnswer", answer); map.put("choiceAnswer", answer);
wrongQuestionList.add(map); wrongQuestionList.add(map);
break; break;
} }
}else {
for (Object o : answerArr) {
String s = Convert.toStr(o, "");
// 删除所选答案,正确答案中还有答案就说明答错了
boolean remove = answerList.remove(s);
if (!remove) {
Map<String, Object> map = new HashMap<>();
map.put("subject", question.getSubject());
map.put("answer", question.getAnswer());
map.put("analysis", question.getAnalysis());
map.put("content", question.getContent());
map.put("choiceAnswer", answer);
wrongQuestionList.add(map);
break;
}
}
} }
if (CollUtil.isEmpty(answerList)) { if (CollUtil.isEmpty(answerList)) {
correct++; correct++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment