yujian
2019-07-19 8222e8b237c5dfb0affcdc03335bfadc06403bf8
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -20,6 +20,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.jd.JDFilter;
import com.yeshi.fanli.dto.jd.JDSearchFilter;
import com.yeshi.fanli.dto.jd.JDSearchResult;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
@@ -49,6 +50,7 @@
import com.yeshi.fanli.util.Utils;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
@@ -375,16 +377,26 @@
         }
      } 
      
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONArray array = JSONArray.fromObject(filter);
         for (int i = 0; i < array.size(); i++) {
            String ty = array.optJSONObject(i).optString("type");
            if ("coupon".equalsIgnoreCase(ty)) { // 有券
               sf.setQuan(1);
            } else if ("tmall".equalsIgnoreCase(ty)) { // 天猫
               sf.setTmall(true);
            }
         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));
         }
      }
@@ -443,9 +455,9 @@
      if (page == 1) {
         // 第一页返回店铺信息
         List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKey(key);
         if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoods() != null
               && listShop.get(0).getListGoods().size() > 2) {
         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)));
         }
      }
@@ -465,54 +477,130 @@
    * @return
    */
   private void searchJDGoods(String key, Integer page, String filter, Integer order, PrintWriter out) {
      JDSearchFilter jdfilter = new JDSearchFilter();
      jdfilter.setKey(SearchFilterUtil.filterSearchContent(key));
      jdfilter.setPageNo(page);
      jdfilter.setPageSize(Constant.PAGE_SIZE);
      JDSearchResult result = null;
      String way = configService.get("jd_api_search_key");
      if ("1".equals(way)) {
         JDFilter filterAPI = new JDFilter();
         filterAPI.setKeyword(SearchFilterUtil.filterSearchContent(key));
         filterAPI.setPageIndex(page);
         filterAPI.setPageSize(Constant.PAGE_SIZE);
      if (order != null) {
         int sort = order.intValue();
         switch (sort) {
         case 1: // 销量 desc
            jdfilter.setSort(JDSearchFilter.SORT_DESC);
            jdfilter.setSortName(JDSearchFilter.SORTNAME_ORDER_COUNT_30DAYS);
            break;
         case 2: // 价格—desc
            jdfilter.setSort(JDSearchFilter.SORT_DESC);
            jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE);
            break;
         case 3: // 价格—asc
            jdfilter.setSort(JDSearchFilter.SORT_ASC);
            jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE);
            break;
         case 4: // 返利比—DESC
            jdfilter.setSort(JDSearchFilter.SORT_DESC);
            jdfilter.setSortName(JDSearchFilter.SORTNAME_COMMISSION_SHARE);
            break;
         default:
            break;
         }
      }
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONArray array = JSONArray.fromObject(filter);
         for (int i = 0; i < array.size(); i++) {
            String ty = array.optJSONObject(i).optString("type");
            if ("coupon".equalsIgnoreCase(ty)) {
               jdfilter.setHasCoupon(1); // 有券
            } else if ("zy".equalsIgnoreCase(ty)) {
               jdfilter.setIsZY(1); // 是否自营
            } else if ("delivery".equalsIgnoreCase(ty)) {
               jdfilter.setDeliveryType(1); // 是否京东配送
         if (order != null) {
            int sort = order.intValue();
            switch (sort) {
            case 1: // 销量 desc
               filterAPI.setSort(JDFilter.SORT_DESC);
               filterAPI.setSortName(JDFilter.SORTNAME_ORDER_COUNT_30DAYS);
               break;
            case 2: // 价格—desc
               filterAPI.setSort(JDFilter.SORT_DESC);
               filterAPI.setSortName(JDFilter.SORTNAME_PRICE);
               break;
            case 3: // 价格—asc
               filterAPI.setSort(JDFilter.SORT_ASC);
               filterAPI.setSortName(JDFilter.SORTNAME_PRICE);
               break;
            case 4: // 返利比—DESC
               filterAPI.setSort(JDFilter.SORT_DESC);
               filterAPI.setSortName(JDFilter.SORTNAME_COMMISSION_SHARE);
               break;
            default:
               break;
            }
         }
      }
         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 {
         // 网页爬取
         JDSearchFilter jdfilter = new JDSearchFilter();
         jdfilter.setKey(SearchFilterUtil.filterSearchContent(key));
         jdfilter.setPageNo(page);
         jdfilter.setPageSize(Constant.PAGE_SIZE);
         if (order != null) {
            int sort = order.intValue();
            switch (sort) {
            case 1: // 销量 desc
               jdfilter.setSort(JDSearchFilter.SORT_DESC);
               jdfilter.setSortName(JDSearchFilter.SORTNAME_ORDER_COUNT_30DAYS);
               break;
            case 2: // 价格—desc
               jdfilter.setSort(JDSearchFilter.SORT_DESC);
               jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE);
               break;
            case 3: // 价格—asc
               jdfilter.setSort(JDSearchFilter.SORT_ASC);
               jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE);
               break;
            case 4: // 返利比—DESC
               jdfilter.setSort(JDSearchFilter.SORT_DESC);
               jdfilter.setSortName(JDSearchFilter.SORTNAME_COMMISSION_SHARE);
               break;
            default:
               break;
            }
         }
         if (!StringUtil.isNullOrEmpty(filter)) {
            JSONObject jsonfilter = JSONObject.fromObject(filter);
            Boolean coupon = jsonfilter.optBoolean("coupon");
            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)) {
               jdfilter.setFromPrice(Integer.parseInt(minPrice));
            }
            String maxPrice = jsonfilter.optString("maxPrice");
            if (!StringUtil.isNullOrEmpty(maxPrice)) {
               jdfilter.setToPrice(Integer.parseInt(maxPrice));
            }
         }
         result = JDUtil.searchByKey(jdfilter);
      }
      long count = 0;
      JSONObject data = new JSONObject();
      JSONArray array = new JSONArray();
      JDSearchResult result = JDUtil.searchByKey(jdfilter);
      if (result != null) {
         PageEntity pageEntity = result.getPageEntity();
         if (pageEntity != null) {
@@ -577,14 +665,15 @@
      }
      
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONArray array = JSONArray.fromObject(filter);
         for (int i = 0; i < array.size(); i++) {
            String ty = array.optJSONObject(i).optString("type");
            if ("coupon".equalsIgnoreCase(ty)) {
               pddfilter.setHasCoupon(true); // 有券
            } else if ("brand".equalsIgnoreCase(ty)) {
               pddfilter.setIsBrand(true); // 是否是品牌
            }
         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); // 是否是品牌
         }
      }