From 2e40f1ff31f63d20729215c81295736dd559e208 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Mon, 6 Jan 2025 13:54:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=90=AC=E4=B9=A6=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BookListeningController.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/BookListeningController.java b/src/main/java/com/peanut/modules/book/controller/BookListeningController.java index a6c746cf..44f01ce3 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookListeningController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookListeningController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*; import java.util.Arrays; import java.util.Date; +import java.util.List; import java.util.Map; /** @@ -53,28 +54,25 @@ public class BookListeningController { public R save( BookListeningEntity booklistening){ Integer bookId = booklistening.getBookId(); Integer userId = booklistening.getUserId(); - BookListeningEntity booklisteningEntity = bookListeningService.getBaseMapper().selectOne(new QueryWrapper().eq("book_id", bookId) + List bls = bookListeningService.list(new QueryWrapper() + .eq("book_id", bookId) + .eq("chapter_id", booklistening.getChapterId()) .eq("user_id", userId)); - if (booklisteningEntity != null) { - BookListeningEntity one = bookListeningService.getOne(new QueryWrapper() - .eq("book_id", booklistening.getBookId()) - .eq("user_id", booklistening.getUserId())); - Integer id = one.getId(); - // 构建新的BookListeningEntity对象,设置需要修改的字段 - BookListeningEntity updatedEntity = new BookListeningEntity(); - updatedEntity.setId(id); - updatedEntity.setPrecent(booklistening.getPrecent()); - updatedEntity.setChapterId(booklistening.getChapterId()); - updatedEntity.setChapterName(booklistening.getChapterName()); - updatedEntity.setUpdateTime(new Date()); - // 执行更新操作 - bookListeningService.updateById(updatedEntity); - return R.ok().put("bookListeningId",booklisteningEntity.getId()); + if (bls.size() > 0) { + Integer id = bls.get(0).getId(); + // 构建新的BookListeningEntity对象,设置需要修改的字段 + BookListeningEntity updatedEntity = new BookListeningEntity(); + updatedEntity.setId(id); + updatedEntity.setPrecent(booklistening.getPrecent()); + updatedEntity.setChapterId(booklistening.getChapterId()); + updatedEntity.setChapterName(booklistening.getChapterName()); + updatedEntity.setUpdateTime(new Date()); + // 执行更新操作 + bookListeningService.updateById(updatedEntity); + return R.ok().put("bookListeningId",bls.get(0).getId()); }else { - bookListeningService.save(booklistening); } - return R.ok(); }