黑馬程序員Java企業(yè)級實戰(zhàn)開發(fā)《學成在線》微服務項目,基于SpringClou

課程計劃排序代碼如下:
@Override
??public void orderByUpOrDown(String moveType, Long teachplanId) {
????Teachplan teachplan = teachplanMapper.selectById(teachplanId);
????Integer grade = teachplan.getGrade();
????if (moveType.equals("moveup") || moveType.equals("movedown") && (grade == 1 || grade == 2)) {
??????changePostition(teachplan, moveType);
????}
?????
??}
??private void changePostition(Teachplan teachplan, String moveType) {
//????定位上一個標題或下一個標題
????LambdaQueryWrapper<Teachplan> wrapper = new LambdaQueryWrapper<>();
????int offset = moveType.equals("moveup") ? -1 : 1;
????wrapper.eq(Teachplan::getOrderby, teachplan.getOrderby() + offset)
????????.eq(Teachplan::getCourseId, teachplan.getCourseId())
????????.eq(Teachplan::getGrade, teachplan.getGrade());
????Teachplan beforeTeachPlan = teachplanMapper.selectOne(wrapper);
????if (beforeTeachPlan == null) {
??????throw new XueChengPlusException("不能移動了");
????}
????beforeTeachPlan.setOrderby(teachplan.getOrderby());
????teachplanMapper.updateById(beforeTeachPlan);
//????定位當前標題
????Teachplan currentTachPlan = teachplanMapper.selectById(teachplan.getId());
????currentTachPlan.setOrderby(teachplan.getOrderby() + offset);
????teachplanMapper.updateById(currentTachPlan);
??}