--新增 修改
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.BookEntity;
|
||||
@@ -8,10 +9,14 @@ import com.peanut.modules.book.entity.BookTeachEntity;
|
||||
import com.peanut.modules.book.service.BookService;
|
||||
import com.peanut.modules.book.service.BookTeachService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("book/teach")
|
||||
public class BookTeachController {
|
||||
@@ -59,4 +64,46 @@ public class BookTeachController {
|
||||
return R.ok().put("bookTeach",byId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/saveTeach")
|
||||
public R save(@RequestBody BookTeachEntity bookTeachEntity) {
|
||||
bookTeachService.save(bookTeachEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/updateTeach")
|
||||
public R updateTeach(@RequestBody BookTeachEntity bookTeachEntity) {
|
||||
|
||||
Integer bookId = bookTeachEntity.getBookId();
|
||||
List<Integer> list = new ArrayList<>();
|
||||
List<BookTeachEntity> bookTeachEntities = this.bookTeachService.getBaseMapper().selectList(new QueryWrapper<BookTeachEntity>()
|
||||
.eq("book_id", bookId)
|
||||
);
|
||||
for(BookTeachEntity entity: bookTeachEntities){
|
||||
entity.setChapter(entity.getChapter() + 1);
|
||||
this.bookTeachService.updateById(entity);
|
||||
}
|
||||
// int[] intArray = list.stream().mapToInt(Integer::intValue).toArray();
|
||||
// for (int i = 0; i < intArray.length; i++) {
|
||||
// int current = intArray[i];
|
||||
// int j = i - 1;
|
||||
// while (j >= 0 && intArray[j] > current) {
|
||||
// intArray[j + 1] = intArray[j];
|
||||
// j--;
|
||||
// }
|
||||
// intArray[j + 1] = current;
|
||||
// }
|
||||
|
||||
this.bookTeachService.updateById(bookTeachEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user