From d28bed1a1275131a5ca37f7da37961e2b518ac07 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 26 八月 2019 13:44:00 +0800
Subject: [PATCH] 淘礼金创建异常处理

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 103 insertions(+), 15 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
index df59aaf..033ec71 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -16,7 +16,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.yeshi.utils.NumberUtil;
 
+import com.google.gson.Gson;
 import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
 import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
 import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
@@ -227,8 +229,9 @@
 
 	@Override
 	public void fanli() {
+		LogHelper.test("澶勭悊杩斿埄鍒拌处");
 		// 鑾峰彇涓荤孩鍖�
-		List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBao.TYPE_TAOBAO, 1000);
+		List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBaoV2.TYPE_ZIGOU, 1000);
 		//
 		// /**
 		// * 闇�瑕佸疄鏃舵洿鏂板緟杩斿埄鐨勮鍗�
@@ -292,10 +295,22 @@
 	public void fanli(HongBaoV2 hb1) throws TaoBaoWeiQuanException {
 		// 鏌ヨ鏈�鏂扮殑绾㈠寘鏁版嵁
 		hb1 = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb1.getId());
+		// 姝e父鐢ㄦ埛鎵嶈兘鍒拌处
+		UserInfo mainUser = userInfoMapper.selectByPrimaryKey(hb1.getUserInfo().getId());
+		if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) {
+			return;
+		}
 		// 鏌ヨ绾㈠寘鐩稿叧鑱旂殑璁㈠崟
 		HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb1.getId());
 		if (hongBaoOrder == null) {
 			LogHelper.error("杩斿埄澶辫触:" + hb1.getId());
+			return;
+		}
+
+		// 鐏板害娴嬭瘯涓紝浜笢/鎷煎澶氫笉杩斿埄
+		if (hongBaoOrder.getCommonOrder() == null
+				|| hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_JD
+				|| hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_PDD) {
 			return;
 		}
 
@@ -419,10 +434,12 @@
 					if (olist != null && olist.size() > 0) {
 						long time = TimeUtil.convertToTimeTemp(olist.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss");
 						olist = TaoKeOrderApiUtil.getTaoBaoAllOrder(TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"),
-								TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+								TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
+								TaoKeOrderApiUtil.TK_STATUS_ALL);
 						List<TaoBaoOrder> thirdOList = TaoKeOrderApiUtil.getTaoBaoThirdAllOrder(
 								TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"), 30, 1,
-								TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+								TaoKeOrderApiUtil.TK_STATUS_ALL, TaoBaoConstant.TAOBAO_AUTH_APPKEY,
+								TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
 						if (thirdOList != null && thirdOList.size() > 0)
 							olist.addAll(thirdOList);
 
@@ -449,8 +466,12 @@
 	public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) {
 		if (orderList != null)
 			for (TaoBaoWeiQuanOrder order : orderList) {
-				if (order.getState().contains("缁存潈鎴愬姛")) {
-					CMQManager.getInstance().addWeiQuanOrderMsg(order);
+				try {
+					if (order.getState().contains("缁存潈鎴愬姛")) {
+						CMQManager.getInstance().addWeiQuanOrderMsg(order);
+					}
+				} catch (Exception e) {
+					LogHelper.error("缁存潈璁㈠崟鍔犲叆鍒伴槦鍒楀嚭閿�:" + order != null ? new Gson().toJson(order) : null);
 				}
 			}
 	}
@@ -553,7 +574,41 @@
 		List<Integer> types = new ArrayList<>();
 		types.add(HongBaoV2.TYPE_YIJI);
 		types.add(HongBaoV2.TYPE_ERJI);
-		List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 1000);
+		long count=	hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid);
+		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, i*1000,1000);
+			if(tempHongBaoList!=null&&tempHongBaoList.size()>0)
+				hongBaoList.addAll(tempHongBaoList);
+		}
+		// 鐏板害娴嬭瘯涓紝浜笢/鎷煎澶氳鍗曞垎浜�/閭�璇疯鍗曚笉杩斿埄
+		for (int i = 0; i < hongBaoList.size(); i++) {
+			HongBaoV2 item = hongBaoList.get(i);
+			if (item.getType() == HongBaoV2.TYPE_SHARE_GOODS) {
+			} else {
+				item = item.getParent();
+			}
+			if (item != null) {
+				HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(item.getId());
+				if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
+					CommonOrder co = hongBaoOrder.getCommonOrder();
+					if (co.getSourceType() == Constant.SOURCE_TYPE_JD
+							|| co.getSourceType() == Constant.SOURCE_TYPE_PDD) {
+						hongBaoList.remove(i);
+						i--;
+					} else {// 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处
+						UserInfo userInfo = userInfoMapper.selectByPrimaryKey(co.getUserInfo().getId());
+						if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
+							hongBaoList.remove(i);
+							i--;
+						}
+					}
+				}
+			}
+		}
 
 		List<Long> hbIdList = new ArrayList<>();
 
@@ -605,7 +660,8 @@
 		types.clear();
 		types.add(HongBaoV2.TYPE_SHARE_YIJI);
 		types.add(HongBaoV2.TYPE_SHARE_ERJI);
-		List<HongBaoV2> hbList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 10000);
+		//TODO 闇�瑕佸鐞嗚秴杩�1w鏉℃暟鎹殑璁㈠崟
+		List<HongBaoV2> hbList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid,0, 10000);
 
 		if (hbList != null && hbList.size() > 0)
 			totalHongBaoList.addAll(hbList);
@@ -689,7 +745,8 @@
 		// 鏌ヨUID鐨勫垎浜禋璁㈠崟
 		types.clear();
 		types.add(HongBaoV2.TYPE_SHARE_GOODS);
-		List<HongBaoV2> hongBaoShareList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 10000);
+		//TODO 闇�瑕佸鐞嗚秴杩�10000鏉℃暟鎹殑璁㈠崟
+		List<HongBaoV2> hongBaoShareList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid,0, 10000);
 		for (HongBaoV2 hongBao : hongBaoShareList) {
 			hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
 			hongBao = filterWeiQuanINGHongBao(hongBao);
@@ -736,9 +793,12 @@
 
 				Date minDate = new Date(TimeUtil
 						.convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
-				long validCount =  hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS, minDate, maxDate);
-				long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ, minDate, maxDate);
-				long invalidCount =hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_SX, minDate, maxDate);
+				long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
+						minDate, maxDate);
+				long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
+						minDate, maxDate);
+				long invalidCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_SX,
+						minDate, maxDate);
 
 				UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
 						(int) validCount, (int) weiQuanCount, (int) invalidCount, sharemoney, new Date());
@@ -931,9 +991,14 @@
 	public void processJDOrder(JDOrder order) {
 		if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0)
 			return;
+
+		// 鎷嗗崟鐨勪笉鍋氬鐞�
+		if (order.getValidCode() == 2)
+			return;
+
 		String uidStr = order.getExt1();
 		Long uid = null;
-		if (!StringUtil.isNullOrEmpty(uidStr))
+		if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr))
 			uid = Long.parseLong(uidStr);
 		Long positionId = order.getOrderItemList().get(0).getPositionId();
 		if (positionId == JDApiUtil.POSITION_FANLI)// 杩斿埄璁㈠崟
@@ -951,6 +1016,7 @@
 
 	/**
 	 * 澶勭悊浜笢杩斿埄璁㈠崟
+	 * 
 	 * @param jdOrder
 	 * @param uid
 	 */
@@ -975,7 +1041,7 @@
 		// 鍔犲叆璁㈠崟
 		Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(jdOrder.getOrderId() + "",
 				Constant.SOURCE_TYPE_JD);
-		if (uid == null && oldOrder.getBeizhu().contains("琛ュ崟"))
+		if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("琛ュ崟"))
 			uid = oldOrder.getUserInfo().getId();
 
 		if (uid == null)
@@ -1023,6 +1089,7 @@
 
 	/**
 	 * 澶勭悊浜笢鍒嗕韩璁㈠崟
+	 * 
 	 * @param order
 	 * @param uid
 	 */
@@ -1073,6 +1140,7 @@
 
 	/**
 	 * 澶勭悊鎷煎澶氳嚜璐繑鍒╄鍗�
+	 * 
 	 * @param pddOrder
 	 * @param uid
 	 */
@@ -1088,7 +1156,7 @@
 
 		// 鍔犲叆璁㈠崟
 		Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD);
-		if (uid == null && oldOrder.getBeizhu().contains("琛ュ崟"))
+		if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("琛ュ崟"))
 			uid = oldOrder.getUserInfo().getId();
 
 		if (uid == null)
@@ -1135,9 +1203,9 @@
 		}
 	}
 
-	
 	/**
 	 * 澶勭悊鎷煎澶氬垎浜鍗�
+	 * 
 	 * @param order
 	 * @param uid
 	 */
@@ -1162,4 +1230,24 @@
 			}
 		}
 	}
+
+	@Override
+	public void repairCommonOrderByByTaoBaoOrder(String orderId) {
+		// 鏍规嵁璁㈠崟鍙锋煡璇㈡窐瀹濊鍗�
+		List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
+		if (orderList != null)
+			for (TaoBaoOrder order : orderList) {
+				// 鏍规嵁浜ゆ槗ID鏌ヨ甯歌璁㈠崟
+				CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
+						order.getTradeId());
+				// 淇orderby
+				if (commonOrder != null) {
+					CommonOrder update = new CommonOrder(commonOrder.getId());
+					update.setOrderBy(order.getOrderBy());
+					update.setUpdateTime(new Date());
+					commonOrderService.updateByPrimaryKeySelective(update);
+				}
+			}
+
+	}
 }

--
Gitblit v1.8.0