| | |
| | | import com.qxueyou.scc.exercise.service.IExerciseService; |
| | | |
| | | /** |
| | | * 试卷部分管理服务层 |
| | | * 试卷部分管理服务层 |
| | | * |
| | | * @author kevin |
| | | * @createTime 2017-11-1 |
| | |
| | | @Override |
| | | public String addExamPaperSection(ExamPaperSectionInfo examPaperSectionInfo) { |
| | | TraceUtils.setCreateTrace(examPaperSectionInfo); |
| | | // 查询当前最大的sectionOrder |
| | | // 查询当前最大的sectionOrder |
| | | String hql = "select max(sectionOrder) from ExamPaperSectionInfo where examPaperId=? and deleteFlag is false"; |
| | | Integer maxOrder = this.findUnique(hql, CollectionUtils.newList(examPaperSectionInfo.getExamPaperId()), |
| | | Integer.class); |
| | | int beginOrder = maxOrder == null ? 0 : maxOrder.intValue(); |
| | | examPaperSectionInfo.setSectionOrder(++beginOrder); |
| | | |
| | | // 获取当前section对应的开始index |
| | | // 获取当前section对应的开始index |
| | | int count = this.findCount("from ExerciseGroupItemRe r where r.deleteFlag is false and r.exerciseGroupId=?", |
| | | CollectionUtils.newList(examPaperSectionInfo.getGroupId())); |
| | | |
| | |
| | | ExamPaperSectionInfo examPaperSectionInfo = read(ExamPaperSectionInfo.class, sectionId); |
| | | ExerciseGroup exerciseGroup = read(ExerciseGroup.class, examPaperSectionInfo.getGroupId()); |
| | | |
| | | // 获取试卷部分原开始位置和结束位置 |
| | | // 获取试卷部分原开始位置和结束位置 |
| | | int origStartIndex = examPaperSectionInfo.getItemStartOrder(); |
| | | int origEndIndex = examPaperSectionInfo.getItemEndOrder(); |
| | | |
| | |
| | | this.deleteAllSectionItem(examPaperSectionInfo.getSectionId()); |
| | | } |
| | | |
| | | // 将题库的题目复制到试卷题库 |
| | | // 将题库的题目复制到试卷题库 |
| | | int itemIndex = origStartIndex; |
| | | ExerciseGroup targetExerciseGroup = new ExerciseGroup(); |
| | | targetExerciseGroup.setGroupId(examPaperSectionInfo.getGroupId()); |
| | |
| | | ExamPaperSectionInfo examPaperSectionInfo = read(ExamPaperSectionInfo.class, sectionId); |
| | | ExerciseGroup exerciseGroup = read(ExerciseGroup.class, examPaperSectionInfo.getGroupId()); |
| | | |
| | | // 获取试卷部分原开始位置和结束位置 |
| | | // 获取试卷部分原开始位置和结束位置 |
| | | int origStartIndex = examPaperSectionInfo.getItemStartOrder(); |
| | | int origEndIndex = examPaperSectionInfo.getItemEndOrder(); |
| | | |
| | | //如果试卷其他部分中已经存在该题目,则返回错误,重复的题目 |
| | | //如果试卷其他部分中已经存在该题目,则返回错误,重复的题目 |
| | | int count = this.findCountByComplexHql("from ExerciseGroupItemRe r where r.deleteFlag is false and r.exerciseGroupId=:paperGroupId and (r.itemOrder<:startIdx or r.itemOrder>:endIdx) and r.exerciseItemId in (:exerciseItemIds)", |
| | | CollectionUtils.newObjectMap("startIdx", origStartIndex, "endIdx", origEndIndex, "paperGroupId", examPaperSectionInfo.getGroupId(), "exerciseItemIds", selectedItemIds)); |
| | | |
| | | if (count > 0) { |
| | | return new Result(false, "请检查选择的题目,同一份试卷中不允许存在相同的题目!"); |
| | | return new Result(false, "请检查选择的题目,同一份试卷中不允许存在相同的题目!"); |
| | | } |
| | | |
| | | // 将题库的题目复制到试卷题库 |
| | | // 将题库的题目复制到试卷题库 |
| | | int copyStartIndex = origEndIndex > 0 ? origEndIndex : origStartIndex; |
| | | ExerciseGroup targetExerciseGroup = new ExerciseGroup(); |
| | | targetExerciseGroup.setGroupId(examPaperSectionInfo.getGroupId()); |
| | |
| | | copyStartIndex); |
| | | long allCount = exerciseGroup.getAllCount() == null ? 0 : exerciseGroup.getAllCount().longValue() + (copyEndIndex - copyStartIndex); |
| | | exerciseGroup.setAllCount(BigInteger.valueOf(allCount)); |
| | | //如果有保存题目则处理索引,否则不处理 |
| | | //如果有保存题目则处理索引,否则不处理 |
| | | if (copyEndIndex - copyStartIndex > 0) { |
| | | examPaperSectionInfo.setItemEndOrder((short) (copyEndIndex)); |
| | | } |
| | |
| | | ExamPaperSectionInfo examPaperSectionInfo = this.read(ExamPaperSectionInfo.class, examPaperSectionId); |
| | | ExerciseGroup exerciseGroup = exerciseGroupService.queryExerciseGroupDetail(examPaperSectionInfo.getGroupId()); |
| | | List<ExerciseItem> items = null; |
| | | // 查询出section 对应的题目信息 |
| | | // 查询出section 对应的题目信息 |
| | | if (examPaperSectionInfo.getItemEndOrder() > 0) { |
| | | int itemCount = examPaperSectionInfo.getItemEndOrder() - examPaperSectionInfo.getItemStartOrder(); |
| | | items = new ArrayList<ExerciseItem>(itemCount); |
| | |
| | | @SuppressWarnings("unchecked") |
| | | private Result updateSectionRangeIndex(String currentSectionid, int adjustNum) { |
| | | ExamPaperSectionInfo currentSectionInfo = this.read(ExamPaperSectionInfo.class, currentSectionid); |
| | | // 如果部分对应的end为-1,则不需要更新endorder |
| | | // 如果部分对应的end为-1,则不需要更新endorder |
| | | String hql = "from ExamPaperSectionInfo where examPaperId=? and sectionOrder>? and deleteFlag is false"; |
| | | List<ExamPaperSectionInfo> lstExamPaperSectionInfo = this.find(hql, |
| | | CollectionUtils.newList(currentSectionInfo.getExamPaperId(), currentSectionInfo.getSectionOrder()), |
| | |
| | | this.saveOrUpdateAll(lstExamPaperSectionInfo); |
| | | } |
| | | } |
| | | //清理试卷缓存 |
| | | //清理试卷缓存 |
| | | this.redisTemplate.delete(currentSectionInfo.getGroupId()); |
| | | return new Result(true); |
| | | } |
| | |
| | | } |
| | | this.deleteSectionItem(examPaperSectionInfo.getSectionId(), examPaperSectionInfo.getGroupId(), |
| | | exerciseItemIds); |
| | | // section坐标置空 |
| | | // section坐标置空 |
| | | examPaperSectionInfo.setItemEndOrder((short) -1); |
| | | this.save(examPaperSectionInfo); |
| | | |
| | |
| | | @Override |
| | | public Result deleteSectionItem(String sectionId, String groupId, String[] exerciseItemIds) { |
| | | if (exerciseItemIds != null && exerciseItemIds.length > 0) { |
| | | // 查询题库与题目的关系 |
| | | // 查询题库与题目的关系 |
| | | List<String> lstRelationIds = new ArrayList<String>(exerciseItemIds.length); |
| | | ExamPaperSectionInfo currentSectionInfo = this.read(ExamPaperSectionInfo.class, sectionId); |
| | | |
| | |
| | | lstRelationIds.add(itemReMap.get(strExerciseItemId).getRelationId()); |
| | | } |
| | | |
| | | // 如果题目删除完了,则设置end为-1 |
| | | // 如果题目删除完了,则设置end为-1 |
| | | if (currentSectionInfo.getItemEndOrder() - exerciseItemIds.length == currentSectionInfo |
| | | .getItemStartOrder()) { |
| | | currentSectionInfo.setItemEndOrder((short) -1); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除试卷习题 |
| | | * 删除试卷习题 |
| | | * |
| | | * |
| | | * @param reIds |
| | |
| | | |
| | | ExerciseGroup group = this.read(ExerciseGroup.class, groupId); |
| | | |
| | | // 更新组试卷习题数量 |
| | | // 更新组试卷习题数量 |
| | | group.setAllCount(group.getAllCount().subtract(new BigInteger(String.valueOf(reIds.length)))); |
| | | TraceUtils.setUpdateTrace(group); |
| | | this.save(group); |
| | | |
| | | // 2.删除试卷题目组关联表数据 |
| | | // 2.删除试卷题目组关联表数据 |
| | | this.bulkUpdateInLoop("delete from ExerciseGroupItemRe where relationId=?", reIds); |
| | | |
| | | // 更新item的顺序号 |
| | | // 更新item的顺序号 |
| | | String hql = "from ExerciseGroupItemRe re where re.exerciseGroupId=? and re.deleteFlag is false order by re.itemOrder asc "; |
| | | List<ExerciseGroupItemRe> lstRe = this.find(hql, CollectionUtils.newList(groupId), ExerciseGroupItemRe.class); |
| | | if (lstRe != null && lstRe.size() > 0) { |
| | |
| | | |
| | | @Override |
| | | public Result saveSectionItem(ExerciseGroup exerciseGroup) { |
| | | //保存题目信息 |
| | | //保存题目信息 |
| | | return exerciseService.saveExerciseItemBatch(exerciseGroup.getGroupId(), exerciseGroup.getItems()); |
| | | } |
| | | |