From eff309f8cb2d37a0836747f9c02e5e8ea19da6f8 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 1 Nov 2023 16:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/BuyOrderController.java | 8 +++- .../modules/book/dao/BuyOrderProductDao.java | 3 +- .../modules/book/dao/ShopProductBookDao.java | 3 +- .../modules/book/entity/ExpressOrder.java | 5 +++ .../modules/book/entity/ShopProduct.java | 15 +++++++ .../book/service/ShopProductBookService.java | 3 ++ .../service/impl/BuyOrderServiceImpl.java | 39 ++++++++++++++++++- .../service/impl/ExpressOrderServiceImpl.java | 2 +- .../impl/ShopProductBookServiceImpl.java | 7 ++++ .../book/vo/response/GoodsResponseVo.java | 8 ++++ src/main/resources/application.yml | 2 +- src/main/resources/weChatConfig.properties | 2 +- 12 files changed, 90 insertions(+), 7 deletions(-) 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 8b5d6b35..903dae58 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -260,7 +260,6 @@ public class BuyOrderController { totalPrice = totalPrice.add(getShoppingAmount(buyOrder)); String orderSn = IdWorker.getTimeId().substring(0, 32); buyOrder.setOrderSn(orderSn); -// buyOrder.setPaymentDate(new Date());//这个是支付时间 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("id", buyOrder.getAddressId()); UserAddress userAddress = userAddressService.getOne(queryWrapper); @@ -272,6 +271,7 @@ public class BuyOrderController { buyOrder.setAddress(userAddress.getDetailAddress()); buyOrderService.save(buyOrder); + //解决购物车相关问题 for (BuyOrderProduct buyOrderProduct : buyOrderProductList) { buyOrderProduct.setOrderId(buyOrder.getOrderId()); if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) { @@ -458,6 +458,12 @@ public class BuyOrderController { paymentInfo.setBuyOrderId(Integer.valueOf(buyOrderEntity.getProductId())); paymentInfo.setTotalAmount(buyOrderEntity.getRealMoney()); wxpayService.prepay(paymentInfo); + rabbitTemplate.convertAndSend( + DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE, + DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY, + buyOrder.getOrderId(), + messagePostProcessor() + ); return R.ok().put("orderSn", timeId); } diff --git a/src/main/java/com/peanut/modules/book/dao/BuyOrderProductDao.java b/src/main/java/com/peanut/modules/book/dao/BuyOrderProductDao.java index adae94de..f924fbb5 100644 --- a/src/main/java/com/peanut/modules/book/dao/BuyOrderProductDao.java +++ b/src/main/java/com/peanut/modules/book/dao/BuyOrderProductDao.java @@ -1,9 +1,10 @@ package com.peanut.modules.book.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.github.yulichang.base.MPJBaseMapper; import com.peanut.modules.book.entity.BuyOrderProduct; import org.apache.ibatis.annotations.Mapper; @Mapper -public interface BuyOrderProductDao extends BaseMapper { +public interface BuyOrderProductDao extends MPJBaseMapper { } diff --git a/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java b/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java index 90f7942a..77c65921 100644 --- a/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java +++ b/src/main/java/com/peanut/modules/book/dao/ShopProductBookDao.java @@ -1,13 +1,14 @@ package com.peanut.modules.book.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.github.yulichang.base.MPJBaseMapper; import com.peanut.modules.book.entity.ShopProductBookEntity; import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface ShopProductBookDao extends BaseMapper { +public interface ShopProductBookDao extends MPJBaseMapper { List getOrderBookId(String orderSn); } diff --git a/src/main/java/com/peanut/modules/book/entity/ExpressOrder.java b/src/main/java/com/peanut/modules/book/entity/ExpressOrder.java index 50e401a2..7b148e62 100644 --- a/src/main/java/com/peanut/modules/book/entity/ExpressOrder.java +++ b/src/main/java/com/peanut/modules/book/entity/ExpressOrder.java @@ -87,6 +87,11 @@ public class ExpressOrder { */ @TableField(exist = false) private String printString; + /** + * 商品列表 + */ + @TableField(exist = false) + private List products; /** * 快递单号 */ diff --git a/src/main/java/com/peanut/modules/book/entity/ShopProduct.java b/src/main/java/com/peanut/modules/book/entity/ShopProduct.java index 7bcf239c..295c1915 100644 --- a/src/main/java/com/peanut/modules/book/entity/ShopProduct.java +++ b/src/main/java/com/peanut/modules/book/entity/ShopProduct.java @@ -151,6 +151,11 @@ public class ShopProduct implements Serializable { */ @TableField(exist = false) private ArrayList bookids; + /** + * 实体书list + */ + @TableField(exist = false) + private List books; /** * 多个电子书Id ArrayList> @@ -167,4 +172,14 @@ public class ShopProduct implements Serializable { @TableField(exist = false) private List shoproudLabels; + /** + * 数量 + */ + @TableField(exist = false) + private Integer quantity; + /** + * 属于的订单,特殊情况下启用 + */ + @TableField(exist = false) + private String orderSn; } diff --git a/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java b/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java index 917fc925..97fd7b15 100644 --- a/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java +++ b/src/main/java/com/peanut/modules/book/service/ShopProductBookService.java @@ -2,6 +2,7 @@ package com.peanut.modules.book.service; import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; +import com.peanut.modules.book.entity.BookEntity; import com.peanut.modules.book.entity.ShopProductBookEntity; import com.peanut.modules.book.vo.ProductBookQueryVO; @@ -17,6 +18,8 @@ public interface ShopProductBookService extends IService List getBookIdsByProductId(Integer productId); + List getBookByProductId(Integer productId); + Integer getProductByBookId(Integer bookId); List getOrderBookId(String orderSn); diff --git a/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java index 0cd82be7..9bf5ad5f 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BuyOrderServiceImpl.java @@ -8,12 +8,15 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.ExcludeEmptyQueryWrapper; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; import com.peanut.config.Constants; import com.peanut.modules.book.dao.BuyOrderDao; +import com.peanut.modules.book.dao.BuyOrderProductDao; import com.peanut.modules.book.dao.ExpressOrderDao; +import com.peanut.modules.book.dao.ShopProductBookDao; import com.peanut.modules.book.entity.*; import com.peanut.modules.book.service.*; import com.peanut.modules.book.to.UserOrderDto; @@ -61,6 +64,9 @@ public class BuyOrderServiceImpl extends ServiceImpl impl @Autowired ShopProductService shopProductService; + @Autowired + private BookService bookService; + @Autowired private BuyOrderProductService buyOrderProductService; @@ -72,7 +78,13 @@ public class BuyOrderServiceImpl extends ServiceImpl impl @Autowired private ExpressOrderDao expressOrderDao; @Autowired + private BuyOrderProductDao buyOrderProductDao; + @Autowired + private ShopProductBookDao shopProductBookDao; + @Autowired private OssService ossService; + @Autowired + private ShopProductBookService shopProductBookService; protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class); @@ -404,7 +416,7 @@ public class BuyOrderServiceImpl extends ServiceImpl impl ShopProduct product = shopProductService.getById(productId); //定义快递商品 ExpressCommodity commodity = new ExpressCommodity(); - commodity.setGoodsName(product.getProductName()); + commodity.setGoodsName(product.getProductName()+" ×"+buyOrderProduct.getQuantity()); commodity.setGoodsquantity(buyOrderProduct.getQuantity()); commodity.setGoodsWeight((product.getWeight().doubleValue())/1000); totalWeight = totalWeight.add( @@ -607,6 +619,7 @@ public class BuyOrderServiceImpl extends ServiceImpl impl goodsResponseVo.setProductImage(shopProduct.getProductImages()); goodsResponseVo.setProductPrice(shopProduct.getPrice()); goodsResponseVo.setQuantity(buyOrderProduct.getQuantity()); + goodsResponseVo.setProductId(shopProduct.getProductId()); QueryWrapper expressOrderQueryWrapper = new QueryWrapper<>(); expressOrderQueryWrapper.eq("id", buyOrderProduct.getExpressOrderId()); ExpressOrder expressOrder = expressOrderService.getOne(expressOrderQueryWrapper); @@ -617,6 +630,11 @@ public class BuyOrderServiceImpl extends ServiceImpl impl expressResponseVo.setPrintTemplate(expressOrder.getPrintTemplate()); } goodsResponseVo.setExpressInfo(expressResponseVo); + + //设置商品对应的具体书 + List bookByProductId = shopProductBookService.getBookByProductId(buyOrderProduct.getProductId()); + goodsResponseVo.setBooks(bookByProductId); + goodsResponseVoList.add(goodsResponseVo); } responseVo.setGoodsList(goodsResponseVoList); @@ -628,6 +646,25 @@ public class BuyOrderServiceImpl extends ServiceImpl impl List collect = buyOrderProductService.getBaseMapper().selectList(b_wrapper).stream().map(BuyOrderProduct::getExpressOrderId).collect(Collectors.toList()); if(collect.size()>0){ List expressOrders = expressOrderService.getBaseMapper().selectList(new LambdaQueryWrapper().in(ExpressOrder::getId, collect)); + for (ExpressOrder e : expressOrders){ + MPJLambdaWrapper buyOrderProductMPJLambdaWrapper = new MPJLambdaWrapper<>(); + buyOrderProductMPJLambdaWrapper.selectAll(ShopProduct.class); + buyOrderProductMPJLambdaWrapper.select(BuyOrderProduct::getQuantity); + buyOrderProductMPJLambdaWrapper.select(BuyOrder::getOrderSn); + buyOrderProductMPJLambdaWrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,BuyOrderProduct::getProductId); + buyOrderProductMPJLambdaWrapper.leftJoin(BuyOrder.class,BuyOrder::getOrderId,BuyOrderProduct::getOrderId); + buyOrderProductMPJLambdaWrapper.eq(BuyOrderProduct::getExpressOrderId,e.getId()); + List shopProducts = buyOrderProductDao.selectJoinList(ShopProduct.class, buyOrderProductMPJLambdaWrapper); + for(ShopProduct s : shopProducts){ + MPJLambdaWrapper shopProductBookEntityMPJLambdaWrapper = new MPJLambdaWrapper<>(); + shopProductBookEntityMPJLambdaWrapper.selectAll(BookEntity.class); + shopProductBookEntityMPJLambdaWrapper.leftJoin(BookEntity.class,BookEntity::getId,ShopProductBookEntity::getBookId); + shopProductBookEntityMPJLambdaWrapper.eq(ShopProductBookEntity::getProductId,s.getProductId()); + List bookEntities = shopProductBookDao.selectJoinList(BookEntity.class, shopProductBookEntityMPJLambdaWrapper); + s.setBooks(bookEntities); + } + e.setProducts(shopProducts); + } responseVo.setExpressOrders(expressOrders); } diff --git a/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java index b384310e..c2669f93 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/ExpressOrderServiceImpl.java @@ -54,7 +54,7 @@ public class ExpressOrderServiceImpl extends ServiceImpl implements ShopProductBookService { @@ -87,6 +88,12 @@ public class ShopProductBookServiceImpl extends ServiceImpl getBookByProductId(Integer productId) { + List collect = getBaseMapper().selectList(new QueryWrapper().eq("product_id", productId)).stream().map(ShopProductBookEntity::getBookId).collect(Collectors.toList()); + return collect.size()==0?null:bookService.list(new LambdaQueryWrapper().in(BookEntity::getId, collect)); + } + @Override public Integer getProductByBookId(Integer bookId) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/peanut/modules/book/vo/response/GoodsResponseVo.java b/src/main/java/com/peanut/modules/book/vo/response/GoodsResponseVo.java index c9c80f9e..99134a1f 100644 --- a/src/main/java/com/peanut/modules/book/vo/response/GoodsResponseVo.java +++ b/src/main/java/com/peanut/modules/book/vo/response/GoodsResponseVo.java @@ -1,8 +1,10 @@ package com.peanut.modules.book.vo.response; +import com.peanut.modules.book.entity.BookEntity; import lombok.Data; import java.math.BigDecimal; +import java.util.List; /** * @Description: 商品信息 Value Object @@ -11,6 +13,8 @@ import java.math.BigDecimal; */ @Data public class GoodsResponseVo { + private Integer ProductId; + private Integer buyOrderProductId; /** * 商品名称 @@ -32,4 +36,8 @@ public class GoodsResponseVo { * 快递 */ private ExpressResponseVo expressInfo; + /** + * 对应的书list + */ + private List books; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4b7d7a8c..ad28466c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ connection-timeout: 6000000ms spring: # 环境 dev|test|prod profiles: - active: dev + active: prod # jackson时间格式化 jackson: time-zone: GMT+8 diff --git a/src/main/resources/weChatConfig.properties b/src/main/resources/weChatConfig.properties index 4b45ba81..a24fe685 100644 --- a/src/main/resources/weChatConfig.properties +++ b/src/main/resources/weChatConfig.properties @@ -5,7 +5,7 @@ wxpay.mchId:1612860909 # ?? URL wxpay.payUrl:https://api.mch.weixin.qq.com/v3/pay/transactions/app # ???? -wxpay.notifyUrl:https://testapi.nuttyreading.com/pay/payNotify +wxpay.notifyUrl:https://api.nuttyreading.com/pay/payNotify # ?? url wxpay.refundNotifyUrl:http://pjm6m9.natappfree.cc/pay/refundNotify # key pem