From 6fdcc0c26dd33e87a024a69ed635d9aedb59cad6 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 07 一月 2020 12:02:50 +0800
Subject: [PATCH] 订单搜索引擎增量更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java |   60 +++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 39 insertions(+), 21 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 3a5bd18..cf9cb03 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
@@ -16,6 +16,8 @@
 import com.google.gson.Gson;
 import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
 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.redpack.RedPackDetail;
 import com.yeshi.fanli.entity.shop.BanLiShopGoods;
 import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
@@ -26,6 +28,7 @@
 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.inter.money.msg.UserMoneyMsgNotificationService;
 import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
 import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
@@ -37,6 +40,7 @@
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.charge.FuLuChargeApiUtil;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
+import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
 import com.yeshi.fanli.util.rocketmq.MQTopicName;
 import com.yeshi.fanli.util.wx.BanLiShopWXPayUtil;
 
@@ -60,10 +64,13 @@
 	@Resource
 	private RedPackDetailService redPackDetailService;
 
+	@Resource
+	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+
 	@Resource(name = "producer")
 	private Producer producer;
 
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
 		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
@@ -112,7 +119,7 @@
 		}
 	}
 
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	@Override
 	public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
 		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
@@ -155,21 +162,9 @@
 	 * 鏀粯鎴愬姛
 	 */
 	private void paySuccess(BanLiShopOrder order) {
-		// 灏嗙孩鍖呮槑缁嗗鏄�
-		RedPackDetail detail = null;
-		try {
-			detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
-					order.getHongBaoPayment());
-		} catch (RedPackDetailException e) {
-			e.printStackTrace();
-		}
-
-		if (detail != null) {
-			redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true);
-		}
 	}
 
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	@Override
 	public void refund(Long orderId) throws BanLiShopOrderException {
 		// 璁㈠崟閫�娆�
@@ -216,8 +211,8 @@
 					order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
 					// 鍙戦�侀��娆炬秷鎭�
 					BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
-					Message message = new Message(MQTopicName.TOPIC_ORDER.name(),
-							OrderTopicTagEnum.banLiShopOrderRefund.name(), new Gson().toJson(msg).getBytes());
+					Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
+							OrderTopicTagEnum.banLiShopOrderRefund, msg);
 					message.setStartDeliverTime(System.currentTimeMillis() + 1000 * 60 * 5L);// 寤舵椂24灏忔椂閫氱煡妫�娴嬪井淇¢��娆剧姸鎬�
 					SendResult result = producer.send(message);
 					if (result == null) {
@@ -229,10 +224,9 @@
 				throw new BanLiShopOrderException(6, "寰俊鏀粯閫�娆惧け璐�");
 			}
 		}
-
 		// 妫�鏌� 鏄惁閫�娆炬垚鍔�
-		if (update.getMoneyPaymentState() != null
-				&& update.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) {
+		if (order.getMoneyPaymentState() != null
+				&& order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) {
 			try {
 				boolean isS = BanLiShopWXPayUtil.isRefundSuccess(order.getOrderNo());
 				if (isS) {
@@ -293,7 +287,7 @@
 		}
 	}
 
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void charge(Long orderId) throws BanLiShopOrderException {
 		BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKey(orderId);
@@ -331,6 +325,30 @@
 		update.setSuccessTime(new Date());
 		banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
 
+		if (order.getHongBaoPayment() != null && order.getHongBaoPayment().compareTo(new BigDecimal(0)) > 0) {
+			// 灏嗙孩鍖呮槑缁嗗鏄�
+			RedPackDetail detail = null;
+			try {
+				detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
+						order.getHongBaoPayment());
+			} catch (RedPackDetailException e) {
+				e.printStackTrace();
+			}
+
+			if (detail != null) {
+				redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true);
+			}
+		}
+
+		// 娑堟伅鍙戦��
+		MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO();
+		dto.setGoodsSetName(order.getOrderGoods().getSetName());
+		dto.setHongBao(order.getHongBaoPayment());
+		dto.setMoney(order.getMoneyPayment());
+		dto.setTime(new Date());
+		userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseSuccess,
+				new Gson().toJson(dto), null);
+
 		try {
 			if (Constant.IS_TEST) {
 				FuLuChargeApiUtil.shaXiangCharge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),

--
Gitblit v1.8.0