保存听书记录,修改

This commit is contained in:
wuchunlei
2025-01-06 13:54:58 +08:00
parent 515a49a285
commit 2e40f1ff31

View File

@@ -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,13 +54,12 @@ public class BookListeningController {
public R save( BookListeningEntity booklistening){
Integer bookId = booklistening.getBookId();
Integer userId = booklistening.getUserId();
BookListeningEntity booklisteningEntity = bookListeningService.getBaseMapper().selectOne(new QueryWrapper<BookListeningEntity>().eq("book_id", bookId)
List<BookListeningEntity> bls = bookListeningService.list(new QueryWrapper<BookListeningEntity>()
.eq("book_id", bookId)
.eq("chapter_id", booklistening.getChapterId())
.eq("user_id", userId));
if (booklisteningEntity != null) {
BookListeningEntity one = bookListeningService.getOne(new QueryWrapper<BookListeningEntity>()
.eq("book_id", booklistening.getBookId())
.eq("user_id", booklistening.getUserId()));
Integer id = one.getId();
if (bls.size() > 0) {
Integer id = bls.get(0).getId();
// 构建新的BookListeningEntity对象设置需要修改的字段
BookListeningEntity updatedEntity = new BookListeningEntity();
updatedEntity.setId(id);
@@ -69,12 +69,10 @@ public class BookListeningController {
updatedEntity.setUpdateTime(new Date());
// 执行更新操作
bookListeningService.updateById(updatedEntity);
return R.ok().put("bookListeningId",booklisteningEntity.getId());
return R.ok().put("bookListeningId",bls.get(0).getId());
}else {
bookListeningService.save(booklistening);
}
return R.ok();
}