perf: 设置小说推荐缓存时间

This commit is contained in:
xiongxiaoyang 2025-04-25 08:30:35 +08:00
parent 3f009dc1f9
commit 415bf8a64c

View File

@ -115,8 +115,8 @@ public class BookServiceImpl implements BookService {
list = initIndexBookSetting(); list = initIndexBookSetting();
} }
result = new ObjectMapper().writeValueAsString( result = new ObjectMapper().writeValueAsString(
list.stream().collect(Collectors.groupingBy(BookSettingVO::getType))); list.stream().collect(Collectors.groupingBy(BookSettingVO::getType)));
cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result); cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result, 3600*24);
} }
return new ObjectMapper().readValue(result, Map.class); return new ObjectMapper().readValue(result, Map.class);
} }
@ -160,7 +160,7 @@ public class BookServiceImpl implements BookService {
} }
bookSettingMapper.delete(deleteFrom(bookSetting).build() bookSettingMapper.delete(deleteFrom(bookSetting).build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
bookSettingMapper.insertMultiple(bookSettingList); bookSettingMapper.insertMultiple(bookSettingList);
return bookSettingVOList; return bookSettingVOList;
@ -219,21 +219,21 @@ public class BookServiceImpl implements BookService {
@Override @Override
public List<BookCategory> listBookCategory() { public List<BookCategory> listBookCategory() {
SelectStatementProvider selectStatementProvider = select(BookCategoryDynamicSqlSupport.id, SelectStatementProvider selectStatementProvider = select(BookCategoryDynamicSqlSupport.id,
BookCategoryDynamicSqlSupport.name, BookCategoryDynamicSqlSupport.workDirection) BookCategoryDynamicSqlSupport.name, BookCategoryDynamicSqlSupport.workDirection)
.from(bookCategory) .from(bookCategory)
.orderBy(BookCategoryDynamicSqlSupport.sort) .orderBy(BookCategoryDynamicSqlSupport.sort)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookCategoryMapper.selectMany(selectStatementProvider); return bookCategoryMapper.selectMany(selectStatementProvider);
} }
@Override @Override
public Book queryBookDetail(Long bookId) { public Book queryBookDetail(Long bookId) {
SelectStatementProvider selectStatement = select(book.allColumns()) SelectStatementProvider selectStatement = select(book.allColumns())
.from(book) .from(book)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookMapper.selectMany(selectStatement).get(0); return bookMapper.selectMany(selectStatement).get(0);
} }
@ -243,45 +243,45 @@ public class BookServiceImpl implements BookService {
PageHelper.startPage(page, pageSize); PageHelper.startPage(page, pageSize);
} }
QueryExpressionDSL<org.mybatis.dynamic.sql.select.SelectModel>.QueryExpressionWhereBuilder where = select( QueryExpressionDSL<org.mybatis.dynamic.sql.select.SelectModel>.QueryExpressionWhereBuilder where = select(
BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.id,
BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum,
BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime,
BookIndexDynamicSqlSupport.isVip) BookIndexDynamicSqlSupport.isVip)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)); .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId));
if ("index_num desc".equals(orderBy)) { if ("index_num desc".equals(orderBy)) {
where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending()); where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending());
} }
return bookIndexMapper.selectMany(where return bookIndexMapper.selectMany(where
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Override @Override
public BookIndex queryBookIndex(Long bookIndexId) { public BookIndex queryBookIndex(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id,
BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum,
BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount,
BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime,
BookIndexDynamicSqlSupport.isVip, BookIndexDynamicSqlSupport.storageType) BookIndexDynamicSqlSupport.isVip, BookIndexDynamicSqlSupport.storageType)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId)) .where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement).get(0); return bookIndexMapper.selectMany(selectStatement).get(0);
} }
@Override @Override
public Long queryPreBookIndexId(Long bookId, Integer indexNum) { public Long queryPreBookIndexId(Long bookId, Integer indexNum) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.and(BookIndexDynamicSqlSupport.indexNum, isLessThan(indexNum)) .and(BookIndexDynamicSqlSupport.indexNum, isLessThan(indexNum))
.orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) .orderBy(BookIndexDynamicSqlSupport.indexNum.descending())
.limit(1) .limit(1)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
List<BookIndex> list = bookIndexMapper.selectMany(selectStatement); List<BookIndex> list = bookIndexMapper.selectMany(selectStatement);
if (list.size() == 0) { if (list.size() == 0) {
return 0L; return 0L;
@ -293,13 +293,13 @@ public class BookServiceImpl implements BookService {
@Override @Override
public Long queryNextBookIndexId(Long bookId, Integer indexNum) { public Long queryNextBookIndexId(Long bookId, Integer indexNum) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.and(BookIndexDynamicSqlSupport.indexNum, isGreaterThan(indexNum)) .and(BookIndexDynamicSqlSupport.indexNum, isGreaterThan(indexNum))
.orderBy(BookIndexDynamicSqlSupport.indexNum) .orderBy(BookIndexDynamicSqlSupport.indexNum)
.limit(1) .limit(1)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
List<BookIndex> list = bookIndexMapper.selectMany(selectStatement); List<BookIndex> list = bookIndexMapper.selectMany(selectStatement);
if (list.size() == 0) { if (list.size() == 0) {
return 0L; return 0L;
@ -311,12 +311,12 @@ public class BookServiceImpl implements BookService {
@Override @Override
public BookContent queryBookContent(Long bookIndexId) { public BookContent queryBookContent(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id, SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id,
BookContentDynamicSqlSupport.content) BookContentDynamicSqlSupport.content)
.from(bookContent) .from(bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId)) .where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId))
.limit(1) .limit(1)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookContentMapper.selectMany(selectStatement).get(0); return bookContentMapper.selectMany(selectStatement).get(0);
} }
@ -344,13 +344,13 @@ public class BookServiceImpl implements BookService {
} }
} }
SelectStatementProvider selectStatement = select(id, catId, catName, bookName, lastIndexId, lastIndexName, SelectStatementProvider selectStatement = select(id, catId, catName, bookName, lastIndexId, lastIndexName,
authorId, authorName, picUrl, bookDesc, wordCount, lastIndexUpdateTime) authorId, authorName, picUrl, bookDesc, wordCount, lastIndexUpdateTime)
.from(book) .from(book)
.where(wordCount, isGreaterThan(0)) .where(wordCount, isGreaterThan(0))
.orderBy(sortSpecification) .orderBy(sortSpecification)
.limit(limit) .limit(limit)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookMapper.selectMany(selectStatement); return bookMapper.selectMany(selectStatement);
} }
@ -363,10 +363,10 @@ public class BookServiceImpl implements BookService {
@Override @Override
public long queryIndexCount(Long bookId) { public long queryIndexCount(Long bookId) {
SelectStatementProvider selectStatement = select(count(BookIndexDynamicSqlSupport.id)) SelectStatementProvider selectStatement = select(count(BookIndexDynamicSqlSupport.id))
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.count(selectStatement); return bookIndexMapper.count(selectStatement);
} }
@ -379,12 +379,12 @@ public class BookServiceImpl implements BookService {
@Override @Override
public Long queryFirstBookIndexId(Long bookId) { public Long queryFirstBookIndexId(Long bookId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.orderBy(BookIndexDynamicSqlSupport.indexNum) .orderBy(BookIndexDynamicSqlSupport.indexNum)
.limit(1) .limit(1)
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement).get(0).getId(); return bookIndexMapper.selectMany(selectStatement).get(0).getId();
} }
@ -399,11 +399,11 @@ public class BookServiceImpl implements BookService {
public void addBookComment(Long userId, BookComment comment) { public void addBookComment(Long userId, BookComment comment) {
//判断该用户是否已评论过该书籍 //判断该用户是否已评论过该书籍
SelectStatementProvider selectStatement = select(count(BookCommentDynamicSqlSupport.id)) SelectStatementProvider selectStatement = select(count(BookCommentDynamicSqlSupport.id))
.from(bookComment) .from(bookComment)
.where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId)) .where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId))
.and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId())) .and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId()))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
if (bookCommentMapper.count(selectStatement) > 0) { if (bookCommentMapper.count(selectStatement) > 0) {
throw new BusinessException(ResponseStatus.HAS_COMMENTS); throw new BusinessException(ResponseStatus.HAS_COMMENTS);
} }
@ -420,10 +420,10 @@ public class BookServiceImpl implements BookService {
public Long getOrCreateAuthorIdByName(String authorName, Byte workDirection) { public Long getOrCreateAuthorIdByName(String authorName, Byte workDirection) {
Long authorId; Long authorId;
SelectStatementProvider selectStatement = select(BookAuthorDynamicSqlSupport.id) SelectStatementProvider selectStatement = select(BookAuthorDynamicSqlSupport.id)
.from(BookAuthorDynamicSqlSupport.bookAuthor) .from(BookAuthorDynamicSqlSupport.bookAuthor)
.where(BookAuthorDynamicSqlSupport.penName, isEqualTo(authorName)) .where(BookAuthorDynamicSqlSupport.penName, isEqualTo(authorName))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
List<BookAuthor> bookAuthors = bookAuthorMapper.selectMany(selectStatement); List<BookAuthor> bookAuthors = bookAuthorMapper.selectMany(selectStatement);
if (bookAuthors.size() > 0) { if (bookAuthors.size() > 0) {
//作者存在 //作者存在
@ -452,11 +452,11 @@ public class BookServiceImpl implements BookService {
public Long queryIdByNameAndAuthor(String bookName, String author) { public Long queryIdByNameAndAuthor(String bookName, String author) {
//查询小说ID //查询小说ID
SelectStatementProvider selectStatement = select(id) SelectStatementProvider selectStatement = select(id)
.from(book) .from(book)
.where(BookDynamicSqlSupport.bookName, isEqualTo(bookName)) .where(BookDynamicSqlSupport.bookName, isEqualTo(bookName))
.and(BookDynamicSqlSupport.authorName, isEqualTo(authorName)) .and(BookDynamicSqlSupport.authorName, isEqualTo(authorName))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
List<Book> books = bookMapper.selectMany(selectStatement); List<Book> books = bookMapper.selectMany(selectStatement);
if (books.size() > 0) { if (books.size() > 0) {
return books.get(0).getId(); return books.get(0).getId();
@ -467,13 +467,13 @@ public class BookServiceImpl implements BookService {
@Override @Override
public List<Integer> queryIndexNumByBookId(Long bookId) { public List<Integer> queryIndexNumByBookId(Long bookId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.indexNum) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.indexNum)
.from(BookIndexDynamicSqlSupport.bookIndex) .from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement).stream().map(BookIndex::getIndexNum) return bookIndexMapper.selectMany(selectStatement).stream().map(BookIndex::getIndexNum)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override @Override
@ -487,13 +487,13 @@ public class BookServiceImpl implements BookService {
picUrl = fileService.transFile(picUrl, picSavePath); picUrl = fileService.transFile(picUrl, picSavePath);
bookMapper.update(update(book) bookMapper.update(update(book)
.set(BookDynamicSqlSupport.picUrl) .set(BookDynamicSqlSupport.picUrl)
.equalTo(picUrl) .equalTo(picUrl)
.set(updateTime) .set(updateTime)
.equalTo(new Date()) .equalTo(new Date())
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@ -504,12 +504,12 @@ public class BookServiceImpl implements BookService {
PageHelper.startPage(page, pageSize); PageHelper.startPage(page, pageSize);
SelectStatementProvider selectStatement = select(id, bookName, picUrl, catName, visitCount, yesterdayBuy, SelectStatementProvider selectStatement = select(id, bookName, picUrl, catName, visitCount, yesterdayBuy,
lastIndexUpdateTime, updateTime, wordCount, lastIndexName, status) lastIndexUpdateTime, updateTime, wordCount, lastIndexName, status)
.from(book) .from(book)
.where(authorId, isEqualTo(author.getId())) .where(authorId, isEqualTo(author.getId()))
.orderBy(BookDynamicSqlSupport.createTime.descending()) .orderBy(BookDynamicSqlSupport.createTime.descending())
.build() .build()
.render(RenderingStrategies.MYBATIS3); .render(RenderingStrategies.MYBATIS3);
return PageBuilder.build(bookMapper.selectMany(selectStatement)); return PageBuilder.build(bookMapper.selectMany(selectStatement));
} }
@ -535,30 +535,30 @@ public class BookServiceImpl implements BookService {
// 用户没有上传封面图片AI自动生成封面图片 // 用户没有上传封面图片AI自动生成封面图片
threadPoolExecutor.execute(() -> { threadPoolExecutor.execute(() -> {
String prompt = String.format("生成一本小说的封面图片,图片中间显示书名《%s》书名下方显示作者“%s 著”。", String prompt = String.format("生成一本小说的封面图片,图片中间显示书名《%s》书名下方显示作者“%s 著”。",
book.getBookName(), book.getAuthorName()); book.getBookName(), book.getAuthorName());
log.debug("prompt:{}", prompt); log.debug("prompt:{}", prompt);
ImageResponse response = openAiImageModel.call( ImageResponse response = openAiImageModel.call(
new ImagePrompt(prompt, new ImagePrompt(prompt,
OpenAiImageOptions.builder() OpenAiImageOptions.builder()
.quality("hd") .quality("hd")
.height(800) .height(800)
.width(600).build()) .width(600).build())
); );
Image output = response.getResult().getOutput(); Image output = response.getResult().getOutput();
Date currentDate = new Date(); Date currentDate = new Date();
String picUrl = Constants.LOCAL_PIC_PREFIX + String picUrl = Constants.LOCAL_PIC_PREFIX +
"aiGen/" + DateUtils.formatDate(currentDate, "yyyy") + "/" + "aiGen/" + DateUtils.formatDate(currentDate, "yyyy") + "/" +
DateUtils.formatDate(currentDate, "MM") + "/" + DateUtils.formatDate(currentDate, "MM") + "/" +
DateUtils.formatDate(currentDate, "dd") + "/" + book.getId() + ".png"; DateUtils.formatDate(currentDate, "dd") + "/" + book.getId() + ".png";
FileUtil.downloadFile(output.getUrl(), picSavePath + picUrl); FileUtil.downloadFile(output.getUrl(), picSavePath + picUrl);
bookMapper.update(update(BookDynamicSqlSupport.book) bookMapper.update(update(BookDynamicSqlSupport.book)
.set(BookDynamicSqlSupport.picUrl) .set(BookDynamicSqlSupport.picUrl)
.equalTo(picUrl) .equalTo(picUrl)
.set(updateTime) .set(updateTime)
.equalTo(currentDate) .equalTo(currentDate)
.where(id, isEqualTo(book.getId())) .where(id, isEqualTo(book.getId()))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
cacheService.set(CacheKey.AI_GEN_PIC + book.getId(), picUrl, 60 * 60); cacheService.set(CacheKey.AI_GEN_PIC + book.getId(), picUrl, 60 * 60);
}); });
} }
@ -567,12 +567,12 @@ public class BookServiceImpl implements BookService {
@Override @Override
public void updateBookStatus(Long bookId, Byte status, Long authorId) { public void updateBookStatus(Long bookId, Byte status, Long authorId) {
bookMapper.update(update(book) bookMapper.update(update(book)
.set(BookDynamicSqlSupport.status) .set(BookDynamicSqlSupport.status)
.equalTo(status) .equalTo(status)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -590,22 +590,22 @@ public class BookServiceImpl implements BookService {
//更新小说主表信息 //更新小说主表信息
bookMapper.update(update(BookDynamicSqlSupport.book) bookMapper.update(update(BookDynamicSqlSupport.book)
.set(BookDynamicSqlSupport.lastIndexId) .set(BookDynamicSqlSupport.lastIndexId)
.equalTo(lastIndexId) .equalTo(lastIndexId)
.set(BookDynamicSqlSupport.lastIndexName) .set(BookDynamicSqlSupport.lastIndexName)
.equalTo(indexName) .equalTo(indexName)
.set(BookDynamicSqlSupport.lastIndexUpdateTime) .set(BookDynamicSqlSupport.lastIndexUpdateTime)
.equalTo(currentDate) .equalTo(currentDate)
.set(BookDynamicSqlSupport.wordCount) .set(BookDynamicSqlSupport.wordCount)
.equalTo(book.getWordCount() + wordCount) .equalTo(book.getWordCount() + wordCount)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
//计算价格 //计算价格
int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue()) 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; int indexNum = 0;
@ -637,23 +637,23 @@ public class BookServiceImpl implements BookService {
public List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit) { public List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit) {
return bookMapper.selectMany(select(book.allColumns()) return bookMapper.selectMany(select(book.allColumns())
.from(book) .from(book)
.where(updateTime, isGreaterThan(startDate)) .where(updateTime, isGreaterThan(startDate))
.and(lastIndexId, isNotNull()) .and(lastIndexId, isNotNull())
.orderBy(updateTime) .orderBy(updateTime)
.limit(limit) .limit(limit)
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Override @Override
public List<Book> queryBookList(Long authorId) { public List<Book> queryBookList(Long authorId) {
return bookMapper.selectMany(select(id, bookName) return bookMapper.selectMany(select(id, bookName)
.from(book) .from(book)
.where(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) .where(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -662,20 +662,20 @@ public class BookServiceImpl implements BookService {
//查询小说章节表信息 //查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany( List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3));
if (bookIndices.size() > 0) { if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0); BookIndex bookIndex = bookIndices.get(0);
//获取小说ID //获取小说ID
Long bookId = bookIndex.getBookId(); Long bookId = bookIndex.getBookId();
//查询小说表信息 //查询小说表信息
List<Book> books = bookMapper.selectMany( List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId) select(wordCount, BookDynamicSqlSupport.authorId)
.from(book) .from(book)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
if (books.size() > 0) { if (books.size() > 0) {
Book book = books.get(0); Book book = books.get(0);
int wordCount = book.getWordCount(); int wordCount = book.getWordCount();
@ -684,8 +684,8 @@ public class BookServiceImpl implements BookService {
//删除目录表和内容表记录 //删除目录表和内容表记录
bookIndexMapper.deleteByPrimaryKey(indexId); bookIndexMapper.deleteByPrimaryKey(indexId);
bookContentMapper.delete( bookContentMapper.delete(
deleteFrom(bookContent).where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)).build() deleteFrom(bookContent).where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)).build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
//更新总字数 //更新总字数
wordCount = wordCount - bookIndex.getWordCount(); wordCount = wordCount - bookIndex.getWordCount();
//更新最新章节 //更新最新章节
@ -693,14 +693,14 @@ public class BookServiceImpl implements BookService {
String lastIndexName = null; String lastIndexName = null;
Date lastIndexUpdateTime = null; Date lastIndexUpdateTime = null;
List<BookIndex> lastBookIndices = bookIndexMapper.selectMany( List<BookIndex> lastBookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.indexName, select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.indexName,
BookIndexDynamicSqlSupport.createTime) BookIndexDynamicSqlSupport.createTime)
.from(BookIndexDynamicSqlSupport.bookIndex) .from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.orderBy(BookIndexDynamicSqlSupport.indexNum.descending()) .orderBy(BookIndexDynamicSqlSupport.indexNum.descending())
.limit(1) .limit(1)
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
if (lastBookIndices.size() > 0) { if (lastBookIndices.size() > 0) {
BookIndex lastBookIndex = lastBookIndices.get(0); BookIndex lastBookIndex = lastBookIndices.get(0);
lastIndexId = lastBookIndex.getId(); lastIndexId = lastBookIndex.getId();
@ -710,19 +710,19 @@ public class BookServiceImpl implements BookService {
} }
//更新小说主表信息 //更新小说主表信息
bookMapper.update(update(BookDynamicSqlSupport.book) bookMapper.update(update(BookDynamicSqlSupport.book)
.set(BookDynamicSqlSupport.wordCount) .set(BookDynamicSqlSupport.wordCount)
.equalTo(wordCount) .equalTo(wordCount)
.set(updateTime) .set(updateTime)
.equalTo(new Date()) .equalTo(new Date())
.set(BookDynamicSqlSupport.lastIndexId) .set(BookDynamicSqlSupport.lastIndexId)
.equalTo(lastIndexId) .equalTo(lastIndexId)
.set(BookDynamicSqlSupport.lastIndexName) .set(BookDynamicSqlSupport.lastIndexName)
.equalTo(lastIndexName) .equalTo(lastIndexName)
.set(BookDynamicSqlSupport.lastIndexUpdateTime) .set(BookDynamicSqlSupport.lastIndexUpdateTime)
.equalTo(lastIndexUpdateTime) .equalTo(lastIndexUpdateTime)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@ -738,34 +738,34 @@ public class BookServiceImpl implements BookService {
public void updateIndexName(Long indexId, String indexName, Long authorId) { public void updateIndexName(Long indexId, String indexName, Long authorId) {
//查询小说章节表信息 //查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany( List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3));
if (bookIndices.size() > 0) { if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0); BookIndex bookIndex = bookIndices.get(0);
//获取小说ID //获取小说ID
Long bookId = bookIndex.getBookId(); Long bookId = bookIndex.getBookId();
//查询小说表信息 //查询小说表信息
List<Book> books = bookMapper.selectMany( List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId) select(wordCount, BookDynamicSqlSupport.authorId)
.from(book) .from(book)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
if (books.size() > 0) { if (books.size() > 0) {
Book book = books.get(0); Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布可以修改 //作者ID相同表明该小说是登录用户发布可以修改
if (book.getAuthorId().equals(authorId)) { if (book.getAuthorId().equals(authorId)) {
bookIndexMapper.update( bookIndexMapper.update(
update(BookIndexDynamicSqlSupport.bookIndex) update(BookIndexDynamicSqlSupport.bookIndex)
.set(BookIndexDynamicSqlSupport.indexName) .set(BookIndexDynamicSqlSupport.indexName)
.equalTo(indexName) .equalTo(indexName)
.set(BookIndexDynamicSqlSupport.updateTime) .set(BookIndexDynamicSqlSupport.updateTime)
.equalTo(new Date()) .equalTo(new Date())
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@ -779,31 +779,31 @@ public class BookServiceImpl implements BookService {
public String queryIndexContent(Long indexId, Long authorId) { public String queryIndexContent(Long indexId, Long authorId) {
//查询小说章节表信息 //查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany( List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3));
if (bookIndices.size() > 0) { if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0); BookIndex bookIndex = bookIndices.get(0);
//获取小说ID //获取小说ID
Long bookId = bookIndex.getBookId(); Long bookId = bookIndex.getBookId();
//查询小说表信息 //查询小说表信息
List<Book> books = bookMapper.selectMany( List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId) select(wordCount, BookDynamicSqlSupport.authorId)
.from(book) .from(book)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
if (books.size() > 0) { if (books.size() > 0) {
Book book = books.get(0); Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布 //作者ID相同表明该小说是登录用户发布
if (book.getAuthorId().equals(authorId)) { if (book.getAuthorId().equals(authorId)) {
return bookContentMapper.selectMany( return bookContentMapper.selectMany(
select(content) select(content)
.from(bookContent) .from(bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId))
.limit(1) .limit(1)
.build().render(RenderingStrategies.MYBATIS3)) .build().render(RenderingStrategies.MYBATIS3))
.get(0).getContent(); .get(0).getContent();
} }
} }
@ -817,20 +817,20 @@ public class BookServiceImpl implements BookService {
//查询小说章节表信息 //查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany( List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount) select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3)); .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategies.MYBATIS3));
if (bookIndices.size() > 0) { if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0); BookIndex bookIndex = bookIndices.get(0);
//获取小说ID //获取小说ID
Long bookId = bookIndex.getBookId(); Long bookId = bookIndex.getBookId();
//查询小说表信息 //查询小说表信息
List<Book> books = bookMapper.selectMany( List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId) select(wordCount, BookDynamicSqlSupport.authorId)
.from(book) .from(book)
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
if (books.size() > 0) { if (books.size() > 0) {
Book book = books.get(0); Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布可以修改 //作者ID相同表明该小说是登录用户发布可以修改
@ -840,29 +840,29 @@ public class BookServiceImpl implements BookService {
//计算价格 //计算价格
int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue()) int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue())
.divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue(); .divide(bookPriceConfig.getWordCount(), 0, RoundingMode.DOWN).intValue();
//更新小说目录表 //更新小说目录表
bookIndexMapper.update( bookIndexMapper.update(
update(BookIndexDynamicSqlSupport.bookIndex) update(BookIndexDynamicSqlSupport.bookIndex)
.set(BookIndexDynamicSqlSupport.indexName) .set(BookIndexDynamicSqlSupport.indexName)
.equalTo(indexName) .equalTo(indexName)
.set(BookIndexDynamicSqlSupport.wordCount) .set(BookIndexDynamicSqlSupport.wordCount)
.equalTo(wordCount) .equalTo(wordCount)
.set(BookIndexDynamicSqlSupport.bookPrice) .set(BookIndexDynamicSqlSupport.bookPrice)
.equalTo(bookPrice) .equalTo(bookPrice)
.set(BookIndexDynamicSqlSupport.updateTime) .set(BookIndexDynamicSqlSupport.updateTime)
.equalTo(currentDate) .equalTo(currentDate)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)) .where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId))
.build().render(RenderingStrategies.MYBATIS3)); .build().render(RenderingStrategies.MYBATIS3));
//更新小说内容表 //更新小说内容表
bookContentMapper.update( bookContentMapper.update(
update(BookContentDynamicSqlSupport.bookContent) update(BookContentDynamicSqlSupport.bookContent)
.set(BookContentDynamicSqlSupport.content) .set(BookContentDynamicSqlSupport.content)
.equalTo(content) .equalTo(content)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)) .where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId))
.build().render(RenderingStrategies.MYBATIS3)); .build().render(RenderingStrategies.MYBATIS3));
} }
} }
@ -873,14 +873,14 @@ public class BookServiceImpl implements BookService {
@Override @Override
public void updateBookPic(Long bookId, String bookPic, Long authorId) { public void updateBookPic(Long bookId, String bookPic, Long authorId) {
bookMapper.update(update(book) bookMapper.update(update(book)
.set(picUrl) .set(picUrl)
.equalTo(bookPic) .equalTo(bookPic)
.set(updateTime) .set(updateTime)
.equalTo(new Date()) .equalTo(new Date())
.where(id, isEqualTo(bookId)) .where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId)) .and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }
@Override @Override