标签:String 答题 数据库 question 存入 paper b0 answer new
用户答题接收答案,并存入数据库
接收方式:键值对接收
@GetMapping("/answers")
@ApiImplicitParams({
@ApiImplicitParam(name = "djPaperid", value = "试卷编号", required = true, dataType = "Integer"),
@ApiImplicitParam(name = "djUserid", value = "答题者Id", required = true, dataType = "String"),
@ApiImplicitParam(name = "djQuestionsids", value = "答题ID", required = true, dataType = "String"),
@ApiImplicitParam(name = "djAnswers", value = "答题内容", required = true, dataType = "String"),
@ApiImplicitParam(name = "djStarttime", value = "开始时间", required = true, dataType = "Date")})
public void answers(HttpServletResponse response,
Integer djPaperid,
String djUserid,
String djAnswers,
String djStarttime) throws Exception {
BigDecimal b0 = new BigDecimal(0);
Paper paper = paperService.selectPaperById(djPaperid);
if (paper != null) {
List<JrAnswTwo> twoList = JSONObject.parseArray(djAnswers, JrAnswTwo.class);
StringBuilder stringBuilder = new StringBuilder();
StringBuilder str = null;
for (JrAnswTwo jrAnswTwo : twoList) {
JrAnswTwo answTwo = new JrAnswTwo();
answTwo.setText(jrAnswTwo.getText());
answTwo.setIsJD(jrAnswTwo.getIsJD());
jrAnswTwoService.insertJrAnswTwo(answTwo);
str = stringBuilder.append(answTwo.getId()).append(",");
//1 单选 2 判断 3 多选 4 简答
Questions question = questionsService.selectQuestionsById(jrAnswTwo.getId().toString());
String stAnswer = question.getStAnswer();//正确答案
if ("4".equals(question.getQuestionType())) continue;
if ("3".equals(question.getQuestionType())){
String[] one = jrAnswTwo.getText().split(",");//考试答案
String[] two = stAnswer.split(",");//正确答案
if (one.length != two.length) continue;
for (int i = 0; i < one.length; i++) {
if (one[i].equals(two[i])){
String s = StringUtil.isEmpty(paper.getManyScore()) ? "0" : paper.getManyScore();
b0 = b0.add(new BigDecimal(s));
}
}
continue;
}
if ("2".equals(question.getQuestionType())){
String s = StringUtil.isEmpty(paper.getJudgmentScore()) ? "0" : paper.getJudgmentScore();
b0 = b0.add(new BigDecimal(s));
continue;
}
if ("1".equals(question.getQuestionType())){
String s = StringUtil.isEmpty(paper.getSingleScore()) ? "0" : paper.getSingleScore();
b0 = b0.add(new BigDecimal(s));
continue;
}
}
Answers answer = new Answers();
answer.setDjId(UUIDUtils.getByUUId());
answer.setDjEndtime(new Date());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date strtodate = formatter.parse(djStarttime);
answer.setDjStarttime(strtodate);
String s = str.toString();
answer.setDjContent(s.substring(0,s.length() - 1));
answer.setDjPaperid(djPaperid);
answer.setDjScore(b0);
answer.setDjUserid(djUserid);
answersService.insertAnswers(answer);
}
writeJSON(b0, response, "200", "成功");
}
标签:String,答题,数据库,question,存入,paper,b0,answer,new 来源: https://blog.csdn.net/weixin_49419695/article/details/111207183
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。