From c76ad0e79b95c0bceed8a0234211f2c7f0168b14 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期二, 23 七月 2019 16:53:12 +0800
Subject: [PATCH] 推广红包-不在收回

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoOrderUtil.java |  112 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 68 insertions(+), 44 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoOrderUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoOrderUtil.java
index 56f34d3..15c0c57 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoOrderUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoOrderUtil.java
@@ -5,14 +5,13 @@
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
@@ -20,8 +19,8 @@
 import org.springframework.stereotype.Component;
 import org.yeshi.utils.HttpUtil;
 
+import com.yeshi.fanli.dto.order.OrderItem;
 import com.yeshi.fanli.entity.bus.user.Order;
-import com.yeshi.fanli.entity.bus.user.OrderItem;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.order.CommonOrder;
 import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
@@ -29,12 +28,6 @@
 import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
 import com.yeshi.fanli.exception.TaoBaoOrderException;
 import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
-import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
-import com.yeshi.fanli.service.inter.order.OrderItemServcie;
-import com.yeshi.fanli.service.inter.order.OrderService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
@@ -47,40 +40,10 @@
 @Component
 public class TaoBaoOrderUtil {
 
-	private final static String CACHENAME = "tbCookie";
-
 	private static final String ORDERFAILURE = "璁㈠崟澶辨晥";
 	private static final String ORDERPAYMENT = "璁㈠崟浠樻";
 	private static final String ORDERSETTLEMENT = "璁㈠崟缁撶畻";
 	private static final String ORDERSUCCESS = "璁㈠崟鎴愬姛";
-
-	@Resource
-	private OrderService orderService;
-	@Resource
-	private HongBaoService hongBaoService;
-	@Resource
-	private ConfigService configService;
-
-	@Resource
-	private OrderItemServcie orderItemServcie;
-
-	@Resource
-	private HongBaoManageService hongBaoManageService;
-
-	@Resource
-	private ThreeSaleSerivce threeSaleSerivce;
-
-	private static TaoBaoOrderUtil taoBaoOrderUtil;
-
-	@PostConstruct
-	public void init() {
-		taoBaoOrderUtil = this;
-		taoBaoOrderUtil.orderService = this.orderService;
-		taoBaoOrderUtil.hongBaoService = this.hongBaoService;
-		taoBaoOrderUtil.configService = this.configService;
-		taoBaoOrderUtil.hongBaoManageService = this.hongBaoManageService;
-		taoBaoOrderUtil.orderItemServcie = this.orderItemServcie;
-	}
 
 	/**
 	 * 鑾峰彇娣樺疂鑱旂洘鐨凜ookie
@@ -595,7 +558,6 @@
 
 	}
 
-
 	/**
 	 * 瑙f瀽缁存潈璁㈠崟
 	 * 
@@ -721,7 +683,65 @@
 			order.setOrderBy(map.get(order.getOrderId()).size() + 1);
 			map.get(order.getOrderId()).add(order);
 		}
+
+		// 璁㈠崟鎺掑簭鍊肩伆搴︽祴璇�
+		try {
+			for (Iterator<String> its = map.keySet().iterator(); its.hasNext();) {
+				String orderId = its.next();
+				try {
+					setOrderBy(map.get(orderId));
+				} catch (Exception e) {
+					LogHelper.errorDetailInfo(e, "璁㈠崟鍙�:" + orderId, "璁㈠崟鎺掑簭鍊肩伆搴︽祴璇�");
+				}
+			}
+		} catch (Exception e) {
+		}
+
 		return map;
+	}
+
+	public static void setOrderBy(List<TaoBaoOrder> orderList) {// 鎻愬彇涓�鏍风殑
+		if (orderList == null || orderList.size() == 1)
+			return;
+		int len = orderList.get(0).getTradeId().length();
+		int startIndex = 0;
+		for (int i = 0; i < len; i++) {
+			boolean isSame = true;
+			for (int j = 0; j < orderList.size() - 1; j++) {
+				if (orderList.get(j).getTradeId().charAt(i) != orderList.get(j + 1).getTradeId().charAt(i)) {
+					isSame = false;
+					break;
+				}
+			}
+			if (!isSame) {
+				startIndex = i;
+				break;
+			}
+		}
+		int endIndex = 0;
+
+		for (int i = len - 1; i >= 0; i--) {
+			boolean isSame = true;
+			for (int j = 0; j < orderList.size() - 1; j++) {
+				if (orderList.get(j).getTradeId().charAt(i) != orderList.get(j + 1).getTradeId().charAt(i)) {
+					isSame = false;
+					break;
+				}
+			}
+			if (!isSame) {
+				endIndex = i;
+				break;
+			}
+		}
+		for (TaoBaoOrder taoBaoOrder : orderList) {
+			String tradeId = taoBaoOrder.getTradeId();
+			String orderByStr = tradeId.substring(startIndex, endIndex + 1);
+			if (orderByStr.length() > 8) {
+				LogHelper.error("璁㈠崟鐨刼rderBy瓒呰繃8浣�:" + taoBaoOrder.getOrderBy());
+			}
+			int orderBy = Integer.parseInt(orderByStr);
+			// taoBaoOrder.setOrderBy(orderBy);
+		}
 	}
 
 	/**
@@ -750,7 +770,10 @@
 		CommonOrder commonOrder = new CommonOrder();
 		commonOrder.setCount(taoBaoOrder.getCount());
 		commonOrder.setCreateTime(new Date());
-		commonOrder.seteIncome(taoBaoOrder.geteIncome());
+		if (taoBaoOrder.geteIncome() != null && taoBaoOrder.getSubsidy() != null)
+			commonOrder.seteIncome(taoBaoOrder.geteIncome().add(taoBaoOrder.getSubsidy()));
+		else
+			commonOrder.seteIncome(taoBaoOrder.geteIncome());
 		commonOrder.setEstimate(taoBaoOrder.getEstimate());
 		commonOrder.setOrderNo(taoBaoOrder.getOrderId());
 		commonOrder.setPayment(taoBaoOrder.getPayment());
@@ -758,8 +781,8 @@
 		if (!StringUtil.isNullOrEmpty(taoBaoOrder.getSettlementTime()))
 			commonOrder.setSettleTime(
 					new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getSettlementTime(), "yyyy-MM-dd HH:mm:ss")));
-		commonOrder.setSourcePosition(
-				String.format("mm_%s_%s_%s", "124933865", taoBaoOrder.getSourceMediaId(), taoBaoOrder.getAdPositionId()));
+		commonOrder.setSourcePosition(String.format("mm_%s_%s_%s", "124933865", taoBaoOrder.getSourceMediaId(),
+				taoBaoOrder.getAdPositionId()));
 		commonOrder.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
 		int state = 0;
 		if ("璁㈠崟浠樻".equalsIgnoreCase(taoBaoOrder.getOrderState())) {
@@ -776,6 +799,7 @@
 		commonOrder.setThirdCreateTime(
 				new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
 		commonOrder.setUpdateTime(new Date());
+		commonOrder.setTradeId(taoBaoOrder.getTradeId());
 
 		return commonOrder;
 

--
Gitblit v1.8.0