diff --git a/README.md b/README.md index ba09206..8388c47 100644 --- a/README.md +++ b/README.md @@ -40,31 +40,19 @@ Springboot+Mybatis+Mysql+Ehcache+Thymeleaf+Layui #### PC站截图 -1. 首页 -![index](./assets/pc_index.png) -2.列表页 +![index](./assets/1588548668698.gif) -![index](./assets/pc_all.png) -3.排行页 -![index](./assets/pc_rank.png) +![index](./assets/1588548784395.gif) -4.详情页 -![index](./assets/pc_detail.png) -5.目录页 +![index](./assets/1588548916980.gif) -![index](./assets/pc_catalog.png) -6.内容页 - -![index](./assets/pc_content1.png) - -![index](./assets/pc_content2.png) #### 手机站截图 diff --git a/assets/1588548668698.gif b/assets/1588548668698.gif new file mode 100644 index 0000000..5659f99 Binary files /dev/null and b/assets/1588548668698.gif differ diff --git a/assets/1588548784395.gif b/assets/1588548784395.gif new file mode 100644 index 0000000..212cbb3 Binary files /dev/null and b/assets/1588548784395.gif differ diff --git a/assets/1588548916980.gif b/assets/1588548916980.gif new file mode 100644 index 0000000..e7d38c7 Binary files /dev/null and b/assets/1588548916980.gif differ diff --git a/novel-crawl/src/main/resources/application.yml b/novel-crawl/src/main/resources/application.yml index 885c68e..c17bd85 100644 --- a/novel-crawl/src/main/resources/application.yml +++ b/novel-crawl/src/main/resources/application.yml @@ -8,6 +8,6 @@ spring: admin: username: admin - password: admin123456 + password: admin diff --git a/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java b/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java index f0d464e..63f5f04 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/filter/NovelFilter.java @@ -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); //根据浏览器类型选择前端模板 diff --git a/novel-front/src/main/java/com/java2nb/novel/core/utils/Constants.java b/novel-front/src/main/java/com/java2nb/novel/core/utils/Constants.java index b69eec3..23dd6f7 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/utils/Constants.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/utils/Constants.java @@ -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; } diff --git a/novel-front/src/main/java/com/java2nb/novel/mapper/FrontBookMapper.java b/novel-front/src/main/java/com/java2nb/novel/mapper/FrontBookMapper.java index 6288143..eaed2d6 100644 --- a/novel-front/src/main/java/com/java2nb/novel/mapper/FrontBookMapper.java +++ b/novel-front/src/main/java/com/java2nb/novel/mapper/FrontBookMapper.java @@ -22,4 +22,11 @@ public interface FrontBookMapper extends BookMapper { void addCommentCount(@Param("bookId") Long bookId); List queryNetworkPicBooks(@Param("limit") Integer limit,@Param("offset") Integer offset); + + /** + * 按评分随机查询小说集合 + * @param limit 查询条数 + * @return 小说集合 + * */ + List selectIdsByScoreAndRandom(@Param("limit") int limit); } 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 b65b445..58072ad 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 @@ -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> 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 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 initIndexBookSetting() { + Date currentDate = new Date(); + List books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM); + if(books.size() == Constants.INDEX_BOOK_SETTING_NUM) { + List bookSettingList = new ArrayList<>(Constants.INDEX_BOOK_SETTING_NUM); + List 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 listClickRank() { List result = (List) cacheService.getObject(CacheKey.INDEX_CLICK_BANK_BOOK_KEY); diff --git a/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml b/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml index fbd24c9..22799f2 100644 --- a/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml +++ b/novel-front/src/main/resources/mybatis/mapping/BookMapper.xml @@ -59,5 +59,9 @@ limit #{offset},#{limit} + \ No newline at end of file diff --git a/sql/book_setting.sql b/sql/book_setting.sql deleted file mode 100644 index a87a1b5..0000000 --- a/sql/book_setting.sql +++ /dev/null @@ -1,68 +0,0 @@ -/* -Navicat MySQL Data Transfer - -Source Server : localhost -Source Server Version : 50624 -Source Host : localhost:3306 -Source Database : novel_biz - -Target Server Type : MYSQL -Target Server Version : 50624 -File Encoding : 65001 - -Date: 2020-05-03 05:31:00 -*/ - -SET FOREIGN_KEY_CHECKS=0; - --- ---------------------------- --- Table structure for book_setting --- ---------------------------- -DROP TABLE IF EXISTS `book_setting`; -CREATE TABLE `book_setting` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `book_id` bigint(20) DEFAULT NULL COMMENT '小说ID', - `sort` tinyint(4) DEFAULT NULL COMMENT '排序号', - `type` tinyint(1) DEFAULT NULL COMMENT '类型,0:轮播图,1:顶部小说栏设置,2:本周强推,3:热门推荐,4:精品推荐', - `create_time` datetime DEFAULT NULL COMMENT '创建时间', - `create_user_id` bigint(20) DEFAULT NULL COMMENT '创建人ID', - `update_time` datetime DEFAULT NULL COMMENT '更新时间', - `update_user_id` bigint(20) DEFAULT NULL COMMENT '更新人ID', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8mb4 COMMENT='首页小说设置表'; - --- ---------------------------- --- Records of book_setting --- ---------------------------- -INSERT INTO `book_setting` VALUES ('32', '1256560013650870272', '1', '0', '2020-04-27 15:45:58', null, '2020-04-27 15:46:03', null); -INSERT INTO `book_setting` VALUES ('33', '1256560647057883136', '2', '0', '2020-04-27 15:46:21', null, '2020-04-27 15:46:24', null); -INSERT INTO `book_setting` VALUES ('34', '1256560985525633024', '3', '0', '2020-04-27 15:47:06', null, '2020-04-27 15:47:09', null); -INSERT INTO `book_setting` VALUES ('35', '1256562255468609536', '4', '0', '2020-04-27 15:47:24', null, '2020-04-27 15:47:27', null); -INSERT INTO `book_setting` VALUES ('36', '1256567122404753408', '1', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('37', '1256562643605307392', '2', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('38', '1256567133926506496', '3', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('39', '1256567122404753408', '4', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('40', '1256567622755860480', '5', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('41', '1256567796077084672', '1', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('42', '1256568783873425408', '2', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('43', '1256569365753413632', '3', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('44', '1256568158427201536', '4', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('45', '1256569055395889152', '5', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('46', '1256571983737307136', '6', '2', null, null, null, null); -INSERT INTO `book_setting` VALUES ('47', '1256572866260811777', '1', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('48', '1256572765551378432', '2', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('49', '1256570746774142976', '3', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('50', '1256570389633351680', '4', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('51', '1256575355232108544', '5', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('52', '1256575330401828864', '6', '3', null, null, null, null); -INSERT INTO `book_setting` VALUES ('53', '1256575474111266816', '1', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('54', '1256576738597453824', '2', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('55', '1256576787712753664', '3', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('56', '1256579884505808896', '4', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('57', '1256579279494234112', '5', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('58', '1256579164301869056', '6', '4', null, null, null, null); -INSERT INTO `book_setting` VALUES ('59', '1256692842384842752', '6', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('60', '1256695607790133248', '7', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('61', '1256623094850568192', '8', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('62', '1256626444941836288', '9', '1', null, null, null, null); -INSERT INTO `book_setting` VALUES ('63', '1256623378670731264', '10', '1', null, null, null, null); diff --git a/sql/crawl_source.sql b/sql/crawl_source.sql deleted file mode 100644 index 835ef68..0000000 --- a/sql/crawl_source.sql +++ /dev/null @@ -1,35 +0,0 @@ -/* -Navicat MySQL Data Transfer - -Source Server : localhost -Source Server Version : 50624 -Source Host : localhost:3306 -Source Database : novel_biz - -Target Server Type : MYSQL -Target Server Version : 50624 -File Encoding : 65001 - -Date: 2020-05-02 12:40:12 -*/ - -SET FOREIGN_KEY_CHECKS=0; - --- ---------------------------- --- Table structure for crawl_source --- ---------------------------- -DROP TABLE IF EXISTS `crawl_source`; -CREATE TABLE `crawl_source` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', - `source_name` varchar(50) DEFAULT NULL COMMENT '源站名', - `crawl_rule` varchar(2048) DEFAULT NULL COMMENT '爬取规则(json串)', - `source_status` tinyint(1) DEFAULT '0' COMMENT '爬虫源状态,0:关闭,1:开启', - `create_time` datetime DEFAULT NULL COMMENT '创建时间', - `update_time` datetime DEFAULT NULL COMMENT '更新时间', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='爬虫源表'; - --- ---------------------------- --- Records of crawl_source --- ---------------------------- -INSERT INTO `crawl_source` VALUES ('2', '百书斋', '{\r\n \"bookListUrl\": \"https://m.baishuzhai.com/blhb/{catId}/{page}.html\",\r\n \"catIdRule\": {\r\n \"catId1\": \"1\",\r\n \"catId2\": \"2\",\r\n \"catId3\": \"3\",\r\n \"catId4\": \"4\",\r\n \"catId5\": \"5\",\r\n \"catId6\": \"6\",\r\n \"catId7\": \"7\"\r\n },\r\n \"bookIdPatten\": \"href=\\\"/ibook/(\\\\d+/\\\\d+)/\\\"\",\r\n \"pagePatten\": \"value=\\\"(\\\\d+)/\\\\d+\\\"\",\r\n \"totalPagePatten\": \"value=\\\"\\\\d+/(\\\\d+)\\\"\",\r\n \"bookDetailUrl\": \"https://m.baishuzhai.com/ibook/{bookId}/\",\r\n \"bookNamePatten\": \"([^/]+)\",\r\n \"authorNamePatten\": \">作者:([^/]+)<\",\r\n \"picUrlPatten\": \"]+)\\\"\\\\s+onerror=\\\"this.src=\",\r\n \"statusPatten\": \"状态:([^/]+)\",\r\n \"bookStatusRule\": {\r\n \"连载\": 0,\r\n \"完成\": 1\r\n },\r\n \"scorePatten\": \"(\\\\d+\\\\.\\\\d+)分\",\r\n \"descStart\": \"

\",\r\n \"descEnd\": \"

\",\r\n \"upadateTimePatten\": \"更新:(\\\\d+-\\\\d+-\\\\d+)\",\r\n \"upadateTimeFormatPatten\": \"yy-MM-dd\",\r\n \"bookIndexUrl\": \"https://m.baishuzhai.com/ibook/{bookId}/all.html\",\r\n \"indexIdPatten\": \"[^/]+\",\r\n \"indexNamePatten\": \"([^/]+)\",\r\n \"bookContentUrl\": \"https://baishuzhai.com/ibook/{bookId}/{indexId}.html\",\r\n \"contentStart\": \"id=\\\"content\\\">\",\r\n \"contentEnd\": \"