Compare commits

...

16 Commits

28 changed files with 764 additions and 171 deletions

View File

@ -40,7 +40,7 @@ novel-plus -- 父工程
```
#### 技术选型
Springboot+Mybatis+Mysql+Ehcache+Thymeleaf+Layui
Springboot+Mybatis+Mysql+ElasticSearch+Ehcache+Thymeleaf+Layui
#### PC站截图
@ -52,69 +52,67 @@ Springboot+Mybatis+Mysql+Ehcache+Thymeleaf+Layui
![img](https://oscimg.oschina.net/oscnet/up-d0b2e03129bfae47b8bb96a491b73d383c5.png)
3. 排行榜
3. 搜索页
![img](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ20200520-215756.png)
![img](https://oscimg.oschina.net/oscnet/up-ed5f689557718924acac76bc3ebca36afcb.png)
4. 排行榜
![img](https://oscimg.oschina.net/oscnet/up-78d5a68586cd92a86c669311f414508f922.png)
4. 详情页
5. 详情页
![img](https://oscimg.oschina.net/oscnet/up-8be2495a2869f93626b0c9c1df6f329747a.png)
5. 阅读页
6. 阅读页
![img](https://oscimg.oschina.net/oscnet/up-517c84148d2db8e11717a8bbecc57fa1be7.png)
6. 用户中心
7. 用户中心
![img](https://oscimg.oschina.net/oscnet/up-805a30e7a663a3fd5cb39a7ea26bc132a01.png)
7. 充值
8. 充值
![img](https://oscimg.oschina.net/oscnet/up-5a601b0b3af3224d0bebcfe12fc15075d34.png)
![img](https://oscimg.oschina.net/oscnet/up-face25d02c07b05b2ce954cc4bf4ee6a0cc.png)
8.作家专区
9. 作家专区
![img](https://oscimg.oschina.net/oscnet/up-30766372cc7f56480ff1d7d55198204f6ea.png)
![img](https://oscimg.oschina.net/oscnet/up-9737995e465b86f3bee3211221f6c3b8a56.png)
9.购买
10. 购买
![img](https://oscimg.oschina.net/oscnet/up-ce0f585efd82a9670335f118cf5897c85e9.png)
![img](https://oscimg.oschina.net/oscnet/up-f849960f4c1303fea77d26e64fc505a7180.png)
#### 手机站截图
1. 首页
![index](./assets/QQ%E5%9B%BE%E7%89%8720191018162208.jpg)
![index](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191018162208.jpg)
2. 小说详情页
![微信图片_20190904181558](./assets/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190904181558.png)
![微信图片_20190904181558](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190904181558.png)
3. 目录页
![QQ图片20191018161901](./assets/QQ%E5%9B%BE%E7%89%8720191108022250.png)
![QQ图片20191018161901](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191108022250.png)
4. 小说阅读页
![QQ图片20191018161901](./assets/QQ%E5%9B%BE%E7%89%8720191018161901.png)
![QQ图片20191018161901](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191018161901.png)
#### 爬虫管理系统截图
![QQ图片20191018161901](./assets/crawl_index.png)
![img](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.2/assets/crawl_index.png)
#### 后台管理系统截图

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 62 KiB

82
es/index_create.txt Normal file
View File

@ -0,0 +1,82 @@
PUT /novel
{
"mappings" : {
"book" : {
"properties" : {
"id" : {
"type" : "long"
},
"authorId" : {
"type" : "long"
},
"authorName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 1.9
},
"bookName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 2
},
"bookDesc" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 0.1
},
"bookStatus" : {
"type" : "short"
},
"catId" : {
"type" : "integer"
},
"catName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 1.0
},
"lastIndexId" : {
"type" : "long"
},
"lastIndexName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 0.1
},
"lastIndexUpdateTime" : {
"type": "keyword"
},
"picUrl" : {
"type" : "keyword"
},
"score" : {
"type" : "float"
},
"wordCount" : {
"type" : "integer"
},
"workDirection" : {
"type" : "short"
},
"visitCount" : {
"type": "long"
}
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -46,4 +46,8 @@ public interface CacheKey {
* */
String RUNNING_CRAWL_THREAD_KEY_PREFIX = "runningCrawlTreadDataKeyPrefix";
/**
* 上一次搜索引擎更新的时间
* */
String ES_LAST_UPDATE_TIME = "esLastUpdateTime";
}

View File

@ -1,6 +1,7 @@
package com.java2nb.novel.core.utils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.Charsets;
import org.apache.http.client.utils.DateUtils;
import org.springframework.core.io.Resource;
@ -9,6 +10,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import javax.imageio.ImageIO;
import java.io.*;
import java.util.Date;
import java.util.Objects;
@ -17,18 +19,21 @@ import java.util.Objects;
* 文件操作工具类
* @author 11797
*/
@Slf4j
public class FileUtil {
/**
* 网络图片转本地
* */
@SneakyThrows
public static String network2Local(String picSrc,String picSavePath,String visitPrefix) {
InputStream input = null;
OutputStream out = null;
try {
//本地图片保存
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
ResponseEntity<Resource> resEntity = RestTemplateUtil.getInstance(Charsets.ISO_8859_1.name()).exchange(picSrc, HttpMethod.GET, requestEntity, Resource.class);
InputStream input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
Date currentDate = new Date();
picSrc = visitPrefix + DateUtils.formatDate(currentDate, "yyyy") + "/" + DateUtils.formatDate(currentDate, "MM") + "/" + DateUtils.formatDate(currentDate, "dd") + "/"
+ UUIDUtil.getUUID32()
@ -38,13 +43,41 @@ public class FileUtil {
if (!parentFile.exists()) {
parentFile.mkdirs();
}
OutputStream out = new FileOutputStream(picFile);
out = new FileOutputStream(picFile);
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1; ) {
out.write(b, 0, n);
}
out.close();
out.flush();
if( ImageIO.read(picFile) == null){
picSrc = "/images/default.gif";
}
}catch (Exception e){
log.error(e.getMessage(),e);
picSrc = "/images/default.gif";
}finally {
if(input != null){
try {
input.close();
} catch (IOException e) {
log.error(e.getMessage(),e);
}finally {
if(out != null){
try {
out.close();
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
}
}
return picSrc;
}

View File

@ -0,0 +1,73 @@
package com.java2nb.novel.core.utils;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
/**
* @author xiongxiaoyang
*/
public class StringUtil {
/**
* 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
* 例如HelloWorld->HELLO_WORLD
* @param name 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String underscoreName(String name) {
StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) {
// 将第一个字符处理成大写
result.append(name.substring(0, 1).toUpperCase());
// 循环处理其余字符
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
// 在大写字母前添加下划线
if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
result.append("_");
}
// 其他字符直接转成大写
result.append(s.toUpperCase());
}
}
return result.toString();
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
* 例如HELLO_WORLD->HelloWorld
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String camelName(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
} else if (!name.contains("_")) {
// 不含下划线,仅将首字母小写
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
continue;
}
// 处理真正的驼峰片段
if (result.length() == 0) {
// 第一个驼峰片段,全部字母都小写
result.append(camel.toLowerCase());
} else {
// 其他的驼峰片段,首字母大写
result.append(camel.substring(0, 1).toUpperCase());
result.append(camel.substring(1).toLowerCase());
}
}
return result.toString();
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -30,6 +30,8 @@ import static java.util.regex.Pattern.compile;
@Slf4j
public class CrawlParser {
private static IdWorker idWorker = new IdWorker();
public static final Integer BOOK_INDEX_LIST_KEY = 1;
public static final Integer BOOK_CONTENT_LIST_KEY = 2;
@ -94,6 +96,8 @@ public class CrawlParser {
String desc = bookDetailHtml.substring(bookDetailHtml.indexOf(ruleBean.getDescStart()) + ruleBean.getDescStart().length());
desc = desc.substring(0, desc.indexOf(ruleBean.getDescEnd()));
//过滤掉简介中的a标签
desc = desc.replaceAll("<a[^<]+</a>","");
//设置书籍简介
book.setBookDesc(desc);
if (StringUtils.isNotBlank(ruleBean.getStatusPatten())) {
@ -173,6 +177,7 @@ public class CrawlParser {
String lastIndexName = null;
while (isFindIndex) {
BookIndex hasIndex = hasIndexs.get(indexNum);
String indexName = indexNameMatch.group(1);
@ -199,7 +204,7 @@ public class CrawlParser {
if(hasIndexs.size() == 0){
//新书入库
//设置目录和章节内容
Long indexId = new IdWorker().nextId();
Long indexId = idWorker.nextId();
lastIndexId = indexId;
lastIndexName = indexName;
bookIndex.setId(indexId);

View File

@ -167,6 +167,11 @@ public class CrawlServiceImpl implements CrawlService {
boolean isFindBookId = bookIdMatcher.find();
while (isFindBookId) {
try {
if(Thread.currentThread().isInterrupted()){
return;
}
String bookId = bookIdMatcher.group(1);
Book book = CrawlParser.parseBook(ruleBean, bookId);
//这里只做新书入库,查询是否存在这本书

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -28,6 +28,18 @@
</dependency>
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>${jest.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>

View File

@ -55,7 +55,7 @@ public class AuthorController extends BaseController{
* 发布小说
* */
@PostMapping("addBook")
public ResultBean addBook(Book book,HttpServletRequest request){
public ResultBean addBook(@RequestParam("bookDesc") String bookDesc,Book book,HttpServletRequest request){
//查询作家信息
Author author = authorService.queryAuthor(getUserDetails(request).getId());
@ -67,6 +67,10 @@ public class AuthorController extends BaseController{
}
//bookDesc不能使用book对象来接收否则会自动去掉前面的空格
book.setBookDesc(bookDesc
.replaceAll("\\n","<br>")
.replaceAll("\\s","&nbsp;"));
//发布小说
bookService.addBook(book,author.getId(),author.getPenName());
@ -109,6 +113,8 @@ public class AuthorController extends BaseController{
return ResultBean.fail(ResponseStatus.AUTHOR_STATUS_FORBIDDEN);
}
content = content.replaceAll("\\n","<br>")
.replaceAll("\\s","&nbsp;");
//发布章节内容
bookService.addBookContent(bookId,indexName,content,author.getId());

View File

@ -79,8 +79,8 @@ public class BookController extends BaseController{
* */
@PostMapping("searchByPage")
public ResultBean searchByPage(BookSP bookSP, @RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "20") int pageSize){
List<BookVO> books = bookService.searchByPage(bookSP,page,pageSize);
return ResultBean.ok(new PageInfo<>(books));
PageInfo<BookVO> pageInfo = bookService.searchByPage(bookSP,page,pageSize);
return ResultBean.ok(pageInfo);
}
/**

View File

@ -0,0 +1,96 @@
package com.java2nb.novel.core.schedule;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.vo.EsBookVO;
import io.searchbox.client.JestClient;
import io.searchbox.core.DocumentResult;
import io.searchbox.core.Index;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* 小说导入搜索引擎
*
* @author Administrator
*/
@ConditionalOnProperty(prefix = "spring.elasticsearch", name = "enable", havingValue = "1")
@Service
@RequiredArgsConstructor
@Slf4j
public class BookToEsSchedule {
private final BookService bookService;
private final CacheService cacheService;
private final JestClient jestClient;
private boolean lock = false;
/**
* 2分钟导入一次
*/
@Scheduled(fixedRate = 1000 * 60 * 2)
public void saveToEs() {
if (!lock) {
lock = true;
try {
//查询需要更新的小说
Date lastDate = (Date) cacheService.getObject(CacheKey.ES_LAST_UPDATE_TIME);
if (lastDate == null) {
lastDate = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01");
}
long count ;
do {
List<Book> books = bookService.queryBookByUpdateTimeByPage(lastDate,100);
for(Book book : books) {
//导入到ES
EsBookVO esBookVO = new EsBookVO();
BeanUtils.copyProperties(book,esBookVO,"lastIndexUpdateTime");
esBookVO.setLastIndexUpdateTime(new SimpleDateFormat("yyyy/MM/dd HH:mm").format(book.getLastIndexUpdateTime()));
Index action = new Index.Builder(esBookVO).index("novel").type("book").id(book.getId().toString()).build();
jestClient.execute(action);
lastDate = book.getUpdateTime();
//1秒钟导入一本书1分钟导入60本
Thread.sleep(1000);
}
count = books.size();
}while (count == 100);
cacheService.setObject(CacheKey.ES_LAST_UPDATE_TIME, lastDate);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
lock = false;
}
}
}

View File

@ -3,6 +3,7 @@ package com.java2nb.novel.core.schedule;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.service.BookService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -13,9 +14,10 @@ import java.util.List;
/**
* 网络图片转存本地任务
*
* @author Administrator
*/
@ConditionalOnProperty(prefix = "pic.save",name = "type",havingValue = "2")
@ConditionalOnProperty(prefix = "pic.save", name = "type", havingValue = "2")
@Service
@RequiredArgsConstructor
@Slf4j
@ -33,20 +35,18 @@ public class Network2LocalPicSchedule {
* 10分钟转一次
*/
@Scheduled(fixedRate = 1000 * 60 * 10)
@SneakyThrows
public void trans() {
log.info("Network2LocalPicSchedule。。。。。。。。。。。。");
Integer offset = 0, limit = 100;
List<Book> networkPicBooks;
do {
networkPicBooks = bookService.queryNetworkPicBooks(limit, offset);
List<Book> networkPicBooks = bookService.queryNetworkPicBooks(100);
for (Book book : networkPicBooks) {
bookService.updateBookPicToLocal(book.getPicUrl(), book.getId());
//3秒钟转化一张图片10分钟转化200张
Thread.sleep(3000);
}
offset += limit;
} while (networkPicBooks.size() > 0);
}

View File

@ -5,6 +5,7 @@ import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.vo.BookVO;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -15,13 +16,13 @@ public interface FrontBookMapper extends BookMapper {
List<BookVO> searchByPage(BookSP params);
void addVisitCount(@Param("bookId") Long bookId);
void addVisitCount(@Param("bookId") Long bookId, @Param("date") Date date);
List<Book> listRecBookByCatId(@Param("catId") Integer catId);
void addCommentCount(@Param("bookId") Long bookId);
List<Book> queryNetworkPicBooks(@Param("limit") Integer limit,@Param("offset") Integer offset);
List<Book> queryNetworkPicBooks(@Param("limit") Integer limit);
/**
* 按评分随机查询小说集合

View File

@ -1,12 +1,14 @@
package com.java2nb.novel.service;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.vo.BookCommentVO;
import com.java2nb.novel.vo.BookSettingVO;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.vo.BookVO;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -44,9 +46,9 @@ public interface BookService {
* @param params 搜索参数
* @param page 页码
* @param pageSize 分页大小
* @return 小说集合
* @return 小说集合分页信息
* */
List<BookVO> searchByPage(BookSP params, int page, int pageSize);
PageInfo searchByPage(BookSP params, int page, int pageSize);
/**
* 查询小说分类列表
@ -179,10 +181,9 @@ public interface BookService {
/**
* 查询网络图片的小说
* @param limit 查询条数
* @param offset 开始行数
* @return 返回小说集合
* */
List<Book> queryNetworkPicBooks(Integer limit, Integer offset);
List<Book> queryNetworkPicBooks(Integer limit);
/**
@ -224,4 +225,13 @@ public interface BookService {
* @param authorId 作者ID
* */
void addBookContent(Long bookId, String indexName, String content, Long authorId);
/**
* 根据更新时间分页查询书籍列表
* @param startDate 开始时间,包括该时间
* @param limit 查询数量
* @return 书籍列表
* */
List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit);
}

View File

@ -1,15 +1,14 @@
package com.java2nb.novel.service.impl;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.exception.BusinessException;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.core.utils.IdWorker;
import com.java2nb.novel.core.utils.*;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.mapper.*;
@ -19,9 +18,18 @@ import com.java2nb.novel.service.BookService;
import com.java2nb.novel.vo.BookCommentVO;
import com.java2nb.novel.vo.BookSettingVO;
import com.java2nb.novel.vo.BookVO;
import com.java2nb.novel.vo.EsBookVO;
import io.searchbox.client.JestClient;
import io.searchbox.core.*;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.mybatis.dynamic.sql.SortSpecification;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
@ -31,6 +39,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.orderbyhelper.OrderByHelper;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -50,14 +59,18 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class BookServiceImpl implements BookService {
/**
* 本地图片保存路径
* */
*/
@Value("${pic.save.path}")
private String picSavePath;
@Value("${spring.elasticsearch.enable}")
private Integer esEnable;
private final FrontBookSettingMapper bookSettingMapper;
private final FrontBookMapper bookMapper;
@ -76,6 +89,8 @@ public class BookServiceImpl implements BookService {
private final AuthorService authorService;
private final JestClient jestClient;
@SneakyThrows
@Override
@ -83,24 +98,24 @@ public class BookServiceImpl implements BookService {
String result = cacheService.get(CacheKey.INDEX_BOOK_SETTINGS_KEY);
if (result == null || result.length() < Constants.OBJECT_JSON_CACHE_EXIST_LENGTH) {
List<BookSettingVO> list = bookSettingMapper.listVO();
if(list.size() == 0) {
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);
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) {
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++) {
@ -114,7 +129,7 @@ public class BookServiceImpl implements BookService {
type = 2;
} else if (i < 26) {
type = 3;
}else{
} else {
type = 4;
}
BookSettingVO bookSettingVO = new BookSettingVO();
@ -126,8 +141,8 @@ public class BookServiceImpl implements BookService {
bookSetting.setUpdateTime(currentDate);
bookSettingList.add(bookSetting);
BeanUtils.copyProperties(book,bookSettingVO);
BeanUtils.copyProperties(bookSetting,bookSettingVO);
BeanUtils.copyProperties(book, bookSettingVO);
BeanUtils.copyProperties(bookSetting, bookSettingVO);
bookSettingVOList.add(bookSettingVO);
}
@ -164,25 +179,174 @@ public class BookServiceImpl implements BookService {
List<BookVO> result = (List<BookVO>) cacheService.getObject(CacheKey.INDEX_UPDATE_BOOK_KEY);
if (result == null || result.size() == 0) {
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);
}
return result;
}
@Override
public List<BookVO> searchByPage(BookSP params, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
public PageInfo searchByPage(BookSP params, int page, int pageSize) {
if (params.getUpdatePeriod() != null) {
long cur = System.currentTimeMillis();
long period = params.getUpdatePeriod() * 24 * 3600 * 1000;
long time = cur - period;
params.setUpdateTimeMin(new Date(time));
}
if (esEnable == 1) {
try {
List<EsBookVO> bookList = new ArrayList<>(0);
//使用搜索引擎搜索
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
// 构造查询哪个字段
if (StringUtils.isNoneBlank(params.getKeyword())) {
boolQueryBuilder = boolQueryBuilder.must(QueryBuilders.queryStringQuery(params.getKeyword()));
}
// 作品方向
if (params.getWorkDirection() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("workDirection", params.getWorkDirection()));
}
// 分类
if (params.getCatId() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("catId", params.getCatId()));
}
if (params.getBookStatus() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("bookStatus", params.getBookStatus()));
}
if (params.getWordCountMin() == null) {
params.setWordCountMin(0);
}
if (params.getWordCountMax() == null) {
params.setWordCountMax(Integer.MAX_VALUE);
}
boolQueryBuilder.filter(QueryBuilders.rangeQuery("wordCount").gte(params.getWordCountMin()).lte(params.getWordCountMax()));
if (params.getUpdateTimeMin() != null) {
boolQueryBuilder.filter(QueryBuilders.rangeQuery("lastIndexUpdateTime").gte(params.getUpdateTimeMin()));
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder);
Count count = new Count.Builder().addIndex("novel").addType("book")
.query(searchSourceBuilder.toString()).build();
CountResult results = jestClient.execute(count);
Double total = results.getCount();
// 高亮字段
HighlightBuilder highlightBuilder = new HighlightBuilder();
highlightBuilder.field("authorName");
highlightBuilder.field("bookName");
highlightBuilder.field("bookDesc");
highlightBuilder.field("lastIndexName");
highlightBuilder.field("catName");
highlightBuilder.preTags("<span style='color:red'>").postTags("</span>");
highlightBuilder.fragmentSize(20000);
searchSourceBuilder.highlighter(highlightBuilder);
//设置排序
if (params.getSort() != null) {
searchSourceBuilder.sort(StringUtil.camelName(params.getSort()), SortOrder.DESC);
}
// 设置分页
searchSourceBuilder.from((page - 1) * pageSize);
searchSourceBuilder.size(pageSize);
// 构建Search对象
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex("novel").addType("book").build();
log.debug(search.toString());
SearchResult result;
result = jestClient.execute(search);
if (result.isSucceeded()) {
log.debug(result.getJsonString());
Map resultMap = new ObjectMapper().readValue(result.getJsonString(), Map.class);
if (resultMap.get("hits") != null) {
Map hitsMap = (Map) resultMap.get("hits");
if (hitsMap.size() > 0 && hitsMap.get("hits") != null) {
List hitsList = (List) hitsMap.get("hits");
if (hitsList.size() > 0 && result.getSourceAsString() != null) {
JavaType jt = new ObjectMapper().getTypeFactory().constructParametricType(ArrayList.class, EsBookVO.class);
bookList = new ObjectMapper().readValue("[" + result.getSourceAsString() + "]", jt);
if (bookList != null) {
for (int i = 0; i < bookList.size(); i++) {
hitsMap = (Map) hitsList.get(i);
Map highlightMap = (Map) hitsMap.get("highlight");
if (highlightMap != null && highlightMap.size() > 0) {
List<String> authorNameList = (List<String>) highlightMap.get("authorName");
if (authorNameList != null && authorNameList.size() > 0) {
bookList.get(i).setAuthorName(authorNameList.get(0));
}
List<String> bookNameList = (List<String>) highlightMap.get("bookName");
if (bookNameList != null && bookNameList.size() > 0) {
bookList.get(i).setBookName(bookNameList.get(0));
}
List<String> bookDescList = (List<String>) highlightMap.get("bookDesc");
if (bookDescList != null && bookDescList.size() > 0) {
bookList.get(i).setBookDesc(bookDescList.get(0));
}
List<String> lastIndexNameList = (List<String>) highlightMap.get("lastIndexName");
if (lastIndexNameList != null && lastIndexNameList.size() > 0) {
bookList.get(i).setLastIndexName(lastIndexNameList.get(0));
}
List<String> catNameList = (List<String>) highlightMap.get("catName");
if (catNameList != null && catNameList.size() > 0) {
bookList.get(i).setCatName(catNameList.get(0));
}
}
}
}
}
}
}
PageInfo<EsBookVO> pageInfo = new PageInfo<>(bookList);
pageInfo.setTotal(total.longValue());
pageInfo.setPageNum(page);
pageInfo.setPageSize(pageSize);
return pageInfo;
}
}catch (Exception e){
log.error(e.getMessage(),e);
}
}
PageHelper.startPage(page, pageSize);
if (StringUtils.isNotBlank(params.getSort())) {
OrderByHelper.orderBy(params.getSort() + " desc");
}
return bookMapper.searchByPage(params);
return new PageInfo<>(bookMapper.searchByPage(params));
}
@Override
@ -197,7 +361,7 @@ public class BookServiceImpl implements BookService {
@Override
public Book queryBookDetail(Long bookId) {
SelectStatementProvider selectStatement = select(id, catName, catId, picUrl, bookName, authorId, authorName, bookDesc, bookStatus, visitCount, wordCount, lastIndexId, lastIndexName, lastIndexUpdateTime,score,status)
SelectStatementProvider selectStatement = select(book.allColumns())
.from(book)
.where(id, isEqualTo(bookId))
.build()
@ -206,15 +370,15 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<BookIndex> queryIndexList(Long bookId,String orderBy, Integer limit) {
if(StringUtils.isNotBlank(orderBy)){
public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer limit) {
if (StringUtils.isNotBlank(orderBy)) {
OrderByHelper.orderBy(orderBy);
}
if(limit != null){
PageHelper.startPage(1,limit);
if (limit != null) {
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)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build()
@ -225,7 +389,7 @@ public class BookServiceImpl implements BookService {
@Override
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)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
.build()
@ -271,7 +435,7 @@ public class BookServiceImpl implements BookService {
@Override
public BookContent queryBookContent(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id,BookContentDynamicSqlSupport.content)
SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id, BookContentDynamicSqlSupport.content)
.from(bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId))
.limit(1)
@ -305,7 +469,7 @@ 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))
.where(wordCount, isGreaterThan(0))
.orderBy(sortSpecification)
.limit(limit)
.build()
@ -316,8 +480,7 @@ public class BookServiceImpl implements BookService {
@Override
public void addVisitCount(Long bookId) {
bookMapper.addVisitCount(bookId);
bookMapper.addVisitCount(bookId, new Date());
}
@Override
@ -349,10 +512,10 @@ public class BookServiceImpl implements BookService {
}
@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);
OrderByHelper.orderBy("t1.create_time desc");
return bookCommentMapper.listCommentByPage(userId,bookId);
return bookCommentMapper.listCommentByPage(userId, bookId);
}
@Transactional(rollbackFor = Exception.class)
@ -361,11 +524,11 @@ public class BookServiceImpl implements BookService {
//判断该用户是否已评论过该书籍
SelectStatementProvider selectStatement = select(count(BookCommentDynamicSqlSupport.id))
.from(bookComment)
.where(BookCommentDynamicSqlSupport.createUserId,isEqualTo(userId))
.and(BookCommentDynamicSqlSupport.bookId,isEqualTo(comment.getBookId()))
.where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId))
.and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId()))
.build()
.render(RenderingStrategies.MYBATIS3);
if(bookCommentMapper.count(selectStatement)>0){
if (bookCommentMapper.count(selectStatement) > 0) {
throw new BusinessException(ResponseStatus.HAS_COMMENTS);
}
//增加评论
@ -382,14 +545,14 @@ public class BookServiceImpl implements BookService {
Long authorId;
SelectStatementProvider selectStatement = select(BookAuthorDynamicSqlSupport.id)
.from(BookAuthorDynamicSqlSupport.bookAuthor)
.where(BookAuthorDynamicSqlSupport.penName,isEqualTo(authorName))
.where(BookAuthorDynamicSqlSupport.penName, isEqualTo(authorName))
.build()
.render(RenderingStrategies.MYBATIS3);
List<BookAuthor> bookAuthors = bookAuthorMapper.selectMany(selectStatement);
if(bookAuthors.size()>0){
if (bookAuthors.size() > 0) {
//作者存在
authorId = bookAuthors.get(0).getId();
}else{
} else {
//作者不存在,先创建作者
Date currentDate = new Date();
authorId = new IdWorker().nextId();
@ -409,18 +572,17 @@ public class BookServiceImpl implements BookService {
}
@Override
public Long queryIdByNameAndAuthor(String bookName, String author) {
//查询小说ID
SelectStatementProvider selectStatement = select(id)
.from(book)
.where(BookDynamicSqlSupport.bookName,isEqualTo(bookName))
.and(BookDynamicSqlSupport.authorName,isEqualTo(authorName))
.where(BookDynamicSqlSupport.bookName, isEqualTo(bookName))
.and(BookDynamicSqlSupport.authorName, isEqualTo(authorName))
.build()
.render(RenderingStrategies.MYBATIS3);
List<Book> books = bookMapper.selectMany(selectStatement);
if(books.size()>0){
if (books.size() > 0) {
return books.get(0).getId();
}
return null;
@ -430,7 +592,7 @@ public class BookServiceImpl implements BookService {
public List<Integer> queryIndexNumByBookId(Long bookId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.indexNum)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId,isEqualTo(bookId))
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build()
.render(RenderingStrategies.MYBATIS3);
@ -438,21 +600,21 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) {
return bookMapper.queryNetworkPicBooks(limit,offset);
public List<Book> queryNetworkPicBooks(Integer limit) {
return bookMapper.queryNetworkPicBooks(limit);
}
@Override
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)
.set(BookDynamicSqlSupport.picUrl)
.equalTo(picUrl)
.set(updateTime)
.equalTo(new Date())
.where(id,isEqualTo(bookId))
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategies.MYBATIS3));
@ -461,7 +623,7 @@ public class BookServiceImpl implements BookService {
@Override
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)
.from(book)
@ -476,10 +638,11 @@ public class BookServiceImpl implements BookService {
@Override
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);
};
}
;
book.setAuthorName(penName);
book.setAuthorId(authorId);
book.setVisitCount(0L);
@ -497,18 +660,18 @@ public class BookServiceImpl implements BookService {
bookMapper.update(update(book)
.set(BookDynamicSqlSupport.status)
.equalTo(status)
.where(id,isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId,isEqualTo(authorId))
.where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build()
.render(RenderingStrategies.MYBATIS3));
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void addBookContent(Long bookId, String indexName, String content, Long authorId) {
Book book = queryBookDetail(bookId);
if(!authorId.equals(book.getAuthorId())){
if (!authorId.equals(book.getAuthorId())) {
//并不是更新自己的小说
return;
}
@ -525,15 +688,15 @@ public class BookServiceImpl implements BookService {
.set(BookDynamicSqlSupport.lastIndexUpdateTime)
.equalTo(currentDate)
.set(BookDynamicSqlSupport.wordCount)
.equalTo(book.getWordCount()+wordCount)
.where(id,isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId,isEqualTo(authorId))
.equalTo(book.getWordCount() + wordCount)
.where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build()
.render(RenderingStrategies.MYBATIS3));
//更新小说目录表
int indexNum = 0;
if(book.getLastIndexId() != null){
indexNum = queryBookIndex(book.getLastIndexId()).getIndexNum()+1;
if (book.getLastIndexId() != null) {
indexNum = queryBookIndex(book.getLastIndexId()).getIndexNum() + 1;
}
BookIndex lastBookIndex = new BookIndex();
lastBookIndex.setId(lastIndexId);
@ -553,7 +716,19 @@ public class BookServiceImpl implements BookService {
bookContentMapper.insertSelective(bookContent);
}
@Override
public List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit) {
return bookMapper.selectMany(select(book.allColumns())
.from(book)
.where(updateTime, isGreaterThan(startDate))
.orderBy(updateTime)
.limit(limit)
.build()
.render(RenderingStrategies.MYBATIS3));
}

View File

@ -0,0 +1,85 @@
package com.java2nb.novel.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.java2nb.novel.entity.Book;
import lombok.Data;
import javax.annotation.Generated;
import java.io.Serializable;
import java.util.Date;
/**
* @author Administrator
*/
@Data
public class EsBookVO {
private Long id;
private Byte workDirection;
private Integer catId;
private String catName;
private String picUrl;
private String bookName;
private Long authorId;
private String authorName;
private String bookDesc;
private Float score;
private Byte bookStatus;
private Long visitCount;
private Integer wordCount;
private Integer commentCount;
private Long lastIndexId;
private String lastIndexName;
private String lastIndexUpdateTime;
private Byte isVip;
private Byte status;
private Integer crawlSourceId;
private String crawlBookId;
private Byte crawlIsStop;
}

View File

@ -6,6 +6,15 @@ spring:
active: dev
include: alipay
elasticsearch:
#是否开启搜索引擎1开启0不开启
enable: 0
jest:
uris: http://127.0.0.1:9200
jwt:
secret: novel!#20191230
expiration: 604800

View File

@ -34,8 +34,9 @@
</select>
<update id="addVisitCount" parameterType="long">
update book set visit_count = visit_count + 1 where id = #{bookId}
<update id="addVisitCount" >
update book set visit_count = visit_count + 1 , update_time = #{date}
where id = #{bookId}
</update>
<select id="listRecBookByCatId" parameterType="int" resultType="com.java2nb.novel.entity.Book">
@ -54,8 +55,8 @@
<select id="queryNetworkPicBooks" resultType="com.java2nb.novel.entity.Book">
select
id,pic_url from book
where pic_url like 'http://%' or pic_url like 'https://%'
limit #{offset},#{limit}
where pic_url like 'http%'
limit #{limit}
</select>
<select id="selectIdsByScoreAndRandom" parameterType="int" resultType="com.java2nb.novel.entity.Book">

View File

@ -130,33 +130,43 @@
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var lock = false;
function addBook() {
if(lock){
return;
}
lock = true;
var bookName = $("#bookName").val();
if(!bookName){
$("#LabErr").html("小说名不能为空");
lock = false;
return;
}
if(bookName.length > 20){
$("#LabErr").html("小说名太长");
lock = false;
return;
}
var picUrl = $("#picUrl").val();
if(!picUrl){
$("#LabErr").html("封面图片不能为空");
lock = false;
return;
}
var bookDesc = $("#bookDesc").val();
if(!bookDesc){
$("#LabErr").html("简介不能为空");
lock = false;
return;
}
$.ajax({
type: "POST",
url: "/author/addBook",
@ -171,11 +181,13 @@
} else {
lock = false;
$("#LabErr").html(data.msg);
}
},
error: function () {
lock = false;
layer.alert('网络异常');
}
})

View File

@ -58,10 +58,8 @@
<b>章节名:</b>
<li><input type="text" id="bookIndex" name="bookIndex" class="s_input" ></li>
<b>章节内容:</b>
<input type="hidden" id="bookContent" name="bookContent" >
<div style="width:600px" id="contentEditor">
</div>
<textarea name="bookContent" rows="30" cols="80" id="bookContent"
class="textarea"></textarea>
<li style="margin-top: 10px"><input type="button" onclick="addBookContent()" name="btnRegister" value="提交"
id="btnRegister" class="btn_red">
@ -114,43 +112,18 @@
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script src="/javascript/common.js" type="text/javascript"></script>
<script type="text/javascript" src="/wangEditor/release/wangEditor.js"></script>
<script language="javascript" type="text/javascript">
var E = window.wangEditor;
var editor2 = new E('#contentEditor');
// 自定义菜单配置
editor2.customConfig.menus = [
'head', // 标题
'bold', // 粗体
'fontSize', // 字号
'fontName', // 字体
'italic', // 斜体
'underline', // 下划线
'strikeThrough', // 删除线
'foreColor', // 文字颜色
//'backColor', // 背景颜色
//'link', // 插入链接
'list', // 列表
'justify', // 对齐方式
'quote', // 引用
'emoticon', // 表情
'image', // 插入图片
//'table', // 表格
//'video', // 插入视频
//'code', // 插入代码
'undo', // 撤销
'redo' // 重复
];
editor2.customConfig.onchange = function (html) {
// html 即变化之后的内容
$("#bookContent").val(html);
}
editor2.create();
var lock = false;
function addBookContent() {
if(lock){
return;
}
lock = true;
var bookId = getSearchString("bookId");
@ -158,12 +131,14 @@
var indexName = $("#bookIndex").val();
if(!indexName){
$("#LabErr").html("章节名不能为空");
lock = false;
return;
}
var content = $("#bookContent").val();
if(!content && content.length<=13){
if(!content){
$("#LabErr").html("章节内容不能为空");
lock = false;
return;
}
@ -182,11 +157,13 @@
} else {
lock = false;
$("#LabErr").html(data.msg);
}
},
error: function () {
lock = false;
layer.alert('网络异常');
}
})

View File

@ -179,9 +179,13 @@
for (var i = 0; i < bookList.length; i++) {
var book = bookList[i];
var end = book.bookDesc.indexOf("<");
/*var end = book.bookDesc.indexOf("<");
if(end != -1) {
book.bookDesc = book.bookDesc.substring(0,end);
}*/
if(book.bookDesc){
book.bookDesc = book.bookDesc.replace(/<[^>]+>/g,"").replace(/\s+/g,"").replace(/&nbsp;/g,"");
}
bookListHtml += ("<div class=\"layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
@ -202,7 +206,7 @@
" </a>\n" +
" <div style=\"margin-top: 5px;color: #4c6978;\">类别:"+book.catName+"</div>\n" +
" <div style=\"margin-top: 5px;color: #4c6978;\">状态:"+(book.bookStatus==0?'连载':'完结')+"</div>\n" +
" <div style=\"margin-top: 5px;color: #4c6978;\">更新:<i>"+book.lastIndexUpdateTime+"</i>\n" +
" <div style=\"margin-top: 5px;color: #4c6978;\">更新:<i>"+book.lastIndexUpdateTime.substr(0,11)+"</i>\n" +
" </div>\n" +
" <div style=\"margin-top: 5px;color: #4c6978;\">简介:"+(book.bookDesc?(book.bookDesc.length>20?(book.bookDesc.substr(0,20)+"..."):book.bookDesc):book.bookDesc)+"</div>\n" +
"\n" +

View File

@ -276,6 +276,10 @@
for (var i = 0; i < 6; i++) {
var hotRecBook = hotRecBooks[i];
if(hotRecBook.bookDesc){
hotRecBook.bookDesc = hotRecBook.bookDesc.replace(/<[^>]+>/g,"").replace(/\s+/g,"");
}
hotRecBooksHtml += ("<div style=\"margin-bottom: 5px\" class=\"layui-col-xs12 layui-col-sm6 layui-col-md4 layui-col-lg4\">\n" +
" <a href=\"/book/"+hotRecBook.bookId+".html\">\n" +
" <div class=\"layui-col-xs5 layui-col-sm4 layui-col-md4 layui-col-lg4\" >\n" +
@ -323,9 +327,8 @@
for (var i = 0; i < 10; i++) {
var updateRankBook = updateRankBooks[i];
var end = updateRankBook.bookDesc.indexOf("<");
if(end != -1) {
updateRankBook.bookDesc = updateRankBook.bookDesc.substring(0,end);
if(updateRankBook.bookDesc){
updateRankBook.bookDesc = updateRankBook.bookDesc.replace(/<[^>]+>/g,"").replace(/\s+/g,"");
}
updateRankBookHtml += ("<div style=\"padding-bottom: 30px\"\n" +

View File

@ -5,7 +5,7 @@
<groupId>com.java2nb</groupId>
<artifactId>novel</artifactId>
<version>2.0.2</version>
<version>2.1.2</version>
<modules>
<module>novel-common</module>
<module>novel-front</module>
@ -36,6 +36,8 @@
<orderbyhelper.version>1.0.2</orderbyhelper.version>
<commons-lang3.version>3.4</commons-lang3.version>
<jjwt.version>0.9.0</jjwt.version>
<elasticsearch.version>6.2.2</elasticsearch.version>
<jest.version>6.3.1</jest.version>
</properties>
<dependencyManagement>