From 1011d9d0aaab0e978caf4513b64f0a369bcd9a96 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 22 七月 2019 15:39:56 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java |  219 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 158 insertions(+), 61 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..045790d 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,138 @@
 	 * @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)) {
+					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();
-		JDSearchResult result = JDUtil.searchByKey(jdfilter);
 		if (result != null) {
 			PageEntity pageEntity = result.getPageEntity();
 			if (pageEntity != null) {
@@ -577,14 +673,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); // 鏄惁鏄搧鐗�
 			}
 		}
 
@@ -595,12 +692,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);
@@ -608,7 +705,7 @@
 				}
 			}
 		}
-
+		
 		data.put("result", array);
 		data.put("count", count);
 		out.print(JsonUtil.loadTrueResult(data));

--
Gitblit v1.8.0