From de10879ac00f9c94dc02cada9a8a6117a8d81caf Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期五, 19 七月 2019 15:40:01 +0800 Subject: [PATCH] 拼多多 京东分享模板兼容 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java | 205 ++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 147 insertions(+), 58 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java index f1f274f..d95cde7 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java +++ b/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)); } } @@ -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: // 浠锋牸鈥攄esc - jdfilter.setSort(JDSearchFilter.SORT_DESC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); - break; - case 3: // 浠锋牸鈥攁sc - jdfilter.setSort(JDSearchFilter.SORT_ASC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); - break; - case 4: // 杩斿埄姣斺�擠ESC - 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: // 浠锋牸鈥攄esc + filterAPI.setSort(JDFilter.SORT_DESC); + filterAPI.setSortName(JDFilter.SORTNAME_PRICE); + break; + case 3: // 浠锋牸鈥攁sc + filterAPI.setSort(JDFilter.SORT_ASC); + filterAPI.setSortName(JDFilter.SORTNAME_PRICE); + break; + case 4: // 杩斿埄姣斺�擠ESC + 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: // 浠锋牸鈥攄esc + jdfilter.setSort(JDSearchFilter.SORT_DESC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); + break; + case 3: // 浠锋牸鈥攁sc + jdfilter.setSort(JDSearchFilter.SORT_ASC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); + break; + case 4: // 杩斿埄姣斺�擠ESC + 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); // 鏄惁鏄搧鐗� } } -- Gitblit v1.8.0