diff --git a/.gitignore b/.gitignore
index 64a69283..195ffc9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ buildNumber.properties
/.idea/
/src/test/
peanut_book.iml
+weChatConfig.properties
diff --git a/pom.xml b/pom.xml
index d9cb5821..e1c2f5d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,499 +1,499 @@
- 4.0.0
- com.peanut
- peanut_book
- 3.0.0
- jar
- peanut_book
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ com.peanut
+ peanut_book
+ 3.0.0
+ jar
+ peanut_book
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.6.6
-
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.6.6
+
-
- UTF-8
- UTF-8
- 1.8
- 3.3.1
- 8.0.28
- 4.0
- 11.2.0.3
- 1.1.13
- 2.3.0
- 2.6
- 1.2.2
- 2.5
- 1.10
- 1.10
- 1.9.0
- 0.7.0
- 0.0.9
- 7.2.23
- 3.10.2
- 4.4
- 2.7.0
- 2.9.9
- 2.8.5
- 1.2.79
- 5.7.22
- 1.18.4
+
+ UTF-8
+ UTF-8
+ 1.8
+ 3.3.1
+ 8.0.28
+ 4.0
+ 11.2.0.3
+ 1.1.13
+ 2.3.0
+ 2.6
+ 1.2.2
+ 2.5
+ 1.10
+ 1.10
+ 1.9.0
+ 0.7.0
+ 0.0.9
+ 7.2.23
+ 3.10.2
+ 4.4
+ 2.7.0
+ 2.9.9
+ 2.8.5
+ 1.2.79
+ 5.7.22
+ 1.18.4
0.5.10
- 1.9.4
+ 1.9.4
-
+
-
- /work/renren
- ${project.artifactId}-${project.version}.jar
- 192.168.1.10:22
- root
- 123456
-
+
+ /work/renren
+ ${project.artifactId}-${project.version}.jar
+ 192.168.1.10:22
+ root
+ 123456
+
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.aspectj
- aspectjweaver
- ${aspectjweaverversion}
-
-
- net.jodah
- expiringmap
- ${expiringmap.varsion}
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.boot
- spring-boot-starter-aop
-
-
- mars
- eh-sdk
- 1.0.0
-
-
- org.springframework
- spring-context-support
-
-
- org.springframework.boot
- spring-boot-starter-data-redis
-
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.aspectj
+ aspectjweaver
+ ${aspectjweaverversion}
+
+
+ net.jodah
+ expiringmap
+ ${expiringmap.varsion}
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+ mars
+ eh-sdk
+ 1.0.0
+
+
+ org.springframework
+ spring-context-support
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
-
- cn.songxinqiang
- com.baidu.ueditor
- 1.1.2-offical
-
+
+ cn.songxinqiang
+ com.baidu.ueditor
+ 1.1.2-offical
+
-
- org.springframework.boot
- spring-boot-starter-validation
-
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
-
-
-
-
-
-
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatisplus.version}
-
-
- com.baomidou
- mybatis-plus-generator
-
-
-
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybatisplus.version}
+
+
+ com.baomidou
+ mybatis-plus-generator
+
+
+
-
- mysql
- mysql-connector-java
- ${mysql.version}
-
+
+ mysql
+ mysql-connector-java
+ ${mysql.version}
+
-
- org.redisson
- redisson
- 3.12.5
-
+
+ org.redisson
+ redisson
+ 3.12.5
+
-
-
- com.aliyun
- dysmsapi20170525
- 2.0.18
-
+
+
+ com.aliyun
+ dysmsapi20170525
+ 2.0.18
+
-
-
- org.springframework.boot
- spring-boot-starter-amqp
-
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
-
-
- e-iceblue
- spire.doc
- 10.9.8
-
+
+
+ e-iceblue
+ spire.doc
+ 10.9.8
+
-
- org.apache.poi
- poi
- 3.17
-
-
- org.apache.poi
- poi-ooxml
- 3.17
-
-
- org.apache.poi
- poi-scratchpad
- 3.17
-
-
- org.apache.poi
- ooxml-schemas
- 1.1
-
-
- org.apache.poi
- poi-ooxml-schemas
- 3.17
-
+
+ org.apache.poi
+ poi
+ 3.17
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.17
+
+
+ org.apache.poi
+ poi-scratchpad
+ 3.17
+
+
+ org.apache.poi
+ ooxml-schemas
+ 1.1
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 3.17
+
-
- com.aspose.words
- aspose-words
- aspose-words-22.10-jdk16
- system
- ${project.basedir}/src/main/resources/lib/aspose-words-22.10-jdk16.jar
-
-
- org.jsoup
- jsoup
- 1.14.3
-
+
+ com.aspose.words
+ aspose-words
+ aspose-words-22.10-jdk16
+ system
+ ${project.basedir}/src/main/resources/lib/aspose-words-22.10-jdk16.jar
+
+
+ org.jsoup
+ jsoup
+ 1.14.3
+
-
-
- com.alipay.sdk
- alipay-sdk-java
- 4.15.20.ALL
-
+
+
+ com.alipay.sdk
+ alipay-sdk-java
+ 4.15.20.ALL
+
-
-
- com.oracle
- ojdbc6
- ${oracle.version}
-
-
-
- com.microsoft.sqlserver
- sqljdbc4
- ${mssql.version}
-
-
-
- org.postgresql
- postgresql
-
+
+
+ com.oracle
+ ojdbc6
+ ${oracle.version}
+
+
+
+ com.microsoft.sqlserver
+ sqljdbc4
+ ${mssql.version}
+
+
+
+ org.postgresql
+ postgresql
+
-
+
-
- org.apache.httpcomponents
- httpclient
-
+
+ org.apache.httpcomponents
+ httpclient
+
-
- com.alibaba
- druid-spring-boot-starter
- ${druid.version}
-
-
- org.quartz-scheduler
- quartz
- ${quartz.version}
-
-
- com.mchange
- c3p0
-
-
-
-
- commons-lang
- commons-lang
- ${commons.lang.version}
-
-
- commons-fileupload
- commons-fileupload
- ${commons.fileupload.version}
-
-
- commons-io
- commons-io
- ${commons.io.version}
-
-
- commons-codec
- commons-codec
- ${commons.codec.version}
-
-
- commons-configuration
- commons-configuration
- ${commons.configuration.version}
-
-
- org.apache.shiro
- shiro-core
- ${shiro.version}
-
-
- org.apache.shiro
- shiro-spring
- ${shiro.version}
-
-
- io.jsonwebtoken
- jjwt
- ${jwt.version}
-
-
- com.github.axet
- kaptcha
- ${kaptcha.version}
-
-
- io.springfox
- springfox-swagger2
- ${swagger.version}
-
-
- io.springfox
- springfox-swagger-ui
- ${swagger.version}
-
-
- com.qiniu
- qiniu-java-sdk
- ${qiniu.version}
-
-
- com.aliyun.oss
- aliyun-sdk-oss
- ${aliyun.oss.version}
-
-
- com.qcloud
- cos_api
- ${qcloud.cos.version}
-
-
- org.slf4j
- slf4j-log4j12
-
-
-
-
- joda-time
- joda-time
- ${joda.time.version}
-
+
+ com.alibaba
+ druid-spring-boot-starter
+ ${druid.version}
+
+
+ org.quartz-scheduler
+ quartz
+ ${quartz.version}
+
+
+ com.mchange
+ c3p0
+
+
+
+
+ commons-lang
+ commons-lang
+ ${commons.lang.version}
+
+
+ commons-fileupload
+ commons-fileupload
+ ${commons.fileupload.version}
+
+
+ commons-io
+ commons-io
+ ${commons.io.version}
+
+
+ commons-codec
+ commons-codec
+ ${commons.codec.version}
+
+
+ commons-configuration
+ commons-configuration
+ ${commons.configuration.version}
+
+
+ org.apache.shiro
+ shiro-core
+ ${shiro.version}
+
+
+ org.apache.shiro
+ shiro-spring
+ ${shiro.version}
+
+
+ io.jsonwebtoken
+ jjwt
+ ${jwt.version}
+
+
+ com.github.axet
+ kaptcha
+ ${kaptcha.version}
+
+
+ io.springfox
+ springfox-swagger2
+ ${swagger.version}
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${swagger.version}
+
+
+ com.qiniu
+ qiniu-java-sdk
+ ${qiniu.version}
+
+
+ com.aliyun.oss
+ aliyun-sdk-oss
+ ${aliyun.oss.version}
+
+
+ com.qcloud
+ cos_api
+ ${qcloud.cos.version}
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+
+
+ joda-time
+ joda-time
+ ${joda.time.version}
+
-
- com.google.code.gson
- gson
- ${gson.version}
-
-
- com.alibaba
- fastjson
- ${fastjson.version}
-
-
- cn.hutool
- hutool-all
- ${hutool.version}
-
-
- org.projectlombok
- lombok
- ${lombok.version}
-
+
+ com.google.code.gson
+ gson
+ ${gson.version}
+
+
+ com.alibaba
+ fastjson
+ ${fastjson.version}
+
+
+ cn.hutool
+ hutool-all
+ ${hutool.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
org.springframework
spring-test
5.3.19
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
-
- com.github.wechatpay-apiv3
- wechatpay-apache-httpclient
- 0.4.9
-
-
- com.twelvemonkeys.common
- common-lang
- 3.5
-
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ com.github.wechatpay-apiv3
+ wechatpay-apache-httpclient
+ 0.4.9
+
+
+ com.twelvemonkeys.common
+ common-lang
+ 3.5
+
-
- com.github.yulichang
- mybatis-plus-join-boot-starter
- 1.4.6
-
-
+
+ com.github.yulichang
+ mybatis-plus-join-boot-starter
+ 1.4.6
+
+
-
- ${project.artifactId}
-
-
- org.apache.maven.wagon
- wagon-ssh
- 2.8
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- true
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- true
-
-
-
- org.codehaus.mojo
- wagon-maven-plugin
- 1.0
-
- target/${pack-name}
-
-
-
- kill -9 `ps -ef |grep ${project.artifactId}.jar|grep -v "grep" |awk '{print $2}'`
-
- ${service-path}/renren.log 2>&1 & ]]>
-
-
-
-
- true
-
-
+
+ ${project.artifactId}
+
+
+ org.apache.maven.wagon
+ wagon-ssh
+ 2.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
+
+ org.codehaus.mojo
+ wagon-maven-plugin
+ 1.0
+
+ target/${pack-name}
+
+
+
+ kill -9 `ps -ef |grep ${project.artifactId}.jar|grep -v "grep" |awk '{print $2}'`
+
+ ${service-path}/renren.log 2>&1 & ]]>
+
+
+
+
+ true
+
+
-
- com.spotify
- docker-maven-plugin
- 0.4.14
-
-
-
-
-
-
-
-
-
- renren/fast
- ${project.basedir}
-
-
- /
- ${project.build.directory}
- ${project.build.finalName}.jar
-
-
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
-
-
- java
-
-
-
-
- test
-
-
-
-
+
+ com.spotify
+ docker-maven-plugin
+ 0.4.14
+
+
+
+
+
+
+
+
+
+ renren/fast
+ ${project.basedir}
+
+
+ /
+ ${project.build.directory}
+ ${project.build.finalName}.jar
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.6.0
+
+
+
+ java
+
+
+
+
+ test
+
+
+
+
-
-
- public
- aliyun nexus
- https://maven.aliyun.com/repository/public/
-
- true
-
-
-
- com.e-iceblue
- http://repo.e-iceblue.cn/repository/maven-public/
-
-
-
-
- public
- aliyun nexus
- https://maven.aliyun.com/repository/public/
-
- true
-
-
- false
-
-
-
+
+
+ public
+ aliyun nexus
+ https://maven.aliyun.com/repository/public/
+
+ true
+
+
+
+ com.e-iceblue
+ https://repo.e-iceblue.cn/repository/maven-public/
+
+
+
+
+ public
+ aliyun nexus
+ https://maven.aliyun.com/repository/public/
+
+ true
+
+
+ false
+
+
+
diff --git a/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java b/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java
index 805f1983..298bf77f 100644
--- a/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java
+++ b/src/main/java/com/peanut/modules/book/dao/ShopProudictBookDao.java
@@ -9,6 +9,5 @@ import java.util.List;
@Mapper
public interface ShopProudictBookDao extends BaseMapper {
-
-
+ List getOrderBookId(String orderSn);
}
diff --git a/src/main/java/com/peanut/modules/book/dao/UserEbookBuyDao.java b/src/main/java/com/peanut/modules/book/dao/UserEbookBuyDao.java
index 2f5e0f47..123577b4 100644
--- a/src/main/java/com/peanut/modules/book/dao/UserEbookBuyDao.java
+++ b/src/main/java/com/peanut/modules/book/dao/UserEbookBuyDao.java
@@ -5,14 +5,17 @@ import com.peanut.modules.book.entity.UserEbookBuyEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
+import java.util.List;
+
/**
* 用户购买书籍表
- *
+ *
* @author yl
* @email yl328572838@163.com
* @date 2022-10-18 16:28:20
*/
@Mapper
public interface UserEbookBuyDao extends MPJBaseMapper {
-
+
+ List getUserBookId(Integer userId);
}
diff --git a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java b/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java
index 7c5d4d25..fde137a2 100644
--- a/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java
+++ b/src/main/java/com/peanut/modules/book/service/ShopProudictBookService.java
@@ -19,4 +19,6 @@ public interface ShopProudictBookService extends IService getOrderBookId(String orderSn);
+
}
diff --git a/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java b/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java
index 4ef1356b..4793f84e 100644
--- a/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java
+++ b/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.UserEbookBuyEntity;
+import java.util.List;
import java.util.Map;
/**
@@ -19,6 +20,8 @@ public interface UserEbookBuyService extends IService {
PageUtils queryPages(Map params);
+ List getUserBookId(Integer userId);
+
}
diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookServiceImpl.java
index dc5b86be..4ad6acc9 100644
--- a/src/main/java/com/peanut/modules/book/service/impl/BookServiceImpl.java
+++ b/src/main/java/com/peanut/modules/book/service/impl/BookServiceImpl.java
@@ -4,37 +4,36 @@ import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.OSSObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Joiner;
-import com.peanut.common.utils.*;
+import com.peanut.common.utils.ConstantPropertiesUtils;
+import com.peanut.common.utils.FileDownloadUtil;
+import com.peanut.common.utils.PageUtils;
+import com.peanut.common.utils.Query;
+import com.peanut.modules.book.dao.BookDao;
import com.peanut.modules.book.entity.*;
-import com.peanut.modules.book.entity.SysDictDataEntity;
-import com.peanut.modules.book.service.*;
-import com.peanut.modules.book.vo.BookIndexVo;
+import com.peanut.modules.book.service.BookChapterService;
+import com.peanut.modules.book.service.BookForumArticlesService;
+import com.peanut.modules.book.service.BookService;
+import com.peanut.modules.book.service.PublisherService;
import com.peanut.modules.sys.service.SysDictDataService;
import com.spire.doc.Document;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import org.apache.commons.lang.StringUtils;
-import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
import java.io.BufferedReader;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.net.URLDecoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
-import com.peanut.modules.book.dao.BookDao;
-import org.springframework.util.CollectionUtils;
-
@Service("bookService")
public class BookServiceImpl extends ServiceImpl implements BookService {
diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java
index 35701f33..4e887746 100644
--- a/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java
+++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProudictBookServiceImpl.java
@@ -1,4 +1,5 @@
package com.peanut.modules.book.service.impl;
+
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -15,17 +16,20 @@ import com.peanut.modules.book.service.ShopProudictBookService;
import com.peanut.modules.book.vo.ProudictBookqueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("shopProudictBookService")
-public class ShopProudictBookServiceImpl extends ServiceImpl implements ShopProudictBookService {
+public class ShopProudictBookServiceImpl extends ServiceImpl implements ShopProudictBookService {
@Autowired
private ShopProductService shopProductService;
@Autowired
private BookService bookService;
+ @Autowired
+ private ShopProudictBookDao shopProudictBookDao;
@Override
public PageUtils queryPage(Map params) {
@@ -42,7 +46,7 @@ public class ShopProudictBookServiceImpl extends ServiceImpl page = this.page(
new Query().getPage(params),
- new QueryWrapper().eq("proudict_id",proudictId)
+ new QueryWrapper().eq("proudict_id", proudictId)
);
List records = page.getRecords();
return new PageUtils(page);
@@ -66,7 +70,7 @@ public class ShopProudictBookServiceImpl extends ServiceImpl getBookidsByProductId(Integer productId) {
- List spbs = this.list(new QueryWrapper().eq("del_flag",0).eq("proudict_id",productId));
+ List spbs = this.list(new QueryWrapper().eq("del_flag", 0).eq("proudict_id", productId));
List ids = new ArrayList();
- for (ShopProudictBookEntity s : spbs){
+ for (ShopProudictBookEntity s : spbs) {
ids.add(s.getBookId());
}
return ids;
@@ -86,21 +90,21 @@ public class ShopProudictBookServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ShopProudictBookEntity::getBookId,bookId);
- wrapper.eq(ShopProudictBookEntity::getDelFlag,0);
+ wrapper.eq(ShopProudictBookEntity::getBookId, bookId);
+ wrapper.eq(ShopProudictBookEntity::getDelFlag, 0);
wrapper.groupBy(ShopProudictBookEntity::getProudictId);
List shopProudictBookEntities = this.getBaseMapper().selectList(wrapper);
List ids = new ArrayList();
- for (ShopProudictBookEntity s : shopProudictBookEntities){
+ for (ShopProudictBookEntity s : shopProudictBookEntities) {
ids.add(s.getProudictId());
}
- if(ids.size()==0){
+ if (ids.size() == 0) {
return null;
}
LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>();
- wrapper1.eq(ShopProductEntity::getDelFlag,0);
- wrapper1.in(ShopProductEntity::getProductId,ids);
+ wrapper1.eq(ShopProductEntity::getDelFlag, 0);
+ wrapper1.in(ShopProductEntity::getProductId, ids);
wrapper1.orderByAsc(ShopProductEntity::getPrice);
wrapper1.last("limit 1");
List shopProductEntities = shopProductService.getBaseMapper().selectList(wrapper1);
@@ -108,5 +112,10 @@ public class ShopProudictBookServiceImpl extends ServiceImpl getOrderBookId(String orderSn) {
+ return shopProudictBookDao.getOrderBookId(orderSn);
+ }
+
}
diff --git a/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java
index 991322d1..aac39f70 100644
--- a/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java
+++ b/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java
@@ -1,30 +1,32 @@
package com.peanut.modules.book.service.impl;
-import com.peanut.modules.book.entity.BuyOrderEntity;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
-
import com.peanut.modules.book.dao.UserEbookBuyDao;
import com.peanut.modules.book.entity.UserEbookBuyEntity;
import com.peanut.modules.book.service.UserEbookBuyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
@Service("userEbookBuyService")
public class UserEbookBuyServiceImpl extends ServiceImpl implements UserEbookBuyService {
+ @Autowired
+ private UserEbookBuyDao userEbookBuyDao;
+
@Override
public PageUtils queryPage(Map params) {
String userId = (String) params.get("userId");
IPage page = this.page(
new Query().getPage(params),
- new QueryWrapper().eq("user_id",userId)
+ new QueryWrapper().eq("user_id", userId)
);
return new PageUtils(page);
@@ -36,7 +38,7 @@ public class UserEbookBuyServiceImpl extends ServiceImpl page = this.page(
new Query().getPage(params),
new QueryWrapper()
- .eq("user_id",userid)
+ .eq("user_id", userid)
);
@@ -44,24 +46,10 @@ public class UserEbookBuyServiceImpl extends ServiceImpl getUserBookId(Integer userId) {
+ return userEbookBuyDao.getUserBookId(userId);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java b/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java
index d427a04d..d09c09df 100644
--- a/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java
+++ b/src/main/java/com/peanut/modules/pay/weChatPay/controller/WeChatPayController.java
@@ -1,4 +1,5 @@
package com.peanut.modules.pay.weChatPay.controller;
+
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
@@ -6,10 +7,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
-import com.peanut.modules.pay.weChatPay.dto.WechatDto;
import com.peanut.modules.pay.weChatPay.config.WechatPayConfig;
+import com.peanut.modules.pay.weChatPay.dto.WechatDto;
import com.peanut.modules.pay.weChatPay.util.HttpUtils;
-import com.peanut.modules.book.entity.BookBuyConfigEntity;
import com.peanut.modules.pay.weChatPay.util.WechatPayValidator;
import com.peanut.modules.pay.weChatPay.util.WxPayUtil;
import lombok.extern.slf4j.Slf4j;
@@ -24,10 +24,9 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
-import javax.annotation.Resource;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.soap.Text;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
@@ -37,14 +36,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
import java.util.*;
-import java.util.concurrent.locks.ReentrantLock;
@Slf4j
@RestController
@@ -53,9 +45,11 @@ import java.util.concurrent.locks.ReentrantLock;
@Configuration
public class WeChatPayController {
- @Autowired private MyUserService userService;
+ @Autowired
+ private MyUserService userService;
- @Autowired private BuyOrderService buyOrderService;
+ @Autowired
+ private BuyOrderService buyOrderService;
@Autowired
@Lazy
@@ -74,17 +68,18 @@ public class WeChatPayController {
private TransactionDetailsService transactionDetailsService;
@Autowired
- private BuyOrderDetailService buyOrderDetailService;
+ private ShopProudictBookService shopProudictBookService;
@Autowired
- private CloseableHttpClient wxPayNoSignClient; //无需应答签名
+ private UserEbookBuyService userEbookBuyService;
+
+ //无需应答签名
@Autowired
private CloseableHttpClient wxPayClient;
@Autowired
private WxPayUtil wxPayUtil;
- private final ReentrantLock lock = new ReentrantLock();
// 由微信生成的应用ID,全局唯一。
- public static final String appId= "wx47134a8f15083734";
+ public static final String appId = "wx47134a8f15083734";
// 直连商户的商户号,由微信支付生成并下发。
public static final String mchId = "1612860909";
// 商户证书序列号 7B5676E3CDF56680D0414A009CE501C844DBE2D6 679AECB2F7AC4183033F713828892BA640E4EEE3
@@ -102,78 +97,76 @@ public class WeChatPayController {
@RequestMapping(value = "/placeAnOrder/app")
@Transactional(rollbackFor = Exception.class)
- public R pay(@RequestBody WechatDto dto ) throws Exception{
+ public R pay(@RequestBody WechatDto dto) throws Exception {
log.info("微信生成订单");
List one = this.buyOrderService.getBaseMapper().selectList(new QueryWrapper().eq("order_sn", dto.getOrderSn()));
BuyOrderEntity order = one.get(0);
-// 获取订单
- Map paramMap = new HashMap<>();
- paramMap.put("appid",appId);
- paramMap.put("mchid",mchId);
- paramMap.put("description","微信充值");
-// 订单编号
- paramMap.put("out_trade_no",order.getOrderSn());
-// paramMap.put("attach",""); //自定义数据 支付完成后才能显示 在查询API和支付通知中原样返回,可作为自定义参数使用
- paramMap.put("notify_url",wechatPayConfig.getNotifyUrl());
+ // 获取订单
+ Map paramMap = new HashMap<>();
+ paramMap.put("appid", appId);
+ paramMap.put("mchid", mchId);
+ paramMap.put("description", "微信充值");
+ // 订单编号
+ paramMap.put("out_trade_no", order.getOrderSn());
+ // paramMap.put("attach",""); //自定义数据 支付完成后才能显示 在查询API和支付通知中原样返回,可作为自定义参数使用
+ paramMap.put("notify_url", wechatPayConfig.getNotifyUrl());
-// paramMap.put("time_expire",afterString);
-// 实收金额0.38乘100=38
- BigDecimal realsmoney= order.getRealMoney();
- BigDecimal hand=new BigDecimal("100");
- realsmoney =realsmoney.multiply(hand) ;
- Map amountMap = new HashMap<>();
- amountMap.put("total",realsmoney);
- amountMap.put("currency","CNY");
+ // paramMap.put("time_expire",afterString);
+ // 实收金额0.38乘100=38
+ BigDecimal realsmoney = order.getRealMoney();
+ BigDecimal hand = new BigDecimal("100");
+ realsmoney = realsmoney.multiply(hand);
+ Map amountMap = new HashMap<>();
+ amountMap.put("total", realsmoney);
+ amountMap.put("currency", "CNY");
- BigDecimal money= order.getRealMoney();
- BigDecimal han=new BigDecimal("100");
- realsmoney =realsmoney.multiply(han) ;
- Map amount = new HashMap<>();
- amount.put("total",realsmoney);
- amount.put("currency","CNY");
+ BigDecimal money = order.getRealMoney();
+ BigDecimal han = new BigDecimal("100");
+ realsmoney = realsmoney.multiply(han);
+ Map amount = new HashMap<>();
+ amount.put("total", realsmoney);
+ amount.put("currency", "CNY");
- if (dto.getTotalAmount()!=order.getRealMoney()) {
+ if (dto.getTotalAmount() != order.getRealMoney()) {
}
-
-
- paramMap.put("amount",amountMap);
+ paramMap.put("amount", amountMap);
JSONObject json = JSONObject.parseObject(JSON.toJSONString(paramMap));
- log.info("请求参数"+paramMap);
+ log.info("请求参数" + paramMap);
com.alibaba.fastjson.JSONObject jsonObject1 = wxPayUtil.doPostWexinV3("https://api.mch.weixin.qq.com/v3/pay/transactions/app", json.toJSONString());
String prepayid = jsonObject1.getString("prepay_id");
-// 传入参数 payUrl 发送post请求
+ // 传入参数 payUrl 发送post请求
HttpPost httpPost = new HttpPost(payUrl);
-// 将json数据转换成字符串
- StringEntity entity = new StringEntity(json.toString(),"utf-8");
-// 设置该请求的Content-Type为application/json 都是json格式
+ // 将json数据转换成字符串
+ StringEntity entity = new StringEntity(json.toString(), "utf-8");
+ // 设置该请求的Content-Type为application/json 都是json格式
entity.setContentType("application/json");
-// 将实体对象设置到HttpPost表示要传递该数据到服务器端。
+ // 将实体对象设置到HttpPost表示要传递该数据到服务器端。
httpPost.setEntity(entity);
-// 设置请求头部的Accept属性为"application/json"表示客户端希望接收的为json。
+ // 设置请求头部的Accept属性为"application/json"表示客户端希望接收的为json。
httpPost.setHeader("Accept", "application/json");
CloseableHttpResponse response = wxPayClient.execute(httpPost);
-// 向微信支付平台发送请求,处理响应结果,并将订单信息保存到数据库中。
- String bodyAsString = EntityUtils.toString(response.getEntity());//响应体
-// 时间戳
- Long timestamp = System.currentTimeMillis()/1000;
-// 随机串
- String nonceStr = UUID.randomUUID().toString().replace("-","");
+ // 向微信支付平台发送请求,处理响应结果,并将订单信息保存到数据库中。
+ String bodyAsString = EntityUtils.toString(response.getEntity());//响应体
+ // 时间戳
+ Long timestamp = System.currentTimeMillis() / 1000;
+ // 随机串
+ String nonceStr = UUID.randomUUID().toString().replace("-", "");
- String sign = wxPayUtil.getSign(WxPayUtil.appId,timestamp,nonceStr,prepayid);
- log.info("签名:"+sign);
+ String sign = wxPayUtil.getSign(WxPayUtil.appId, timestamp, nonceStr, prepayid);
+ log.info("签名:" + sign);
Map Map = new HashMap();
- Map.put("prepayid",prepayid);
- Map.put("timestamp",timestamp+"");
- Map.put("noncestr",nonceStr);
- Map.put("sign",sign);
- Map.put("appid",appId);
- Map.put("package","Sign=WXPay");
- Map.put("extData","sign");
- Map.put("partnerid",mchId);
+ Map.put("prepayid", prepayid);
+ Map.put("timestamp", timestamp + "");
+ Map.put("noncestr", nonceStr);
+ Map.put("sign", sign);
+ Map.put("appid", appId);
+ Map.put("package", "Sign=WXPay");
+ Map.put("extData", "sign");
+ Map.put("partnerid", mchId);
try {
int statusCode = response.getStatusLine().getStatusCode(); //响应状态码
if (statusCode == 200) { //处理成功
@@ -198,13 +191,14 @@ public class WeChatPayController {
System.out.println("下单失败 = " + statusCode + ",返回结果 = " + bodyAsString);
throw new IOException("request failed");
}
- }finally {
+ } finally {
response.close();
}
// 返回url和订单号
- return R.ok().put("paramMap" ,paramMap).put("Map",Map);
+ return R.ok().put("paramMap", paramMap).put("Map", Map);
}
+
/**
* 获取私钥。
*
@@ -227,8 +221,8 @@ public class WeChatPayController {
throw new RuntimeException("无效的密钥格式");
}
}
+
/**
- *
* 微信支付回调
*
* @param request
@@ -236,121 +230,119 @@ public class WeChatPayController {
* @return
*/
@PostMapping("/payNotify")
+ @Transactional
public R payNotify(HttpServletRequest request, HttpServletResponse response) {
- log.info("##############################微信支付回调#######################");
-
-
-// 处理通知参数
- Map bodyMap = getNotifyBody(request);
- if(bodyMap==null){
+ log.info("微信支付回调");
+ // 处理通知参数
+ Map bodyMap = getNotifyBody(request);
+ if (bodyMap == null) {
return null;
}
- if(lock.tryLock()) {
- try {
-// 解密resource中的通知数据
- String resource = bodyMap.get("resource").toString();
- Map resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(),1);
- String orderNo = resourceMap.get("out_trade_no").toString();
- String transactionId = resourceMap.get("transaction_id").toString();
-// 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
- BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper().eq("order_sn", orderNo));
- PayWechatOrderEntity wechatEntity = new PayWechatOrderEntity();
- if(!ObjectUtils.isEmpty(order)){
- wechatEntity = this.payWechatOrderService.getOne(new QueryWrapper().eq("order_sn", order.getOrderSn()));
- }else{
- log.error("无效订单!");
- return R.error(500,"无效订单!");
- }
-// 1.根据订单id获取订单信息
- if("order".equals(order.getOrderType())){
- BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", wechatEntity.getOrderSn()));
- BigDecimal realMoney = orderEntity.getRealMoney();
-
- //更新 订单 记录
- // 1. 根据订单 ID 查询订单详情
- // 2. 由订单详情获取商品信息
- // 3. 查询商品信息得到 book_id
- // 4. 查询用户的所有 book_id
- // 5. 取差集
- /*
- list1.removeAll(list2)
- */
- // 6. 为用户添加书籍
-
- if (wechatEntity.getTotalAmount().compareTo(realMoney) == 0) {
- buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"0");
- }
- }
- if("point".equals(order.getOrderType())){
- PayWechatOrderEntity buy_order_id = payWechatOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", order.getOrderSn()));
- Integer buyorder= buy_order_id.getBuyOrderId();
- BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(buyorder);
- String realMoney =bookBuyConfigEntity.getRealMoney();
- Integer money = Integer.valueOf(realMoney);
- userService.rechargeHSPoint(Integer.valueOf(order.getUserId()),money);
- TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
- transactionDetailsEntity.setUserId(order.getUserId());
- transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
- transactionDetailsEntity.setOrderType("充值");
- transactionDetailsEntity.setRelationId(buy_order_id.getId().intValue());
- transactionDetailsEntity.setRemark("充值");
-
- MyUserEntity user = userService.getById(Integer.valueOf(order.getUserId()));
- BigDecimal peanutCoin = user.getPeanutCoin();
- transactionDetailsEntity.setUserBalance(peanutCoin);
- transactionDetailsEntity.setUserName(user.getNickname());
- transactionDetailsEntity.setTel(user.getTel());
- transactionDetailsService.save(transactionDetailsEntity);
-// 插入 花生币 充值记录
- PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
- payPaymentOrderEntity.setUserId(Integer.valueOf(order.getUserId()));
- payPaymentOrderEntity.setOrderId(String.valueOf(buy_order_id.getId()));
- payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
- payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
- payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
- payPaymentOrderEntity.setRechargeStatus("success");
- payPaymentOrderEntity.setSuccessTime(new Date());
- payPaymentOrderEntity.setUserName(user.getNickname());
- payPaymentOrderEntity.setTel(user.getTel());
- payPaymentOrderService.save(payPaymentOrderEntity);
- buyOrderService.updateOrderStatus(Integer.valueOf(order.getUserId()),order.getOrderSn(),"2");
- }
-
- } finally {
-// 要主动释放锁
- lock.unlock();
+ // 解密resource中的通知数据
+ String resource = bodyMap.get("resource").toString();
+ Map resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(), 1);
+ String orderNo = resourceMap.get("out_trade_no").toString();
+ // 根据订单号,做幂等处理,并且在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱
+ BuyOrderEntity order = this.buyOrderService.getOne(new QueryWrapper().eq("order_sn", orderNo));
+ PayWechatOrderEntity wechatEntity;
+ if (!ObjectUtils.isEmpty(order)) {
+ wechatEntity = this.payWechatOrderService.getOne(new QueryWrapper().eq("order_sn", order.getOrderSn()));
+ } else {
+ log.error("无效订单!");
+ return R.error(500, "无效订单!");
+ }
+ // 1.根据订单id获取订单信息
+ if ("order".equals(order.getOrderType())) {
+ BuyOrderEntity orderEntity = buyOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", wechatEntity.getOrderSn()));
+ BigDecimal realMoney = orderEntity.getRealMoney();
+ System.out.println("=========== 获取到 orderSn==================" + order.getOrderSn());
+ // 查询订单的所有 book_id
+ List orderBookIdList = shopProudictBookService.getOrderBookId(order.getOrderSn());
+ System.out.println("=========== 获取到 orderBookIdList==========" + orderBookIdList);
+ // 去重
+ Set set = new HashSet<>(orderBookIdList);
+ orderBookIdList.clear();
+ orderBookIdList.addAll(set);
+ // 查询用户的所有 book_id
+ System.out.println("==============去重后orderBookIdList=========" + orderBookIdList);
+ List userBookIdList = userEbookBuyService.getUserBookId(order.getUserId());
+ System.out.println("==============userBookIdList===============" + userBookIdList);
+ // 取差集
+ orderBookIdList.removeAll(userBookIdList);
+ System.out.println("============== 差集========================" + orderBookIdList);
+ // 为用户添加书籍
+ List userEbookBuyEntities = new ArrayList<>();
+ for (Integer bookId : orderBookIdList) {
+ UserEbookBuyEntity entity = new UserEbookBuyEntity();
+ entity.setUserId(order.getUserId());
+ entity.setBookId(bookId);
+ userEbookBuyEntities.add(entity);
+ }
+ System.out.println("============userEbookBuyEntities===========" + userEbookBuyEntities);
+ boolean b = userEbookBuyService.saveBatch(userEbookBuyEntities);
+ System.out.println("============result========================" + b);
+ if (wechatEntity.getTotalAmount().compareTo(realMoney) == 0) {
+ buyOrderService.updateOrderStatus(order.getUserId(), order.getOrderSn(), "0");
}
}
+ if ("point".equals(order.getOrderType())) {
+ PayWechatOrderEntity buy_order_id = payWechatOrderService.getBaseMapper().selectOne(new QueryWrapper().eq("order_sn", order.getOrderSn()));
+ Integer buyorder = buy_order_id.getBuyOrderId();
+ BookBuyConfigEntity bookBuyConfigEntity = bookBuyConfigService.getById(buyorder);
+ String realMoney = bookBuyConfigEntity.getRealMoney();
+ int money = Integer.parseInt(realMoney);
+ userService.rechargeHSPoint(order.getUserId(), money);
+ TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
+ transactionDetailsEntity.setUserId(order.getUserId());
+ transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
+ transactionDetailsEntity.setOrderType("充值");
+ transactionDetailsEntity.setRelationId(buy_order_id.getId().intValue());
+ transactionDetailsEntity.setRemark("充值");
-// 成功应答
+ MyUserEntity user = userService.getById(order.getUserId());
+ BigDecimal peanutCoin = user.getPeanutCoin();
+ transactionDetailsEntity.setUserBalance(peanutCoin);
+ transactionDetailsEntity.setUserName(user.getNickname());
+ transactionDetailsEntity.setTel(user.getTel());
+ transactionDetailsService.save(transactionDetailsEntity);
+ // 插入 花生币 充值记录
+ PayPaymentOrderEntity payPaymentOrderEntity = new PayPaymentOrderEntity();
+ payPaymentOrderEntity.setUserId(order.getUserId());
+ payPaymentOrderEntity.setOrderId(String.valueOf(buy_order_id.getId()));
+ payPaymentOrderEntity.setRealAmount(new BigDecimal(bookBuyConfigEntity.getRealMoney()));
+ payPaymentOrderEntity.setRechargeAmount(new BigDecimal(bookBuyConfigEntity.getMoney()));
+ payPaymentOrderEntity.setRechargeChannel(bookBuyConfigEntity.getQudao());
+ payPaymentOrderEntity.setRechargeStatus("success");
+ payPaymentOrderEntity.setSuccessTime(new Date());
+ payPaymentOrderEntity.setUserName(user.getNickname());
+ payPaymentOrderEntity.setTel(user.getTel());
+ payPaymentOrderService.save(payPaymentOrderEntity);
+ buyOrderService.updateOrderStatus(order.getUserId(), order.getOrderSn(), "2");
+ }
+ // 成功应答
return R.ok();
}
-
-
- private Map getNotifyBody(HttpServletRequest request ){
-// 处理通知参数
+ private Map getNotifyBody(HttpServletRequest request) {
+ // 处理通知参数
String body = HttpUtils.readData(request);
- log.info("zhifu回调参数:{}",body);
-
-// 转换为Map
- Map bodyMap = JSONObject.parseObject(body, new TypeReference