yujian
2019-11-07 3f76ec837b343e5a8538f2ce50010714d16cdeef
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicRecommendController.java
@@ -20,14 +20,17 @@
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
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.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.Utils;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import net.sf.json.JSONObject;
@@ -64,7 +67,6 @@
      TaoBaoGoodsBrief tb = null;
      String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
      Pattern p = Pattern.compile(URL_REGEX);
      Matcher matcher = p.matcher(url);
      if (!matcher.find()) {// 不包含链接
@@ -150,10 +152,23 @@
      Pattern p = Pattern.compile(URL_REGEX);
      Matcher matcher = p.matcher(text);
      if (!matcher.find()) {// 不包含链接
         // 解析淘口令
         if (analysisTaoToken(text, out))
            return;
         // 商品详情
         // 发现
         // 没有链接,标题过长也不处理
         if (text.length() > 50) {
         if (text.startsWith("【") && text.contains("】")) {
            int end = text.indexOf("】");
            if (end > 2)
               text = text.substring(1, end);
         }
         LogHelper.test("根据粘贴板推荐:" + text);
         if (text.length() > 80) {
            out.print(JsonUtil.loadFalseResult("值过长"));
            return;
         }
@@ -249,4 +264,48 @@
      out.print(JsonUtil.loadTrueResult(root));
   }
   /**
    * 解析淘口令
    *
    * @param text
    * @param out
    * @return
    */
   private boolean analysisTaoToken(String text, PrintWriter out) {
      String token = StringUtil.picUpTaoToken(text);
      if (!StringUtil.isNullOrEmpty(token)) {
         Long auctionId = TaoKeApiUtil.tokenConvertAuctionId(token);
         if (auctionId != null) {
            TaoBaoGoodsBrief tb = null;
            try {
               tb = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
            } catch (TaobaoGoodsDownException e) {
               e.printStackTrace();
            }
            if (tb != null) {
               JSONObject data = new JSONObject();
               JSONObject taoBaoGoodsJSON = new JSONObject();
               taoBaoGoodsJSON.put("title", tb.getTitle());
               taoBaoGoodsJSON.put("zkPrice", tb.getZkPrice());
               taoBaoGoodsJSON.put("auctionId", tb.getAuctionId());
               taoBaoGoodsJSON.put("url", "http://item.taobao.com/item.htm?id=" + tb.getAuctionId());
               data.put("taoBaoGoodsBrief", taoBaoGoodsJSON);
               if (!StringUtil.isNullOrEmpty(tb.getPictUrl())) {
                  if (tb.getImgList() == null)
                     tb.setImgList(new ArrayList<>());
                  tb.getImgList().add(0, TbImgUtil.getTBSize220Img(tb.getPictUrl()));
               }
               data.put("tbImgs", tb.getImgList());
               JSONObject root = new JSONObject();
               root.put("type", 1);
               root.put("data", data);
               out.print(JsonUtil.loadTrueResult(root));
               return true;
            }
         }
      }
      return false;
   }
}