From 415bf8a64c4d75b019381bacba7d22c3d340e7b0 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Fri, 25 Apr 2025 08:30:35 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AE=BE=E7=BD=AE=E5=B0=8F=E8=AF=B4?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E7=BC=93=E5=AD=98=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../novel/service/impl/BookServiceImpl.java | 476 +++++++++--------- 1 file changed, 238 insertions(+), 238 deletions(-) diff --git a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java index 9e2b2bb..396d01e 100644 --- a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java +++ b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java @@ -115,8 +115,8 @@ public class BookServiceImpl implements BookService { list = initIndexBookSetting(); } result = new ObjectMapper().writeValueAsString( - list.stream().collect(Collectors.groupingBy(BookSettingVO::getType))); - cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result); + list.stream().collect(Collectors.groupingBy(BookSettingVO::getType))); + cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result, 3600*24); } return new ObjectMapper().readValue(result, Map.class); } @@ -160,7 +160,7 @@ public class BookServiceImpl implements BookService { } bookSettingMapper.delete(deleteFrom(bookSetting).build() - .render(RenderingStrategies.MYBATIS3)); + .render(RenderingStrategies.MYBATIS3)); bookSettingMapper.insertMultiple(bookSettingList); return bookSettingVOList; @@ -219,21 +219,21 @@ public class BookServiceImpl implements BookService { @Override public List listBookCategory() { SelectStatementProvider selectStatementProvider = select(BookCategoryDynamicSqlSupport.id, - BookCategoryDynamicSqlSupport.name, BookCategoryDynamicSqlSupport.workDirection) - .from(bookCategory) - .orderBy(BookCategoryDynamicSqlSupport.sort) - .build() - .render(RenderingStrategies.MYBATIS3); + BookCategoryDynamicSqlSupport.name, BookCategoryDynamicSqlSupport.workDirection) + .from(bookCategory) + .orderBy(BookCategoryDynamicSqlSupport.sort) + .build() + .render(RenderingStrategies.MYBATIS3); return bookCategoryMapper.selectMany(selectStatementProvider); } @Override public Book queryBookDetail(Long bookId) { SelectStatementProvider selectStatement = select(book.allColumns()) - .from(book) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(book) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3); return bookMapper.selectMany(selectStatement).get(0); } @@ -243,45 +243,45 @@ public class BookServiceImpl implements BookService { PageHelper.startPage(page, pageSize); } QueryExpressionDSL.QueryExpressionWhereBuilder where = select( - BookIndexDynamicSqlSupport.id, - BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, - BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, - BookIndexDynamicSqlSupport.isVip) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)); + BookIndexDynamicSqlSupport.id, + BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, + BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, + BookIndexDynamicSqlSupport.isVip) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)); if ("index_num desc".equals(orderBy)) { where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending()); } return bookIndexMapper.selectMany(where - .build() - .render(RenderingStrategies.MYBATIS3)); + .build() + .render(RenderingStrategies.MYBATIS3)); } @Override public BookIndex queryBookIndex(Long bookIndexId) { SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, - BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, - BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, - BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime, - BookIndexDynamicSqlSupport.isVip, BookIndexDynamicSqlSupport.storageType) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId)) - .build() - .render(RenderingStrategies.MYBATIS3); + BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, + BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, + BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime, + BookIndexDynamicSqlSupport.isVip, BookIndexDynamicSqlSupport.storageType) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId)) + .build() + .render(RenderingStrategies.MYBATIS3); return bookIndexMapper.selectMany(selectStatement).get(0); } @Override public Long queryPreBookIndexId(Long bookId, Integer indexNum) { SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .and(BookIndexDynamicSqlSupport.indexNum, isLessThan(indexNum)) - .orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) - .limit(1) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .and(BookIndexDynamicSqlSupport.indexNum, isLessThan(indexNum)) + .orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) + .limit(1) + .build() + .render(RenderingStrategies.MYBATIS3); List list = bookIndexMapper.selectMany(selectStatement); if (list.size() == 0) { return 0L; @@ -293,13 +293,13 @@ public class BookServiceImpl implements BookService { @Override public Long queryNextBookIndexId(Long bookId, Integer indexNum) { SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .and(BookIndexDynamicSqlSupport.indexNum, isGreaterThan(indexNum)) - .orderBy(BookIndexDynamicSqlSupport.indexNum) - .limit(1) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .and(BookIndexDynamicSqlSupport.indexNum, isGreaterThan(indexNum)) + .orderBy(BookIndexDynamicSqlSupport.indexNum) + .limit(1) + .build() + .render(RenderingStrategies.MYBATIS3); List list = bookIndexMapper.selectMany(selectStatement); if (list.size() == 0) { return 0L; @@ -311,12 +311,12 @@ public class BookServiceImpl implements BookService { @Override public BookContent queryBookContent(Long bookIndexId) { SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id, - BookContentDynamicSqlSupport.content) - .from(bookContent) - .where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId)) - .limit(1) - .build() - .render(RenderingStrategies.MYBATIS3); + BookContentDynamicSqlSupport.content) + .from(bookContent) + .where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId)) + .limit(1) + .build() + .render(RenderingStrategies.MYBATIS3); return bookContentMapper.selectMany(selectStatement).get(0); } @@ -344,13 +344,13 @@ public class BookServiceImpl implements BookService { } } SelectStatementProvider selectStatement = select(id, catId, catName, bookName, lastIndexId, lastIndexName, - authorId, authorName, picUrl, bookDesc, wordCount, lastIndexUpdateTime) - .from(book) - .where(wordCount, isGreaterThan(0)) - .orderBy(sortSpecification) - .limit(limit) - .build() - .render(RenderingStrategies.MYBATIS3); + authorId, authorName, picUrl, bookDesc, wordCount, lastIndexUpdateTime) + .from(book) + .where(wordCount, isGreaterThan(0)) + .orderBy(sortSpecification) + .limit(limit) + .build() + .render(RenderingStrategies.MYBATIS3); return bookMapper.selectMany(selectStatement); } @@ -363,10 +363,10 @@ public class BookServiceImpl implements BookService { @Override public long queryIndexCount(Long bookId) { SelectStatementProvider selectStatement = select(count(BookIndexDynamicSqlSupport.id)) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3); return bookIndexMapper.count(selectStatement); } @@ -379,12 +379,12 @@ public class BookServiceImpl implements BookService { @Override public Long queryFirstBookIndexId(Long bookId) { SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .orderBy(BookIndexDynamicSqlSupport.indexNum) - .limit(1) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .orderBy(BookIndexDynamicSqlSupport.indexNum) + .limit(1) + .build() + .render(RenderingStrategies.MYBATIS3); return bookIndexMapper.selectMany(selectStatement).get(0).getId(); } @@ -399,11 +399,11 @@ public class BookServiceImpl implements BookService { public void addBookComment(Long userId, BookComment comment) { //判断该用户是否已评论过该书籍 SelectStatementProvider selectStatement = select(count(BookCommentDynamicSqlSupport.id)) - .from(bookComment) - .where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId)) - .and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId())) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(bookComment) + .where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId)) + .and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId())) + .build() + .render(RenderingStrategies.MYBATIS3); if (bookCommentMapper.count(selectStatement) > 0) { throw new BusinessException(ResponseStatus.HAS_COMMENTS); } @@ -420,10 +420,10 @@ public class BookServiceImpl implements BookService { public Long getOrCreateAuthorIdByName(String authorName, Byte workDirection) { Long authorId; SelectStatementProvider selectStatement = select(BookAuthorDynamicSqlSupport.id) - .from(BookAuthorDynamicSqlSupport.bookAuthor) - .where(BookAuthorDynamicSqlSupport.penName, isEqualTo(authorName)) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(BookAuthorDynamicSqlSupport.bookAuthor) + .where(BookAuthorDynamicSqlSupport.penName, isEqualTo(authorName)) + .build() + .render(RenderingStrategies.MYBATIS3); List bookAuthors = bookAuthorMapper.selectMany(selectStatement); if (bookAuthors.size() > 0) { //作者存在 @@ -452,11 +452,11 @@ public class BookServiceImpl implements BookService { public Long queryIdByNameAndAuthor(String bookName, String author) { //查询小说ID SelectStatementProvider selectStatement = select(id) - .from(book) - .where(BookDynamicSqlSupport.bookName, isEqualTo(bookName)) - .and(BookDynamicSqlSupport.authorName, isEqualTo(authorName)) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(book) + .where(BookDynamicSqlSupport.bookName, isEqualTo(bookName)) + .and(BookDynamicSqlSupport.authorName, isEqualTo(authorName)) + .build() + .render(RenderingStrategies.MYBATIS3); List books = bookMapper.selectMany(selectStatement); if (books.size() > 0) { return books.get(0).getId(); @@ -467,13 +467,13 @@ public class BookServiceImpl implements BookService { @Override public List queryIndexNumByBookId(Long bookId) { SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.indexNum) - .from(BookIndexDynamicSqlSupport.bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3); + .from(BookIndexDynamicSqlSupport.bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3); return bookIndexMapper.selectMany(selectStatement).stream().map(BookIndex::getIndexNum) - .collect(Collectors.toList()); + .collect(Collectors.toList()); } @Override @@ -487,13 +487,13 @@ public class BookServiceImpl implements BookService { picUrl = fileService.transFile(picUrl, picSavePath); bookMapper.update(update(book) - .set(BookDynamicSqlSupport.picUrl) - .equalTo(picUrl) - .set(updateTime) - .equalTo(new Date()) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(BookDynamicSqlSupport.picUrl) + .equalTo(picUrl) + .set(updateTime) + .equalTo(new Date()) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @@ -504,12 +504,12 @@ public class BookServiceImpl implements BookService { PageHelper.startPage(page, pageSize); SelectStatementProvider selectStatement = select(id, bookName, picUrl, catName, visitCount, yesterdayBuy, - lastIndexUpdateTime, updateTime, wordCount, lastIndexName, status) - .from(book) - .where(authorId, isEqualTo(author.getId())) - .orderBy(BookDynamicSqlSupport.createTime.descending()) - .build() - .render(RenderingStrategies.MYBATIS3); + lastIndexUpdateTime, updateTime, wordCount, lastIndexName, status) + .from(book) + .where(authorId, isEqualTo(author.getId())) + .orderBy(BookDynamicSqlSupport.createTime.descending()) + .build() + .render(RenderingStrategies.MYBATIS3); return PageBuilder.build(bookMapper.selectMany(selectStatement)); } @@ -535,30 +535,30 @@ public class BookServiceImpl implements BookService { // 用户没有上传封面图片,AI自动生成封面图片 threadPoolExecutor.execute(() -> { String prompt = String.format("生成一本小说的封面图片,图片中间显示书名《%s》,书名下方显示作者“%s 著”。", - book.getBookName(), book.getAuthorName()); + book.getBookName(), book.getAuthorName()); log.debug("prompt:{}", prompt); ImageResponse response = openAiImageModel.call( - new ImagePrompt(prompt, - OpenAiImageOptions.builder() - .quality("hd") - .height(800) - .width(600).build()) + new ImagePrompt(prompt, + OpenAiImageOptions.builder() + .quality("hd") + .height(800) + .width(600).build()) ); Image output = response.getResult().getOutput(); Date currentDate = new Date(); String picUrl = Constants.LOCAL_PIC_PREFIX + - "aiGen/" + DateUtils.formatDate(currentDate, "yyyy") + "/" + - DateUtils.formatDate(currentDate, "MM") + "/" + - DateUtils.formatDate(currentDate, "dd") + "/" + book.getId() + ".png"; + "aiGen/" + DateUtils.formatDate(currentDate, "yyyy") + "/" + + DateUtils.formatDate(currentDate, "MM") + "/" + + DateUtils.formatDate(currentDate, "dd") + "/" + book.getId() + ".png"; FileUtil.downloadFile(output.getUrl(), picSavePath + picUrl); bookMapper.update(update(BookDynamicSqlSupport.book) - .set(BookDynamicSqlSupport.picUrl) - .equalTo(picUrl) - .set(updateTime) - .equalTo(currentDate) - .where(id, isEqualTo(book.getId())) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(BookDynamicSqlSupport.picUrl) + .equalTo(picUrl) + .set(updateTime) + .equalTo(currentDate) + .where(id, isEqualTo(book.getId())) + .build() + .render(RenderingStrategies.MYBATIS3)); cacheService.set(CacheKey.AI_GEN_PIC + book.getId(), picUrl, 60 * 60); }); } @@ -567,12 +567,12 @@ public class BookServiceImpl implements BookService { @Override public void updateBookStatus(Long bookId, Byte status, Long authorId) { bookMapper.update(update(book) - .set(BookDynamicSqlSupport.status) - .equalTo(status) - .where(id, isEqualTo(bookId)) - .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(BookDynamicSqlSupport.status) + .equalTo(status) + .where(id, isEqualTo(bookId)) + .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @Transactional(rollbackFor = Exception.class) @@ -590,22 +590,22 @@ public class BookServiceImpl implements BookService { //更新小说主表信息 bookMapper.update(update(BookDynamicSqlSupport.book) - .set(BookDynamicSqlSupport.lastIndexId) - .equalTo(lastIndexId) - .set(BookDynamicSqlSupport.lastIndexName) - .equalTo(indexName) - .set(BookDynamicSqlSupport.lastIndexUpdateTime) - .equalTo(currentDate) - .set(BookDynamicSqlSupport.wordCount) - .equalTo(book.getWordCount() + wordCount) - .where(id, isEqualTo(bookId)) - .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(BookDynamicSqlSupport.lastIndexId) + .equalTo(lastIndexId) + .set(BookDynamicSqlSupport.lastIndexName) + .equalTo(indexName) + .set(BookDynamicSqlSupport.lastIndexUpdateTime) + .equalTo(currentDate) + .set(BookDynamicSqlSupport.wordCount) + .equalTo(book.getWordCount() + wordCount) + .where(id, isEqualTo(bookId)) + .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) + .build() + .render(RenderingStrategies.MYBATIS3)); //计算价格 int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue()) - .divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue(); + .divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue(); //更新小说目录表 int indexNum = 0; @@ -637,23 +637,23 @@ public class BookServiceImpl implements BookService { public List queryBookByUpdateTimeByPage(Date startDate, int limit) { return bookMapper.selectMany(select(book.allColumns()) - .from(book) - .where(updateTime, isGreaterThan(startDate)) - .and(lastIndexId, isNotNull()) - .orderBy(updateTime) - .limit(limit) - .build() - .render(RenderingStrategies.MYBATIS3)); + .from(book) + .where(updateTime, isGreaterThan(startDate)) + .and(lastIndexId, isNotNull()) + .orderBy(updateTime) + .limit(limit) + .build() + .render(RenderingStrategies.MYBATIS3)); } @Override public List queryBookList(Long authorId) { return bookMapper.selectMany(select(id, bookName) - .from(book) - .where(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .from(book) + .where(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @Transactional(rollbackFor = Exception.class) @@ -662,20 +662,20 @@ public class BookServiceImpl implements BookService { //查询小说章节表信息 List bookIndices = bookIndexMapper.selectMany( - select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); + select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); if (bookIndices.size() > 0) { BookIndex bookIndex = bookIndices.get(0); //获取小说ID Long bookId = bookIndex.getBookId(); //查询小说表信息 List books = bookMapper.selectMany( - select(wordCount, BookDynamicSqlSupport.authorId) - .from(book) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + select(wordCount, BookDynamicSqlSupport.authorId) + .from(book) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); if (books.size() > 0) { Book book = books.get(0); int wordCount = book.getWordCount(); @@ -684,8 +684,8 @@ public class BookServiceImpl implements BookService { //删除目录表和内容表记录 bookIndexMapper.deleteByPrimaryKey(indexId); bookContentMapper.delete( - deleteFrom(bookContent).where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)).build() - .render(RenderingStrategies.MYBATIS3)); + deleteFrom(bookContent).where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)).build() + .render(RenderingStrategies.MYBATIS3)); //更新总字数 wordCount = wordCount - bookIndex.getWordCount(); //更新最新章节 @@ -693,14 +693,14 @@ public class BookServiceImpl implements BookService { String lastIndexName = null; Date lastIndexUpdateTime = null; List lastBookIndices = bookIndexMapper.selectMany( - select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.indexName, - BookIndexDynamicSqlSupport.createTime) - .from(BookIndexDynamicSqlSupport.bookIndex) - .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) - .orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) - .limit(1) - .build() - .render(RenderingStrategies.MYBATIS3)); + select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.indexName, + BookIndexDynamicSqlSupport.createTime) + .from(BookIndexDynamicSqlSupport.bookIndex) + .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) + .orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) + .limit(1) + .build() + .render(RenderingStrategies.MYBATIS3)); if (lastBookIndices.size() > 0) { BookIndex lastBookIndex = lastBookIndices.get(0); lastIndexId = lastBookIndex.getId(); @@ -710,19 +710,19 @@ public class BookServiceImpl implements BookService { } //更新小说主表信息 bookMapper.update(update(BookDynamicSqlSupport.book) - .set(BookDynamicSqlSupport.wordCount) - .equalTo(wordCount) - .set(updateTime) - .equalTo(new Date()) - .set(BookDynamicSqlSupport.lastIndexId) - .equalTo(lastIndexId) - .set(BookDynamicSqlSupport.lastIndexName) - .equalTo(lastIndexName) - .set(BookDynamicSqlSupport.lastIndexUpdateTime) - .equalTo(lastIndexUpdateTime) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(BookDynamicSqlSupport.wordCount) + .equalTo(wordCount) + .set(updateTime) + .equalTo(new Date()) + .set(BookDynamicSqlSupport.lastIndexId) + .equalTo(lastIndexId) + .set(BookDynamicSqlSupport.lastIndexName) + .equalTo(lastIndexName) + .set(BookDynamicSqlSupport.lastIndexUpdateTime) + .equalTo(lastIndexUpdateTime) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @@ -738,34 +738,34 @@ public class BookServiceImpl implements BookService { public void updateIndexName(Long indexId, String indexName, Long authorId) { //查询小说章节表信息 List bookIndices = bookIndexMapper.selectMany( - select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); + select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); if (bookIndices.size() > 0) { BookIndex bookIndex = bookIndices.get(0); //获取小说ID Long bookId = bookIndex.getBookId(); //查询小说表信息 List books = bookMapper.selectMany( - select(wordCount, BookDynamicSqlSupport.authorId) - .from(book) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + select(wordCount, BookDynamicSqlSupport.authorId) + .from(book) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); if (books.size() > 0) { Book book = books.get(0); //作者ID相同,表明该小说是登录用户发布,可以修改 if (book.getAuthorId().equals(authorId)) { bookIndexMapper.update( - update(BookIndexDynamicSqlSupport.bookIndex) - .set(BookIndexDynamicSqlSupport.indexName) - .equalTo(indexName) - .set(BookIndexDynamicSqlSupport.updateTime) - .equalTo(new Date()) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + update(BookIndexDynamicSqlSupport.bookIndex) + .set(BookIndexDynamicSqlSupport.indexName) + .equalTo(indexName) + .set(BookIndexDynamicSqlSupport.updateTime) + .equalTo(new Date()) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @@ -779,31 +779,31 @@ public class BookServiceImpl implements BookService { public String queryIndexContent(Long indexId, Long authorId) { //查询小说章节表信息 List bookIndices = bookIndexMapper.selectMany( - select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); + select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); if (bookIndices.size() > 0) { BookIndex bookIndex = bookIndices.get(0); //获取小说ID Long bookId = bookIndex.getBookId(); //查询小说表信息 List books = bookMapper.selectMany( - select(wordCount, BookDynamicSqlSupport.authorId) - .from(book) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + select(wordCount, BookDynamicSqlSupport.authorId) + .from(book) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); if (books.size() > 0) { Book book = books.get(0); //作者ID相同,表明该小说是登录用户发布 if (book.getAuthorId().equals(authorId)) { return bookContentMapper.selectMany( - select(content) - .from(bookContent) - .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) - .limit(1) - .build().render(RenderingStrategies.MYBATIS3)) - .get(0).getContent(); + select(content) + .from(bookContent) + .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) + .limit(1) + .build().render(RenderingStrategies.MYBATIS3)) + .get(0).getContent(); } } @@ -817,20 +817,20 @@ public class BookServiceImpl implements BookService { //查询小说章节表信息 List bookIndices = bookIndexMapper.selectMany( - select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) - .from(bookIndex) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); + select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) + .from(bookIndex) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); if (bookIndices.size() > 0) { BookIndex bookIndex = bookIndices.get(0); //获取小说ID Long bookId = bookIndex.getBookId(); //查询小说表信息 List books = bookMapper.selectMany( - select(wordCount, BookDynamicSqlSupport.authorId) - .from(book) - .where(id, isEqualTo(bookId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + select(wordCount, BookDynamicSqlSupport.authorId) + .from(book) + .where(id, isEqualTo(bookId)) + .build() + .render(RenderingStrategies.MYBATIS3)); if (books.size() > 0) { Book book = books.get(0); //作者ID相同,表明该小说是登录用户发布,可以修改 @@ -840,29 +840,29 @@ public class BookServiceImpl implements BookService { //计算价格 int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue()) - .divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue(); + .divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue(); //更新小说目录表 bookIndexMapper.update( - update(BookIndexDynamicSqlSupport.bookIndex) - .set(BookIndexDynamicSqlSupport.indexName) - .equalTo(indexName) - .set(BookIndexDynamicSqlSupport.wordCount) - .equalTo(wordCount) - .set(BookIndexDynamicSqlSupport.bookPrice) - .equalTo(bookPrice) - .set(BookIndexDynamicSqlSupport.updateTime) - .equalTo(currentDate) - .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) - .build().render(RenderingStrategies.MYBATIS3)); + update(BookIndexDynamicSqlSupport.bookIndex) + .set(BookIndexDynamicSqlSupport.indexName) + .equalTo(indexName) + .set(BookIndexDynamicSqlSupport.wordCount) + .equalTo(wordCount) + .set(BookIndexDynamicSqlSupport.bookPrice) + .equalTo(bookPrice) + .set(BookIndexDynamicSqlSupport.updateTime) + .equalTo(currentDate) + .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) + .build().render(RenderingStrategies.MYBATIS3)); //更新小说内容表 bookContentMapper.update( - update(BookContentDynamicSqlSupport.bookContent) - .set(BookContentDynamicSqlSupport.content) - .equalTo(content) - .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) - .build().render(RenderingStrategies.MYBATIS3)); + update(BookContentDynamicSqlSupport.bookContent) + .set(BookContentDynamicSqlSupport.content) + .equalTo(content) + .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) + .build().render(RenderingStrategies.MYBATIS3)); } } @@ -873,14 +873,14 @@ public class BookServiceImpl implements BookService { @Override public void updateBookPic(Long bookId, String bookPic, Long authorId) { bookMapper.update(update(book) - .set(picUrl) - .equalTo(bookPic) - .set(updateTime) - .equalTo(new Date()) - .where(id, isEqualTo(bookId)) - .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) - .build() - .render(RenderingStrategies.MYBATIS3)); + .set(picUrl) + .equalTo(bookPic) + .set(updateTime) + .equalTo(new Date()) + .where(id, isEqualTo(bookId)) + .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) + .build() + .render(RenderingStrategies.MYBATIS3)); } @Override @@ -889,4 +889,4 @@ public class BookServiceImpl implements BookService { } -} +} \ No newline at end of file