yujian
2019-09-25 3b67318adb6ee3854cca9ef4134b3747bddb44df
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -56,6 +56,7 @@
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.Utils;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
import com.yeshi.fanli.util.cache.IntegralGetCacheManager;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
@@ -67,6 +68,7 @@
import com.yeshi.fanli.util.taobao.SearchFilterUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.msg.TokenVO;
@@ -188,6 +190,7 @@
         return;
      }
      int type = 3;
      CommonGoods commonGoods = null;
      text = matcher.group();
@@ -213,7 +216,8 @@
         }
         tb = TaoBaoUtil.isAlimama(id);
         if (tb == null) {
            tb = TaoBaoUtil.parsePhoneTmAndTb(id);
            type = 4;
            tb = TaoBaoUtil.getTmallGoodsInfo(id);
         }
      } else if (text.contains("http://zmnxbc.com")) { // 手机端天猫APP分享
         tb = TaoBaoUtil.parsePhoneShareUrlByTM(text);
@@ -224,7 +228,8 @@
         id = map.get("id").replace("}", "");
         tb = TaoBaoUtil.isAlimama(id);
         if (tb == null) {
            tb = TaoBaoUtil.parsePhoneTmAndTb(id);
            type = 4;
            tb = TaoBaoUtil.getTmallGoodsInfo(id);
         }
      } else {
         tb = TaoBaoUtil.parsePhoneShareUrlByTB(text);
@@ -233,8 +238,17 @@
            String jdId = JDUtil.getJDGoodsId(text);
            if (!StringUtil.isNullOrEmpty(jdId)) {
               JDGoods goods = JDApiUtil.getGoodsDetail(Long.parseLong(jdId));
               if (goods != null)
               if (goods != null) {
                  commonGoods = CommonGoodsFactory.create(goods);
               } else {
                  type = 4;
                  goods = JDUtil.getSimpleGoodsInfo(jdId);
                  if (goods != null) {
                     commonGoods = new CommonGoods();
                     commonGoods.setTitle(goods.getSkuName());
                     commonGoods.setPicture(goods.getPicUrl());
                  }
               }
            } else {
               String pddId = PinDuoDuoUtil.getPDDGoodsId(text);
               if (!StringUtil.isNullOrEmpty(pddId)) {
@@ -245,12 +259,42 @@
            }
         }
      }
      if (tb == null && commonGoods == null) {
         out.println(JsonUtil.loadFalseResult("暂未找到该商品,请稍后再试!"));
         return;
      }
      if (type == 4) {
         if (!VersionUtil.greaterThan_2_0_1(acceptData.getPlatform(), acceptData.getVersion())) {
            out.println(JsonUtil.loadFalseResult("暂未找到该商品,请稍后再试!"));
            return;
         }
         JSONObject data = new JSONObject();
         if (tb != null) {
            commonGoods = new CommonGoods();
            commonGoods.setTitle(tb.getTitle());
            commonGoods.setPicture(tb.getPictUrl());
         }
         if (StringUtil.isNullOrEmpty(commonGoods.getTitle()) || StringUtil.isNullOrEmpty(commonGoods.getPicture())) {
            out.println(JsonUtil.loadFalseResult("暂未找到该商品,请稍后再试!"));
            return;
         }
         JSONObject goodsJSON = new JSONObject();
         goodsJSON.put("title", commonGoods.getTitle());
         goodsJSON.put("pictUrl", commonGoods.getPicture());
         data.put("type", type);
         data.put("desc", "该商品无推广信息");
         data.put("goods", goodsJSON);
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      JSONObject data = new JSONObject();
      if (VersionUtil.greaterThan_1_6_5(acceptData.getPlatform(), acceptData.getVersion())) {
@@ -265,13 +309,14 @@
               out.println(JsonUtil.loadFalseResult("暂未找到该商品,请稍后再试!"));
               return;
            }
            commonGoods = CommonGoodsFactory.create(goodsBrief);
            commonGoods = CommonGoodsFactory.create(tb);
         }
         BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
         BigDecimal shareRate = hongBaoManageService.getShareRate();
         Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
               .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
         data.put("type", 3);
         data.put("type", type);
         data.put("goods",
               gson.toJson(GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate)));
         out.print(JsonUtil.loadTrueResult(data));
@@ -355,6 +400,7 @@
    * @param goodsType
    * @param out
    */
   @RequestSerializableByKey(key = "'tokenReceive-'+#uid")
   @RequestMapping(value = "tokenReceive", method = RequestMethod.POST)
   public void tokenReceive(AcceptData acceptData, Long uid, String token, PrintWriter out) {
      try {
@@ -479,18 +525,18 @@
      /*--------- 京东商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
         searchJDGoods(searchkey, page, filter, order, out);
         searchJDGoods(acceptData, searchkey, page, filter, order, out);
         return;
      }
      /*-------- 拼多多商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
         searchPDDGoods(searchkey, page, filter, order, out);
         searchPDDGoods(acceptData, searchkey, page, filter, order, out);
         return;
      }
      /*-------- 淘宝商品  -------*/
      searchTaoBaoGoods(searchkey, page, filter, order, out);
      searchTaoBaoGoods(acceptData, searchkey, page, filter, order, out);
   }
   /**
@@ -504,7 +550,7 @@
    * @param endprice
    * @return
    */
   private void searchTaoBaoGoods(String key, Integer page, String filter, Integer order, PrintWriter out) {
   private void searchTaoBaoGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order, PrintWriter out) {
      SearchFilter sf = new SearchFilter();
      sf.setKey(SearchFilterUtil.filterSearchContent(key));
      sf.setPage(page);
@@ -598,12 +644,23 @@
      data.put("result", gson.toJson(list));
      data.put("count", result.getTaoBaoHead().getDocsfound());
      if (page == 1) {
         // 第一页返回店铺信息
      if (page == 1) { // 第一页返回店铺信息
         List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKeyV2(key);
         if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoodsVO() != null
               && listShop.get(0).getListGoodsVO().size() > 2) {
            data.put("shop", JsonUtil.getApiCommonGson().toJson(listShop.get(0)));
            String platform = acceptData.getPlatform();
            TaoBaoShopVO taoBaoShop = listShop.get(0);
            if (("ios".equalsIgnoreCase(platform) && VersionUtil.greaterThan_2_0(platform, acceptData.getVersion()))
               || ("android".equalsIgnoreCase(platform) && VersionUtil.greaterThan_2_0_1(platform, acceptData.getVersion()))) {
               BrandInfoVO brandInfoVO = new BrandInfoVO();
               brandInfoVO.setId(taoBaoShop.getId());
               brandInfoVO.setName(taoBaoShop.getShopName());
               brandInfoVO.setIcon(taoBaoShop.getShopIcon());
               brandInfoVO.setListGoods(taoBaoShop.getListGoodsVO());
               data.put("shop", JsonUtil.getApiCommonGson().toJson(brandInfoVO));
            } else {
               data.put("shop", JsonUtil.getApiCommonGson().toJson(taoBaoShop));
            }
         }
      }
      out.print(JsonUtil.loadTrueResult(data));
@@ -620,7 +677,7 @@
    * @param endprice
    * @return
    */
   private void searchJDGoods(String key, Integer page, String filter, Integer order, PrintWriter out) {
   private void searchJDGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order, PrintWriter out) {
      JDSearchResult result = null;
      boolean hasCoupon = false;
@@ -795,7 +852,7 @@
    * @param endprice
    * @return
    */
   private void searchPDDGoods(String key, Integer page, String filter, Integer order, PrintWriter out) {
   private void searchPDDGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order, PrintWriter out) {
      PDDSearchFilter pddfilter = new PDDSearchFilter();
      pddfilter.setKw(SearchFilterUtil.filterSearchContent(key));
      pddfilter.setPage(page);