mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-26 17:20:52 +00:00
用户购买功能实现
This commit is contained in:
parent
401d23871d
commit
0fa929f9de
@ -43,6 +43,7 @@ public enum ResponseStatus {
|
|||||||
USERNAME_PASS_ERROR(1004,"手机号或密码错误!"),
|
USERNAME_PASS_ERROR(1004,"手机号或密码错误!"),
|
||||||
TWO_PASSWORD_DIFF(1005, "两次输入的新密码不匹配!"),
|
TWO_PASSWORD_DIFF(1005, "两次输入的新密码不匹配!"),
|
||||||
OLD_PASSWORD_ERROR(1006, "旧密码不匹配!"),
|
OLD_PASSWORD_ERROR(1006, "旧密码不匹配!"),
|
||||||
|
USER_NO_BALANCE(1007, "用户余额不足"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论相关错误
|
* 评论相关错误
|
||||||
|
@ -0,0 +1,110 @@
|
|||||||
|
package com.java2nb.novel.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import javax.annotation.Generated;
|
||||||
|
|
||||||
|
public class UserBuyRecord {
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Long bookId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private String bookName;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Long bookIndexId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private String bookIndexName;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Integer buyAmount;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Long getBookId() {
|
||||||
|
return bookId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setBookId(Long bookId) {
|
||||||
|
this.bookId = bookId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public String getBookName() {
|
||||||
|
return bookName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setBookName(String bookName) {
|
||||||
|
this.bookName = bookName == null ? null : bookName.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Long getBookIndexId() {
|
||||||
|
return bookIndexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setBookIndexId(Long bookIndexId) {
|
||||||
|
this.bookIndexId = bookIndexId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public String getBookIndexName() {
|
||||||
|
return bookIndexName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setBookIndexName(String bookIndexName) {
|
||||||
|
this.bookIndexName = bookIndexName == null ? null : bookIndexName.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Integer getBuyAmount() {
|
||||||
|
return buyAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setBuyAmount(Integer buyAmount) {
|
||||||
|
this.buyAmount = buyAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.java2nb.novel.mapper;
|
||||||
|
|
||||||
|
import java.sql.JDBCType;
|
||||||
|
import java.util.Date;
|
||||||
|
import javax.annotation.Generated;
|
||||||
|
import org.mybatis.dynamic.sql.SqlColumn;
|
||||||
|
import org.mybatis.dynamic.sql.SqlTable;
|
||||||
|
|
||||||
|
public final class UserBuyRecordDynamicSqlSupport {
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final UserBuyRecord userBuyRecord = new UserBuyRecord();
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Long> id = userBuyRecord.id;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Long> userId = userBuyRecord.userId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Long> bookId = userBuyRecord.bookId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<String> bookName = userBuyRecord.bookName;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Long> bookIndexId = userBuyRecord.bookIndexId;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<String> bookIndexName = userBuyRecord.bookIndexName;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Integer> buyAmount = userBuyRecord.buyAmount;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final SqlColumn<Date> createTime = userBuyRecord.createTime;
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
public static final class UserBuyRecord extends SqlTable {
|
||||||
|
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
|
||||||
|
|
||||||
|
public final SqlColumn<Long> userId = column("user_id", JDBCType.BIGINT);
|
||||||
|
|
||||||
|
public final SqlColumn<Long> bookId = column("book_id", JDBCType.BIGINT);
|
||||||
|
|
||||||
|
public final SqlColumn<String> bookName = column("book_name", JDBCType.VARCHAR);
|
||||||
|
|
||||||
|
public final SqlColumn<Long> bookIndexId = column("book_index_id", JDBCType.BIGINT);
|
||||||
|
|
||||||
|
public final SqlColumn<String> bookIndexName = column("book_index_name", JDBCType.VARCHAR);
|
||||||
|
|
||||||
|
public final SqlColumn<Integer> buyAmount = column("buy_amount", JDBCType.INTEGER);
|
||||||
|
|
||||||
|
public final SqlColumn<Date> createTime = column("create_time", JDBCType.TIMESTAMP);
|
||||||
|
|
||||||
|
public UserBuyRecord() {
|
||||||
|
super("user_buy_record");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,216 @@
|
|||||||
|
package com.java2nb.novel.mapper;
|
||||||
|
|
||||||
|
import static com.java2nb.novel.mapper.UserBuyRecordDynamicSqlSupport.*;
|
||||||
|
import static org.mybatis.dynamic.sql.SqlBuilder.*;
|
||||||
|
|
||||||
|
import com.java2nb.novel.entity.UserBuyRecord;
|
||||||
|
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;
|
||||||
|
import org.apache.ibatis.annotations.Result;
|
||||||
|
import org.apache.ibatis.annotations.ResultMap;
|
||||||
|
import org.apache.ibatis.annotations.Results;
|
||||||
|
import org.apache.ibatis.annotations.SelectProvider;
|
||||||
|
import org.apache.ibatis.annotations.UpdateProvider;
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
|
import org.mybatis.dynamic.sql.BasicColumn;
|
||||||
|
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
|
||||||
|
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
|
||||||
|
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
|
||||||
|
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
|
||||||
|
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
|
||||||
|
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
|
||||||
|
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
||||||
|
import org.mybatis.dynamic.sql.update.UpdateDSL;
|
||||||
|
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
|
||||||
|
import org.mybatis.dynamic.sql.update.UpdateModel;
|
||||||
|
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
|
||||||
|
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
|
||||||
|
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserBuyRecordMapper {
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
BasicColumn[] selectList = BasicColumn.columnList(id, userId, bookId, bookName, bookIndexId, bookIndexName, buyAmount, createTime);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||||
|
long count(SelectStatementProvider selectStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@DeleteProvider(type=SqlProviderAdapter.class, method="delete")
|
||||||
|
int delete(DeleteStatementProvider deleteStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@InsertProvider(type=SqlProviderAdapter.class, method="insert")
|
||||||
|
int insert(InsertStatementProvider<UserBuyRecord> insertStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
|
||||||
|
int insertMultiple(MultiRowInsertStatementProvider<UserBuyRecord> multipleInsertStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||||
|
@ResultMap("UserBuyRecordResult")
|
||||||
|
Optional<UserBuyRecord> selectOne(SelectStatementProvider selectStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@SelectProvider(type=SqlProviderAdapter.class, method="select")
|
||||||
|
@Results(id="UserBuyRecordResult", value = {
|
||||||
|
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
|
||||||
|
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
|
||||||
|
@Result(column="book_id", property="bookId", jdbcType=JdbcType.BIGINT),
|
||||||
|
@Result(column="book_name", property="bookName", jdbcType=JdbcType.VARCHAR),
|
||||||
|
@Result(column="book_index_id", property="bookIndexId", jdbcType=JdbcType.BIGINT),
|
||||||
|
@Result(column="book_index_name", property="bookIndexName", jdbcType=JdbcType.VARCHAR),
|
||||||
|
@Result(column="buy_amount", property="buyAmount", jdbcType=JdbcType.INTEGER),
|
||||||
|
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
|
||||||
|
})
|
||||||
|
List<UserBuyRecord> selectMany(SelectStatementProvider selectStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
|
||||||
|
int update(UpdateStatementProvider updateStatement);
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default long count(CountDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.countFrom(this::count, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int delete(DeleteDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.deleteFrom(this::delete, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int deleteByPrimaryKey(Long id_) {
|
||||||
|
return delete(c ->
|
||||||
|
c.where(id, isEqualTo(id_))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int insert(UserBuyRecord record) {
|
||||||
|
return MyBatis3Utils.insert(this::insert, record, userBuyRecord, c ->
|
||||||
|
c.map(id).toProperty("id")
|
||||||
|
.map(userId).toProperty("userId")
|
||||||
|
.map(bookId).toProperty("bookId")
|
||||||
|
.map(bookName).toProperty("bookName")
|
||||||
|
.map(bookIndexId).toProperty("bookIndexId")
|
||||||
|
.map(bookIndexName).toProperty("bookIndexName")
|
||||||
|
.map(buyAmount).toProperty("buyAmount")
|
||||||
|
.map(createTime).toProperty("createTime")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int insertMultiple(Collection<UserBuyRecord> records) {
|
||||||
|
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, userBuyRecord, c ->
|
||||||
|
c.map(id).toProperty("id")
|
||||||
|
.map(userId).toProperty("userId")
|
||||||
|
.map(bookId).toProperty("bookId")
|
||||||
|
.map(bookName).toProperty("bookName")
|
||||||
|
.map(bookIndexId).toProperty("bookIndexId")
|
||||||
|
.map(bookIndexName).toProperty("bookIndexName")
|
||||||
|
.map(buyAmount).toProperty("buyAmount")
|
||||||
|
.map(createTime).toProperty("createTime")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int insertSelective(UserBuyRecord record) {
|
||||||
|
return MyBatis3Utils.insert(this::insert, record, userBuyRecord, c ->
|
||||||
|
c.map(id).toPropertyWhenPresent("id", record::getId)
|
||||||
|
.map(userId).toPropertyWhenPresent("userId", record::getUserId)
|
||||||
|
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
|
||||||
|
.map(bookName).toPropertyWhenPresent("bookName", record::getBookName)
|
||||||
|
.map(bookIndexId).toPropertyWhenPresent("bookIndexId", record::getBookIndexId)
|
||||||
|
.map(bookIndexName).toPropertyWhenPresent("bookIndexName", record::getBookIndexName)
|
||||||
|
.map(buyAmount).toPropertyWhenPresent("buyAmount", record::getBuyAmount)
|
||||||
|
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default Optional<UserBuyRecord> selectOne(SelectDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.selectOne(this::selectOne, selectList, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default List<UserBuyRecord> select(SelectDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.selectList(this::selectMany, selectList, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default List<UserBuyRecord> selectDistinct(SelectDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.selectDistinct(this::selectMany, selectList, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default Optional<UserBuyRecord> selectByPrimaryKey(Long id_) {
|
||||||
|
return selectOne(c ->
|
||||||
|
c.where(id, isEqualTo(id_))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int update(UpdateDSLCompleter completer) {
|
||||||
|
return MyBatis3Utils.update(this::update, userBuyRecord, completer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
static UpdateDSL<UpdateModel> updateAllColumns(UserBuyRecord record, UpdateDSL<UpdateModel> dsl) {
|
||||||
|
return dsl.set(id).equalTo(record::getId)
|
||||||
|
.set(userId).equalTo(record::getUserId)
|
||||||
|
.set(bookId).equalTo(record::getBookId)
|
||||||
|
.set(bookName).equalTo(record::getBookName)
|
||||||
|
.set(bookIndexId).equalTo(record::getBookIndexId)
|
||||||
|
.set(bookIndexName).equalTo(record::getBookIndexName)
|
||||||
|
.set(buyAmount).equalTo(record::getBuyAmount)
|
||||||
|
.set(createTime).equalTo(record::getCreateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
static UpdateDSL<UpdateModel> updateSelectiveColumns(UserBuyRecord record, UpdateDSL<UpdateModel> dsl) {
|
||||||
|
return dsl.set(id).equalToWhenPresent(record::getId)
|
||||||
|
.set(userId).equalToWhenPresent(record::getUserId)
|
||||||
|
.set(bookId).equalToWhenPresent(record::getBookId)
|
||||||
|
.set(bookName).equalToWhenPresent(record::getBookName)
|
||||||
|
.set(bookIndexId).equalToWhenPresent(record::getBookIndexId)
|
||||||
|
.set(bookIndexName).equalToWhenPresent(record::getBookIndexName)
|
||||||
|
.set(buyAmount).equalToWhenPresent(record::getBuyAmount)
|
||||||
|
.set(createTime).equalToWhenPresent(record::getCreateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int updateByPrimaryKey(UserBuyRecord record) {
|
||||||
|
return update(c ->
|
||||||
|
c.set(userId).equalTo(record::getUserId)
|
||||||
|
.set(bookId).equalTo(record::getBookId)
|
||||||
|
.set(bookName).equalTo(record::getBookName)
|
||||||
|
.set(bookIndexId).equalTo(record::getBookIndexId)
|
||||||
|
.set(bookIndexName).equalTo(record::getBookIndexName)
|
||||||
|
.set(buyAmount).equalTo(record::getBuyAmount)
|
||||||
|
.set(createTime).equalTo(record::getCreateTime)
|
||||||
|
.where(id, isEqualTo(record::getId))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||||
|
default int updateByPrimaryKeySelective(UserBuyRecord record) {
|
||||||
|
return update(c ->
|
||||||
|
c.set(userId).equalToWhenPresent(record::getUserId)
|
||||||
|
.set(bookId).equalToWhenPresent(record::getBookId)
|
||||||
|
.set(bookName).equalToWhenPresent(record::getBookName)
|
||||||
|
.set(bookIndexId).equalToWhenPresent(record::getBookIndexId)
|
||||||
|
.set(bookIndexName).equalToWhenPresent(record::getBookIndexName)
|
||||||
|
.set(buyAmount).equalToWhenPresent(record::getBuyAmount)
|
||||||
|
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||||
|
.where(id, isEqualTo(record::getId))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -44,7 +44,7 @@
|
|||||||
</javaClientGenerator>
|
</javaClientGenerator>
|
||||||
|
|
||||||
<!--生成全部表tableName设为%-->
|
<!--生成全部表tableName设为%-->
|
||||||
<table tableName="author_code" domainObjectName="AuthorCode"/>
|
<table tableName="user_buy_record" domainObjectName="UserBuyRecord"/>
|
||||||
|
|
||||||
<!-- 指定数据库表 -->
|
<!-- 指定数据库表 -->
|
||||||
<!--<table schema="jly" tableName="job_position" domainObjectName="JobPositionTest"/>-->
|
<!--<table schema="jly" tableName="job_position" domainObjectName="JobPositionTest"/>-->
|
||||||
|
@ -116,7 +116,11 @@ public class BookController extends BaseController{
|
|||||||
public ResultBean queryBookIndexAbout(Long bookId,Long lastBookIndexId) {
|
public ResultBean queryBookIndexAbout(Long bookId,Long lastBookIndexId) {
|
||||||
Map<String,Object> data = new HashMap<>(2);
|
Map<String,Object> data = new HashMap<>(2);
|
||||||
data.put("bookIndexCount",bookService.queryIndexCount(bookId));
|
data.put("bookIndexCount",bookService.queryIndexCount(bookId));
|
||||||
data.put("lastBookContent",bookService.queryBookContent(lastBookIndexId).getContent().substring(0,42));
|
String lastBookContent = bookService.queryBookContent(lastBookIndexId).getContent();
|
||||||
|
if(lastBookContent.length()>42){
|
||||||
|
lastBookContent=lastBookContent.substring(0,42);
|
||||||
|
}
|
||||||
|
data.put("lastBookContent",lastBookContent);
|
||||||
return ResultBean.ok(data);
|
return ResultBean.ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,4 +165,6 @@ public class BookController extends BaseController{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.java2nb.novel.entity.*;
|
|||||||
import com.java2nb.novel.service.AuthorService;
|
import com.java2nb.novel.service.AuthorService;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
import com.java2nb.novel.service.NewsService;
|
import com.java2nb.novel.service.NewsService;
|
||||||
|
import com.java2nb.novel.service.UserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -34,6 +35,8 @@ public class PageController extends BaseController{
|
|||||||
|
|
||||||
private final AuthorService authorService;
|
private final AuthorService authorService;
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("{url}.html")
|
@RequestMapping("{url}.html")
|
||||||
public String module(@PathVariable("url") String url) {
|
public String module(@PathVariable("url") String url) {
|
||||||
@ -121,7 +124,7 @@ public class PageController extends BaseController{
|
|||||||
* 内容页
|
* 内容页
|
||||||
* */
|
* */
|
||||||
@RequestMapping("/book/{bookId}/{bookIndexId}.html")
|
@RequestMapping("/book/{bookId}/{bookIndexId}.html")
|
||||||
public String indexList(@PathVariable("bookId") Long bookId,@PathVariable("bookIndexId") Long bookIndexId, Model model) {
|
public String indexList(@PathVariable("bookId") Long bookId,@PathVariable("bookIndexId") Long bookIndexId, HttpServletRequest request,Model model) {
|
||||||
//查询书籍
|
//查询书籍
|
||||||
Book book = bookService.queryBookDetail(bookId);
|
Book book = bookService.queryBookDetail(bookId);
|
||||||
model.addAttribute("book",book);
|
model.addAttribute("book",book);
|
||||||
@ -137,6 +140,23 @@ public class PageController extends BaseController{
|
|||||||
//查询内容
|
//查询内容
|
||||||
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
|
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
|
||||||
model.addAttribute("bookContent",bookContent);
|
model.addAttribute("bookContent",bookContent);
|
||||||
|
//判断该目录是否收费
|
||||||
|
if(bookIndex.getIsVip() == 1){
|
||||||
|
UserDetails user = getUserDetails(request);
|
||||||
|
if(user == null){
|
||||||
|
//未登录
|
||||||
|
return "redirect:/user/login.html?originUrl="+request.getRequestURI();
|
||||||
|
}
|
||||||
|
//收费,判断用户是否购买过该目录
|
||||||
|
boolean isBuy = userService.queryIsBuyBookIndex(user.getId(),bookIndexId);
|
||||||
|
if(!isBuy){
|
||||||
|
//没有购买过,需要购买
|
||||||
|
bookContent.setContent(null);
|
||||||
|
model.addAttribute("needBuy",true);
|
||||||
|
return "book/book_content";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.addAttribute("needBuy",false);
|
||||||
return ThreadLocalUtil.getTemplateDir()+"book/book_content";
|
return ThreadLocalUtil.getTemplateDir()+"book/book_content";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.java2nb.novel.core.cache.CacheService;
|
|||||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||||
import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
|
import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
|
||||||
import com.java2nb.novel.entity.User;
|
import com.java2nb.novel.entity.User;
|
||||||
|
import com.java2nb.novel.entity.UserBuyRecord;
|
||||||
import com.java2nb.novel.form.UserForm;
|
import com.java2nb.novel.form.UserForm;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
import com.java2nb.novel.service.UserService;
|
import com.java2nb.novel.service.UserService;
|
||||||
@ -264,6 +265,21 @@ public class UserController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买小说章节
|
||||||
|
* */
|
||||||
|
@PostMapping("buyBookIndex")
|
||||||
|
public ResultBean buyBookIndex(UserBuyRecord buyRecord, HttpServletRequest request) {
|
||||||
|
UserDetails userDetails = getUserDetails(request);
|
||||||
|
if (userDetails == null) {
|
||||||
|
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||||
|
}
|
||||||
|
userService.buyBookIndex(userDetails.getId(),buyRecord);
|
||||||
|
return ResultBean.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.java2nb.novel.service;
|
|||||||
|
|
||||||
|
|
||||||
import com.java2nb.novel.core.bean.UserDetails;
|
import com.java2nb.novel.core.bean.UserDetails;
|
||||||
|
import com.java2nb.novel.entity.UserBuyRecord;
|
||||||
import com.java2nb.novel.form.UserForm;
|
import com.java2nb.novel.form.UserForm;
|
||||||
import com.java2nb.novel.vo.BookReadHistoryVO;
|
import com.java2nb.novel.vo.BookReadHistoryVO;
|
||||||
import com.java2nb.novel.vo.BookShelfVO;
|
import com.java2nb.novel.vo.BookShelfVO;
|
||||||
@ -122,4 +123,19 @@ public interface UserService {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param amount 增加的余额 */
|
* @param amount 增加的余额 */
|
||||||
void addAmount(Long userId, int amount);
|
void addAmount(Long userId, int amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断用户是否购买过该小说章节
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param bookIndexId 章节目录ID
|
||||||
|
* @return true:购买过,false:没购买
|
||||||
|
* */
|
||||||
|
boolean queryIsBuyBookIndex(Long userId, Long bookIndexId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买小说章节
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param buyRecord 购买信息
|
||||||
|
* */
|
||||||
|
void buyBookIndex(Long userId, UserBuyRecord buyRecord);
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,12 @@ package com.java2nb.novel.service.impl;
|
|||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.java2nb.novel.core.bean.UserDetails;
|
import com.java2nb.novel.core.bean.UserDetails;
|
||||||
import com.java2nb.novel.core.utils.BeanUtil;
|
import com.java2nb.novel.core.utils.BeanUtil;
|
||||||
|
import com.java2nb.novel.entity.*;
|
||||||
|
import com.java2nb.novel.entity.User;
|
||||||
import com.java2nb.novel.form.UserForm;
|
import com.java2nb.novel.form.UserForm;
|
||||||
import com.java2nb.novel.service.UserService;
|
import com.java2nb.novel.service.UserService;
|
||||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||||
import com.java2nb.novel.core.exception.BusinessException;
|
import com.java2nb.novel.core.exception.BusinessException;
|
||||||
import com.java2nb.novel.entity.User;
|
|
||||||
import com.java2nb.novel.entity.UserBookshelf;
|
|
||||||
import com.java2nb.novel.entity.UserFeedback;
|
|
||||||
import com.java2nb.novel.entity.UserReadHistory;
|
|
||||||
import com.java2nb.novel.mapper.*;
|
import com.java2nb.novel.mapper.*;
|
||||||
import com.java2nb.novel.vo.BookReadHistoryVO;
|
import com.java2nb.novel.vo.BookReadHistoryVO;
|
||||||
import com.java2nb.novel.vo.BookShelfVO;
|
import com.java2nb.novel.vo.BookShelfVO;
|
||||||
@ -31,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.book;
|
||||||
|
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.id;
|
||||||
import static com.java2nb.novel.mapper.UserBookshelfDynamicSqlSupport.userBookshelf;
|
import static com.java2nb.novel.mapper.UserBookshelfDynamicSqlSupport.userBookshelf;
|
||||||
import static com.java2nb.novel.mapper.UserDynamicSqlSupport.*;
|
import static com.java2nb.novel.mapper.UserDynamicSqlSupport.*;
|
||||||
import static com.java2nb.novel.mapper.UserFeedbackDynamicSqlSupport.userFeedback;
|
import static com.java2nb.novel.mapper.UserFeedbackDynamicSqlSupport.userFeedback;
|
||||||
@ -54,6 +54,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
private final UserFeedbackMapper userFeedbackMapper;
|
private final UserFeedbackMapper userFeedbackMapper;
|
||||||
|
|
||||||
|
private final UserBuyRecordMapper userBuyRecordMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -266,5 +268,40 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean queryIsBuyBookIndex(Long userId, Long bookIndexId) {
|
||||||
|
|
||||||
|
return userBuyRecordMapper.count(c ->
|
||||||
|
c.where(UserBuyRecordDynamicSqlSupport.userId, isEqualTo(userId))
|
||||||
|
.and(UserBuyRecordDynamicSqlSupport.bookIndexId,isEqualTo(bookIndexId))) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void buyBookIndex(Long userId, UserBuyRecord buyRecord) {
|
||||||
|
//查询用户余额
|
||||||
|
long balance = userInfo(userId).getAccountBalance();
|
||||||
|
if(balance<10){
|
||||||
|
//余额不足
|
||||||
|
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)
|
||||||
|
.where(id,isEqualTo(userId))
|
||||||
|
.build()
|
||||||
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
onselect="document.selection.empty()">
|
onselect="document.selection.empty()">
|
||||||
|
|
||||||
<input type="hidden" id="bookId" th:value="${book.id}"/>
|
<input type="hidden" id="bookId" th:value="${book.id}"/>
|
||||||
|
<input type="hidden" id="bookName" th:value="${book.bookName}"/>
|
||||||
|
<input type="hidden" id="preIndexName" th:value="${bookIndex.indexName}"/>
|
||||||
|
|
||||||
<input type="hidden" id="preContentId" th:value="${bookIndex.id}"/>
|
<input type="hidden" id="preContentId" th:value="${bookIndex.id}"/>
|
||||||
|
|
||||||
<div th:replace="common/top :: top('10')">
|
<div th:replace="common/top :: top('10')">
|
||||||
@ -86,7 +89,7 @@
|
|||||||
作者:<a th:href="'javascript:searchByK(\''+${book.authorName}+'\')'" th:text="${book.authorName}"></a><span th:text="'字数:'+${bookIndex.wordCount}"></span><span th:text="'更新时间:'+${#dates.format(bookIndex.updateTime, 'yy/MM/dd HH:mm:ss')}"></span>
|
作者:<a th:href="'javascript:searchByK(\''+${book.authorName}+'\')'" th:text="${book.authorName}"></a><span th:text="'字数:'+${bookIndex.wordCount}"></span><span th:text="'更新时间:'+${#dates.format(bookIndex.updateTime, 'yy/MM/dd HH:mm:ss')}"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="txtwrap" th:if="${bookIndex.isVip == 1}">
|
<div class="txtwrap" th:if="${needBuy}">
|
||||||
<div id="showReading" class="readBox" style="font-size: 16px; font-family: microsoft yahei">
|
<div id="showReading" class="readBox" style="font-size: 16px; font-family: microsoft yahei">
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
@ -112,7 +115,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul class="order_list">
|
<ul class="order_list">
|
||||||
<li>价格:<span class="red">10屋币(1元=100屋币)</span></li>
|
<li>价格:<span class="red">10屋币(1元=100屋币)</span></li>
|
||||||
<li id="panelPay" class="btns"><a class="btn_red" href="/pay?cid=2052117" >购买</a></li>
|
<li id="panelPay" class="btns"><a class="btn_red" href="javascript:buyBookIndex()" >购买</a></li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<input type="hidden" name="HidCId" id="HidCId" value="2052117">
|
<input type="hidden" name="HidCId" id="HidCId" value="2052117">
|
||||||
@ -121,7 +124,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="txtwrap" th:if="${bookIndex.isVip != 1}">
|
<div class="txtwrap" th:if="${!needBuy}">
|
||||||
<div id="showReading" class="readBox" style="font-size: 16px; font-family: microsoft yahei" th:utext="${bookContent.content}">
|
<div id="showReading" class="readBox" style="font-size: 16px; font-family: microsoft yahei" th:utext="${bookContent.content}">
|
||||||
|
|
||||||
|
|
||||||
@ -328,6 +331,33 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buyBookIndex(){
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "/user/buyBookIndex",
|
||||||
|
data: {'bookId':$("#bookId").val(),"bookName":$("#bookName").val(),
|
||||||
|
"bookIndexId":$("#preContentId").val(),"bookIndexName":$("#preIndexName").val()},
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
if (data.code == 200) {
|
||||||
|
location.reload();
|
||||||
|
|
||||||
|
|
||||||
|
} else if(data.code == 1001){
|
||||||
|
//未登录
|
||||||
|
|
||||||
|
}else {
|
||||||
|
layer.alert(data.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
layer.alert('网络异常');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$.post("/book/addVisitCount", {"bookId": $("#bookId").val()}, function () {
|
$.post("/book/addVisitCount", {"bookId": $("#bookId").val()}, function () {
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
1198
sql/20200513.sql
Normal file
1198
sql/20200513.sql
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user