admin
2020-03-01 ec8a1c6f81b5747e9efce86faaba33d10df7f61d
fanli/src/main/java/com/yeshi/fanli/service/manger/goods/ConvertLinkManager.java
@@ -13,8 +13,12 @@
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.goods.ConvertLinkExceptionException;
import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.manger.goods.tb.TaoBaoTokenAuctionIdMapManager;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.jd.JDApiUtil;
import com.yeshi.fanli.util.jd.JDUtil;
@@ -36,20 +40,19 @@
   @Resource
   private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
   @Resource
   private RedisManager redisManager;
   @Resource
   private TaoBaoTokenAuctionIdMapManager taoBaoTokenAuctionIdMapManager;
   /**
    * 
    * @Title: convertJDLinkFromText
    * @Description:转链文本中的京东短链
    * @param text
    * @param uid
    * @param share
    * @return
    * @throws Exception
    * String 返回类型
    * @throws
    * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param
    *         uid @param share @return @throws Exception String 返回类型 @throws
    */
   private String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
   public String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
      StringBuilder builder = new StringBuilder(text);
      String newText = builder.toString();
@@ -85,21 +88,14 @@
   /**
    * 
    * @Title: convertTBLinkFromText
    * @Description: 转链文本中的淘口令
    * @param text
    * @param uid
    * @param share
    * @return
    * @throws Exception
    * String 返回类型
    * @throws
    * @Title: convertTBLinkFromText @Description: 转链文本中的淘口令 @param text @param
    *         uid @param share @return @throws Exception String 返回类型 @throws
    */
   private String convertTBLinkFromText(String text, Long uid, boolean share) throws Exception {
      StringBuilder builder = new StringBuilder(text);
      String newText = builder.toString();
      List<String> tokenList = TaoBaoUtil.getTokenListFromText(newText);
      List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
      if (tokenList != null && tokenList.size() > 0) {
         String relationId = null;
@@ -112,7 +108,7 @@
         tokenSet.addAll(tokenList);
         Map<String, String> tokenMap = new HashMap<>();
         for (String token : tokenSet) {
            Long auctionId = TaoKeApiUtil.tokenConvertAuctionId(token);
            Long auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token);
            if (auctionId == null)
               throw new Exception("从淘口令获取商品失败");
            TaoBaoGoodsBrief simpleGoods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
@@ -174,7 +170,7 @@
            if (StringUtil.isNullOrEmpty(newToken)) {
               throw new Exception("口令转链失败");
            }
            tokenMap.put(token, newToken);
            tokenMap.put(token, TaoBaoUtil.filterTaoToken(newToken));
         }
         for (String token : tokenSet) {
@@ -188,17 +184,32 @@
   /**
    * 
    * @Title: convertLinkFromText
    * @Description: 从文本转链
    * @param text
    * @return
    * String 返回类型
    * @throws
    * @Title: convertLinkFromText @Description: 从文本转链 @param text @return
    *         String 返回类型 @throws
    */
   public String convertLinkFromText(String text, Long uid, boolean share) throws Exception {
   public String convertLinkFromText(String text, Long uid, boolean share)
         throws ConvertLinkExceptionException, Exception {
      String newText = convertJDLinkFromText(text, uid, share);
      newText = convertTBLinkFromText(newText, uid, share);
      if (text.equalsIgnoreCase(newText))
         throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接");
      return newText;
   }
   /**
    * 创建口令 @Title: createTaoBaoToken @Description: @param uid 用户ID @param
    * picturl @param title @param link @return String 返回类型 @throws
    */
   public String createTaoBaoToken(Long uid, String picturl, String title, String link) {
      String token = TaoKeApiUtil.getTKToken(picturl, title, link);
      if (!StringUtil.isNullOrEmpty(token)) {
         // 缓存30分钟
         redisManager.cacheCommonString(
               RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoUserTKToken, uid + "-" + StringUtil.Md5(token)), "1",
               60 * 30);
      }
      return token;
   }
}