找回密码
 会员注册
查看: 38|回复: 0

答题情况和每题得分

[复制链接]

5

主题

0

回帖

16

积分

新手上路

积分
16
发表于 2024-9-12 23:16:15 | 显示全部楼层 |阅读模式
文章目录1.提交答题情况1.PracticeDetailController.java2.PracticeDetailService.java3.PracticeDetailServiceImpl.java4.PracticeDetailDao.java5.PracticeDetailDao.xml6.reqSubmitSubjectDetailReq.java7.dto1.SubjectDetailDTO.java2.SubjectDTO.java3.SubjectOptionDTO.java8.测试1.接口设计2.db1.更新提交时间和用时practice_info2.练习细节如果有的话就更新记录practice_detail3.测试遇到一个bug,即使题目正确也会插入答案状态为0,状态设置的时候有问题2.答案解析-每题得分1.GetScoreDetailReq.java2.ScoreDetailVO.java3.PracticeDetailController.java4.PracticeDetailService.java5.PracticeDetailServiceImpl.java6.PracticeDetailDao.xml7.测试1.提交答题情况1.PracticeDetailController.java/***提交题目,每一次点下一题,都会调用这个接口*/@PostMapping(value="/submitSubject")publicResultsubmitSubject(@RequestBodySubmitSubjectDetailReqreq){try{if(log.isInfoEnabled()){log.info("练习提交题目入参{}",JSON.toJSONString(req));}Preconditions.checkArgument(!Objects.isNull(req),"参数不能为空!")reconditions.checkArgument(!Objects.isNull(req.getPracticeId()),"练习id不能为空!")reconditions.checkArgument(!Objects.isNull(req.getSubjectId()),"题目id不能为空!")reconditions.checkArgument(!Objects.isNull(req.getSubjectType()),"题目类型不能为空!")reconditions.checkArgument(!StringUtils.isBlank(req.getTimeUse()),"用时不能为空!");Booleanresult=practiceDetailService.submitSubject(req);log.info("练习提交题目出参{}",result);returnResult.ok(result);}catch(IllegalArgumentExceptione){log.error("参数异常!错误原因{}",e.getMessage(),e);returnResult.fail(e.getMessage());}catch(Exceptione){log.error("练习提交题目异常!错误原因{}",e.getMessage(),e);returnResult.fail("练习提交题目异常!");}}123456789101112131415161718192021222324252.PracticeDetailService.javapackagecom.sunxiansheng.practice.server.service;importcom.sunxiansheng.practice.api.req.SubmitSubjectDetailReq;/***Description:*@Authorsun*@Create2024/7/812:28*@Version1.0*/publicinterfacePracticeDetailService{/***练习提交题目*/BooleansubmitSubject(SubmitSubjectDetailReqreq);}123456789101112131415161718193.PracticeDetailServiceImpl.javapackagecom.sunxiansheng.practice.server.service.impl;importcom.sunxiansheng.practice.api.enums.SubjectInfoTypeEnum;importcom.sunxiansheng.practice.api.req.SubmitSubjectDetailReq;importcom.sunxiansheng.practice.server.dao.*;importcom.sunxiansheng.practice.server.entity.dto.SubjectDTO;importcom.sunxiansheng.practice.server.entity.po.PracticeDetailPO;importcom.sunxiansheng.practice.server.entity.po.PracticePO;importcom.sunxiansheng.practice.server.entity.po.SubjectMultiplePO;importcom.sunxiansheng.practice.server.entity.po.SubjectRadioPO;importcom.sunxiansheng.practice.server.service.PracticeDetailService;importcom.sunxiansheng.practice.server.util.LoginUtil;importlombok.extern.slf4j.Slf4j;importorg.apache.commons.lang3.StringUtils;importorg.springframework.stereotype.Service;importorg.springframework.transaction.annotation.Transactional;importorg.springframework.util.CollectionUtils;importjavax.annotation.Resource;importjava.util.Collections;importjava.util.Date;importjava.util.List;importjava.util.Objects;/***Description:*@Authorsun*@Create2024/6/2517:08*@Version1.0*/@Service@Slf4jpublicclassPracticeDetailServiceImplimplementsPracticeDetailService{@ResourceprivatePracticeDaopracticeDao;@ResourceprivateSubjectDaosubjectDao;@ResourceprivateSubjectRadioDaosubjectRadioDao;@ResourceprivateSubjectMultipleDaosubjectMultipleDao;@ResourceprivatePracticeDetailDaopracticeDetailDao;@Override@Transactional(rollbackFor=Exception.class)publicBooleansubmitSubject(SubmitSubjectDetailReqreq){//获取req的信息LongpracticeId=req.getPracticeId();LongsubjectId=req.getSubjectId();ListanswerContents=req.getAnswerContents();IntegersubjectType=req.getSubjectType();StringtimeUse=req.getTimeUse();//==============================处理用时==============================if(timeUse.equals("0")){timeUse="000000";}Stringhour=timeUse.substring(0,2);Stringminute=timeUse.substring(2,4);Stringsecond=timeUse.substring(4,6);//==============================处理用时==============================//==============================根据id更新时间==============================PracticePOpracticePO=newPracticePO();practicePO.setId(practiceId);practicePO.setTimeUse(hour+":"+minute+":"+second);practicePO.setSubmitTime(newDate());practiceDao.update(practicePO);//==============================根据id更新时间==============================//==============================给练习的细节插入一条记录==============================PracticeDetailPOpracticeDetailPO=newPracticeDetailPO();//基本信息填充practiceDetailPO.setPracticeId(practiceId);practiceDetailPO.setSubjectId(subjectId);practiceDetailPO.setSubjectType(subjectType);StringloginId=LoginUtil.getLoginId();practiceDetailPO.setCreatedBy(loginId);practiceDetailPO.setCreatedTime(newDate());practiceDetailPO.setIsDeleted(0);//修改答案数组,将答案变成1,2,3...这种格式的StringanswerContent=getAnswerContent(answerContents);practiceDetailPO.setAnswerContent(answerContent);//从数据库中获取正确答案,并判断答案是否正确SubjectDTOsubjectDTO=newSubjectDTO();subjectDTO.setSubjectId(req.getSubjectId());subjectDTO.setSubjectType(req.getSubjectType());//根据subjectId和subjectType来获取题目答案//初始化为0IntegeranswerStatus=0;StringBuffercorrectAnswer=newStringBuffer();//获得正确答案的字符串extracted(subjectType,subjectId,correctAnswer);//如果答案正确,则答案的状态就会是1,否则是0if(Objects.equals(correctAnswer.toString(),answerContent)){//practiceDetailPO.setAnswerStatus(1);answerStatus=1;}practiceDetailPO.setAnswerStatus(answerStatus);//到此练习的细节就构建完毕了//查询练习细节是否已经存在了,如果存在就更新,不存在就插入PracticeDetailPOexistDetail=practiceDetailDao.selectDetail(practiceId,subjectId,loginId);if(Objects.isNull(existDetail)){practiceDetailDao.insertSingle(practiceDetailPO);}else{practiceDetailPO.setId(existDetail.getId());practiceDetailDao.update(practiceDetailPO);}//==============================给练习的细节插入一条记录==============================returntrue;}/***根据题目id和类型,得到正确答案的字符串*@paramsubjectType*@paramsubjectId*@paramcorrectAnswer*/privatevoidextracted(IntegersubjectType,LongsubjectId,StringBuffercorrectAnswer){//单选if(subjectType==SubjectInfoTypeEnum.RADIO.getCode()){//查询单选题目细节ListsubjectRadioPOS=subjectRadioDao.selectBySubjectId(subjectId);//得到对的那个的选项类型subjectRadioPOS.forEach(radio->{if(Objects.equals(radio.getIsCorrect(),1)){correctAnswer.append(radio.getOptionType());}});}//多选if(subjectType==SubjectInfoTypeEnum.MULTIPLE.getCode()){//查询多选题目细节ListsubjectMultiplePOS=subjectMultipleDao.selectBySubjectId(subjectId);//得到所有的对的选项类型subjectMultiplePOS.forEach(multiple->{if(Objects.equals(multiple.getIsCorrect(),1)){correctAnswer.append(multiple.getOptionType()).append(",");}});//去掉最后一个逗号if(correctAnswer.length()>0){correctAnswer.deleteCharAt(correctAnswer.length()-1);}}//判断if(subjectType==SubjectInfoTypeEnum.JUDGE.getCode()){//查询判断题目细节ListsubjectMultiplePOS=subjectMultipleDao.selectBySubjectId(subjectId);//判断题只能有一条细节,所以取第一个就可以IntegerisCorrect=subjectMultiplePOS.get(0).getIsCorrect();correctAnswer.append(isCorrect);}}/***修改答案数组,将答案变成1,2,3...这种格式的*@paramanswerContents*@return*/privatestaticStringgetAnswerContent(ListanswerContents){StringanswerContent="";//判空if(!CollectionUtils.isEmpty(answerContents)){//排序Collections.sort(answerContents);//拼接answerContent=StringUtils.join(answerContents,",");}returnanswerContent;}}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841854.PracticeDetailDao.java/***更新练习详情*/intupdate(PracticeDetailPOpracticeDetailPO);12345.PracticeDetailDao.xmlupdatepractice_detailanswer_status=#{answerStatus},answer_content=#{answerContent},whereid=#{id,jdbcType=BIGINT}1234567891011126.reqSubmitSubjectDetailReq.javapackagecom.sunxiansheng.practice.api.req;importlombok.Data;importjava.io.Serializable;importjava.util.List;@DatapublicclassSubmitSubjectDetailReqimplementsSerializable{/***练习id*/privateLongpracticeId;/***题目id*/privateLongsubjectId;/***题目答案*/privateListanswerContents;/***题目类型*/privateIntegersubjectType;/***用时*/privateStringtimeUse;}1234567891011121314151617181920212223242526272829303132333435367.dto1.SubjectDetailDTO.javapackagecom.sunxiansheng.practice.server.entity.dto;importlombok.Data;importjava.io.Serializable;importjava.util.List;@DatapublicclassSubjectDetailDTOimplementsSerializable{/***题目id*/privateLongid;/***题目名称*/privateStringsubjectName;/***判断题答案*/privateIntegerisCorrect;/***题目解析*/privateStringsubjectParse;/***单选、多选、判断题目答案*/privateListoptionList;}123456789101112131415161718192021222324252627282930313233343536372.SubjectDTO.javapackagecom.sunxiansheng.practice.server.entity.dto;importlombok.Data;importjava.io.Serializable;@DatapublicclassSubjectDTOimplementsSerializable{/***题目id*/privateLongid;/***题目id*/privateLongsubjectId;/***题目名称*/privateStringsubjectName;/***题目类型*/privateIntegersubjectType;}1234567891011121314151617181920212223242526272829303.SubjectOptionDTO.javapackagecom.sunxiansheng.practice.server.entity.dto;importlombok.Data;importjava.io.Serializable;@DatapublicclassSubjectOptionDTOimplementsSerializable{/***答案类型*/privateIntegeroptionType;/***答案内容*/privateStringoptionContent;/***是否为正确答案*/privateIntegerisCorrect;}123456789101112131415161718192021222324258.测试1.接口设计2.db1.更新提交时间和用时practice_info2.练习细节如果有的话就更新记录practice_detail3.测试遇到一个bug,即使题目正确也会插入答案状态为0,状态设置的时候有问题2.答案解析-每题得分1.GetScoreDetailReq.javapackagecom.sunxiansheng.practice.api.req;importlombok.Data;importjava.io.Serializable;@DatapublicclassGetScoreDetailReqimplementsSerializable{/***练习id*/privateLongpracticeId;}1234567891011121314152.ScoreDetailVO.javapackagecom.sunxiansheng.practice.api.vo;importlombok.Data;importjava.io.Serializable;@DatapublicclassScoreDetailVOimplementsSerializable{/***题目id*/privateLongsubjectId;/***题目类型*/privateIntegersubjectType;/***是否正确*/privateIntegerisCorrect;}12345678910111213141516171819202122232425263.PracticeDetailController.java/***答案解析-每题得分*/@PostMapping(value="/getScoreDetail")publicResult>getScoreDetail(@RequestBodyGetScoreDetailReqreq){try{if(log.isInfoEnabled()){log.info("每题得分入参{}",JSON.toJSONString(req));}Preconditions.checkArgument(!Objects.isNull(req),"参数不能为空!")reconditions.checkArgument(!Objects.isNull(req.getPracticeId()),"练习id不能为空!");Listlist=practiceDetailService.getScoreDetail(req);if(log.isInfoEnabled()){log.info("每题得分出参{}",JSON.toJSONString(list));}returnResult.ok(list);}catch(IllegalArgumentExceptione){log.error("参数异常!错误原因{}",e.getMessage(),e);returnResult.fail(e.getMessage());}catch(Exceptione){log.error("每题得分异常!错误原因{}",e.getMessage(),e);returnResult.fail("每题得分异常!");}}123456789101112131415161718192021222324254.PracticeDetailService.java/***每题得分详情*/ListgetScoreDetail(GetScoreDetailReqreq);123455.PracticeDetailServiceImpl.java@OverridepublicListgetScoreDetail(GetScoreDetailReqreq){//获取练习idLongpracticeId=req.getPracticeId();//根据练习id查询题目id,题目类型,题目状态List practiceDetailPOList=practiceDetailDao.selectByPracticeId(practiceId);//判空if(CollectionUtils.isEmpty(practiceDetailPOList)){returnCollections.emptyList();}//将其map成要返回的结果Listres=practiceDetailPOList.stream().map(po->{//将每一个practiceDetailPO都map成ScoreDetailVOScoreDetailVOscoreDetailVO=newScoreDetailVO();scoreDetailVO.setSubjectId(po.getSubjectId());scoreDetailVO.setSubjectType(po.getSubjectType());scoreDetailVO.setIsCorrect(po.getAnswerStatus());returnscoreDetailVO;}).collect(Collectors.toList());returnres;}12345678910111213141516171819202122236.PracticeDetailDao.xmlselectsubject_idassubjectId,subject_typeassubjectType,answer_statusasanswerStatusfrompractice_detailwherepractice_id=#{practiceId}andis_deleted=01234567.测试
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2024-12-25 13:37 , Processed in 0.302364 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表