发表于: 2017-12-31 16:50:39
0 565
一.今天完成的主要事情
1.完成大部分的学习模块学员端的功能实现
其中值得一提的是获取各种情况下的题目的IdList这个接口
/**
* 获取练习题目ID列表接口
*
* @param
* @return
* @throws ServiceException
* @throws ServiceDaoException
*/
//TODO 测试完毕后加上/u
@RequestMapping(value = "/a/practice/key/list", method = RequestMethod.GET)
public String getPracticeIdList(HttpServletRequest request, HttpServletResponse response, ModelMap model,
Long studentId, Integer subjectType, Integer type, String special) throws Exception {
log.info("Interface GET /a/u/practice/key/list, Method getPracticeIdList() parameters: subjectType: " +
subjectType + ", type: " + type + ", special: " + special);
int validateResult = ParamsUtil.checkParamsOfGetPracticeIdList(studentId, subjectType, type, special);
if (validateResult != 0) {
model.addAttribute("code", validateResult);
return "/common/failure";
}
try {
log.info("Key parameter: parameter type is : " + type);
//获取该学员的做对的题目idList, 以及做错的题目IdList
List<Long> rightPracticeIds = new ArrayList<>();
List<Long> wrongPracticeIds = new ArrayList<>();
if (type != 3) {
rightPracticeIds = noteService.getPracticeIdsByStudentIdAndSubjectTypeAndResult(studentId, subjectType, 1, 0, Integer.MAX_VALUE);
wrongPracticeIds = noteService.getPracticeIdsByStudentIdAndSubjectTypeAndResult(studentId, subjectType, 0, 0, Integer.MAX_VALUE);
log.info("get right practice id list, size is : " + rightPracticeIds.size() + ", get wrong practice id list, size is: " + wrongPracticeIds.size());
}
List<Long> practiceIdList = new ArrayList<>();
switch (type) {
case 0:
//顺序
practiceIdList = subjectPracticeService.getSubjectPracticeIdsBySubjectType(subjectType, 0, Integer.MAX_VALUE);
break;
case 1:
//随机
practiceIdList = subjectPracticeService.getSubjectPracticeIdsBySubjectType(subjectType, 0, Integer.MAX_VALUE);
Collections.shuffle(practiceIdList);
break;
case 2:
//考点
Map<String, Object> querySpecialPracticeIdsMap = DynamicUtil.getSpecialPracticeParams(subjectType, special, false);
practiceIdList = subjectPracticeService.getIdsByDynamicCondition(SubjectPractice.class, querySpecialPracticeIdsMap, 0, Integer.MAX_VALUE);
break;
case 3:
//模拟考试
practiceIdList = subjectPracticeService.getMockExamPracticeIdsBySubjectType(subjectType);
break;
case 4:
//收藏
practiceIdList = studentFavoriteRelationService.getTargetIdsByStudentIdAndTargetType(studentId, subjectType, 0, Integer.MAX_VALUE);
break;
case 5:
//错题
practiceIdList = wrongPracticeIds;
break;
default:
break;
}
log.info("get practice Id list , list size is : " + practiceIdList.size());
List<StudentPracticeKey> resultList = StudentPracticeKey.generateStudentPracticeKeyList(practiceIdList, rightPracticeIds, wrongPracticeIds, type);
model.addAttribute("code", 0);
model.addAttribute("studentPracticeKeyList", resultList);
model.addAttribute("total", practiceIdList.size());
return "/yi-nucleus-service/subjectPractice/json/subjectPracticeIdList";
} catch (Throwable t) {
log.error(t.getMessage());
log.error("Method getPracticeIdList() failed, parameters: subjectType: " + subjectType + ", type: " + type + ", special: " + special);
model.addAttribute("code", -1);
return "/common/failure";
}
}
其中,值得一提的是标粗的两个方法
第一个是一个自己封装到service中的方法,因为这个方法的功能是根据科目类型获取模拟考试的idList,该功能不可避免的要进行一定的逻辑判断,而且还要调用好几次service,因为要找出不同类型(单选题,判断题,多选题)的数据,但是该方法不能在所有项目中复用,而且只查一张表,那么就可以将其封装到service中,调用时只调用一次service即可,简化controller中的代码.
所以service中的代码为:
@Override
public List<Long> getMockExamPracticeIdsBySubjectType(Integer subjectType) throws ServiceException, ServiceDaoException {
if (log.isInfoEnabled()) {
log.info(" get mockExam practice Ids by subjectType, subjectType is : " + subjectType);
}
List<Long> singleChoiceIdList = null;
List<Long> judgmentIdList = null;
List<Long> multipleIdList = new ArrayList<>();
try {
singleChoiceIdList = dao.getIdList("getSubjectPracticeIdsBySubjectTypeAndType", new Object[]{subjectType, "单选题"}, 0, Integer.MAX_VALUE, false);
judgmentIdList = dao.getIdList("getSubjectPracticeIdsBySubjectTypeAndType", new Object[]{subjectType, "判断题"}, 0, Integer.MAX_VALUE, false);
multipleIdList = (subjectType == 4) ? dao.getIdList("getSubjectPracticeIdsBySubjectTypeAndType", new Object[]{subjectType, "多选题"}, 0, Integer.MAX_VALUE, false): multipleIdList;
} catch (DaoException e) {
log.error(" get mockExam practice Ids wrong by subjectType : " + subjectType);
log.error(e);
e.printStackTrace();
throw new ServiceDaoException(e);
}
List<Long> resultList = getMockExamIdList(singleChoiceIdList, judgmentIdList, multipleIdList, subjectType);
if (log.isInfoEnabled()) {
log.info(" get mockExam practice Ids success : resultList size is: " + resultList.size());
}
return resultList;
}
这里标粗的代码一是根据类型查数据库,将各种类型的题目查询出来,二是根据查询出来的结果和科目类型,生成最后的模拟考试题目.这个方法的代码为
/**
* 获取模拟考试IdList
* */
private static List<Long> getMockExamIdList(List<Long> singleChoiceIds, List<Long> judgmentIds, List<Long> multipleChoiceIds, Integer subjectType){
if (subjectType == 1)
return getSubjectOneMockExamIdList(singleChoiceIds, judgmentIds);
else
return getSubjectFourMockExamIdList(singleChoiceIds, judgmentIds, multipleChoiceIds);
}
/**
* 获取科目一模拟考试IdList
* */
private static List<Long> getSubjectOneMockExamIdList(List<Long> singleChoiceIds, List<Long> judgmentIds){
Collections.shuffle(singleChoiceIds);
Collections.shuffle(judgmentIds);
List<Long> resultIds = new ArrayList<>(100);
for (int i=0; i<40; i++){
resultIds.add(judgmentIds.get(i));
}
for (int i=0; i<60; i++){
resultIds.add(singleChoiceIds.get(i));
}
return resultIds;
}
/**
* 获取科目四模拟考试IdList
* */
private static List<Long> getSubjectFourMockExamIdList(List<Long> singleChoiceIds, List<Long> judgmentIds, List<Long> multipleChoiceIds){
Collections.shuffle(singleChoiceIds);
Collections.shuffle(judgmentIds);
Collections.shuffle(multipleChoiceIds);
List<Long> resultIds = new ArrayList<>(50);
for (int i=0; i<20; i++){
resultIds.add(judgmentIds.get(i));
}
for (int i=0; i<20; i++){
resultIds.add(singleChoiceIds.get(i));
}
for (int i=0; i<10; i++){
resultIds.add(multipleChoiceIds.get(i));
}
return resultIds;
}
逻辑代码都不难,总的思想就是将一个个的功能划分为更小的模块,组装起来,实现最后的功能,这样那一部分出问题,就去查找相应部分的问题即可.
后续还要在重构的时候加上常量和注释,目前先写到这里
至于其他的一些接口,没有太过于复杂的,只是简单的增删改查而已,代码就不贴出来了
2.明天计划完成的事情
1.找PM沟通相应的需求问题
2.继续完成学员端的学习模块的部分
3.遇到的问题
暂无
4.收获
以上
5,项目进度情况
暂无延期风险
评论