保存听书记录,修改
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,28 +54,25 @@ public class BookListeningController {
|
|||||||
public R save( BookListeningEntity booklistening){
|
public R save( BookListeningEntity booklistening){
|
||||||
Integer bookId = booklistening.getBookId();
|
Integer bookId = booklistening.getBookId();
|
||||||
Integer userId = booklistening.getUserId();
|
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));
|
.eq("user_id", userId));
|
||||||
if (booklisteningEntity != null) {
|
if (bls.size() > 0) {
|
||||||
BookListeningEntity one = bookListeningService.getOne(new QueryWrapper<BookListeningEntity>()
|
Integer id = bls.get(0).getId();
|
||||||
.eq("book_id", booklistening.getBookId())
|
// 构建新的BookListeningEntity对象,设置需要修改的字段
|
||||||
.eq("user_id", booklistening.getUserId()));
|
BookListeningEntity updatedEntity = new BookListeningEntity();
|
||||||
Integer id = one.getId();
|
updatedEntity.setId(id);
|
||||||
// 构建新的BookListeningEntity对象,设置需要修改的字段
|
updatedEntity.setPrecent(booklistening.getPrecent());
|
||||||
BookListeningEntity updatedEntity = new BookListeningEntity();
|
updatedEntity.setChapterId(booklistening.getChapterId());
|
||||||
updatedEntity.setId(id);
|
updatedEntity.setChapterName(booklistening.getChapterName());
|
||||||
updatedEntity.setPrecent(booklistening.getPrecent());
|
updatedEntity.setUpdateTime(new Date());
|
||||||
updatedEntity.setChapterId(booklistening.getChapterId());
|
// 执行更新操作
|
||||||
updatedEntity.setChapterName(booklistening.getChapterName());
|
bookListeningService.updateById(updatedEntity);
|
||||||
updatedEntity.setUpdateTime(new Date());
|
return R.ok().put("bookListeningId",bls.get(0).getId());
|
||||||
// 执行更新操作
|
|
||||||
bookListeningService.updateById(updatedEntity);
|
|
||||||
return R.ok().put("bookListeningId",booklisteningEntity.getId());
|
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
bookListeningService.save(booklistening);
|
bookListeningService.save(booklistening);
|
||||||
}
|
}
|
||||||
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user