From 3e4ef41ffacd7f5fda2e81c3810cd11a6375b83c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 15 六月 2020 16:32:35 +0800
Subject: [PATCH] 好单库转链支持

---
 fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java |   74 +++++++++++++++++++++++++++++++-----
 1 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java b/fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java
index 0642586..1f941c8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java
@@ -1,10 +1,13 @@
 package com.yeshi.fanli.service.manger.goods;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.annotation.Resource;
 
@@ -12,6 +15,7 @@
 import org.yeshi.utils.StringUtil;
 
 import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
+import com.yeshi.fanli.dto.taobao.api.TaoKeOfficialActivityConvertResultDTO;
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
 import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
 import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException;
@@ -25,6 +29,7 @@
 import com.yeshi.fanli.util.jd.JDUtil;
 import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
 import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
+import com.yeshi.fanli.util.taobao.HaoDanKuApiUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
@@ -122,6 +127,22 @@
 		return newText;
 	}
 
+	// 鑾峰彇娣樺疂瀹樻柟娲诲姩ID鍐呭
+	public List<String> getTaoBaoOfficialActivityId(String text) {
+
+		// {娣樺疂娲诲姩:13123123}
+		String regex = "(\\{\u6dd8\u5b9d\u6d3b\u52a8\\:){1}+[0-9]{5,20}\\}{1}";
+		Pattern pattern = Pattern.compile(regex);
+		Matcher m = pattern.matcher(text);
+		List<String> urlList = new ArrayList<>();
+		while (m.find()) {
+			urlList.add(m.group());
+		}
+
+		return urlList;
+
+	}
+
 	/**
 	 * 
 	 * @Title: convertTBLinkFromText @Description: 杞摼鏂囨湰涓殑娣樺彛浠� @param text @param
@@ -131,6 +152,8 @@
 
 		StringBuilder builder = new StringBuilder(text);
 		String newText = builder.toString();
+
+		// 瑙f瀽娣樺彛浠�
 		List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
 		if (tokenList != null && tokenList.size() > 0) {
 
@@ -152,16 +175,18 @@
 					throw new Exception("鍟嗗搧淇℃伅鑾峰彇澶辫触");
 				String link = null;
 				if (share) {
-					TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId,
-							new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
-									TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT));
-					if (goods == null)
-						throw new Exception("鍟嗗搧杞摼澶辫触");
-
-					link = goods.getCouponLink();
-					if (StringUtil.isNullOrEmpty(link)) {
-						link = goods.getAuctionUrl();
-					}
+					//鏆傛椂璋冪敤濂藉崟搴揂PI
+					 link=HaoDanKuApiUtil.getInstance().convertLink(auctionId, TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT, null);
+//					TaoBaoGoodsBrief goods =  TaoKeApiUtil.specialConvertCoupon(auctionId,
+//							new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
+//									TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT));
+//					if (goods == null)
+//						throw new Exception("鍟嗗搧杞摼澶辫触");
+//
+//					link = goods.getCouponLink();
+//					if (StringUtil.isNullOrEmpty(link)) {
+//						link = goods.getAuctionUrl();
+//					}
 					if (StringUtil.isNullOrEmpty(link))
 						throw new Exception("鍟嗗搧杞摼澶辫触");
 					link += "&relationId=" + relationId;
@@ -215,6 +240,33 @@
 				newText = newText.replace(token, tokenMap.get(token));
 			}
 		}
+
+		// 瑙f瀽娣樺疂瀹樻柟娲诲姩ID
+		List<String> list = getTaoBaoOfficialActivityId(newText);
+		if (list.size() > 0) {
+			String relationId = null;
+			if (share) {
+				relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid);
+				if (StringUtil.isNullOrEmpty(relationId))
+					throw new Exception("娣樺疂鏈巿鏉�");
+			}
+			for (String st : list) {
+				String activityid = st.replace("{娣樺疂娲诲姩:", "").replace("}", "");
+				if (!StringUtil.isNullOrEmpty(activityid)) {
+					String adzoneId = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3];
+					TaoKeOfficialActivityConvertResultDTO dto = TaoKeApiUtil.officialActivityConvert(adzoneId,
+							activityid, relationId);
+					String link = dto.getShort_click_url();
+					if (StringUtil.isNullOrEmpty(link)) {
+						link = dto.getClick_url();
+					}
+
+					String token = TaoKeApiUtil.getTKToken("http://", "娣樺疂瀹樻柟娲诲姩", link);
+					newText = newText.replace(st, TaoBaoUtil.filterTaoToken(token));
+				}
+			}
+		}
+
 		return newText;
 	}
 
@@ -226,7 +278,7 @@
 	public String convertLinkFromText(String text, Long uid, boolean share)
 			throws ConvertLinkExceptionException, Exception {
 		String newText = convertJDLinkFromText(text, uid, share);
-		newText = convertPDDLinkFromText(text, uid, share);
+		newText = convertPDDLinkFromText(newText, uid, share);
 		newText = convertTBLinkFromText(newText, uid, share);
 		if (text.equalsIgnoreCase(newText))
 			throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "涓嶅寘鍚彲杞摼鐨勫彛浠や笌閾炬帴");

--
Gitblit v1.8.0