diff --git a/peanut_book.iml b/peanut_book.iml index 1daccaec..6274e151 100644 --- a/peanut_book.iml +++ b/peanut_book.iml @@ -1,8 +1,276 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java index 2aea0b27..9f30f893 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookTeachController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookTeachController.java @@ -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 list = new ArrayList<>(); + List bookTeachEntities = this.bookTeachService.getBaseMapper().selectList(new QueryWrapper() + .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(); + } + + }