From a0c42ecea0a5118ce07bf1610aa107a6bca8cab2 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Tue, 26 Nov 2024 15:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=B7=E5=A4=96=E8=AF=BB=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/peanut/config/ShiroConfig.java | 1 + .../controller/BookAbroadController.java | 104 ++++++++ .../bookAbroad/controller/HomeController.java | 230 ++++++++++++++++++ .../controller/OrderController.java | 53 ++++ .../service/BookAbroadCommentLikeService.java | 7 + .../service/BookAbroadCommentService.java | 7 + .../service/BookAbroadLableService.java | 7 + .../service/BookAbroadToLableService.java | 7 + .../BookAbroadCommentLikeServiceImpl.java | 13 + .../impl/BookAbroadCommentServiceImpl.java | 13 + .../impl/BookAbroadLableServiceImpl.java | 13 + .../impl/BookAbroadToLableServiceImpl.java | 13 + .../common/dao/BookAbroadCommentDao.java | 9 + .../common/dao/BookAbroadCommentLikeDao.java | 9 + .../common/dao/BookAbroadLableDao.java | 9 + .../common/dao/BookAbroadToLableDao.java | 9 + .../common/entity/BookAbroadComment.java | 39 +++ .../common/entity/BookAbroadCommentLike.java | 22 ++ .../common/entity/BookAbroadLable.java | 54 ++++ .../common/entity/BookAbroadToLable.java | 40 +++ .../modules/common/entity/BookEntity.java | 4 + .../common/entity/BookReadRateEntity.java | 6 +- .../modules/common/entity/BuyOrder.java | 6 +- .../controller/BookAbroadController.java | 147 +++++++++++ .../service/BookAbroadCommentLikeService.java | 7 + .../service/BookAbroadCommentService.java | 7 + .../service/BookAbroadLableService.java | 7 + .../service/BookAbroadToLableService.java | 7 + .../BookAbroadCommentLikeServiceImpl.java | 13 + .../impl/BookAbroadCommentServiceImpl.java | 13 + .../impl/BookAbroadLableServiceImpl.java | 13 + .../impl/BookAbroadToLableServiceImpl.java | 13 + .../modules/pay/paypal/PaypalConfig.java | 183 ++++++++++++++ .../modules/pay/paypal/PaypalController.java | 150 ++++++++++++ .../sys/entity/SysUserTokenEntity.java | 2 + .../service/impl/SysUserTokenServiceImpl.java | 4 +- .../resources/mapper/sys/SysUserTokenDao.xml | 2 +- 37 files changed, 1234 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/peanut/modules/bookAbroad/controller/BookAbroadController.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/controller/OrderController.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentLikeService.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentService.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadLableService.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadToLableService.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentLikeServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadLableServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadToLableServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/common/dao/BookAbroadCommentDao.java create mode 100644 src/main/java/com/peanut/modules/common/dao/BookAbroadCommentLikeDao.java create mode 100644 src/main/java/com/peanut/modules/common/dao/BookAbroadLableDao.java create mode 100644 src/main/java/com/peanut/modules/common/dao/BookAbroadToLableDao.java create mode 100644 src/main/java/com/peanut/modules/common/entity/BookAbroadComment.java create mode 100644 src/main/java/com/peanut/modules/common/entity/BookAbroadCommentLike.java create mode 100644 src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java create mode 100644 src/main/java/com/peanut/modules/common/entity/BookAbroadToLable.java create mode 100644 src/main/java/com/peanut/modules/master/controller/BookAbroadController.java create mode 100644 src/main/java/com/peanut/modules/master/service/BookAbroadCommentLikeService.java create mode 100644 src/main/java/com/peanut/modules/master/service/BookAbroadCommentService.java create mode 100644 src/main/java/com/peanut/modules/master/service/BookAbroadLableService.java create mode 100644 src/main/java/com/peanut/modules/master/service/BookAbroadToLableService.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentLikeServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/BookAbroadLableServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/master/service/impl/BookAbroadToLableServiceImpl.java create mode 100644 src/main/java/com/peanut/modules/pay/paypal/PaypalConfig.java create mode 100644 src/main/java/com/peanut/modules/pay/paypal/PaypalController.java diff --git a/src/main/java/com/peanut/config/ShiroConfig.java b/src/main/java/com/peanut/config/ShiroConfig.java index 352e60e6..5256f933 100644 --- a/src/main/java/com/peanut/config/ShiroConfig.java +++ b/src/main/java/com/peanut/config/ShiroConfig.java @@ -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"); diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/BookAbroadController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/BookAbroadController.java new file mode 100644 index 00000000..7be79ba2 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/BookAbroadController.java @@ -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 getBookAbroadCommentTree(@RequestBody Map params) { + List comments = bookAbroadCommentService.list(new LambdaQueryWrapper() + .eq(BookAbroadComment::getBookId,params.get("bookId"))); + List commentsTree = comments.stream().filter((bookAbroadComment) -> + bookAbroadComment.getPid() == 0 + ).map((comment)->{ + comment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper() + .eq(BookAbroadCommentLike::getCommentId,comment.getId()) + .eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId()))); + comment.setUserEntity(userService.getOne(new LambdaQueryWrapper() + .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 getLabelChildrens(BookAbroadComment root,List all){ + List children = all.stream().filter(bookAbroadComment -> { + return root.getId().equals(bookAbroadComment.getPid()); + }).map(bookAbroadComment -> { + bookAbroadComment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper() + .eq(BookAbroadCommentLike::getCommentId,bookAbroadComment.getId()) + .eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId()))); + bookAbroadComment.setUserEntity(userService.getOne(new LambdaQueryWrapper() + .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 params){ + bookAbroadCommentService.removeById(params.get("commentId").toString()); + return R.ok(); + } + //点赞 + @RequestMapping("/insertBookAbroadCommentLike") + public R insertBookAbroadCommentLike(@RequestBody BookAbroadCommentLike commentLike){ + int count = bookAbroadCommentLikeService.count(new LambdaQueryWrapper() + .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 params){ + bookAbroadCommentLikeService.removeById(params.get("commentLikeId").toString()); + return R.ok(); + } + + + +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java new file mode 100644 index 00000000..3c8590e0 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/HomeController.java @@ -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 params){ + MPJLambdaWrapper 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 wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserEbookBuyEntity::getUserId,ShiroUtils.getUId()); + wrapper.groupBy(UserEbookBuyEntity::getBookId); + Set bookIds = userEbookBuyService.getBaseMapper().selectList(wrapper).stream() + .map(UserEbookBuyEntity::getBookId).collect(Collectors.toSet()); + //查询未购买图书 + List noBooks = bookService.list(new LambdaQueryWrapper() + .eq(BookEntity::getState,1) + .eq(BookEntity::getBookType,0) + .notIn(BookEntity::getId,bookIds) + .last("limit 2")); + Set books = new HashSet<>(); + //查询阅读进度 + List readRateList = bookReadRateService.list(new LambdaQueryWrapper() + .eq(BookReadRateEntity::getUserId,ShiroUtils.getUId()) + .orderByDesc(BookReadRateEntity::getUpdateTime)); + //根据阅读记录,查询同标签下书籍 + if (readRateList.size()>0){ + //书籍绑定的标签 + List tolableBookList = toLableService.list(new LambdaQueryWrapper() + .eq(BookAbroadToLable::getBookId,readRateList.get(0).getBookId())); + for (BookAbroadToLable tolableBook : tolableBookList) { + //标签下的书籍 + List tolableLableList = toLableService.list(new LambdaQueryWrapper() + .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 params) { + List list = lableService.list(new LambdaQueryWrapper() + .eq(BookAbroadLable::getPid,0) + .eq(BookAbroadLable::getType,params.get("type"))); + return R.ok().put("lableList",list); + } + + //获取子标签 + @RequestMapping("/getBookAbroadLableListByPid") + public R getBookAbroadLableListByPid(@RequestBody Map params) { + List list = lableService.list(new LambdaQueryWrapper() + .eq(BookAbroadLable::getPid,params.get("pid"))); + return R.ok().put("lableList",list); + } + + //通过标签获取绑定图书 + @RequestMapping("/getAbroadBookListByLable") + public R getAbroadBookListByLable(@RequestBody Map params) { + MPJLambdaWrapper 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 params) { + BookEntity bookEntity = bookService.getById(params.get("bookId").toString()); + bookEntity.setAuthor(authorService.getById(bookEntity.getAuthorId())); + bookEntity.setIsBuy(false); + int count = userEbookBuyService.count(new LambdaQueryWrapper() + .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 params) { + List chapterList = bookChapterService.list(new LambdaQueryWrapper() + .eq(BookChapterEntity::getBookId,params.get("bookId")) + .orderByAsc(BookChapterEntity::getId)); + return R.ok().put("chapterList",chapterList); + } + + //章节内容 + @RequestMapping("/getBookChapterContent") + public R getBookChapterContent(@RequestBody Map params) { + Page contentPage = bookChapterContentService.page(new Page<>( + Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), + new LambdaQueryWrapper() + .eq(BookChapterContentEntity::getBookChatperId,params.get("chapterId")) + .orderByAsc(BookChapterContentEntity::getNumber)); + return R.ok().put("contentPage",contentPage); + } + + //获取当前书的阅读记录 + @RequestMapping("/getBookReadRate") + public R getBookReadRate(@RequestBody Map params){ + BookReadRateEntity brr = bookReadRateService.getOne(new LambdaQueryWrapper() + .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() + .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() + .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 params){ + Set bookList = new HashSet<>(); + //书籍绑定的标签 + List tolableBookList = toLableService.list(new LambdaQueryWrapper() + .eq(BookAbroadToLable::getBookId,params.get("bookId"))); + for (BookAbroadToLable tolableBook : tolableBookList) { + //标签下的书籍 + List tolableLableList = toLableService.list(new LambdaQueryWrapper() + .eq(BookAbroadToLable::getLableId,tolableBook.getLableId())); + for (BookAbroadToLable tolableLable : tolableLableList) { + bookList.add(bookService.getById(tolableLable.getBookId())); + } + } + return R.ok().put("bookList",bookList); + } + + + + +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/controller/OrderController.java b/src/main/java/com/peanut/modules/bookAbroad/controller/OrderController.java new file mode 100644 index 00000000..4f4ce813 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/controller/OrderController.java @@ -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; + }; + } + +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentLikeService.java b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentLikeService.java new file mode 100644 index 00000000..089dac0b --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentLikeService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentService.java b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentService.java new file mode 100644 index 00000000..97b5b472 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadCommentService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadLableService.java b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadLableService.java new file mode 100644 index 00000000..6ad338ab --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadLableService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadToLableService.java b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadToLableService.java new file mode 100644 index 00000000..5c8f344b --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/BookAbroadToLableService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentLikeServiceImpl.java b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentLikeServiceImpl.java new file mode 100644 index 00000000..4a4e1a62 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentLikeServiceImpl.java @@ -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 implements BookAbroadCommentLikeService { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentServiceImpl.java b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentServiceImpl.java new file mode 100644 index 00000000..c8607aff --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadCommentServiceImpl.java @@ -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 implements BookAbroadCommentService { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadLableServiceImpl.java b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadLableServiceImpl.java new file mode 100644 index 00000000..47b1906f --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadLableServiceImpl.java @@ -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 implements BookAbroadLableService { +} diff --git a/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadToLableServiceImpl.java b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadToLableServiceImpl.java new file mode 100644 index 00000000..6dc39134 --- /dev/null +++ b/src/main/java/com/peanut/modules/bookAbroad/service/impl/BookAbroadToLableServiceImpl.java @@ -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 implements BookAbroadToLableService { +} diff --git a/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentDao.java b/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentDao.java new file mode 100644 index 00000000..8d3fa968 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentLikeDao.java b/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentLikeDao.java new file mode 100644 index 00000000..067a3f58 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/BookAbroadCommentLikeDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/common/dao/BookAbroadLableDao.java b/src/main/java/com/peanut/modules/common/dao/BookAbroadLableDao.java new file mode 100644 index 00000000..067cf01c --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/BookAbroadLableDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/common/dao/BookAbroadToLableDao.java b/src/main/java/com/peanut/modules/common/dao/BookAbroadToLableDao.java new file mode 100644 index 00000000..585f13b9 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/dao/BookAbroadToLableDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/common/entity/BookAbroadComment.java b/src/main/java/com/peanut/modules/common/entity/BookAbroadComment.java new file mode 100644 index 00000000..e2c6a7b4 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/BookAbroadComment.java @@ -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 children; +} diff --git a/src/main/java/com/peanut/modules/common/entity/BookAbroadCommentLike.java b/src/main/java/com/peanut/modules/common/entity/BookAbroadCommentLike.java new file mode 100644 index 00000000..ae4ae4d7 --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/BookAbroadCommentLike.java @@ -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; +} diff --git a/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java b/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java new file mode 100644 index 00000000..5ad0ffcf --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/BookAbroadLable.java @@ -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 children; +} diff --git a/src/main/java/com/peanut/modules/common/entity/BookAbroadToLable.java b/src/main/java/com/peanut/modules/common/entity/BookAbroadToLable.java new file mode 100644 index 00000000..91ecf46d --- /dev/null +++ b/src/main/java/com/peanut/modules/common/entity/BookAbroadToLable.java @@ -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; +} diff --git a/src/main/java/com/peanut/modules/common/entity/BookEntity.java b/src/main/java/com/peanut/modules/common/entity/BookEntity.java index ecbbf805..0e7ac93d 100644 --- a/src/main/java/com/peanut/modules/common/entity/BookEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/BookEntity.java @@ -73,6 +73,10 @@ public class BookEntity implements Serializable { * 价格 */ private BigDecimal price; + /** + * 海外价格 + */ + private BigDecimal abroadPrice; /** * 价格 */ diff --git a/src/main/java/com/peanut/modules/common/entity/BookReadRateEntity.java b/src/main/java/com/peanut/modules/common/entity/BookReadRateEntity.java index bfefeeca..122edce6 100644 --- a/src/main/java/com/peanut/modules/common/entity/BookReadRateEntity.java +++ b/src/main/java/com/peanut/modules/common/entity/BookReadRateEntity.java @@ -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; diff --git a/src/main/java/com/peanut/modules/common/entity/BuyOrder.java b/src/main/java/com/peanut/modules/common/entity/BuyOrder.java index adeeabfd..a816b97d 100644 --- a/src/main/java/com/peanut/modules/common/entity/BuyOrder.java +++ b/src/main/java/com/peanut/modules/common/entity/BuyOrder.java @@ -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; diff --git a/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java b/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java new file mode 100644 index 00000000..4980e106 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/controller/BookAbroadController.java @@ -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 params) { + Page comments = bookAbroadCommentService.page( + new Page<>(Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), + new LambdaQueryWrapper().like(BookAbroadComment::getContent,params.get("content"))); + return R.ok().put("comments",comments); + } + //删除评论 + @RequestMapping("/delBookAbroadComment") + public R delBookAbroadComment(@RequestBody Map 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 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() + .eq(BookAbroadToLable::getLableId,lable.getId())); + if (count > 0){ + return R.error("存在绑定书籍,删除后再操作"); + } + } + labelService.updateById(lable); + return R.ok(); + } + + //删除标签 + @RequestMapping("/delBookAbroadLable") + public R delBookAbroadLable(@RequestBody Map params){ + BookAbroadLable oldLable = labelService.getById(params.get("id").toString()); + int count = toLableService.count(new LambdaQueryWrapper() + .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() + .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 params){ + String[] strings = params.get("ids").toString().split(","); + toLableService.removeByIds(Arrays.asList(strings)); + return R.ok(); + } + + //通过标签获取绑定图书 + @RequestMapping("/getAbroadBookListByLable") + public R getAbroadBookListByLable(@RequestBody Map params) { + MPJLambdaWrapper 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 getLableTree(@RequestBody Map params) { + List labels = labelService.list(new LambdaQueryWrapper() + .eq(BookAbroadLable::getType,params.get("type"))); + List 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 getLabelChildrens(BookAbroadLable root,List all){ + List 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; + } +} diff --git a/src/main/java/com/peanut/modules/master/service/BookAbroadCommentLikeService.java b/src/main/java/com/peanut/modules/master/service/BookAbroadCommentLikeService.java new file mode 100644 index 00000000..37165c44 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/BookAbroadCommentLikeService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/master/service/BookAbroadCommentService.java b/src/main/java/com/peanut/modules/master/service/BookAbroadCommentService.java new file mode 100644 index 00000000..b124a6a4 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/BookAbroadCommentService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/master/service/BookAbroadLableService.java b/src/main/java/com/peanut/modules/master/service/BookAbroadLableService.java new file mode 100644 index 00000000..46090dcd --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/BookAbroadLableService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/master/service/BookAbroadToLableService.java b/src/main/java/com/peanut/modules/master/service/BookAbroadToLableService.java new file mode 100644 index 00000000..92ca23ac --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/BookAbroadToLableService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentLikeServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentLikeServiceImpl.java new file mode 100644 index 00000000..70ae1e9a --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentLikeServiceImpl.java @@ -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 implements BookAbroadCommentLikeService { +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentServiceImpl.java new file mode 100644 index 00000000..4033933e --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadCommentServiceImpl.java @@ -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 implements BookAbroadCommentService { +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/BookAbroadLableServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadLableServiceImpl.java new file mode 100644 index 00000000..dc00eaa8 --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadLableServiceImpl.java @@ -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 implements BookAbroadLableService { +} diff --git a/src/main/java/com/peanut/modules/master/service/impl/BookAbroadToLableServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadToLableServiceImpl.java new file mode 100644 index 00000000..af06abef --- /dev/null +++ b/src/main/java/com/peanut/modules/master/service/impl/BookAbroadToLableServiceImpl.java @@ -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 implements BookAbroadToLableService { +} diff --git a/src/main/java/com/peanut/modules/pay/paypal/PaypalConfig.java b/src/main/java/com/peanut/modules/pay/paypal/PaypalConfig.java new file mode 100644 index 00000000..fc157040 --- /dev/null +++ b/src/main/java/com/peanut/modules/pay/paypal/PaypalConfig.java @@ -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; + } + +} diff --git a/src/main/java/com/peanut/modules/pay/paypal/PaypalController.java b/src/main/java/com/peanut/modules/pay/paypal/PaypalController.java new file mode 100644 index 00000000..9402feac --- /dev/null +++ b/src/main/java/com/peanut/modules/pay/paypal/PaypalController.java @@ -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 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 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 params) throws Exception{ + JSONObject res = paypalConfig.orderInfo(params.get("paypalId").toString()); + return R.ok().put("res",res); + } + + @RequestMapping("/capture") + public R capture(@RequestBody Map params) throws Exception{ + JSONObject res = paypalConfig.capture(params.get("paypalId").toString()); + return R.ok().put("res",res); + } + + @RequestMapping("/refund") + public R refund(@RequestBody Map params) throws Exception{ + JSONObject res = paypalConfig.refund(params.get("captureId").toString()); + return R.ok().put("res",res); + } + + @RequestMapping("/refundInfo") + public R refundInfo(@RequestBody Map 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 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 params) throws Exception{ + String res = params.get("verifyData").toString(); + Map 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); + } + + +} diff --git a/src/main/java/com/peanut/modules/sys/entity/SysUserTokenEntity.java b/src/main/java/com/peanut/modules/sys/entity/SysUserTokenEntity.java index 06424086..723fa54a 100644 --- a/src/main/java/com/peanut/modules/sys/entity/SysUserTokenEntity.java +++ b/src/main/java/com/peanut/modules/sys/entity/SysUserTokenEntity.java @@ -36,6 +36,8 @@ public class SysUserTokenEntity implements Serializable { private String tokenMedical; //token private String tokenSociology; + //token + private String tokenAbroad; //过期时间 private Date expireTime; //更新时间 diff --git a/src/main/java/com/peanut/modules/sys/service/impl/SysUserTokenServiceImpl.java b/src/main/java/com/peanut/modules/sys/service/impl/SysUserTokenServiceImpl.java index b1f8cff7..0850ed29 100644 --- a/src/main/java/com/peanut/modules/sys/service/impl/SysUserTokenServiceImpl.java +++ b/src/main/java/com/peanut/modules/sys/service/impl/SysUserTokenServiceImpl.java @@ -44,12 +44,14 @@ public class SysUserTokenServiceImpl extends ServiceImpl \ No newline at end of file