2024-10-15 19:33:37 +08:00
|
|
|
import { BookService } from "../../../define/db/service/Book/bookService";
|
2024-11-09 16:46:06 +08:00
|
|
|
import { Book } from "../../../model/book/book";
|
2024-10-15 19:33:37 +08:00
|
|
|
|
|
|
|
|
export class BookBasic {
|
|
|
|
|
bookService: BookService
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
|
|
async InitService() {
|
|
|
|
|
if (!this.bookService) {
|
|
|
|
|
this.bookService = await BookService.getInstance()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#region 事务操作
|
|
|
|
|
async transaction(callback: (realm: any) => void) {
|
|
|
|
|
await this.InitService();
|
|
|
|
|
this.bookService.transaction(() => {
|
|
|
|
|
callback(this.bookService.realm)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过小说ID获取小说数据
|
|
|
|
|
* @param bookId 小说ID
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
async GetBookDataById(bookId: string): Promise<Book.SelectBook> {
|
|
|
|
|
await this.InitService();
|
|
|
|
|
let book = this.bookService.GetBookDataById(bookId);
|
|
|
|
|
if (book == null) {
|
|
|
|
|
let msg = '未找到对应的小说数据,请检查'
|
|
|
|
|
throw new Error(msg);
|
|
|
|
|
}
|
|
|
|
|
return book
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新小说指定ID的数据
|
|
|
|
|
* @param bookId 小说ID
|
|
|
|
|
* @param data 小说要更新的数据
|
|
|
|
|
*/
|
|
|
|
|
async UpdateBookData(bookId: string, data: Book.SelectBook): Promise<Book.SelectBook> {
|
|
|
|
|
await this.InitService();
|
|
|
|
|
let res = this.bookService.UpdateBookData(bookId, data)
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除指定的小说数据
|
|
|
|
|
* @param bookId 需要删除的小说ID
|
|
|
|
|
*/
|
|
|
|
|
async DeleteBookData(bookId: string): Promise<void> {
|
|
|
|
|
await this.InitService();
|
|
|
|
|
this.bookService.DeleteBookData(bookId)
|
|
|
|
|
}
|
|
|
|
|
}
|