mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-01 07:16:39 +00:00
Compare commits
7 Commits
v2.8.0
...
release_v2
Author | SHA1 | Date | |
---|---|---|---|
68a1ece57c | |||
77645da2bd | |||
36376aa623 | |||
9e98665cca | |||
9a19a33406 | |||
a4f7042b87 | |||
31aa3192fd |
@ -44,6 +44,7 @@ GitHub仓库地址: https://github.com/201206030/novel-cloud
|
||||
- [x] 阅读主题模块。
|
||||
- [x] 作家专区。
|
||||
- [x] 充值。
|
||||
- [x] 订阅。
|
||||
- [x] 后台管理系统。
|
||||
- [x] 爬虫管理系统。
|
||||
|
||||
@ -219,6 +220,11 @@ docker安装教程:[点击前往](https://my.oschina.net/java2nb/blog/4271989)
|
||||
|
||||

|
||||
|
||||
### 免责声明
|
||||
|
||||
本项目提供的爬虫工具仅用于采集项目初期的测试数据,请勿用于商业盈利。
|
||||
用户使用本系统从事任何违法违规的事情,一切后果由用户自行承担,作者不承担任何责任。
|
||||
|
||||
#### 备注
|
||||
|
||||
精品小说屋所有相关项目均已在开源中国公开,感兴趣的可进入[开源中国](https://www.oschina.net/p/fiction_house)按关键字`精品小说屋`搜索。
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>2.8.0</version>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -3,6 +3,10 @@ package com.java2nb.novel.core.utils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.regex.Pattern.*;
|
||||
|
||||
/**
|
||||
* @author xiongxiaoyang
|
||||
@ -70,4 +74,83 @@ public class StringUtil {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串有效汉字
|
||||
* */
|
||||
public static String getChineseValidWord(String origStr){
|
||||
|
||||
//可以替换大部分空白字符, 不限于空格 . 说明:\s 可以匹配空格、制表符、换页符等空白字符的其中任意一个
|
||||
origStr = origStr.replaceAll("\\s*","");
|
||||
|
||||
/* //完全清除标点
|
||||
origStr = origStr.replaceAll("\\pP","");*/
|
||||
|
||||
//清除所有符号,只留下字母 数字 汉字 共3类.
|
||||
origStr = origStr.replaceAll("[\\pP\\p{Punct}]","");
|
||||
|
||||
//去除字母和数字
|
||||
origStr = origStr.replaceAll("[A-Za-z0-9]*","");
|
||||
|
||||
return origStr;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串英文单词数量
|
||||
* */
|
||||
public static int getEnglishWordCount(String origStr){
|
||||
Pattern pattern = compile("\\b\\w+\\b");
|
||||
Matcher matcher = pattern.matcher(origStr);
|
||||
int count = 0;
|
||||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串中文汉字数量
|
||||
* */
|
||||
public static int getChineseWordCount(String origStr){
|
||||
Pattern pattern = compile("[\u4e00-\u9fa5]");
|
||||
Matcher matcher = pattern.matcher(origStr);
|
||||
int count = 0;
|
||||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串有效数字数量
|
||||
* */
|
||||
public static int getNumberWordCount(String origStr){
|
||||
Pattern pattern = compile("\\d+");
|
||||
Matcher matcher = pattern.matcher(origStr);
|
||||
int count = 0;
|
||||
while (matcher.find()) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串有效字数
|
||||
* */
|
||||
public static int getStrValidWordCount(String origStr){
|
||||
return getChineseWordCount(origStr) + getEnglishWordCount(origStr) + getNumberWordCount(origStr);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "Welcome to China. 你好呀!中国人,我是1123号程序员, 来给你服务23天. Hello Word";
|
||||
System.out.println(getChineseWordCount(str));
|
||||
System.out.println(getEnglishWordCount(str));
|
||||
System.out.println(getNumberWordCount(str));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public class BookIndex {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private Byte isVip;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private Integer bookPrice;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
private Date createTime;
|
||||
|
||||
@ -88,6 +91,16 @@ public class BookIndex {
|
||||
this.isVip = isVip;
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public Integer getBookPrice() {
|
||||
return bookPrice;
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public void setBookPrice(Integer bookPrice) {
|
||||
this.bookPrice = bookPrice;
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
|
@ -28,6 +28,9 @@ public final class BookIndexDynamicSqlSupport {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Byte> isVip = bookIndex.isVip;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Integer> bookPrice = bookIndex.bookPrice;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Date> createTime = bookIndex.createTime;
|
||||
|
||||
@ -48,6 +51,8 @@ public final class BookIndexDynamicSqlSupport {
|
||||
|
||||
public final SqlColumn<Byte> isVip = column("is_vip", JDBCType.TINYINT);
|
||||
|
||||
public final SqlColumn<Integer> bookPrice = column("book_price", JDBCType.INTEGER);
|
||||
|
||||
public final SqlColumn<Date> createTime = column("create_time", JDBCType.TIMESTAMP);
|
||||
|
||||
public final SqlColumn<Date> updateTime = column("update_time", JDBCType.TIMESTAMP);
|
||||
|
@ -4,10 +4,12 @@ import static com.java2nb.novel.mapper.BookIndexDynamicSqlSupport.*;
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.*;
|
||||
|
||||
import com.java2nb.novel.entity.BookIndex;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
import org.apache.ibatis.annotations.DeleteProvider;
|
||||
import org.apache.ibatis.annotations.InsertProvider;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -35,45 +37,46 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
||||
@Mapper
|
||||
public interface BookIndexMapper {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, bookId, indexNum, indexName, wordCount, isVip, createTime, updateTime);
|
||||
BasicColumn[] selectList = BasicColumn.columnList(id, bookId, indexNum, indexName, wordCount, isVip, bookPrice, createTime, updateTime);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||
@SelectProvider(type = SqlProviderAdapter.class, method = "select")
|
||||
long count(SelectStatementProvider selectStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@DeleteProvider(type=SqlProviderAdapter.class, method="delete")
|
||||
@DeleteProvider(type = SqlProviderAdapter.class, method = "delete")
|
||||
int delete(DeleteStatementProvider deleteStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@InsertProvider(type=SqlProviderAdapter.class, method="insert")
|
||||
@InsertProvider(type = SqlProviderAdapter.class, method = "insert")
|
||||
int insert(InsertStatementProvider<BookIndex> insertStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
|
||||
@InsertProvider(type = SqlProviderAdapter.class, method = "insertMultiple")
|
||||
int insertMultiple(MultiRowInsertStatementProvider<BookIndex> multipleInsertStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||
@SelectProvider(type = SqlProviderAdapter.class, method = "select")
|
||||
@ResultMap("BookIndexResult")
|
||||
Optional<BookIndex> selectOne(SelectStatementProvider selectStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||
@Results(id="BookIndexResult", value = {
|
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
||||
@Result(column="book_id", property="bookId", jdbcType=JdbcType.BIGINT),
|
||||
@Result(column="index_num", property="indexNum", jdbcType=JdbcType.INTEGER),
|
||||
@Result(column="index_name", property="indexName", jdbcType=JdbcType.VARCHAR),
|
||||
@Result(column="word_count", property="wordCount", jdbcType=JdbcType.INTEGER),
|
||||
@Result(column="is_vip", property="isVip", jdbcType=JdbcType.TINYINT),
|
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
|
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
|
||||
@SelectProvider(type = SqlProviderAdapter.class, method = "select")
|
||||
@Results(id = "BookIndexResult", value = {
|
||||
@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
|
||||
@Result(column = "book_id", property = "bookId", jdbcType = JdbcType.BIGINT),
|
||||
@Result(column = "index_num", property = "indexNum", jdbcType = JdbcType.INTEGER),
|
||||
@Result(column = "index_name", property = "indexName", jdbcType = JdbcType.VARCHAR),
|
||||
@Result(column = "word_count", property = "wordCount", jdbcType = JdbcType.INTEGER),
|
||||
@Result(column = "is_vip", property = "isVip", jdbcType = JdbcType.TINYINT),
|
||||
@Result(column = "book_price", property = "bookPrice", jdbcType = JdbcType.INTEGER),
|
||||
@Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
|
||||
@Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP)
|
||||
})
|
||||
List<BookIndex> selectMany(SelectStatementProvider selectStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
|
||||
@UpdateProvider(type = SqlProviderAdapter.class, method = "update")
|
||||
int update(UpdateStatementProvider updateStatement);
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
@ -88,50 +91,53 @@ public interface BookIndexMapper {
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int deleteByPrimaryKey(Long id_) {
|
||||
return delete(c ->
|
||||
c.where(id, isEqualTo(id_))
|
||||
return delete(c ->
|
||||
c.where(id, isEqualTo(id_))
|
||||
);
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int insert(BookIndex record) {
|
||||
return MyBatis3Utils.insert(this::insert, record, bookIndex, c ->
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(indexNum).toProperty("indexNum")
|
||||
.map(indexName).toProperty("indexName")
|
||||
.map(wordCount).toProperty("wordCount")
|
||||
.map(isVip).toProperty("isVip")
|
||||
.map(createTime).toProperty("createTime")
|
||||
.map(updateTime).toProperty("updateTime")
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(indexNum).toProperty("indexNum")
|
||||
.map(indexName).toProperty("indexName")
|
||||
.map(wordCount).toProperty("wordCount")
|
||||
.map(isVip).toProperty("isVip")
|
||||
.map(bookPrice).toProperty("bookPrice")
|
||||
.map(createTime).toProperty("createTime")
|
||||
.map(updateTime).toProperty("updateTime")
|
||||
);
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int insertMultiple(Collection<BookIndex> records) {
|
||||
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, bookIndex, c ->
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(indexNum).toProperty("indexNum")
|
||||
.map(indexName).toProperty("indexName")
|
||||
.map(wordCount).toProperty("wordCount")
|
||||
.map(isVip).toProperty("isVip")
|
||||
.map(createTime).toProperty("createTime")
|
||||
.map(updateTime).toProperty("updateTime")
|
||||
c.map(id).toProperty("id")
|
||||
.map(bookId).toProperty("bookId")
|
||||
.map(indexNum).toProperty("indexNum")
|
||||
.map(indexName).toProperty("indexName")
|
||||
.map(wordCount).toProperty("wordCount")
|
||||
.map(isVip).toProperty("isVip")
|
||||
.map(bookPrice).toProperty("bookPrice")
|
||||
.map(createTime).toProperty("createTime")
|
||||
.map(updateTime).toProperty("updateTime")
|
||||
);
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int insertSelective(BookIndex record) {
|
||||
return MyBatis3Utils.insert(this::insert, record, bookIndex, c ->
|
||||
c.map(id).toPropertyWhenPresent("id", record::getId)
|
||||
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
|
||||
.map(indexNum).toPropertyWhenPresent("indexNum", record::getIndexNum)
|
||||
.map(indexName).toPropertyWhenPresent("indexName", record::getIndexName)
|
||||
.map(wordCount).toPropertyWhenPresent("wordCount", record::getWordCount)
|
||||
.map(isVip).toPropertyWhenPresent("isVip", record::getIsVip)
|
||||
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
|
||||
.map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
|
||||
c.map(id).toPropertyWhenPresent("id", record::getId)
|
||||
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
|
||||
.map(indexNum).toPropertyWhenPresent("indexNum", record::getIndexNum)
|
||||
.map(indexName).toPropertyWhenPresent("indexName", record::getIndexName)
|
||||
.map(wordCount).toPropertyWhenPresent("wordCount", record::getWordCount)
|
||||
.map(isVip).toPropertyWhenPresent("isVip", record::getIsVip)
|
||||
.map(bookPrice).toPropertyWhenPresent("bookPrice", record::getBookPrice)
|
||||
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
|
||||
.map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@ -153,7 +159,7 @@ public interface BookIndexMapper {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default Optional<BookIndex> selectByPrimaryKey(Long id_) {
|
||||
return selectOne(c ->
|
||||
c.where(id, isEqualTo(id_))
|
||||
c.where(id, isEqualTo(id_))
|
||||
);
|
||||
}
|
||||
|
||||
@ -170,6 +176,7 @@ public interface BookIndexMapper {
|
||||
.set(indexName).equalTo(record::getIndexName)
|
||||
.set(wordCount).equalTo(record::getWordCount)
|
||||
.set(isVip).equalTo(record::getIsVip)
|
||||
.set(bookPrice).equalTo(record::getBookPrice)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
.set(updateTime).equalTo(record::getUpdateTime);
|
||||
}
|
||||
@ -182,6 +189,7 @@ public interface BookIndexMapper {
|
||||
.set(indexName).equalToWhenPresent(record::getIndexName)
|
||||
.set(wordCount).equalToWhenPresent(record::getWordCount)
|
||||
.set(isVip).equalToWhenPresent(record::getIsVip)
|
||||
.set(bookPrice).equalToWhenPresent(record::getBookPrice)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
.set(updateTime).equalToWhenPresent(record::getUpdateTime);
|
||||
}
|
||||
@ -189,28 +197,30 @@ public interface BookIndexMapper {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int updateByPrimaryKey(BookIndex record) {
|
||||
return update(c ->
|
||||
c.set(bookId).equalTo(record::getBookId)
|
||||
.set(indexNum).equalTo(record::getIndexNum)
|
||||
.set(indexName).equalTo(record::getIndexName)
|
||||
.set(wordCount).equalTo(record::getWordCount)
|
||||
.set(isVip).equalTo(record::getIsVip)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
.set(updateTime).equalTo(record::getUpdateTime)
|
||||
.where(id, isEqualTo(record::getId))
|
||||
c.set(bookId).equalTo(record::getBookId)
|
||||
.set(indexNum).equalTo(record::getIndexNum)
|
||||
.set(indexName).equalTo(record::getIndexName)
|
||||
.set(wordCount).equalTo(record::getWordCount)
|
||||
.set(isVip).equalTo(record::getIsVip)
|
||||
.set(bookPrice).equalTo(record::getBookPrice)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
.set(updateTime).equalTo(record::getUpdateTime)
|
||||
.where(id, isEqualTo(record::getId))
|
||||
);
|
||||
}
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
default int updateByPrimaryKeySelective(BookIndex record) {
|
||||
return update(c ->
|
||||
c.set(bookId).equalToWhenPresent(record::getBookId)
|
||||
.set(indexNum).equalToWhenPresent(record::getIndexNum)
|
||||
.set(indexName).equalToWhenPresent(record::getIndexName)
|
||||
.set(wordCount).equalToWhenPresent(record::getWordCount)
|
||||
.set(isVip).equalToWhenPresent(record::getIsVip)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
.set(updateTime).equalToWhenPresent(record::getUpdateTime)
|
||||
.where(id, isEqualTo(record::getId))
|
||||
c.set(bookId).equalToWhenPresent(record::getBookId)
|
||||
.set(indexNum).equalToWhenPresent(record::getIndexNum)
|
||||
.set(indexName).equalToWhenPresent(record::getIndexName)
|
||||
.set(wordCount).equalToWhenPresent(record::getWordCount)
|
||||
.set(isVip).equalToWhenPresent(record::getIsVip)
|
||||
.set(bookPrice).equalToWhenPresent(record::getBookPrice)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
.set(updateTime).equalToWhenPresent(record::getUpdateTime)
|
||||
.where(id, isEqualTo(record::getId))
|
||||
);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>2.8.0</version>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -224,6 +224,9 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
boolean isFindBookId = bookIdMatcher.find();
|
||||
while (isFindBookId) {
|
||||
try {
|
||||
//1.阻塞过程(使用了 sleep,同步锁的 wait,socket 中的 receiver,accept 等方法时)
|
||||
//捕获中断异常InterruptedException来退出线程。
|
||||
//2.非阻塞过程中通过判断中断标志来退出线程。
|
||||
if(Thread.currentThread().isInterrupted()){
|
||||
return;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>2.8.0</version>
|
||||
<version>2.9.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -282,6 +282,7 @@ public class UserController extends BaseController {
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
buyRecord.setBuyAmount(bookService.queryBookIndex(buyRecord.getBookIndexId()).getBookPrice());
|
||||
userService.buyBookIndex(userDetails.getId(),buyRecord);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.java2nb.novel.core.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 章节费用配置
|
||||
* @author cd
|
||||
*/
|
||||
@Component
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "book.price")
|
||||
public class BookPriceConfig {
|
||||
|
||||
private BigDecimal wordCount;
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ 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.config.BookPriceConfig;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.core.exception.BusinessException;
|
||||
import com.java2nb.novel.core.utils.*;
|
||||
@ -88,6 +89,8 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
private final FileService fileService;
|
||||
|
||||
private final BookPriceConfig bookPriceConfig;
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
@ -256,7 +259,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.bookPrice, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
|
||||
.from(bookIndex)
|
||||
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
|
||||
.build()
|
||||
@ -544,7 +547,7 @@ public class BookServiceImpl implements BookService {
|
||||
}
|
||||
Long lastIndexId = new IdWorker().nextId();
|
||||
Date currentDate = new Date();
|
||||
int wordCount = content.length();
|
||||
int wordCount = StringUtil.getStrValidWordCount(content);
|
||||
|
||||
//更新小说主表信息
|
||||
bookMapper.update(update(BookDynamicSqlSupport.book)
|
||||
@ -560,6 +563,10 @@ public class BookServiceImpl implements BookService {
|
||||
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
|
||||
//计算价格
|
||||
int bookPrice = new BigDecimal(wordCount).divide(bookPriceConfig.getWordCount()).multiply(bookPriceConfig.getValue()).intValue();
|
||||
|
||||
//更新小说目录表
|
||||
int indexNum = 0;
|
||||
if (book.getLastIndexId() != null) {
|
||||
@ -572,6 +579,7 @@ public class BookServiceImpl implements BookService {
|
||||
lastBookIndex.setIndexNum(indexNum);
|
||||
lastBookIndex.setBookId(bookId);
|
||||
lastBookIndex.setIsVip(isVip);
|
||||
lastBookIndex.setBookPrice(bookPrice);
|
||||
lastBookIndex.setCreateTime(currentDate);
|
||||
lastBookIndex.setUpdateTime(currentDate);
|
||||
bookIndexMapper.insertSelective(lastBookIndex);
|
||||
@ -786,7 +794,11 @@ public class BookServiceImpl implements BookService {
|
||||
//作者ID相同,表明该小说是登录用户发布,可以修改
|
||||
if (book.getAuthorId().equals(authorId)) {
|
||||
Date currentDate = new Date();
|
||||
int wordCount = content.length();
|
||||
int wordCount = StringUtil.getStrValidWordCount(content);
|
||||
|
||||
//计算价格
|
||||
int bookPrice = new BigDecimal(wordCount).divide(bookPriceConfig.getWordCount()).multiply(bookPriceConfig.getValue()).intValue();
|
||||
|
||||
|
||||
//更新小说目录表
|
||||
int update = bookIndexMapper.update(
|
||||
@ -795,6 +807,8 @@ public class BookServiceImpl implements BookService {
|
||||
.equalTo(indexName)
|
||||
.set(BookIndexDynamicSqlSupport.wordCount)
|
||||
.equalTo(wordCount)
|
||||
.set(BookIndexDynamicSqlSupport.bookPrice)
|
||||
.equalTo(bookPrice)
|
||||
.set(BookIndexDynamicSqlSupport.updateTime)
|
||||
.equalTo(currentDate)
|
||||
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId))
|
||||
|
@ -284,20 +284,19 @@ public class UserServiceImpl implements UserService {
|
||||
public void buyBookIndex(Long userId, UserBuyRecord buyRecord) {
|
||||
//查询用户余额
|
||||
long balance = userInfo(userId).getAccountBalance();
|
||||
if(balance<10){
|
||||
if(balance<buyRecord.getBuyAmount()){
|
||||
//余额不足
|
||||
throw new BusinessException(ResponseStatus.USER_NO_BALANCE);
|
||||
}
|
||||
buyRecord.setUserId(userId);
|
||||
buyRecord.setCreateTime(new Date());
|
||||
buyRecord.setBuyAmount(10);
|
||||
//生成购买记录
|
||||
userBuyRecordMapper.insertSelective(buyRecord);
|
||||
|
||||
//减少用户余额
|
||||
userMapper.update(update(user)
|
||||
.set(UserDynamicSqlSupport.accountBalance)
|
||||
.equalTo(balance-10)
|
||||
.equalTo(balance-buyRecord.getBuyAmount())
|
||||
.where(id,isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
|
@ -57,3 +57,11 @@ author:
|
||||
share-proportion: 0.7
|
||||
#兑换比率(人民币)
|
||||
exchange-proportion: 0.01
|
||||
|
||||
#小说章节定价规则
|
||||
book:
|
||||
price:
|
||||
#字数
|
||||
word-count: 1000
|
||||
#价值(屋币)
|
||||
value: 5
|
@ -116,7 +116,7 @@
|
||||
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAX4WEeZOhVYVmRzc9paH9JSy/08L4LdXX0bnEtd0tA2crFh4MPja1O/9L0Y0B5Q7Mkw2OnJlkYmOh3/iyqfPkkn99UiP/cCDJ38/2cPKg8P57VHEmkKJr8/tJbwExBtkfhGxxoA1kMIQUaw59BH5iPe">
|
||||
</div>
|
||||
<ul class="order_list">
|
||||
<li>价格:<span class="red">10屋币(1元=100屋币)</span></li>
|
||||
<li>价格:<span class="red" th:text="${bookIndex.bookPrice}+'屋币(1元=100屋币)'"></span></li>
|
||||
<li id="panelPay" class="btns"><a class="btn_red" href="javascript:buyBookIndex()" >购买</a></li>
|
||||
|
||||
</ul>
|
||||
|
@ -238,7 +238,7 @@
|
||||
<div class="Readarea ReadAjax_content screen_container"
|
||||
style="color: rgb(0, 0, 0); font-size: 10px;background-color: #fff" th:if="${needBuy}">
|
||||
<h5>此章为VIP章节,需要订阅后才能继续阅读</h5>
|
||||
价格:<span style="color: red">10屋币(1元=100屋币)</span><br/>
|
||||
价格:<span style="color: red" th:text="${bookIndex.bookPrice}+'屋币(1元=100屋币)'"></span><br/>
|
||||
<a href="javascript:buyBookIndex()" type="button" class="layui-btn layui-btn-sm layui-btn-radius">购买</a>
|
||||
|
||||
</div>
|
||||
|
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.java2nb</groupId>
|
||||
<artifactId>novel</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<version>2.9.0</version>
|
||||
<modules>
|
||||
<module>novel-common</module>
|
||||
<module>novel-front</module>
|
||||
|
1
sql/20201122.sql
Normal file
1
sql/20201122.sql
Normal file
@ -0,0 +1 @@
|
||||
alter table book_index add column `book_price` int(3) DEFAULT 0 COMMENT '章节费用(屋币)' after `is_vip`;
|
@ -1868,3 +1868,5 @@ CREATE TABLE `author_income` (
|
||||
|
||||
|
||||
alter table book add column `yesterday_buy` int(11) DEFAULT '0' COMMENT '昨日订阅数' after comment_count;
|
||||
|
||||
alter table book_index add column `book_price` int(3) DEFAULT 0 COMMENT '章节费用(屋币)' after `is_vip`;
|
Reference in New Issue
Block a user