【代码优化】SYSTEM:微信小程序的订阅

This commit is contained in:
YunaiV 2024-07-30 23:12:06 +08:00
parent 9058c152d8
commit 7782b36f90
7 changed files with 24 additions and 13 deletions

View File

@ -66,7 +66,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
private ProductSkuApi productSkuApi; private ProductSkuApi productSkuApi;
@Resource @Resource
@Lazy @Lazy // 延迟加载避免循环依赖
private TradeOrderApi tradeOrderApi; private TradeOrderApi tradeOrderApi;
// TODO @芋艿在详细预览下 // TODO @芋艿在详细预览下

View File

@ -33,6 +33,7 @@ import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronization;
@ -56,6 +57,7 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
public class AfterSaleServiceImpl implements AfterSaleService { public class AfterSaleServiceImpl implements AfterSaleService {
@Resource @Resource
@Lazy // 延迟加载避免循环依赖
private TradeOrderUpdateService tradeOrderUpdateService; private TradeOrderUpdateService tradeOrderUpdateService;
@Resource @Resource
private TradeOrderQueryService tradeOrderQueryService; private TradeOrderQueryService tradeOrderQueryService;

View File

@ -83,8 +83,6 @@ import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.DELIV
@Slf4j @Slf4j
public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
public static final String ORDER_DETAIL_PATH = "pages/order/detail"; // 订单详情页
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@Resource @Resource
@ -373,6 +371,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
MapUtil.<String, Object>builder().put("expressName", express != null ? express.getName() : "") MapUtil.<String, Object>builder().put("expressName", express != null ? express.getName() : "")
.put("logisticsNo", express != null ? deliveryReqVO.getLogisticsNo() : "").build()); .put("logisticsNo", express != null ? deliveryReqVO.getLogisticsNo() : "").build());
// TODO @puhui999可以改成 4.1 4.2因为都算通知哈
// 4. 发送站内信 // 4. 发送站内信
tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO() tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO()
.setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null)); .setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null));
@ -384,8 +383,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
public void sendDeliveryOrderMessage(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) { public void sendDeliveryOrderMessage(TradeOrderDO order, TradeOrderDeliveryReqVO deliveryReqVO) {
// 构建并发送模版消息 // 构建并发送模版消息
Long orderId = order.getId(); Long orderId = order.getId();
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(ORDER_DETAIL_PATH + "?id=" + orderId) socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO()
.setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()).setTemplateTitle(DELIVERY_ORDER) .setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue())
.setTemplateTitle(DELIVERY_ORDER)
.setPage("pages/order/detail?id=" + orderId) // 订单详情页
.addMessage("character_string3", String.valueOf(orderId)) // 订单编号 .addMessage("character_string3", String.valueOf(orderId)) // 订单编号
.addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态 .addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态
.addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间 .addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间

View File

@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -28,11 +29,13 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_DELIV
public class TradeCombinationOrderHandler implements TradeOrderHandler { public class TradeCombinationOrderHandler implements TradeOrderHandler {
@Resource @Resource
@Lazy // 延迟加载避免循环依赖
private TradeOrderUpdateService orderUpdateService; private TradeOrderUpdateService orderUpdateService;
@Resource @Resource
private TradeOrderQueryService orderQueryService; private TradeOrderQueryService orderQueryService;
@Resource @Resource
@Lazy // 延迟加载避免循环依赖
private CombinationRecordApi combinationRecordApi; private CombinationRecordApi combinationRecordApi;
@Override @Override

View File

@ -10,6 +10,7 @@ public interface MessageTemplateConstants {
//======================= 小程序订阅消息 ======================= //======================= 小程序订阅消息 =======================
String WALLET_RECHARGER_PAID = "充值成功通知"; String WALLET_RECHARGER_PAID = "充值成功通知";
// TODO @puhui999这个放在售后那aftersale
String WALLET_RECHARGE_REFUNDED = "退款申请通知"; String WALLET_RECHARGE_REFUNDED = "退款申请通知";
} }

View File

@ -59,8 +59,6 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
private static final String WALLET_RECHARGE_ORDER_SUBJECT = "钱包余额充值"; private static final String WALLET_RECHARGE_ORDER_SUBJECT = "钱包余额充值";
public static final String WALLET_MONEY_PATH = "pages/user/wallet/money"; // 钱包详情页
@Resource @Resource
private PayWalletRechargeMapper walletRechargeMapper; private PayWalletRechargeMapper walletRechargeMapper;
@Resource @Resource
@ -148,8 +146,10 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
// 1. 获得会员钱包信息 // 1. 获得会员钱包信息
PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId()); PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId());
// 2. 构建并发送模版消息 // 2. 构建并发送模版消息
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO()
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGER_PAID) .setUserId(wallet.getUserId()).setUserType(wallet.getUserType())
.setTemplateTitle(WALLET_RECHARGER_PAID)
.setPage("pages/user/wallet/money") // 钱包详情界面
.addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号 .addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号
.addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额 .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额
.addMessage("time3", LocalDateTimeUtil.formatNormal(walletRecharge.getCreateTime())) // 充值时间 .addMessage("time3", LocalDateTimeUtil.formatNormal(walletRecharge.getCreateTime())) // 充值时间
@ -229,8 +229,10 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
PayWalletDO wallet = payWalletService.getWallet(walletId); PayWalletDO wallet = payWalletService.getWallet(walletId);
// 2. 构建并发送模版消息 // 2. 构建并发送模版消息
String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName(); String thing8 = PayRefundStatusEnum.isSuccess(payRefund.getStatus()) ? SUCCESS.getName() : FAILURE.getName();
socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO().setPage(WALLET_MONEY_PATH) socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO()
.setUserId(wallet.getUserId()).setUserType(wallet.getUserType()).setTemplateTitle(WALLET_RECHARGE_REFUNDED) .setUserId(wallet.getUserId()).setUserType(wallet.getUserType())
.setTemplateTitle(WALLET_RECHARGE_REFUNDED)
.setPage("pages/user/wallet/money") // 钱包详情界面
.addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号 .addMessage("character_string1", String.valueOf(payRefund.getId())) // 退款订单编号
.addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间 .addMessage("time7", LocalDateTimeUtil.formatNormal(payRefund.getCreateTime())) // 申请时间
.addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额 .addMessage("amount3", fenToYuanStr(payRefund.getRefundPrice())) // 退款金额

View File

@ -195,10 +195,12 @@ wx:
miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档
# appid: wx62056c0d5e8db250 # 测试号(牛希尧提供的) # appid: wx62056c0d5e8db250 # 测试号(牛希尧提供的)
# secret: 333ae72f41552af1e998fe1f54e1584a # secret: 333ae72f41552af1e998fe1f54e1584a
appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 # appid: wx63c280fe3248a3e7 # wenhualian的接口测试号
secret: 6f270509224a7ae1296bbf1c8cb97aed # secret: 6f270509224a7ae1296bbf1c8cb97aed
# appid: wxc4598c446f8a9cb3 # 测试号Kongdy 提供的) # appid: wxc4598c446f8a9cb3 # 测试号Kongdy 提供的)
# secret: 4a1a04e07f6a4a0751b39c3064a92c8b # secret: 4a1a04e07f6a4a0751b39c3064a92c8b
appid: wx66186af0759f47c9 # 测试号puhui 提供的)
secret: 3218bcbd112cbc614c7264ceb20144ac
config-storage: config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis会自动从 Spring 中获取 type: RedisTemplate # 采用 RedisTemplate 操作 Redis会自动从 Spring 中获取
key-prefix: wa # Redis Key 的前缀 key-prefix: wa # Redis Key 的前缀