|
@@ -315,28 +315,52 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
} else {
|
|
|
parentId = kmtExerciseQuestion.getParentId();
|
|
|
}
|
|
|
- List<String> tempList = kmtExerciseMapper.findQuestionIdByParentId(parentId);
|
|
|
+ List<KmtExerciseQuestion> tempList = kmtExerciseMapper.findQuByParentId(parentId);
|
|
|
//移动小题
|
|
|
if (request.getType() == 1){
|
|
|
//第一个小题不能往上移
|
|
|
if (tempList != null && tempList.size() > 0){
|
|
|
- if (kmtExerciseQuestion.getId().equals(tempList.get(0))){
|
|
|
+ if (kmtExerciseQuestion.getId().equals(tempList.get(0).getId())){
|
|
|
return responseEntity.failure(ResponseConstant.CODE_000, "已移动到第一小题");
|
|
|
}
|
|
|
+ //如果是第二个小题上移, 修改题目的父子关系
|
|
|
+ if (kmtExerciseQuestion.getId().equals(tempList.get(1).getId())){
|
|
|
+ //先特殊修改第一题和第二题, 第三题开始修改父题
|
|
|
+ kmtExerciseMapper.updateParentIdAndQuestionClassTypeAndNumById(null,
|
|
|
+ 1, kmtExerciseQuestion.getNum() - 1, kmtExerciseQuestion.getId());
|
|
|
+ kmtExerciseMapper.updateParentIdAndQuestionClassTypeAndNumById(kmtExerciseQuestion.getId(),
|
|
|
+ 2, kmtExerciseQuestion.getNum(), tempList.get(0).getId());
|
|
|
+ for (int i =2; i < tempList.size(); i++){
|
|
|
+ kmtExerciseMapper.updateParentIdById(kmtExerciseQuestion.getId(), tempList.get(i).getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //上移
|
|
|
+ kmtExerciseMapper.updateByBookIdAndNum(kmtExerciseQuestion.getBookId(), kmtExerciseQuestion.getNum(),kmtExerciseQuestion.getNum() - 1);
|
|
|
+ kmtExerciseMapper.updateQuestionNumByQuestionId(kmtExerciseQuestion.getId(), kmtExerciseQuestion.getNum() - 1);
|
|
|
+ }
|
|
|
}
|
|
|
- //上移
|
|
|
- kmtExerciseMapper.updateByBookIdAndNum(kmtExerciseQuestion.getBookId(), kmtExerciseQuestion.getNum(),kmtExerciseQuestion.getNum() - 1);
|
|
|
- kmtExerciseMapper.updateQuestionNumByQuestionId(kmtExerciseQuestion.getId(), kmtExerciseQuestion.getNum() - 1);
|
|
|
} else if (request.getType() == 2){
|
|
|
//最后一个小题不能往下移
|
|
|
if (tempList != null && tempList.size() > 0){
|
|
|
- if (kmtExerciseQuestion.getId().equals(tempList.get(tempList.size() - 1))){
|
|
|
+ if (kmtExerciseQuestion.getId().equals(tempList.get(tempList.size() - 1).getId())){
|
|
|
return responseEntity.failure(ResponseConstant.CODE_000, "已移动到最后一个小题的位置");
|
|
|
}
|
|
|
+ //如果是第一小题的下移, 修改题目父子关系
|
|
|
+ if (kmtExerciseQuestion.getId().equals(tempList.get(0).getId())){
|
|
|
+ //先特殊修改第一题和第二题, 第三题开始修改父题
|
|
|
+ kmtExerciseMapper.updateParentIdAndQuestionClassTypeAndNumById(tempList.get(1).getId(),
|
|
|
+ 2, kmtExerciseQuestion.getNum() + 1, kmtExerciseQuestion.getId());
|
|
|
+ kmtExerciseMapper.updateParentIdAndQuestionClassTypeAndNumById(null,
|
|
|
+ 1, kmtExerciseQuestion.getNum(), tempList.get(1).getId());
|
|
|
+ for (int i =2; i < tempList.size(); i++){
|
|
|
+ kmtExerciseMapper.updateParentIdById(tempList.get(1).getId(), tempList.get(i).getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //下移
|
|
|
+ kmtExerciseMapper.updateByBookIdAndNum(kmtExerciseQuestion.getBookId(), kmtExerciseQuestion.getNum(), kmtExerciseQuestion.getNum() + 1);
|
|
|
+ kmtExerciseMapper.updateQuestionNumByQuestionId(kmtExerciseQuestion.getId(), kmtExerciseQuestion.getNum() + 1);
|
|
|
+ }
|
|
|
}
|
|
|
- //下移
|
|
|
- kmtExerciseMapper.updateByBookIdAndNum(kmtExerciseQuestion.getBookId(), kmtExerciseQuestion.getNum(), kmtExerciseQuestion.getNum() + 1);
|
|
|
- kmtExerciseMapper.updateQuestionNumByQuestionId(kmtExerciseQuestion.getId(), kmtExerciseQuestion.getNum() + 1);
|
|
|
}
|
|
|
} else if (request.getQuestionClassType() == 1){
|
|
|
if (request.getType() == 1){
|