派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
src/main/java/com/qxueyou/scc/exam/service/impl/ExamPaperSectionService.java
@@ -27,7 +27,7 @@
import com.qxueyou.scc.exercise.service.IExerciseService;
/**
 * 试卷部分管理服务层
 * 试卷部分管理服务层
 *
 * @author kevin
 * @createTime 2017-11-1
@@ -60,14 +60,14 @@
    @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()));
@@ -111,7 +111,7 @@
        ExamPaperSectionInfo examPaperSectionInfo = read(ExamPaperSectionInfo.class, sectionId);
        ExerciseGroup exerciseGroup = read(ExerciseGroup.class, examPaperSectionInfo.getGroupId());
        // 获取试卷部分原开始位置和结束位置
        // 获取试卷部分原开始位置和结束位置
        int origStartIndex = examPaperSectionInfo.getItemStartOrder();
        int origEndIndex = examPaperSectionInfo.getItemEndOrder();
@@ -119,7 +119,7 @@
            this.deleteAllSectionItem(examPaperSectionInfo.getSectionId());
        }
        // 将题库的题目复制到试卷题库
        // 将题库的题目复制到试卷题库
        int itemIndex = origStartIndex;
        ExerciseGroup targetExerciseGroup = new ExerciseGroup();
        targetExerciseGroup.setGroupId(examPaperSectionInfo.getGroupId());
@@ -148,19 +148,19 @@
        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());
@@ -169,7 +169,7 @@
                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));
        }
@@ -183,7 +183,7 @@
        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);
@@ -197,7 +197,7 @@
    @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()),
@@ -213,7 +213,7 @@
                this.saveOrUpdateAll(lstExamPaperSectionInfo);
            }
        }
        //清理试卷缓存
        //清理试卷缓存
        this.redisTemplate.delete(currentSectionInfo.getGroupId());
        return new Result(true);
    }
@@ -237,7 +237,7 @@
            }
            this.deleteSectionItem(examPaperSectionInfo.getSectionId(), examPaperSectionInfo.getGroupId(),
                    exerciseItemIds);
            // section坐标置空
            // section坐标置空
            examPaperSectionInfo.setItemEndOrder((short) -1);
            this.save(examPaperSectionInfo);
@@ -247,7 +247,7 @@
    @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);
@@ -267,7 +267,7 @@
                lstRelationIds.add(itemReMap.get(strExerciseItemId).getRelationId());
            }
            // 如果题目删除完了,则设置end为-1
            // 如果题目删除完了,则设置end为-1
            if (currentSectionInfo.getItemEndOrder() - exerciseItemIds.length == currentSectionInfo
                    .getItemStartOrder()) {
                currentSectionInfo.setItemEndOrder((short) -1);
@@ -287,7 +287,7 @@
    }
    /**
     * 删除试卷习题
     * 删除试卷习题
     *
     *
     * @param reIds
@@ -298,15 +298,15 @@
        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) {
@@ -320,7 +320,7 @@
    @Override
    public Result saveSectionItem(ExerciseGroup exerciseGroup) {
        //保存题目信息
        //保存题目信息
        return exerciseService.saveExerciseItemBatch(exerciseGroup.getGroupId(), exerciseGroup.getItems());
    }