文档更新

This commit is contained in:
xxy
2020-05-04 09:26:37 +08:00
parent fe8b554ce4
commit a9319041a7
13 changed files with 83 additions and 3540 deletions

View File

@ -50,10 +50,10 @@ public class NovelFilter implements Filter {
}
String userMark = CookieUtil.getCookie(req,Constants.USER_CLIENT_MARK);
String userMark = CookieUtil.getCookie(req,Constants.USER_CLIENT_MARK_KEY);
if(userMark == null){
userMark = UUIDUtil.getUUID32();
CookieUtil.setCookie(resp,Constants.USER_CLIENT_MARK,userMark);
CookieUtil.setCookie(resp,Constants.USER_CLIENT_MARK_KEY,userMark);
}
ThreadLocalUtil.setCientId(userMark);
//根据浏览器类型选择前端模板

View File

@ -17,7 +17,17 @@ public class Constants {
public static final String LOCAL_PIC_PREFIX = "/localPic/";
/**
* 用户客户端标识
* 用户客户端标识保存key
* */
public static final String USER_CLIENT_MARK = "userClientMark";
public static final String USER_CLIENT_MARK_KEY = "userClientMarkKey";
/**
* Object Json 缓存存在的最小长度
* */
public static final int OBJECT_JSON_CACHE_EXIST_LENGTH = 5;
/**
* 首页设置的小说数量
* */
public static final int INDEX_BOOK_SETTING_NUM = 32;
}

View File

@ -22,4 +22,11 @@ public interface FrontBookMapper extends BookMapper {
void addCommentCount(@Param("bookId") Long bookId);
List<Book> queryNetworkPicBooks(@Param("limit") Integer limit,@Param("offset") Integer offset);
/**
* 按评分随机查询小说集合
* @param limit 查询条数
* @return 小说集合
* */
List<Book> selectIdsByScoreAndRandom(@Param("limit") int limit);
}

View File

@ -24,11 +24,13 @@ import org.apache.commons.lang3.StringUtils;
import org.mybatis.dynamic.sql.SortSpecification;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.orderbyhelper.OrderByHelper;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -76,14 +78,64 @@ public class BookServiceImpl implements BookService {
@Override
public Map<Byte, List<BookSettingVO>> listBookSettingVO() {
String result = cacheService.get(CacheKey.INDEX_BOOK_SETTINGS_KEY);
if (result == null || result.length() < 10) {
if (result == null || result.length() < Constants.OBJECT_JSON_CACHE_EXIST_LENGTH) {
List<BookSettingVO> list = bookSettingMapper.listVO();
if(list.size() == 0) {
//如果首页小说没有被设置,则初始化首页小说设置
list = initIndexBookSetting();
}
result = new ObjectMapper().writeValueAsString(list.stream().collect(Collectors.groupingBy(BookSettingVO::getType)));
cacheService.set(CacheKey.INDEX_BOOK_SETTINGS_KEY, result);
}
return new ObjectMapper().readValue(result,Map.class);
}
/**
* 初始化首页小说设置
* */
private List<BookSettingVO> initIndexBookSetting() {
Date currentDate = new Date();
List<Book> books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM);
if(books.size() == 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);
for (int i = 0; i < books.size(); i++) {
Book book = books.get(i);
byte type;
if (i < 4) {
type = 0;
} else if (i < 14) {
type = 1;
} else if (i < 20) {
type = 2;
} else if (i < 26) {
type = 3;
}else{
type = 4;
}
BookSettingVO bookSettingVO = new BookSettingVO();
BookSetting bookSetting = new BookSetting();
bookSetting.setType(type);
bookSetting.setSort((byte) i);
bookSetting.setBookId(book.getId());
bookSetting.setCreateTime(currentDate);
bookSetting.setUpdateTime(currentDate);
bookSettingList.add(bookSetting);
BeanUtils.copyProperties(book,bookSettingVO);
BeanUtils.copyProperties(bookSetting,bookSettingVO);
bookSettingVOList.add(bookSettingVO);
}
bookSettingMapper.insertMultiple(bookSettingList);
return bookSettingVOList;
}
return new ArrayList<>(0);
}
@Override
public List<Book> listClickRank() {
List<Book> result = (List<Book>) cacheService.getObject(CacheKey.INDEX_CLICK_BANK_BOOK_KEY);

View File

@ -59,5 +59,9 @@
limit #{offset},#{limit}
</select>
<select id="selectIdsByScoreAndRandom" parameterType="int" resultType="com.java2nb.novel.entity.Book">
select id,book_name,author_name,pic_url,book_desc,score from book ORDER BY score,RAND() LIMIT #{limit};
</select>
</mapper>