修复有重复数据
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 听书进度表
|
||||
@@ -54,25 +55,14 @@ public class BookListeningController {
|
||||
public R save( BookListeningEntity booklistening){
|
||||
Integer bookId = booklistening.getBookId();
|
||||
Integer userId = booklistening.getUserId();
|
||||
List<BookListeningEntity> bls = bookListeningService.list(new QueryWrapper<BookListeningEntity>()
|
||||
List<Integer> bls = bookListeningService.list(new QueryWrapper<BookListeningEntity>()
|
||||
.eq("book_id", bookId)
|
||||
.eq("chapter_id", booklistening.getChapterId())
|
||||
.eq("user_id", userId));
|
||||
.eq("user_id", userId))
|
||||
.stream().map(BookListeningEntity::getId).collect(Collectors.toList());
|
||||
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);
|
||||
bookListeningService.removeByIds(bls);
|
||||
}
|
||||
bookListeningService.save(booklistening);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@@ -81,12 +71,14 @@ public class BookListeningController {
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody BookListeningEntity booklistening) {
|
||||
BookListeningEntity one = bookListeningService.getOne(new QueryWrapper<BookListeningEntity>()
|
||||
List<Integer> blIds = bookListeningService.list(new QueryWrapper<BookListeningEntity>()
|
||||
.eq("book_id", booklistening.getBookId())
|
||||
.eq("user_id", booklistening.getUserId()));
|
||||
if (one != null) {
|
||||
Integer id = one.getId();
|
||||
|
||||
.eq("user_id", booklistening.getUserId()))
|
||||
.stream().map(BookListeningEntity::getId).collect(Collectors.toList());
|
||||
if (blIds.size() > 1) {
|
||||
bookListeningService.removeByIds(blIds);
|
||||
}else if (blIds.size() > 0) {
|
||||
Integer id = blIds.get(0);
|
||||
// 构建新的BookListeningEntity对象,设置需要修改的字段
|
||||
BookListeningEntity updatedEntity = new BookListeningEntity();
|
||||
updatedEntity.setId(id);
|
||||
@@ -94,12 +86,11 @@ public class BookListeningController {
|
||||
updatedEntity.setChapterId(booklistening.getChapterId());
|
||||
updatedEntity.setChapterName(booklistening.getChapterName());
|
||||
updatedEntity.setUpdateTime(new Date());
|
||||
|
||||
// 执行更新操作
|
||||
bookListeningService.updateById(updatedEntity);
|
||||
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
bookListeningService.save(booklistening);
|
||||
return R.ok();
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user