保存听书记录,修改
This commit is contained in:
@@ -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<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();
|
||||
// 构建新的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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user