From 880c412b193258397ed39e48a9f3640b1f75d1cc Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Sat, 7 Oct 2023 10:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/BookController.java | 17 ++++++++++ .../book/controller/BuyOrderController.java | 12 +++++++ .../ShopProductLabelController.java | 2 +- .../book/service/UserEbookBuyService.java | 3 ++ .../service/impl/UserEbookBuyServiceImpl.java | 34 ++++++++----------- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/BookController.java b/src/main/java/com/peanut/modules/book/controller/BookController.java index a13e945e..a708c582 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookController.java @@ -59,6 +59,8 @@ public class BookController { private ShopProductService shopProductService; @Autowired private ShopProudictBookService shopProudictBookService; + @Autowired + private ShopProductToLabelService shopProductToLabelService; final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10); /** @@ -82,6 +84,21 @@ public class BookController { return R.ok().put("page", page); } + /** + * 获取精品图书 + * @return + */ + @RequestMapping("/getJPBooks") + public R getJPBooks(){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ShopProductToLabelEntity::getSplId,5);//精选图书 + wrapper.eq(ShopProductToLabelEntity::getDelFlag,0); + List pIds = shopProductToLabelService.getBaseMapper().selectList(wrapper).stream().map(ShopProductToLabelEntity::getProductId).collect(Collectors.toList()); + + List shopProductEntities = shopProductService.getBaseMapper().selectList(new LambdaQueryWrapper().in(ShopProductEntity::getProductId, pIds)); + return R.ok().put("Products",shopProductEntities); + } + /** diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index 02bc6ef7..6733f094 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -7,6 +7,7 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; @@ -71,6 +72,8 @@ public class BuyOrderController { private PayWechatOrderService payWechatOrderService; @Autowired private PayZfbOrderService payZfbOrderService; + @Autowired + private ShopProudictBookService shopProudictBookService; // @Autowired // private /** @@ -255,6 +258,15 @@ public class BuyOrderController { transactionDetailsEntity.setOrderType("购买健康超市用品!"); transactionDetailsService.save(transactionDetailsEntity); + //购买成功后,添加书到个人表中 + List pros = products.stream().map(BuyOrderDetailEntity::getProductId).collect(Collectors.toList()); + for (Integer s : pros){ + List collect = shopProudictBookService.getBaseMapper().selectList(new LambdaQueryWrapper() + .eq(ShopProudictBookEntity::getProudictId, s) + .eq(ShopProudictBookEntity::getDelFlag, 0)).stream().map(ShopProudictBookEntity::getBookId).collect(Collectors.toList()); + userEbookBuyService.addBookForUser(buyOrder.getUserId(),collect); + } + }else{ return R.error("余额不足!"); } diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java b/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java index 0f5e6403..25b17d29 100644 --- a/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java +++ b/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java @@ -29,7 +29,6 @@ public class ShopProductLabelController { @Autowired private ShopProductLabelService shopProductLabelService; - @Autowired private ShopProductToLabelService shopProductToLabelService; @Autowired @@ -113,6 +112,7 @@ public class ShopProductLabelController { MPJLambdaWrapper shopProductEntityMPJLambdaWrapper = new MPJLambdaWrapper(); shopProductEntityMPJLambdaWrapper.selectAll(ShopProductEntity.class); shopProductEntityMPJLambdaWrapper.leftJoin(ShopProductEntity.class,ShopProductEntity::getProductId,ShopProductToLabelEntity::getProductId); + shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getSplId,splId); shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getDelFlag,0); shopProductEntityMPJLambdaWrapper.eq(ShopProductEntity::getDelFlag,0); Page shopProductEntityPage = shopProductToLabelDao.selectJoinPage(new Page(page, limit), ShopProductEntity.class, shopProductEntityMPJLambdaWrapper); diff --git a/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java b/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java index 4ef1356b..aa0e2c17 100644 --- a/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java +++ b/src/main/java/com/peanut/modules/book/service/UserEbookBuyService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; import com.peanut.modules.book.entity.UserEbookBuyEntity; +import java.util.List; import java.util.Map; /** @@ -19,6 +20,8 @@ public interface UserEbookBuyService extends IService { PageUtils queryPages(Map params); + void addBookForUser(Integer userId, List bookIds); + } diff --git a/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java index 991322d1..19ed63e4 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/UserEbookBuyServiceImpl.java @@ -1,8 +1,10 @@ package com.peanut.modules.book.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.peanut.modules.book.entity.BuyOrderEntity; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -45,23 +47,17 @@ public class UserEbookBuyServiceImpl extends ServiceImpl bookIds) { + for (Integer i:bookIds){ + List userEbookBuyEntities = this.getBaseMapper().selectList(new LambdaQueryWrapper().eq(UserEbookBuyEntity::getUserId, userId).eq(UserEbookBuyEntity::getBookId, i)); + if(userEbookBuyEntities.size()==0){ + UserEbookBuyEntity userEbookBuyEntity = new UserEbookBuyEntity(); + userEbookBuyEntity.setUserId(userId); + userEbookBuyEntity.setBookId(i); + userEbookBuyEntity.setPayTime(new Date()); + this.save(userEbookBuyEntity); + } + } + } } \ No newline at end of file