From 457265eb82265650cf6c87519803975f23bd2fd3 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 13 四月 2020 18:33:21 +0800
Subject: [PATCH] 订单统计与返利到账集成测试相关的bug修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java |   79 +++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
index 6d7a272..daa1f7a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -29,6 +29,7 @@
 import com.yeshi.fanli.dto.HongBao;
 import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
 import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
+import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
 import com.yeshi.fanli.entity.bus.user.HongBaoV2;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.money.TeamRewardDebt;
@@ -52,7 +53,6 @@
 import com.yeshi.fanli.service.inter.order.CommonOrderService;
 import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
 import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
-import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
 import com.yeshi.fanli.service.manger.order.TeamRewardManager;
 import com.yeshi.fanli.service.manger.order.TeamSubsidyManager;
 import com.yeshi.fanli.util.Constant;
@@ -123,7 +123,7 @@
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
-	public void inviteSettleTB(Long uid) throws OrderMoneySettleException {
+	public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
 		// 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
 		int sourceType = Constant.SOURCE_TYPE_TAOBAO;
 		List<Integer> types = new ArrayList<>();
@@ -131,13 +131,13 @@
 		types.add(HongBaoV2.TYPE_ERJI);
 		types.add(HongBaoV2.TYPE_SHARE_YIJI);
 		types.add(HongBaoV2.TYPE_SHARE_ERJI);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -161,12 +161,13 @@
 			}
 		}
 
-		// 閭�璇疯禋鍒拌处浜嬪姟娑堟伅
-		OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
-				sourceType, null, null, new Date(), 0);
+		String taskKey = getTaskKey(uid);
+
+		TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
+				new Date());
 
 		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
-		String taskKey = getTaskKey(uid);
+
 		msg.setKey(taskKey);
 		// 娣诲姞浜嬪姟娑堟伅
 		try {
@@ -174,14 +175,16 @@
 				@Override
 				public TransactionStatus execute(Message arg0, Object arg1) {
 					try {
-						fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey);
+						fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey, maxPregetTime);
 					} catch (Exception e) {
+						e.printStackTrace();
 						return TransactionStatus.RollbackTransaction;
 					}
 					return TransactionStatus.CommitTransaction;
 				}
 			}, null);
 		} catch (Exception e) {
+			e.printStackTrace();
 			LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
 		}
 		System.out.println(new Gson().toJson(mqMsg));
@@ -189,7 +192,7 @@
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
-	public void inviteSettleJD(Long uid) throws OrderMoneySettleException {
+	public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
 		// 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
 		int sourceType = Constant.SOURCE_TYPE_JD;
 		List<Integer> types = new ArrayList<>();
@@ -197,13 +200,13 @@
 		types.add(HongBaoV2.TYPE_ERJI);
 		types.add(HongBaoV2.TYPE_SHARE_YIJI);
 		types.add(HongBaoV2.TYPE_SHARE_ERJI);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -228,10 +231,11 @@
 		}
 
 		// 閭�璇疯禋鍒拌处浜嬪姟娑堟伅
-		OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
-				sourceType, null, null, new Date(), 0);
-		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
+
 		String taskKey = getTaskKey(uid);
+		TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
+				new Date());
+		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
 		msg.setKey(taskKey);
 		// 娣诲姞浜嬪姟娑堟伅
 		try {
@@ -239,7 +243,7 @@
 				@Override
 				public TransactionStatus execute(Message arg0, Object arg1) {
 					try {
-						fanliInvite(hongBaoList, uid, sourceType, taskKey);
+						fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
 					} catch (Exception e) {
 						e.printStackTrace();
 						return TransactionStatus.RollbackTransaction;
@@ -254,7 +258,7 @@
 
 	@Transactional(rollbackFor = Exception.class)
 	@Override
-	public void inviteSettlePDD(Long uid) throws OrderMoneySettleException {
+	public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
 		// 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
 		int sourceType = Constant.SOURCE_TYPE_PDD;
 		List<Integer> types = new ArrayList<>();
@@ -262,13 +266,13 @@
 		types.add(HongBaoV2.TYPE_ERJI);
 		types.add(HongBaoV2.TYPE_SHARE_YIJI);
 		types.add(HongBaoV2.TYPE_SHARE_ERJI);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -293,10 +297,10 @@
 		}
 
 		// 閭�璇疯禋鍒拌处浜嬪姟娑堟伅
-		OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
-				sourceType, null, null, new Date(), 0);
-		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
 		String taskKey = getTaskKey(uid);
+		TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
+				new Date());
+		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
 		msg.setKey(taskKey);
 		// 娣诲姞浜嬪姟娑堟伅
 		try {
@@ -304,7 +308,7 @@
 				@Override
 				public TransactionStatus execute(Message arg0, Object arg1) {
 					try {
-						fanliInvite(hongBaoList, uid, sourceType, taskKey);
+						fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
 					} catch (Exception e) {
 						return TransactionStatus.RollbackTransaction;
 					}
@@ -319,6 +323,7 @@
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void shareSettleTB(Long uid) throws OrderMoneySettleException {
+		Date maxPregetTime = new Date();
 		/**
 		 * 澶勭悊鍒嗕韩璧�
 		 */
@@ -327,13 +332,13 @@
 
 		// 鏌ヨUID鐨勫垎浜禋璁㈠崟
 		types.add(HongBaoV2.TYPE_SHARE_GOODS);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -365,6 +370,7 @@
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void shareSettleJD(Long uid) throws OrderMoneySettleException {
+		Date maxPregetTime = new Date();
 		/**
 		 * 澶勭悊鍒嗕韩璧�
 		 */
@@ -373,13 +379,13 @@
 
 		// 鏌ヨUID鐨勫垎浜禋璁㈠崟
 		types.add(HongBaoV2.TYPE_SHARE_GOODS);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -406,6 +412,7 @@
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void shareSettlePDD(Long uid) throws OrderMoneySettleException {
+		Date maxPregetTime = new Date();
 		/**
 		 * 澶勭悊鍒嗕韩璧�
 		 */
@@ -414,13 +421,13 @@
 
 		// 鏌ヨUID鐨勫垎浜禋璁㈠崟
 		types.add(HongBaoV2.TYPE_SHARE_GOODS);
-		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
+		long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
 		List<HongBaoV2> hongBaoList = new ArrayList<>();
 		// 1000鏉℃暟鎹负1椤�
 		int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
 		for (int i = 0; i < page; i++) {
 			List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
-					i * 1000, 1000);
+					maxPregetTime, i * 1000, 1000);
 			if (tempHongBaoList != null && tempHongBaoList.size() > 0)
 				hongBaoList.addAll(tempHongBaoList);
 		}
@@ -592,7 +599,7 @@
 	}
 
 	@Transactional
-	private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key)
+	private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime)
 			throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException {
 		List<Long> hbIdList = new ArrayList<>();
 		BigDecimal invitemoney = new BigDecimal(0);
@@ -633,11 +640,8 @@
 
 		// 閭�璇疯禋鍒拌处
 		if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
-			Calendar ca = Calendar.getInstance();
-			Date date = new Date(TimeUtil.convertToTimeTemp(
-					ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
 			// 鑾峰彇褰撳墠鐨勬湀浠�
-			teamRewardManager.addToEincome(uid, date, invitemoney, sourceType);
+			teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType);
 		}
 
 		hongBaoV2SettleTempService.addTemp(hbIdList, key);
@@ -645,7 +649,8 @@
 		// 鎵�鏈夌殑杩斿埄鍒拌处绾㈠寘ID
 		for (Long hongBaoId : hbIdList) {
 			try {
-				HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
+				if (Constant.ENABLE_MQ)
+					HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
 			} catch (Exception e) {
 				LogHelper.errorDetailInfo(e);
 			}
@@ -863,9 +868,9 @@
 	 */
 	@Transactional(rollbackFor = Exception.class)
 	@Override
-	public void inviteSubsidySettle(Long uid, String taskKey)
+	public void inviteSubsidySettle(Long uid, String taskKey,Date maxPreGetTime)
 			throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
-		teamSubsidyManager.addToTeamEincome(uid, taskKey);
+		teamSubsidyManager.addToTeamEincome(uid, taskKey,maxPreGetTime);
 	}
 
 	private String getTaskKey(Long uid) {

--
Gitblit v1.8.0