索引+搜索优化

This commit is contained in:
xiongxiaoyang 2020-05-20 21:23:59 +08:00
parent 8a628f081f
commit 002a0723f7
3 changed files with 177 additions and 168 deletions

View File

@ -11,17 +11,20 @@ PUT /novel
}, },
"authorName" : { "authorName" : {
"type" : "text", "type" : "text",
"analyzer": "ik_smart" "analyzer": "ik_smart",
"boost": 1
}, },
"bookName" : { "bookName" : {
"type" : "text", "type" : "text",
"analyzer": "ik_smart" "analyzer": "ik_smart",
"boost": 2
}, },
"bookDesc" : { "bookDesc" : {
"type" : "text", "type" : "text",
"analyzer": "ik_smart" "analyzer": "ik_smart",
"boost": 0.1
}, },
"bookStatus" : { "bookStatus" : {
@ -34,7 +37,8 @@ PUT /novel
"catName" : { "catName" : {
"type" : "text", "type" : "text",
"analyzer": "ik_smart" "analyzer": "ik_smart",
"boost": 0.5
}, },
"lastIndexId" : { "lastIndexId" : {
@ -43,7 +47,8 @@ PUT /novel
"lastIndexName" : { "lastIndexName" : {
"type" : "text", "type" : "text",
"analyzer": "ik_smart" "analyzer": "ik_smart",
"boost": 0.1
}, },
"lastIndexUpdateTime" : { "lastIndexUpdateTime" : {

View File

@ -64,7 +64,7 @@ public class BookServiceImpl implements BookService {
/** /**
* 本地图片保存路径 * 本地图片保存路径
* */ */
@Value("${pic.save.path}") @Value("${pic.save.path}")
private String picSavePath; private String picSavePath;
@ -98,24 +98,24 @@ public class BookServiceImpl implements BookService {
String result = cacheService.get(CacheKey.INDEX_BOOK_SETTINGS_KEY); String result = cacheService.get(CacheKey.INDEX_BOOK_SETTINGS_KEY);
if (result == null || result.length() < Constants.OBJECT_JSON_CACHE_EXIST_LENGTH) { if (result == null || result.length() < Constants.OBJECT_JSON_CACHE_EXIST_LENGTH) {
List<BookSettingVO> list = bookSettingMapper.listVO(); List<BookSettingVO> list = bookSettingMapper.listVO();
if(list.size() == 0) { if (list.size() == 0) {
//如果首页小说没有被设置则初始化首页小说设置 //如果首页小说没有被设置则初始化首页小说设置
list = initIndexBookSetting(); list = initIndexBookSetting();
} }
result = new ObjectMapper().writeValueAsString(list.stream().collect(Collectors.groupingBy(BookSettingVO::getType))); result = new ObjectMapper().writeValueAsString(list.stream().collect(Collectors.groupingBy(BookSettingVO::getType)));
cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result); cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result);
} }
return new ObjectMapper().readValue(result,Map.class); return new ObjectMapper().readValue(result, Map.class);
} }
/** /**
* 初始化首页小说设置 * 初始化首页小说设置
* */ */
private List<BookSettingVO> initIndexBookSetting() { private List<BookSettingVO> initIndexBookSetting() {
Date currentDate = new Date(); Date currentDate = new Date();
List<Book> books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM); List<Book> books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM);
if(books.size() == Constants.INDEX_BOOK_SETTING_NUM) { if (books.size() == Constants.INDEX_BOOK_SETTING_NUM) {
List<BookSetting> bookSettingList = new ArrayList<>(Constants.INDEX_BOOK_SETTING_NUM); List<BookSetting> bookSettingList = new ArrayList<>(Constants.INDEX_BOOK_SETTING_NUM);
List<BookSettingVO> bookSettingVOList = new ArrayList<>(Constants.INDEX_BOOK_SETTING_NUM); List<BookSettingVO> bookSettingVOList = new ArrayList<>(Constants.INDEX_BOOK_SETTING_NUM);
for (int i = 0; i < books.size(); i++) { for (int i = 0; i < books.size(); i++) {
@ -129,7 +129,7 @@ public class BookServiceImpl implements BookService {
type = 2; type = 2;
} else if (i < 26) { } else if (i < 26) {
type = 3; type = 3;
}else{ } else {
type = 4; type = 4;
} }
BookSettingVO bookSettingVO = new BookSettingVO(); BookSettingVO bookSettingVO = new BookSettingVO();
@ -141,8 +141,8 @@ public class BookServiceImpl implements BookService {
bookSetting.setUpdateTime(currentDate); bookSetting.setUpdateTime(currentDate);
bookSettingList.add(bookSetting); bookSettingList.add(bookSetting);
BeanUtils.copyProperties(book,bookSettingVO); BeanUtils.copyProperties(book, bookSettingVO);
BeanUtils.copyProperties(bookSetting,bookSettingVO); BeanUtils.copyProperties(bookSetting, bookSettingVO);
bookSettingVOList.add(bookSettingVO); bookSettingVOList.add(bookSettingVO);
} }
@ -179,13 +179,12 @@ public class BookServiceImpl implements BookService {
List<BookVO> result = (List<BookVO>) cacheService.getObject(CacheKey.INDEX_UPDATE_BOOK_KEY); List<BookVO> result = (List<BookVO>) cacheService.getObject(CacheKey.INDEX_UPDATE_BOOK_KEY);
if (result == null || result.size() == 0) { if (result == null || result.size() == 0) {
List<Book> bookPOList = listRank((byte) 2, 23); List<Book> bookPOList = listRank((byte) 2, 23);
result = BeanUtil.copyList(bookPOList,BookVO.class); result = BeanUtil.copyList(bookPOList, BookVO.class);
cacheService.setObject(CacheKey.INDEX_UPDATE_BOOK_KEY, result, 60 * 10); cacheService.setObject(CacheKey.INDEX_UPDATE_BOOK_KEY, result, 60 * 10);
} }
return result; return result;
} }
@SneakyThrows
@Override @Override
public PageInfo searchByPage(BookSP params, int page, int pageSize) { public PageInfo searchByPage(BookSP params, int page, int pageSize) {
@ -197,7 +196,10 @@ public class BookServiceImpl implements BookService {
params.setUpdateTimeMin(new Date(time)); params.setUpdateTimeMin(new Date(time));
} }
if(esEnable == 1) { if (esEnable == 1) {
try {
List<EsBookVO> bookList = new ArrayList<>(0); List<EsBookVO> bookList = new ArrayList<>(0);
//使用搜索引擎搜索 //使用搜索引擎搜索
@ -220,28 +222,30 @@ public class BookServiceImpl implements BookService {
boolQueryBuilder.filter(QueryBuilders.termQuery("bookStatus", params.getBookStatus())); boolQueryBuilder.filter(QueryBuilders.termQuery("bookStatus", params.getBookStatus()));
} }
if(params.getWordCountMin() == null){ if (params.getWordCountMin() == null) {
params.setWordCountMin(0); params.setWordCountMin(0);
} }
if(params.getWordCountMax() == null){ if (params.getWordCountMax() == null) {
params.setWordCountMax(Integer.MAX_VALUE); params.setWordCountMax(Integer.MAX_VALUE);
} }
boolQueryBuilder.filter(QueryBuilders.rangeQuery("wordCount").gte(params.getWordCountMin()).lte(params.getWordCountMax())); boolQueryBuilder.filter(QueryBuilders.rangeQuery("wordCount").gte(params.getWordCountMin()).lte(params.getWordCountMax()));
if(params.getUpdateTimeMin() != null){ if (params.getUpdateTimeMin() != null) {
boolQueryBuilder.filter(QueryBuilders.rangeQuery("lastIndexUpdateTime").gte(params.getUpdateTimeMin())); boolQueryBuilder.filter(QueryBuilders.rangeQuery("lastIndexUpdateTime").gte(params.getUpdateTimeMin()));
} }
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder); searchSourceBuilder.query(boolQueryBuilder);
Count count = new Count.Builder().addIndex("novel").addType("book") Count count = new Count.Builder().addIndex("novel").addType("book")
.query(searchSourceBuilder.toString()).build(); .query(searchSourceBuilder.toString()).build();
CountResult results = jestClient.execute(count); CountResult results = jestClient.execute(count);
Double total = results.getCount(); Double total = results.getCount();
// 设置高亮字段
// 临时屏蔽小程序未处理的高亮字段等小程序处理后再放开 // 临时屏蔽小程序未处理的高亮字段等小程序处理后再放开
HighlightBuilder highlightBuilder = new HighlightBuilder(); HighlightBuilder highlightBuilder = new HighlightBuilder();
@ -251,11 +255,12 @@ public class BookServiceImpl implements BookService {
highlightBuilder.field("lastIndexName"); highlightBuilder.field("lastIndexName");
highlightBuilder.field("catName"); highlightBuilder.field("catName");
highlightBuilder.preTags("<span style='color:red'>").postTags("</span>"); highlightBuilder.preTags("<span style='color:red'>").postTags("</span>");
highlightBuilder.fragmentSize(200); highlightBuilder.fragmentSize(20000);
searchSourceBuilder.highlighter(highlightBuilder); searchSourceBuilder.highlighter(highlightBuilder);
//设置排序 //设置排序
if(params.getSort() != null){ if (params.getSort() != null) {
searchSourceBuilder.sort(StringUtil.camelName(params.getSort()), SortOrder.DESC); searchSourceBuilder.sort(StringUtil.camelName(params.getSort()), SortOrder.DESC);
} }
@ -266,8 +271,9 @@ public class BookServiceImpl implements BookService {
// 构建Search对象 // 构建Search对象
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex("novel").addType("book").build(); Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex("novel").addType("book").build();
log.debug(search.toString()); log.debug(search.toString());
SearchResult result ; SearchResult result;
result = jestClient.execute(search); result = jestClient.execute(search);
if (result.isSucceeded()) {
log.debug(result.getJsonString()); log.debug(result.getJsonString());
Map resultMap = new ObjectMapper().readValue(result.getJsonString(), Map.class); Map resultMap = new ObjectMapper().readValue(result.getJsonString(), Map.class);
@ -316,7 +322,6 @@ public class BookServiceImpl implements BookService {
} }
} }
} }
} }
@ -327,19 +332,19 @@ public class BookServiceImpl implements BookService {
pageInfo.setPageNum(page); pageInfo.setPageNum(page);
pageInfo.setPageSize(pageSize); pageInfo.setPageSize(pageSize);
return pageInfo; return pageInfo;
}
}catch (Exception e){
log.error(e.getMessage(),e);
}
}
}else{
PageHelper.startPage(page, pageSize); PageHelper.startPage(page, pageSize);
if (StringUtils.isNotBlank(params.getSort())) { if (StringUtils.isNotBlank(params.getSort())) {
OrderByHelper.orderBy(params.getSort() + " desc"); OrderByHelper.orderBy(params.getSort() + " desc");
} }
return new PageInfo<>(bookMapper.searchByPage(params)); return new PageInfo<>(bookMapper.searchByPage(params));
}
} }
@ -365,15 +370,15 @@ public class BookServiceImpl implements BookService {
} }
@Override @Override
public List<BookIndex> queryIndexList(Long bookId,String orderBy, Integer limit) { public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer limit) {
if(StringUtils.isNotBlank(orderBy)){ if (StringUtils.isNotBlank(orderBy)) {
OrderByHelper.orderBy(orderBy); OrderByHelper.orderBy(orderBy);
} }
if(limit != null){ if (limit != null) {
PageHelper.startPage(1,limit); PageHelper.startPage(1, limit);
} }
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime,BookIndexDynamicSqlSupport.isVip) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId)) .where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build() .build()
@ -384,7 +389,7 @@ public class BookServiceImpl implements BookService {
@Override @Override
public BookIndex queryBookIndex(Long bookIndexId) { public BookIndex queryBookIndex(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, BookIndexDynamicSqlSupport.updateTime,BookIndexDynamicSqlSupport.isVip) SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
.from(bookIndex) .from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId)) .where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
.build() .build()
@ -430,7 +435,7 @@ public class BookServiceImpl implements BookService {
@Override @Override
public BookContent queryBookContent(Long bookIndexId) { public BookContent queryBookContent(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id,BookContentDynamicSqlSupport.content) SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id, BookContentDynamicSqlSupport.content)
.from(bookContent) .from(bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId)) .where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId))
.limit(1) .limit(1)
@ -464,7 +469,7 @@ public class BookServiceImpl implements BookService {
} }
SelectStatementProvider selectStatement = select(id, catId, catName, bookName, lastIndexId, lastIndexName, authorId, authorName, picUrl, bookDesc, wordCount, lastIndexUpdateTime) SelectStatementProvider selectStatement = select(id, catId, catName, bookName, lastIndexId, lastIndexName, 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()
@ -475,7 +480,7 @@ public class BookServiceImpl implements BookService {
@Override @Override
public void addVisitCount(Long bookId) { public void addVisitCount(Long bookId) {
bookMapper.addVisitCount(bookId,new Date()); bookMapper.addVisitCount(bookId, new Date());
} }
@Override @Override
@ -507,10 +512,10 @@ public class BookServiceImpl implements BookService {
} }
@Override @Override
public List<BookCommentVO> listCommentByPage(Long userId,Long bookId, int page, int pageSize) { public List<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
PageHelper.startPage(page, pageSize); PageHelper.startPage(page, pageSize);
OrderByHelper.orderBy("t1.create_time desc"); OrderByHelper.orderBy("t1.create_time desc");
return bookCommentMapper.listCommentByPage(userId,bookId); return bookCommentMapper.listCommentByPage(userId, bookId);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -519,11 +524,11 @@ public class BookServiceImpl implements BookService {
//判断该用户是否已评论过该书籍 //判断该用户是否已评论过该书籍
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);
} }
//增加评论 //增加评论
@ -540,14 +545,14 @@ public class BookServiceImpl implements BookService {
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) {
//作者存在 //作者存在
authorId = bookAuthors.get(0).getId(); authorId = bookAuthors.get(0).getId();
}else{ } else {
//作者不存在先创建作者 //作者不存在先创建作者
Date currentDate = new Date(); Date currentDate = new Date();
authorId = new IdWorker().nextId(); authorId = new IdWorker().nextId();
@ -567,18 +572,17 @@ public class BookServiceImpl implements BookService {
} }
@Override @Override
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();
} }
return null; return null;
@ -588,7 +592,7 @@ public class BookServiceImpl implements BookService {
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);
@ -597,20 +601,20 @@ public class BookServiceImpl implements BookService {
@Override @Override
public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) { public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) {
return bookMapper.queryNetworkPicBooks(limit,offset); return bookMapper.queryNetworkPicBooks(limit, offset);
} }
@Override @Override
public void updateBookPicToLocal(String picUrl, Long bookId) { public void updateBookPicToLocal(String picUrl, Long bookId) {
picUrl = FileUtil.network2Local(picUrl,picSavePath, Constants.LOCAL_PIC_PREFIX); picUrl = FileUtil.network2Local(picUrl, picSavePath, Constants.LOCAL_PIC_PREFIX);
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));
@ -619,7 +623,7 @@ public class BookServiceImpl implements BookService {
@Override @Override
public List<Book> listBookPageByUserId(Long userId, int page, int pageSize) { public List<Book> listBookPageByUserId(Long userId, int page, int pageSize) {
PageHelper.startPage(page,pageSize); PageHelper.startPage(page, pageSize);
SelectStatementProvider selectStatement = select(id, bookName, visitCount, lastIndexName, status) SelectStatementProvider selectStatement = select(id, bookName, visitCount, lastIndexName, status)
.from(book) .from(book)
@ -634,10 +638,11 @@ public class BookServiceImpl implements BookService {
@Override @Override
public void addBook(Book book, Long authorId, String penName) { public void addBook(Book book, Long authorId, String penName) {
//判断小说名是否存在 //判断小说名是否存在
if(queryIdByNameAndAuthor(book.getBookName(),penName)!=null){ if (queryIdByNameAndAuthor(book.getBookName(), penName) != null) {
//该作者发布过此书名的小说 //该作者发布过此书名的小说
throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS); throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS);
}; }
;
book.setAuthorName(penName); book.setAuthorName(penName);
book.setAuthorId(authorId); book.setAuthorId(authorId);
book.setVisitCount(0L); book.setVisitCount(0L);
@ -655,8 +660,8 @@ public class BookServiceImpl implements BookService {
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));
} }
@ -666,7 +671,7 @@ public class BookServiceImpl implements BookService {
public void addBookContent(Long bookId, String indexName, String content, Long authorId) { public void addBookContent(Long bookId, String indexName, String content, Long authorId) {
Book book = queryBookDetail(bookId); Book book = queryBookDetail(bookId);
if(!authorId.equals(book.getAuthorId())){ if (!authorId.equals(book.getAuthorId())) {
//并不是更新自己的小说 //并不是更新自己的小说
return; return;
} }
@ -683,15 +688,15 @@ public class BookServiceImpl implements BookService {
.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 indexNum = 0; int indexNum = 0;
if(book.getLastIndexId() != null){ if (book.getLastIndexId() != null) {
indexNum = queryBookIndex(book.getLastIndexId()).getIndexNum()+1; indexNum = queryBookIndex(book.getLastIndexId()).getIndexNum() + 1;
} }
BookIndex lastBookIndex = new BookIndex(); BookIndex lastBookIndex = new BookIndex();
lastBookIndex.setId(lastIndexId); lastBookIndex.setId(lastIndexId);
@ -711,18 +716,17 @@ public class BookServiceImpl implements BookService {
bookContentMapper.insertSelective(bookContent); bookContentMapper.insertSelective(bookContent);
} }
@Override @Override
public List<Book> queryBookByUpdateTimeByPage(Date startDate, Date endDate, int page, int pageSize) { public List<Book> queryBookByUpdateTimeByPage(Date startDate, Date endDate, int page, int pageSize) {
PageHelper.startPage(page,pageSize); PageHelper.startPage(page, pageSize);
return bookMapper.selectMany(select(book.allColumns()) return bookMapper.selectMany(select(book.allColumns())
.from(book) .from(book)
.where(updateTime,isGreaterThanOrEqualTo(startDate)) .where(updateTime, isGreaterThanOrEqualTo(startDate))
.and(updateTime,isLessThan(endDate)) .and(updateTime, isLessThan(endDate))
.build() .build()
.render(RenderingStrategies.MYBATIS3)); .render(RenderingStrategies.MYBATIS3));
} }

View File

@ -11,7 +11,7 @@ spring:
#是否开启搜索引擎1开启0不开启 #是否开启搜索引擎1开启0不开启
enable: 0 enable: 0
jest: jest:
uris: http://198.245.61.51:9200 uris: http://127.0.0.1:9200