yujian
2019-07-29 cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -98,12 +98,10 @@
   @Resource
   private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   /**
    * 粘贴板信息推荐
    * 
@@ -145,37 +143,13 @@
            out.print(JsonUtil.loadFalseResult("值过长"));
            return;
         }
         SearchFilter sf = new SearchFilter();
         sf.setKey(text);
         JSONObject root = new JSONObject();
         TaoBaoSearchResult result = TaoBaoUtil.search(sf);
         if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0)
            for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) {
               // 是属于淘宝联盟商品
               if (goods.getTitle().equalsIgnoreCase(text)) {
                  root.put("type", 2);
                  JSONObject data = new JSONObject();
                  data.put("title", goods.getTitle());
                  root.put("data", data);
                  out.print(JsonUtil.loadTrueResult(root));
                  return;
               }
            }
         // 查询大淘客标题
         List<DaTaoKeDetail> list = daTaoKeGoodsDetailService.listByDtitle(text);
         if (list != null && list.size() > 0) {
            root.put("type", 2);
            JSONObject data = new JSONObject();
            data.put("title", list.get(0).getdTitle());
            root.put("data", data);
            out.print(JsonUtil.loadTrueResult(root));
            return;
         }
         out.print(JsonUtil.loadFalseResult("暂不支持该类型!"));
         root.put("type", 2);
         JSONObject data = new JSONObject();
         data.put("title", text);
         root.put("data", data);
         out.print(JsonUtil.loadTrueResult(root));
         return;
      }
@@ -236,9 +210,7 @@
      out.print(JsonUtil.loadTrueResult(root));
   }
   /**
    * 搜索候选词
    * 
@@ -281,32 +253,33 @@
    * @param kw
    * @param page
    * @param filter
    * @param order      销量由高到低:1 、 价格从高到低:2 、 价格从低到高:3 、 推广量高到低:4(综合默认)、返利比高到低:5
    *                   、返利比低到高:6 、推荐20
    * @param order
    *            销量由高到低:1 、 价格从高到低:2 、 价格从低到高:3 、 推广量高到低:4(综合默认)、返利比高到低:5
    *            、返利比低到高:6 、推荐20
    * @param startprice
    * @param endprice
    * @param fastFilter
    * @param out
    */
   @RequestMapping(value = "searchGoods")
   public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter, Integer order,
         PrintWriter out) {
      if (goodsType == null || goodsType < 1 || goodsType >3) {
   public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter,
         Integer order, PrintWriter out) {
      if (goodsType == null || goodsType < 1 || goodsType > 3) {
         out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
         return;
      }
      if (page == null || page < 1) {
         out.print(JsonUtil.loadFalseResult(1, "页码不能小于1"));
         return;
      }
      if (StringUtil.isNullOrEmpty(key)) {
         out.print(JsonUtil.loadFalseResult(1, "请输入搜索内容"));
         return;
      }
      final String searchkey = key.trim();
      executor.execute(new Runnable() {
         @Override
         public void run() {
@@ -317,12 +290,11 @@
            String device = acceptData.getDevice();
            sb.append(platform).append(link).append(packages).append(link).append(device);
            String bid = StringUtil.Md5(sb.toString());
            // 加入搜索历史记录
            historySearchService.addHistorySearch(searchkey, bid);
         }
      });
      if (searchkey.startsWith("http://") || searchkey.startsWith("https://")) {
         JSONObject data = new JSONObject();
@@ -332,19 +304,19 @@
         return;
      }
      /*--------- 京东商品  -------*/
      /*--------- 京东商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
         searchJDGoods(searchkey, page, filter, order, out);
         return;
      }
      /*-------- 拼多多商品  -------*/
      /*-------- 拼多多商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
         searchPDDGoods(searchkey, page, filter, order, out);
         return;
      }
      /*-------- 淘宝商品  -------*/
      /*-------- 淘宝商品  -------*/
      searchTaoBaoGoods(searchkey, page, filter, order, out);
   }
@@ -375,25 +347,25 @@
         } else if (order == 4) { // 返利比高到低
            sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW);
         }
      }
      }
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONObject jsonfilter = JSONObject.fromObject(filter);
         Boolean coupon = jsonfilter.optBoolean("coupon");
         if (coupon != null && coupon) {
            sf.setQuan(1); // 有券
         }
         Boolean tmall = jsonfilter.optBoolean("tmall");
         if (tmall != null && tmall) {
            sf.setTmall(true); // 天猫
         }
         String minPrice = jsonfilter.optString("minPrice");
         if (!StringUtil.isNullOrEmpty(minPrice)) {
            sf.setStartPrice(new BigDecimal(minPrice));
         }
         String maxPrice = jsonfilter.optString("maxPrice");
         if (!StringUtil.isNullOrEmpty(maxPrice)) {
            sf.setEndPrice(new BigDecimal(maxPrice));
@@ -405,10 +377,10 @@
      if (page == 1) {
         daTaoKeList = daTaoKeGoodsDetailService.listByDtitle(key);
      }
      // 淘宝api搜索商品
      TaoBaoSearchResult result = TaoBaoUtil.search(sf);
      // 搜索是否在营销主商品库
      if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
         ThreadUtil.run(new Runnable() {
@@ -420,7 +392,7 @@
            }
         });
      }
      List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = null;
      if (result != null) {
         taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
@@ -428,7 +400,7 @@
      if (taoBaoGoodsBriefs == null) {
         taoBaoGoodsBriefs = new ArrayList<>();
      }
      if (daTaoKeList != null && daTaoKeList.size() > 0) {
         try {
            Collections.reverse(daTaoKeList);
@@ -438,7 +410,7 @@
         } catch (Exception e) {
         }
      }
      List<GoodsDetailVO> list = new ArrayList<GoodsDetailVO>();
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
@@ -448,7 +420,7 @@
      Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
            .excludeFieldsWithoutExposeAnnotation().create();
      JSONObject data = new JSONObject();
      data.put("result", gson.toJson(list));
      data.put("count", result.getTaoBaoHead().getDocsfound());
@@ -464,7 +436,6 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 京东
    * 
@@ -477,7 +448,7 @@
    * @return
    */
   private void searchJDGoods(String key, Integer page, String filter, Integer order, PrintWriter out) {
      JDSearchResult result = null;
      String way = configService.get("jd_api_search_key");
      if ("1".equals(way)) {
@@ -510,31 +481,29 @@
            }
         }
         if (!StringUtil.isNullOrEmpty(filter)) {
            JSONObject jsonfilter = JSONObject.fromObject(filter);
            Boolean coupon = jsonfilter.optBoolean("coupon");
            if (coupon != null && coupon) {
               filterAPI.setIsCoupon(1); // 有券
            }
            Boolean zy = jsonfilter.optBoolean("zy");
            if (zy != null && zy) {
               filterAPI.setOwner("g"); // 自营
            }
            String minPrice = jsonfilter.optString("minPrice");
            if (!StringUtil.isNullOrEmpty(minPrice)) {
               filterAPI.setPricefrom(Double.parseDouble(minPrice));
            }
            String maxPrice = jsonfilter.optString("maxPrice");
            if (!StringUtil.isNullOrEmpty(maxPrice)) {
               filterAPI.setPriceto(Double.parseDouble(maxPrice));
            }
         }
         result = JDApiUtil.queryByKey(filterAPI);
      } else {
         // 网页爬取
@@ -573,31 +542,39 @@
            if (coupon != null && coupon) {
               jdfilter.setHasCoupon(1); // 有券
            }
            Boolean zy = jsonfilter.optBoolean("zy");
            if (zy != null && zy) {
               jdfilter.setIsZY(1); // 自营
            }
            Boolean delivery = jsonfilter.optBoolean("delivery");
            if (delivery != null && delivery) {
               jdfilter.setDeliveryType(1); // 京东配送
            }
            String minPrice = jsonfilter.optString("minPrice");
            if (!StringUtil.isNullOrEmpty(minPrice)) {
               if (minPrice.contains(".")) {
                  minPrice = minPrice.replace(".", "-");
                  minPrice = minPrice.split("-")[0];
               }
               jdfilter.setFromPrice(Integer.parseInt(minPrice));
            }
            String maxPrice = jsonfilter.optString("maxPrice");
            if (!StringUtil.isNullOrEmpty(maxPrice)) {
               if (maxPrice.contains(".")) {
                  maxPrice = maxPrice.replace(".", "-");
                  maxPrice = maxPrice.split("-")[0];
               }
               jdfilter.setToPrice(Integer.parseInt(maxPrice));
            }
         }
         result = JDUtil.searchByKey(jdfilter);
      }
      long count = 0;
      JSONObject data = new JSONObject();
      JSONArray array = new JSONArray();
@@ -627,7 +604,7 @@
   }
   /**
    * 京东
    *   拼多多
    * 
    * @param kw
    * @param page
@@ -663,14 +640,14 @@
            break;
         }
      }
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONObject jsonfilter = JSONObject.fromObject(filter);
         Boolean coupon = jsonfilter.optBoolean("coupon");
         if (coupon != null && coupon) {
            pddfilter.setHasCoupon(true); // 有券
         }
         Boolean brand = jsonfilter.optBoolean("brand");
         if (brand != null && brand) {
            pddfilter.setIsBrand(true); // 是否是品牌
@@ -684,12 +661,12 @@
      PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
      if (result != null) {
         count = result.getTotalCount();
         Gson gson = JsonUtil.getApiCommonGson();
         List<PDDGoodsDetail> goodsList = result.getGoodsList();
         if (goodsList != null && goodsList.size() > 0) {
            BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
            BigDecimal shareRate = hongBaoManageService.getShareRate();
            Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                  .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
            for (PDDGoodsDetail goods : goodsList) {
               GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertPDDGoods(goods, null, fanLiRate,
                     shareRate);