Commit 01bd69f5 by wqc

多选题答题计算

parent 7df2ecf5
......@@ -34,7 +34,7 @@ public class QuestionApi {
@ApiOperation("答题")
@PostMapping(value = "/answer")
public ResultVo answer(@RequestBody AnswerRec vo) {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
// AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getAnswerList(), "缺少答案");
return ResultVo.success(questionService.answer(vo));
}
......
......@@ -45,7 +45,7 @@ public class AddressService {
}
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)
.eq(Address::getUserId, vo.getUserId())
.notIn(Address::getId, vo.getId()));
......
......@@ -25,11 +25,13 @@ import com.zq.user.vo.AnswerRecVo;
import com.zq.user.vo.QuestionFindVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author wilmiam
......@@ -135,30 +137,47 @@ public class QuestionService {
String questionId = obj.getStr("questionId");
// 用户所选答案
JSONArray answerArr = obj.getJSONArray("answer");
Question question = questionDao.selectById(questionId);
String answer = question.getAnswer();
// 正确答案
List<String> answerList = StrUtil.split(answer, ',');
for (Object o : answerArr) {
String s = Convert.toStr(o, "");
// 删除所选答案,正确答案中还有答案就说明答错了
boolean remove = answerList.remove(s);
if (!remove) {
if(answerArr.size()>1){
String[] split = StringUtils.strip(answerArr.toString(), "[]").split(",");
List<String> list = new ArrayList<>();
for (String s : split) {
String str= s.replace("\"", "");
list.add(str);
}
String collect = list.stream().collect(Collectors.joining(","));
if (!collect.equals(answer)){
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;
}
}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)) {
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