海外读书

This commit is contained in:
wuchunlei
2024-11-26 15:13:38 +08:00
parent 3fc7a80580
commit a0c42ecea0
37 changed files with 1234 additions and 9 deletions

View File

@@ -68,6 +68,7 @@ public class ShiroConfig {
filterMap.put("/pay/aliPay/notify","anon"); // 支付宝回调接口
filterMap.put("/pay/payNotify","anon"); // 微信回调接口
filterMap.put("/pay/refundNotify","anon"); // 微信退款回调接口
filterMap.put("/pay/paypal/receivePaypalStatus","anon"); // paypal回调接口
filterMap.put("/weChat/**","anon");
filterMap.put("/book/baseArea/getAllBaseArea","anon");//登录前获取全部区域
// filterMap.put("/book/bookchaptercontent/**","anon");

View File

@@ -0,0 +1,104 @@
package com.peanut.modules.bookAbroad.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.bookAbroad.service.BookAbroadCommentLikeService;
import com.peanut.modules.bookAbroad.service.BookAbroadCommentService;
import com.peanut.modules.bookAbroad.service.BookAbroadLableService;
import com.peanut.modules.bookAbroad.service.BookAbroadToLableService;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.MyUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@RestController("bookAbroad")
@RequestMapping("bookAbroad")
public class BookAbroadController {
@Autowired
private MyUserService userService;
@Autowired
private BookAbroadCommentService bookAbroadCommentService;
@Autowired
private BookAbroadCommentLikeService bookAbroadCommentLikeService;
//评论
@RequestMapping("/insertBookAbroadComment")
public R insertBookAbroadComment(@RequestBody BookAbroadComment comment){
comment.setUserId(ShiroUtils.getUId());
bookAbroadCommentService.save(comment);
return R.ok();
}
//评论树
@RequestMapping("/getBookAbroadCommentTree")
public List<BookAbroadComment> getBookAbroadCommentTree(@RequestBody Map<String,Object> params) {
List<BookAbroadComment> comments = bookAbroadCommentService.list(new LambdaQueryWrapper<BookAbroadComment>()
.eq(BookAbroadComment::getBookId,params.get("bookId")));
List<BookAbroadComment> commentsTree = comments.stream().filter((bookAbroadComment) ->
bookAbroadComment.getPid() == 0
).map((comment)->{
comment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
.eq(BookAbroadCommentLike::getCommentId,comment.getId())
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
comment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
.eq(MyUserEntity::getId,comment.getUserId())));
comment.setChildren(getLabelChildrens(comment,comments));
return comment;
}).collect(Collectors.toList());
return commentsTree;
}
private List<BookAbroadComment> getLabelChildrens(BookAbroadComment root,List<BookAbroadComment> all){
List<BookAbroadComment> children = all.stream().filter(bookAbroadComment -> {
return root.getId().equals(bookAbroadComment.getPid());
}).map(bookAbroadComment -> {
bookAbroadComment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
.eq(BookAbroadCommentLike::getCommentId,bookAbroadComment.getId())
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
bookAbroadComment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
.eq(MyUserEntity::getId,bookAbroadComment.getUserId())));
bookAbroadComment.setChildren(getLabelChildrens(bookAbroadComment, all));
return bookAbroadComment;
}).collect(Collectors.toList());
return children;
}
//删除评论
@RequestMapping("/delBookAbroadComment")
public R delBookAbroadComment(@RequestBody Map<String,Object> params){
bookAbroadCommentService.removeById(params.get("commentId").toString());
return R.ok();
}
//点赞
@RequestMapping("/insertBookAbroadCommentLike")
public R insertBookAbroadCommentLike(@RequestBody BookAbroadCommentLike commentLike){
int count = bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
.eq(BookAbroadCommentLike::getCommentId,commentLike.getCommentId())
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId()));
if (count > 0) {
return R.error("已点赞");
}
commentLike.setUserId(ShiroUtils.getUId());
bookAbroadCommentLikeService.save(commentLike);
return R.ok();
}
//取消点赞
@RequestMapping("/delBookAbroadCommentLike")
public R delBookAbroadCommentLike(@RequestBody Map<String,Object> params){
bookAbroadCommentLikeService.removeById(params.get("commentLikeId").toString());
return R.ok();
}
}

View File

@@ -0,0 +1,230 @@
package com.peanut.modules.bookAbroad.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import com.peanut.modules.book.service.*;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.master.service.BookAbroadToLableService;
import com.peanut.modules.bookAbroad.service.BookAbroadLableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@RestController("bookAbroadHome")
@RequestMapping("bookAbroad/home")
public class HomeController {
@Autowired
private BookReadRateService bookReadRateService;
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private BookService bookService;
@Autowired
private BookAbroadLableService lableService;
@Autowired
private BookAbroadToLableService toLableService;
@Autowired
private AuthorService authorService;
@Autowired
private BookChapterService bookChapterService;
@Autowired
private BookChapterContentService bookChapterContentService;
//我的图书
@RequestMapping("/getMyBooks")
public R getMyBooks(@RequestBody Map<String,Object> params){
MPJLambdaWrapper<UserEbookBuyEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.leftJoin(BookReadRateEntity.class,BookReadRateEntity::getBookId,UserEbookBuyEntity::getBookId);
wrapper.leftJoin(BookEntity.class,BookEntity::getId,UserEbookBuyEntity::getBookId);
wrapper.eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId());
wrapper.select(BookEntity::getId,BookEntity::getName,BookEntity::getImages);
wrapper.select(BookReadRateEntity::getPrecent);
wrapper.orderByDesc(BookReadRateEntity::getUpdateTime);
wrapper.groupBy(UserEbookBuyEntity::getBookId);
Page p = userEbookBuyService.pageMaps(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
return R.ok().put("page",p);
}
//推荐图书
@RequestMapping("/getRecommendBooks")
public R getRecommendBooks(){
//查询已购买图书
LambdaQueryWrapper<UserEbookBuyEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId());
wrapper.groupBy(UserEbookBuyEntity::getBookId);
Set<Integer> bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream()
.map(UserEbookBuyEntity::getBookId).collect(Collectors.toSet());
//查询未购买图书
List<BookEntity> noBooks = bookService.list(new LambdaQueryWrapper<BookEntity>()
.eq(BookEntity::getState,1)
.eq(BookEntity::getBookType,0)
.notIn(BookEntity::getId,bookIds)
.last("limit 2"));
Set<BookEntity> books = new HashSet<>();
//查询阅读进度
List<BookReadRateEntity> readRateList = bookReadRateService.list(new LambdaQueryWrapper<BookReadRateEntity>()
.eq(BookReadRateEntity::getUserId,ShiroUtils.getUId())
.orderByDesc(BookReadRateEntity::getUpdateTime));
//根据阅读记录,查询同标签下书籍
if (readRateList.size()>0){
//书籍绑定的标签
List<BookAbroadToLable> tolableBookList = toLableService.list(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getBookId,readRateList.get(0).getBookId()));
for (BookAbroadToLable tolableBook : tolableBookList) {
//标签下的书籍
List<BookAbroadToLable> tolableLableList = toLableService.list(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getLableId,tolableBook.getLableId()));
for (BookAbroadToLable tolableLable : tolableLableList) {
if (bookIds.add(tolableLable.getBookId())) {
books.add(bookService.getById(tolableLable.getBookId()));
if (books.size()==2){
break;
}
}
}
}
}
//补充标签未填满位置
if (books.size()!=2){
int surplus = 2-books.size();
for (int i=0;i<surplus; i++){
books.add(noBooks.get(i));
}
}
return R.ok().put("books",books);
}
//获取标签列表
@RequestMapping("/getBookAbroadLableList")
public R getBookAbroadLableList(@RequestBody Map<String,Object> params) {
List<BookAbroadLable> list = lableService.list(new LambdaQueryWrapper<BookAbroadLable>()
.eq(BookAbroadLable::getPid,0)
.eq(BookAbroadLable::getType,params.get("type")));
return R.ok().put("lableList",list);
}
//获取子标签
@RequestMapping("/getBookAbroadLableListByPid")
public R getBookAbroadLableListByPid(@RequestBody Map<String,Object> params) {
List<BookAbroadLable> list = lableService.list(new LambdaQueryWrapper<BookAbroadLable>()
.eq(BookAbroadLable::getPid,params.get("pid")));
return R.ok().put("lableList",list);
}
//通过标签获取绑定图书
@RequestMapping("/getAbroadBookListByLable")
public R getAbroadBookListByLable(@RequestBody Map<String,Object> params) {
MPJLambdaWrapper<BookAbroadToLable> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(BookEntity.class,BookEntity::getId,BookAbroadToLable::getBookId);
wrapper.selectAs(BookAbroadToLable::getId,"toLableId");
wrapper.selectAs(BookEntity::getId,"bookId");
wrapper.selectAs(BookEntity::getAbroadPrice,"abroadPrice");
wrapper.select(BookEntity::getImages);
wrapper.select(BookEntity::getName);
wrapper.eq(BookAbroadToLable::getLableId,params.get("lableId"));
return R.ok().put("bookList",toLableService.listMaps(wrapper));
}
//图书详情
@RequestMapping("/getBookInfo")
public R getBookInfo(@RequestBody Map<String,Object> params) {
BookEntity bookEntity = bookService.getById(params.get("bookId").toString());
bookEntity.setAuthor(authorService.getById(bookEntity.getAuthorId()));
bookEntity.setIsBuy(false);
int count = userEbookBuyService.count(new LambdaQueryWrapper<UserEbookBuyEntity>()
.eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId())
.eq(UserEbookBuyEntity::getBookId,params.get("bookId")));
if (count > 0) {
bookEntity.setIsBuy(true);
}
return R.ok().put("bookInfo",bookEntity);
}
//图书章节
@RequestMapping("/getBookChapter")
public R getBookChapter(@RequestBody Map<String,Object> params) {
List<BookChapterEntity> chapterList = bookChapterService.list(new LambdaQueryWrapper<BookChapterEntity>()
.eq(BookChapterEntity::getBookId,params.get("bookId"))
.orderByAsc(BookChapterEntity::getId));
return R.ok().put("chapterList",chapterList);
}
//章节内容
@RequestMapping("/getBookChapterContent")
public R getBookChapterContent(@RequestBody Map<String,Object> params) {
Page<BookChapterContentEntity> contentPage = bookChapterContentService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),
new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookChatperId,params.get("chapterId"))
.orderByAsc(BookChapterContentEntity::getNumber));
return R.ok().put("contentPage",contentPage);
}
//获取当前书的阅读记录
@RequestMapping("/getBookReadRate")
public R getBookReadRate(@RequestBody Map<String,Object> params){
BookReadRateEntity brr = bookReadRateService.getOne(new LambdaQueryWrapper<BookReadRateEntity>()
.eq(BookReadRateEntity::getUserId,ShiroUtils.getUId())
.eq(BookReadRateEntity::getBookId,params.get("bookId")));
return R.ok().put("bookReadRate",brr);
}
//新增阅读记录
@RequestMapping("/insertBookReadRate")
public R insertBookReadRate(@RequestBody BookReadRateEntity bookReadRate){
//计算百分比
int count = bookChapterContentService.count(new LambdaQueryWrapper<BookChapterContentEntity>()
.eq(BookChapterContentEntity::getBookId,bookReadRate.getBookId()));
BookChapterContentEntity bcc = bookChapterContentService.getById(bookReadRate.getContentId());
int pre = bcc.getNumber()*100/count;
bookReadRate.setPrecent(pre);
BookReadRateEntity brr = bookReadRateService.getOne(new LambdaQueryWrapper<BookReadRateEntity>()
.eq(BookReadRateEntity::getUserId,ShiroUtils.getUId())
.eq(BookReadRateEntity::getBookId,bookReadRate.getBookId()));
if (brr==null){
bookReadRate.setUserId(ShiroUtils.getUId());
bookReadRateService.save(bookReadRate);
}else {
brr.setChapterId(bookReadRate.getChapterId());
brr.setChapterName(bookReadRate.getChapterName());
brr.setContentId(bookReadRate.getContentId());
brr.setPrecent(bookReadRate.getPrecent());
brr.setUpdateTime(new Date());
bookReadRateService.updateById(brr);
}
return R.ok();
}
//相关图书
@RequestMapping("/getRecommendBook")
public R getRecommendBook(@RequestBody Map<String,Object> params){
Set<BookEntity> bookList = new HashSet<>();
//书籍绑定的标签
List<BookAbroadToLable> tolableBookList = toLableService.list(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getBookId,params.get("bookId")));
for (BookAbroadToLable tolableBook : tolableBookList) {
//标签下的书籍
List<BookAbroadToLable> tolableLableList = toLableService.list(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getLableId,tolableBook.getLableId()));
for (BookAbroadToLable tolableLable : tolableLableList) {
bookList.add(bookService.getById(tolableLable.getBookId()));
}
}
return R.ok().put("bookList",bookList);
}
}

View File

@@ -0,0 +1,53 @@
package com.peanut.modules.bookAbroad.controller;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.peanut.common.utils.R;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.service.BuyOrderService;
import com.peanut.modules.common.entity.BuyOrder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController("bookAbroadOrder")
@RequestMapping("bookAbroad/order")
public class OrderController {
@Autowired
private BuyOrderService buyOrderService;
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* 充值专用订单生成接口
*/
@RequestMapping("/rechargeSave")
public R rechargeSave(@RequestBody BuyOrder buyOrder){
buyOrder.setOrderStatus("0");
buyOrder.setOrderType("abroadBook");
String timeId = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(timeId);
buyOrderService.save(buyOrder);
rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(),
messagePostProcessor()
);
return R.ok().put("orderSn", timeId);
}
private MessagePostProcessor messagePostProcessor() {
return message -> {
//设置有效期30分钟
message.getMessageProperties().setExpiration(String.valueOf(30 * 60 * 1000));
return message;
};
}
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.bookAbroad.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadCommentLike;
public interface BookAbroadCommentLikeService extends IService<BookAbroadCommentLike> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.bookAbroad.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadComment;
public interface BookAbroadCommentService extends IService<BookAbroadComment> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.bookAbroad.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadLable;
public interface BookAbroadLableService extends IService<BookAbroadLable> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.bookAbroad.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadToLable;
public interface BookAbroadToLableService extends IService<BookAbroadToLable> {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.bookAbroad.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.bookAbroad.service.BookAbroadCommentLikeService;
import com.peanut.modules.common.dao.BookAbroadCommentLikeDao;
import com.peanut.modules.common.entity.BookAbroadCommentLike;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("bookAbroadCommentLikeService")
public class BookAbroadCommentLikeServiceImpl extends ServiceImpl<BookAbroadCommentLikeDao, BookAbroadCommentLike> implements BookAbroadCommentLikeService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.bookAbroad.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadCommentDao;
import com.peanut.modules.common.entity.BookAbroadComment;
import com.peanut.modules.bookAbroad.service.BookAbroadCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("bookAbroadComment")
public class BookAbroadCommentServiceImpl extends ServiceImpl<BookAbroadCommentDao, BookAbroadComment> implements BookAbroadCommentService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.bookAbroad.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadLableDao;
import com.peanut.modules.common.entity.BookAbroadLable;
import com.peanut.modules.bookAbroad.service.BookAbroadLableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("bookAbroadLableService")
public class BookAbroadLableServiceImpl extends ServiceImpl<BookAbroadLableDao, BookAbroadLable> implements BookAbroadLableService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.bookAbroad.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.bookAbroad.service.BookAbroadToLableService;
import com.peanut.modules.common.dao.BookAbroadToLableDao;
import com.peanut.modules.common.entity.BookAbroadToLable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("bookAbroadToLableService")
public class BookAbroadToLableServiceImpl extends ServiceImpl<BookAbroadToLableDao, BookAbroadToLable> implements BookAbroadToLableService {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.BookAbroadComment;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BookAbroadCommentDao extends MPJBaseMapper<BookAbroadComment> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.BookAbroadCommentLike;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BookAbroadCommentLikeDao extends MPJBaseMapper<BookAbroadCommentLike> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.BookAbroadLable;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BookAbroadLableDao extends MPJBaseMapper<BookAbroadLable> {
}

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.BookAbroadToLable;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BookAbroadToLableDao extends MPJBaseMapper<BookAbroadToLable> {
}

View File

@@ -0,0 +1,39 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
//海外书籍评论
@Data
@TableName("book_abroad_comment")
public class BookAbroadComment implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
//父id
private Integer pid;
//书籍id
private Integer bookId;
//用户id
private Integer userId;
//评论内容
private String content;
//创建时间
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private int isLike;
@TableField(exist = false)
private MyUserEntity userEntity;
@TableField(exist = false)
private List<BookAbroadComment> children;
}

View File

@@ -0,0 +1,22 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
//海外书籍评论点赞
@Data
@TableName("book_abroad_comment_like")
public class BookAbroadCommentLike implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
//评论id
private Integer commentId;
//用户id
private Integer userId;
@TableLogic
private Integer delFlag;
}

View File

@@ -0,0 +1,54 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
//海外书籍分类
@Data
@TableName("book_abroad_lable")
public class BookAbroadLable implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
/**
* 父id
*/
private Integer pid;
/**
* 类型0分类标签 1营销标签
*/
private Integer type;
/**
* 标题
*/
private String title;
/**
* 0否1是
*/
private Integer isLast;
/**
* 权重
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private List<BookAbroadLable> children;
}

View File

@@ -0,0 +1,40 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
//海外书籍分类绑定表
@Data
@TableName("book_abroad_to_lable")
public class BookAbroadToLable implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
/**
* 书籍id
*/
private Integer bookId;
/**
* 标签id
*/
private Integer lableId;
/**
* 权重
*/
private Integer sort;
/**
* 创建时间
*/
private Date createTime;
@TableLogic
private Integer delFlag;
}

View File

@@ -73,6 +73,10 @@ public class BookEntity implements Serializable {
* 价格
*/
private BigDecimal price;
/**
* 海外价格
*/
private BigDecimal abroadPrice;
/**
* 价格
*/

View File

@@ -1,9 +1,6 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.util.Date;
@@ -67,6 +64,7 @@ public class BookReadRateEntity implements Serializable {
/**
*
*/
@TableLogic
private Integer delFlag;

View File

@@ -67,11 +67,11 @@ public class BuyOrder implements Serializable {
*/
private String address;
/**
* 订单来源0疯子读书1国学众妙之门2医学吴门医述
* 订单来源0疯子读书1国学众妙之门2医学吴门医述3海外读书
*/
private Integer come;
/**
* 支付方式 1微信2支付宝3ios内购 4虚拟币
* 支付方式 1微信2支付宝3ios内购 4虚拟币 5PayPal
*/
private String paymentMethod;
/**
@@ -149,7 +149,7 @@ public class BuyOrder implements Serializable {
private String buyType;
/**
* vip order point
* vip order point abroadBook
*/
private String orderType;

View File

@@ -0,0 +1,147 @@
package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.master.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@RestController("masterBookAbroad")
@RequestMapping("master/bookAbroad")
public class BookAbroadController {
@Autowired
private BookAbroadCommentService bookAbroadCommentService;
@Autowired
private com.peanut.modules.bookAbroad.service.BookAbroadLableService labelService;
@Autowired
private com.peanut.modules.bookAbroad.service.BookAbroadToLableService toLableService;
//评论列表
@RequestMapping("/getBookAbroadCommentList")
public R getBookAbroadCommentList(@RequestBody Map<String,Object> params) {
Page comments = bookAbroadCommentService.page(
new Page<>(Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),
new LambdaQueryWrapper<BookAbroadComment>().like(BookAbroadComment::getContent,params.get("content")));
return R.ok().put("comments",comments);
}
//删除评论
@RequestMapping("/delBookAbroadComment")
public R delBookAbroadComment(@RequestBody Map<String,Object> params){
bookAbroadCommentService.removeById(params.get("commentId").toString());
return R.ok();
}
//新增标签
@RequestMapping("/insertBookAbroadLable")
public R insertBookAbroadLable(@RequestBody BookAbroadLable lable){
labelService.save(lable);
return R.ok();
}
//标签详情
@RequestMapping("/bookAbroadLableInfo")
public R bookAbroadLableInfo(@RequestBody Map<String,Object> params){
BookAbroadLable lable = labelService.getById(params.get("id").toString());
return R.ok().put("lable",lable);
}
//修改标签
@RequestMapping("/updateBookAbroadLable")
public R updateBookAbroadLable(@RequestBody BookAbroadLable lable){
BookAbroadLable oldLable = labelService.getById(lable.getId());
if (oldLable.getIsLast()!=lable.getIsLast()) {
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getLableId,lable.getId()));
if (count > 0){
return R.error("存在绑定书籍,删除后再操作");
}
}
labelService.updateById(lable);
return R.ok();
}
//删除标签
@RequestMapping("/delBookAbroadLable")
public R delBookAbroadLable(@RequestBody Map<String,Object> params){
BookAbroadLable oldLable = labelService.getById(params.get("id").toString());
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getLableId,params.get("id").toString()));
if (count > 0){
return R.error("存在绑定书籍,删除后再操作");
}
labelService.removeById(oldLable.getId());
return R.ok();
}
//绑定图书和标签
@RequestMapping("/insertBookAbroadToLable")
public R insertBookAbroadToLable(@RequestBody BookAbroadToLable toLable){
int count = toLableService.count(new LambdaQueryWrapper<BookAbroadToLable>()
.eq(BookAbroadToLable::getBookId,toLable.getBookId())
.eq(BookAbroadToLable::getLableId,toLable.getLableId()));
if (count > 0) {
return R.error("已存在");
}
toLableService.save(toLable);
return R.ok();
}
//解绑
@RequestMapping("/delBookAbroadToLable")
public R delBookAbroadToLable(@RequestBody Map<String,Object> params){
String[] strings = params.get("ids").toString().split(",");
toLableService.removeByIds(Arrays.asList(strings));
return R.ok();
}
//通过标签获取绑定图书
@RequestMapping("/getAbroadBookListByLable")
public R getAbroadBookListByLable(@RequestBody Map<String,Object> params) {
MPJLambdaWrapper<BookAbroadToLable> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(BookEntity.class,BookEntity::getId,BookAbroadToLable::getBookId);
wrapper.selectAs(BookAbroadToLable::getId,"id");
wrapper.select(BookEntity::getName);
wrapper.eq(BookAbroadToLable::getLableId,params.get("lableId"));
return R.ok().put("bookList",toLableService.listMaps(wrapper));
}
//标签树
@RequestMapping("/getLableTree")
public List<BookAbroadLable> getLableTree(@RequestBody Map<String,Object> params) {
List<BookAbroadLable> labels = labelService.list(new LambdaQueryWrapper<BookAbroadLable>()
.eq(BookAbroadLable::getType,params.get("type")));
List<BookAbroadLable> labelsTree = labels.stream().filter((bookAbroadLable) ->
bookAbroadLable.getPid() == 0
).map((label)->{
label.setChildren(getLabelChildrens(label,labels));
return label;
}).sorted((label1,label2)->{
return (label1.getSort() == null? 0 : label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
}).collect(Collectors.toList());
return labelsTree;
}
private List<BookAbroadLable> getLabelChildrens(BookAbroadLable root,List<BookAbroadLable> all){
List<BookAbroadLable> children = all.stream().filter(bookAbroadLable -> {
return root.getId().equals(bookAbroadLable.getPid());
}).map(bookAbroadLable -> {
bookAbroadLable.setChildren(getLabelChildrens(bookAbroadLable, all));
return bookAbroadLable;
}).sorted((label1,label2)->{
return (label1.getSort()==null?0:label1.getSort()) - (label2.getSort()==null?0:label2.getSort());
}).collect(Collectors.toList());
return children;
}
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadCommentLike;
public interface BookAbroadCommentLikeService extends IService<BookAbroadCommentLike> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadComment;
public interface BookAbroadCommentService extends IService<BookAbroadComment> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadLable;
public interface BookAbroadLableService extends IService<BookAbroadLable> {
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.BookAbroadToLable;
public interface BookAbroadToLableService extends IService<BookAbroadToLable> {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadCommentLikeDao;
import com.peanut.modules.common.entity.BookAbroadCommentLike;
import com.peanut.modules.master.service.BookAbroadCommentLikeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("masterBookAbroadCommentLikeService")
public class BookAbroadCommentLikeServiceImpl extends ServiceImpl<BookAbroadCommentLikeDao, BookAbroadCommentLike> implements BookAbroadCommentLikeService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadCommentDao;
import com.peanut.modules.common.entity.BookAbroadComment;
import com.peanut.modules.master.service.BookAbroadCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("masterBookAbroadCommentService")
public class BookAbroadCommentServiceImpl extends ServiceImpl<BookAbroadCommentDao, BookAbroadComment> implements BookAbroadCommentService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadLableDao;
import com.peanut.modules.common.entity.BookAbroadLable;
import com.peanut.modules.master.service.BookAbroadLableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("masterBookAbroadLableService")
public class BookAbroadLableServiceImpl extends ServiceImpl<BookAbroadLableDao, BookAbroadLable> implements BookAbroadLableService {
}

View File

@@ -0,0 +1,13 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BookAbroadToLableDao;
import com.peanut.modules.common.entity.BookAbroadToLable;
import com.peanut.modules.master.service.BookAbroadToLableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("masterBookAbroadToLableService")
public class BookAbroadToLableServiceImpl extends ServiceImpl<BookAbroadToLableDao, BookAbroadToLable> implements BookAbroadToLableService {
}

View File

@@ -0,0 +1,183 @@
package com.peanut.modules.pay.paypal;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
@Component
@Slf4j
public class PaypalConfig {
//沙盒
public static final String modeUrl = "https://api-m.sandbox.paypal.com";
public static final String CLIENID ="Ab8SeEuhkLGp6Fts9V3Cti0UcXQhITRWZkiHDM3U1fDY9YrrRc5IOcYHPfV6qROhmh0hvgysqrfOCSUr";
public static final String SECRET ="EF63FGWI9fd4q07Ndvc_h8P7jxiZcGOWn8Ul_y1_EKpluKJNFHOW8BP62Kf1wBDQ3XYIeqF8_kVrDF7C";
public static final String WEBSCR ="https://www.sandbox.paypal.com/cgi-bin/webscr";//回调验证地址
//正式
// public static final String modeUrl = "https://api-m.paypal.com";
// public static final String CLIENID ="";
// public static final String SECRET ="";
// public static final String WEBSCR ="https://www.paypal.com/cgi-bin/webscr";
public static final String accessTokenURL = "/v1/oauth2/token";
public static final String createOrderURL = "/v2/checkout/orders";
public static final String captureURL = "/v2/checkout/orders/%1s/capture";
public static final String orderInfoURL = "/v2/checkout/orders/";
public static final String refundURL = "/v2/payments/captures/%1s/refund";
public static final String refundInfoURL = "/v2/payments/refunds/";
//回调验证
public String receiveVerify(String verifyData) throws Exception{
URL url = new URL(WEBSCR);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(verifyData);
writer.flush();
writer.close();
connection.getOutputStream().close();
InputStream responseStream = connection.getResponseCode() / 100 == 2
? connection.getInputStream()
: connection.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
return response;
}
//退款查询
public JSONObject refundInfo(String refundId) throws Exception{
URL url = new URL(modeUrl+refundInfoURL+refundId);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setRequestProperty("Authorization", "Bearer " + getAccessToken().get("access_token"));
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
return JSONObject.parseObject(response);
}
//退款
public JSONObject refund(String captureId) throws Exception{
URL url = new URL(String.format(modeUrl+refundURL,captureId));
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setRequestProperty("Authorization", "Bearer " + getAccessToken().get("access_token"));
httpConn.setRequestProperty("Prefer", "return=representation");
httpConn.setDoOutput(true);
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
return JSONObject.parseObject(response);
}
//订单查询
public JSONObject orderInfo(String paypalOrderId) throws Exception{
URL url = new URL(modeUrl+orderInfoURL+paypalOrderId);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Authorization", "Bearer " + getAccessToken().get("access_token"));
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
return JSONObject.parseObject(response);
}
//用户授权支付成功,进行扣款操作
public JSONObject capture(String paypalOrderId) throws Exception{
URL url = new URL(String.format(modeUrl+captureURL,paypalOrderId));
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setRequestProperty("Authorization", "Bearer " + getAccessToken().get("access_token"));
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
return JSONObject.parseObject(response);
}
//下单
public JSONObject createOrder(JSONObject jsonObject){
try{
URL u = new URL(modeUrl+createOrderURL);
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + getAccessToken().get("access_token"));
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(jsonObject.toString());
writer.flush();
writer.close();
connection.getOutputStream().close();
InputStream responseStream = connection.getResponseCode() / 100 == 2
? connection.getInputStream()
: connection.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
return JSONObject.parseObject(response);
}catch (Exception e) {
log.error(">>>>>>>>>>:PayPal创建订单网络连接失败 reason = {}", e.getMessage());
e.printStackTrace();
return JSONObject.parseObject("{'error':'PayPal创建订单网络连接失败请联系管理员'}");
}
}
public JSONObject getAccessToken(){
try {
String credentials = CLIENID + ":" + SECRET;
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes());
URL url = new URL(modeUrl+accessTokenURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Authorization", "Basic " + encodedCredentials);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
String postParameters = "grant_type=client_credentials";
try (OutputStream os = connection.getOutputStream()) {
byte[] postParametersBytes = postParameters.getBytes();
os.write(postParametersBytes);
os.flush();
}
InputStream responseStream = connection.getResponseCode() / 100 == 2
? connection.getInputStream()
: connection.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
return JSONObject.parseObject(response);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,150 @@
package com.peanut.modules.pay.paypal;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.peanut.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* paypal支付
*/
@RestController
@RequestMapping("/pay/paypal")
@Slf4j
public class PaypalController {
//点击购买 ->去支付 ->跳转完成、取消页面
// ->创建订单 ->(支付完成)确认付款,打款到商家账户 ->支付成功
@Autowired
private PaypalConfig paypalConfig;
@RequestMapping("/getAccessToken")
public R getAccessToken(){
JSONObject res = paypalConfig.getAccessToken();
return R.ok().put("res",res);
}
@RequestMapping("/createOrder")
public R createOrder(@RequestBody Map<String,Object> params){
JSONArray purchase_units = new JSONArray();
JSONObject purchaseUnit = new JSONObject();
JSONObject amount = new JSONObject();
amount.put("currency_code", "USD");//美元
amount.put("value", params.get("amount"));// 金额
purchaseUnit.put("custom_id",params.get("orderSn"));
purchaseUnit.put("invoice_id",params.get("orderSn"));
purchaseUnit.put("amount",amount);
purchaseUnit.put("description", params.get("description"));
purchase_units.add(purchaseUnit);
//取消地址、返回地址设置
JSONObject applicationContext = new JSONObject();
applicationContext.put("user_action", "PAY_NOW");//付款按钮显示立即付款
applicationContext.put("shipping_preference", "NO_SHIPPING");//从 PayPal 网站编辑送货地址。推荐用于数字商品。
applicationContext.put("return_url", params.get("returnUrl"));//客户批准付款后重定向到客户的 URL
applicationContext.put("cancel_url", params.get("cancelUrl"));//客户取消付款后,客户被重定向的 URL
JSONObject jsonObject = new JSONObject();
// 用户付款了,商户立即收款
jsonObject.put("intent","CAPTURE");
jsonObject.put("purchase_units",purchase_units);
jsonObject.put("application_context", applicationContext);
JSONObject res = paypalConfig.createOrder(jsonObject);
if (res.containsKey("links")&&res.containsKey("status")){
if ("CREATED".equals(res.get("status").toString())){
List<JSONObject> links = (List)res.get("links");
for (JSONObject o:links) {
if ("approve".equals(o.get("rel").toString())){
return R.ok().put("res",o.get("href").toString());
}
}
}
}
return R.error(res.get("error").toString());
}
@RequestMapping("/orderInfo")
public R orderInfo(@RequestBody Map<String,Object> params) throws Exception{
JSONObject res = paypalConfig.orderInfo(params.get("paypalId").toString());
return R.ok().put("res",res);
}
@RequestMapping("/capture")
public R capture(@RequestBody Map<String,Object> params) throws Exception{
JSONObject res = paypalConfig.capture(params.get("paypalId").toString());
return R.ok().put("res",res);
}
@RequestMapping("/refund")
public R refund(@RequestBody Map<String,Object> params) throws Exception{
JSONObject res = paypalConfig.refund(params.get("captureId").toString());
return R.ok().put("res",res);
}
@RequestMapping("/refundInfo")
public R refundInfo(@RequestBody Map<String,Object> params) throws Exception{
JSONObject res = paypalConfig.refundInfo(params.get("refundId").toString());
return R.ok().put("res",res);
}
@RequestMapping("/receivePaypalStatus")
public void receivePaypalStatus(HttpServletRequest request, HttpServletResponse response) throws Exception{
//获取paypal请求参数,并拼接验证参数
Enumeration<String> en = request.getParameterNames();
String str = "cmd=_notify-validate";
while (en.hasMoreElements()) {
String paramName = en.nextElement();
String paramValue = request.getParameter(paramName);
str = str + "&" + paramName + "=" + paramValue;
}
System.out.println(str);
//发送给papal,确认回调信息的安全性
String res = paypalConfig.receiveVerify(str);
if ("VERIFIED".equals(res)){
// 交易状态 Completed 代表交易成功
String paymentStatus = request.getParameter("payment_status");
// 交易时间
String paymentDate = request.getParameter("payment_date");
// 付款人email
String payerEmail = request.getParameter("payer_email");
// 付款人id
String payerId = request.getParameter("payer_id");
// 交易金额
String mcGross = request.getParameter("mc_gross");
// 手续费
String paymentFee = request.getParameter("payment_fee");
// 自定义字段,存放订单号
String custom = request.getParameter("custom");
}
}
@RequestMapping("/receiveVerify")
public R receiveVerify(@RequestBody Map<String,Object> params) throws Exception{
String res = params.get("verifyData").toString();
Map<String,Object> map = new HashMap<>();
String[] items = res.split("&");
for (String item : items) {
String[] keyValues = item.split("=");
if (keyValues.length>1){
map.put(keyValues[0],keyValues[1]);
}else {
map.put(keyValues[0],"");
}
}
return R.ok().put("res",map);
}
}

View File

@@ -36,6 +36,8 @@ public class SysUserTokenEntity implements Serializable {
private String tokenMedical;
//token
private String tokenSociology;
//token
private String tokenAbroad;
//过期时间
private Date expireTime;
//更新时间

View File

@@ -44,12 +44,14 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse
//根部不同登录平台生成不同token
HttpServletRequest request = HttpContextUtil.getHttpServletRequest();
String appType = request.getHeader("appType")==null?"":request.getHeader("appType");
if ("".equals(appType)){
if ("".equals(appType)){//同时修改 SysUserTokenDao.xml
tokenEntity.setToken(token);
}else if ("medical".equals(appType)){
tokenEntity.setTokenMedical(token);
}else if ("sociology".equals(appType)){
tokenEntity.setTokenSociology(token);
}else if ("abroad".equals(appType)){
tokenEntity.setTokenAbroad(token);
}
tokenEntity.setUserId(userId);
tokenEntity.setUpdateTime(now);