From c54fb6a88876be994906d57d2d18e844686964d0 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 01 七月 2020 14:16:13 +0800
Subject: [PATCH] rcoketmq集中管理

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java |   86 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 80 insertions(+), 6 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
index cf9cb03..8649bee 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
@@ -18,16 +18,21 @@
 import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
 import com.yeshi.fanli.dto.msg.MsgRedPackUseContentDTO;
 import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
+import com.yeshi.fanli.entity.common.AdminUser;
+import com.yeshi.fanli.entity.common.Config;
 import com.yeshi.fanli.entity.redpack.RedPackDetail;
 import com.yeshi.fanli.entity.shop.BanLiShopGoods;
 import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
 import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets;
 import com.yeshi.fanli.entity.shop.BanLiShopOrder;
 import com.yeshi.fanli.entity.shop.ChargeTypeEnum;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.exception.redpack.RedPackBalanceException;
 import com.yeshi.fanli.exception.redpack.RedPackDetailException;
 import com.yeshi.fanli.exception.shop.BanLiShopOrderException;
 import com.yeshi.fanli.exception.shop.FuLuChargeException;
+import com.yeshi.fanli.service.AdminUserService;
+import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
 import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
 import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
@@ -36,9 +41,12 @@
 import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopOrderPayService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
+import com.yeshi.fanli.service.manger.msg.RocketMQManager;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.ThreadUtil;
 import com.yeshi.fanli.util.charge.FuLuChargeApiUtil;
+import com.yeshi.fanli.util.email.MailSenderUtil;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
 import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
 import com.yeshi.fanli.util.rocketmq.MQTopicName;
@@ -67,8 +75,14 @@
 	@Resource
 	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
 
-	@Resource(name = "producer")
-	private Producer producer;
+	@Resource
+	private ConfigService configService;
+
+	@Resource
+	private AdminUserService adminUserService;
+
+	@Resource
+	private RocketMQManager rocketMQManager;
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
@@ -119,7 +133,7 @@
 		}
 	}
 
-	@Transactional(rollbackFor=Exception.class)
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
 		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
@@ -162,9 +176,26 @@
 	 * 鏀粯鎴愬姛
 	 */
 	private void paySuccess(BanLiShopOrder order) {
+		ThreadUtil.run(new Runnable() {
+
+			@Override
+			public void run() {
+				long[] targetUids = new long[] { 3L, 4L };
+				Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey());
+				String[] sts = config.getValue().split(",");
+				String account = sts[0];
+				String pwd = sts[1];
+				for (long adminId : targetUids) {
+					AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId);
+					String msg = "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�";
+					boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "鏈夋柊鐨勭孩鍖呭晢鍩庤鍗�", msg);
+				}
+			}
+		});
+
 	}
 
-	@Transactional(rollbackFor=Exception.class)
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void refund(Long orderId) throws BanLiShopOrderException {
 		// 璁㈠崟閫�娆�
@@ -213,8 +244,7 @@
 					BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
 					Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
 							OrderTopicTagEnum.banLiShopOrderRefund, msg);
-					message.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60 * 5L);// 寤舵椂24灏忔椂閫氱煡妫�娴嬪井淇¢��娆剧姸鎬�
-					SendResult result = producer.send(message);
+					SendResult result = rocketMQManager.sendNormalMsg(message, 1000 * 60 * 5L,null);
 					if (result == null) {
 						throw new BanLiShopOrderException(8, "娑堟伅鍙戦�佸け璐�");
 					}
@@ -361,4 +391,48 @@
 		}
 	}
 
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void invalidOrderByOrderId(Long orderId, String stateDesc) throws BanLiShopOrderException {
+
+		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
+		if (order == null)
+			return;
+		// 閫�娆�
+		if (order.getState() == BanLiShopOrder.STATE_NO_PAY) {// 鐘舵�佽繕鏄湭鏀粯
+			// 閫�娆剧孩鍖�
+			if (order.getHongBaoPaymentState() != null
+					&& order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
+				BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
+				BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
+						.selectByPrimaryKey(goods.getGoodsClass().getId());
+				BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
+				// 绾㈠寘閫�娆�
+				RedPackDetail detail = null;
+				try {
+					detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
+							set.getName(), order.getHongBaoPayment());
+				} catch (RedPackDetailException e) {
+					e.printStackTrace();
+				}
+
+				if (detail == null)
+					throw new BanLiShopOrderException(4, "绾㈠寘璇︽儏澶辫触");
+				try {
+					redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
+				} catch (RedPackBalanceException e) {
+					throw new BanLiShopOrderException(5, "绾㈠寘閫�娆惧け璐�");
+				}
+
+				BanLiShopOrder update = new BanLiShopOrder(order.getId());
+				update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
+				update.setUpdateTime(new Date());
+				banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
+			}
+
+			banLiShopOrderService.invalidOrderByOrderId(orderId, stateDesc);
+		}
+
+	}
+
 }

--
Gitblit v1.8.0