From fdff4c4c320fdbaa9bf789a9dae74e2c18fb9d99 Mon Sep 17 00:00:00 2001
From: Administrator <Administrator@S0ZHK00LKCA6OYY>
Date: 星期五, 09 十一月 2018 10:52:10 +0800
Subject: [PATCH] 修改API监控
---
fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java | 489 +++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 390 insertions(+), 99 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java
index a77241b..3a92bba 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/SearchController.java
@@ -18,6 +18,8 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.taobao.TbImgUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -32,6 +34,7 @@
import com.yeshi.fanli.entity.taobao.SearchFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
+import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
@@ -48,7 +51,6 @@
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.taobao.SearchFilterUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import org.yeshi.utils.JsonUtil;
@Controller
@RequestMapping("api/v1/search")
@@ -406,116 +408,405 @@
/**
- * 鏍规嵁鐢ㄦ埛鎼滅储鍏抽敭璇� 杩涜绮鹃�夊簱鍟嗗搧绛涢��
+ * 鎼滅储-鏂扮増
* @param acceptData
+ * @param kw
* @param page
- * @param key
+ * @param filter
+ * @param order 閿�閲忕敱楂樺埌浣�:1 銆� 浠锋牸浠庨珮鍒颁綆:2 銆� 浠锋牸浠庝綆鍒伴珮:3 銆� 鎺ㄥ箍閲忛珮鍒颁綆:4锛堢患鍚堥粯璁わ級銆佽繑鍒╂瘮楂樺埌浣�:5 銆佽繑鍒╂瘮浣庡埌楂�:6 銆佹帹鑽�20
+ * @param startprice
+ * @param endprice
+ * @param fastFilter
* @param out
*/
- @RequestMapping(value = "getQualityRecommend", method = RequestMethod.POST)
- public void getQualityRecommend(AcceptData acceptData, int page, String kw, PrintWriter out) {
+ @RequestMapping(value = "searchgoods")
+ public void searchgoods(AcceptData acceptData, String kw, int page, String filter, String order, String startprice,
+ String endprice, String fastFilter, PrintWriter out) {
+
+ String bid = getHistorySearchBid(acceptData);
+
+ historySearchService.addHistorySearch(kw, bid);
+
System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
if (system == null) {
out.print(JsonUtil.loadFalseResult("绯荤粺涓嶅瓨鍦�"));
return;
}
- try {
-
- // page浠�1寮�濮�
- page += 1;
- // 璇锋眰娣樺疂鎺ュ彛椤电爜
- int pageNo = page;
-
- int pageSize = Constant.PAGE_SIZE;
-
-
- /* 璁$畻绮鹃�夊簱鏁版嵁 鎬婚〉鏁� */
- long incount = qualityGoodsService.countRecommendBykey(kw);
-
- int totalPage = (int) (incount % pageSize == 0 ? incount / pageSize : incount / pageSize + 1);
-
- pageNo = page - totalPage;
-
-
- /* 鏌ヨ绮鹃�夊簱鏁版嵁 */
- if (pageNo <= 0 ) {
-
- List<QualityFactory> listQuality =
- qualityGoodsService.listRecommendBykey((page - 1) * pageSize, pageSize, kw);
-
-
- List<TaoBaoGoodsBrief> searchWuLiaoList = null;
-
- /* 绮鹃�夊簱鏁版嵁涓嶈冻10鏉� */
- if (listQuality != null && listQuality.size() != 0 && listQuality.size() < 10) {
-
- SearchFilter searchfilter = new SearchFilter();
- // 璇锋眰绗竴椤垫暟鎹�
- searchfilter.setPage(1);
- searchfilter.setPageSize(pageSize);
- searchfilter.setKey(SearchFilterUtil.filterSearchContent(kw));
- // 鍚埜
- searchfilter.setQuan(1);
- // 浠锋牸浣庝簬220
- searchfilter.setEndPrice(new BigDecimal(220));
- // 濂借瘎鐜囨槸鍚﹂珮浜庤涓氬潎鍊硷紱
- searchfilter.setIncludeGoodRate(true);
-
- searchfilter.setMaterialId("6707");
- // 閿�閲忛珮鍒颁綆
- searchfilter.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
-
- searchWuLiaoList = taoKeGoodsService.searchWuLiaoList(searchfilter);
- }
-
- Map<String, String> map = manageService.convertMap();
-
- JSONObject data = taoKeGoodsService.listQualityGoods(listQuality, searchWuLiaoList, map);
-
- out.print(JsonUtil.loadTrueResult(data));
-
- return;
- }
-
-
- if (pageNo > 0 && totalPage > 0) {
- List<QualityFactory> list =
- qualityGoodsService.listRecommendBykey((totalPage - 1) * pageSize, pageSize, kw);
-
- if (list != null && list.size() != 0 && list.size() < 10) {
- // 椤电爜+ 1 宸茶姹備竴娆℃窐瀹濇帴鍙�
- pageNo += 1 ;
- }
- }
-
-
- /* 缃戠粶璇锋眰 */
- SearchFilter searchfilter = new SearchFilter();
-
- searchfilter.setPage(pageNo);
- searchfilter.setPageSize(pageSize);
- searchfilter.setKey(SearchFilterUtil.filterSearchContent(kw));
- // 鍚埜
- searchfilter.setQuan(1);
- // 浠锋牸浣庝簬220
- searchfilter.setEndPrice(new BigDecimal(220));
- // 濂借瘎鐜囨槸鍚﹂珮浜庤涓氬潎鍊硷紱
- searchfilter.setIncludeGoodRate(true);
-
- searchfilter.setMaterialId("6707");
- // 閿�閲忛珮鍒颁綆
- searchfilter.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
-
- // 鏌ヨ鐗╂枡鎺ュ彛
- JSONObject result = taoKeGoodsService.searchWuLiao(searchfilter);
-
- out.print(JsonUtil.loadTrueResult(result));
-
- } catch (Exception e) {
- e.printStackTrace();
+ if (!StringUtil.isNullOrEmpty(kw) && (kw.startsWith("http://") || kw.startsWith("https://"))) {
+ out.print(JsonUtil.loadFalseResult("鏃犳硶鎼滅储閾炬帴"));
+ return;
}
+
+ if (!StringUtil.isNullOrEmpty(fastFilter)) {
+ if (!StringUtil.isNullOrEmpty(filter)) {
+ JSONArray filterArray = JSONArray.fromObject(filter);
+ JSONArray fastFilterArray = JSONArray.fromObject(fastFilter);
+ filterArray.addAll(fastFilterArray);
+ filter = filterArray.toString();
+ } else {
+ filter = fastFilter;
+ }
+ }
+
+
+ // 鏄惁鏄帹鑽�
+ boolean recommend = false;
+ if (!StringUtil.isNullOrEmpty(fastFilter)) {
+ // 鏌ヨ娣樺疂澶╃尗
+ JSONArray array = JSONArray.fromObject(filter);
+ for (int i = 0; i < array.size(); i++) {
+ String ty = array.optJSONObject(i).optString("type");
+
+ if ("recommend".equalsIgnoreCase(ty)) {
+ recommend = true;
+ }
+ }
+ }
+
+
+ JSONObject data = null;
+ if (!recommend) {
+ // 娣樺疂鎺ュ彛璇锋眰
+ data = searchGoods(kw, page, filter, order, startprice, endprice);
+ } else {
+ // 鎺ㄨ崘锛氱簿閫夊簱
+ data = searchQualityGoods(kw, page, filter, order, startprice, endprice);
+ }
+
+ // 鑾峰彇鎺ㄨ崘璇�
+ List<String> listRecommendWords = new ArrayList<String>();
+ // 缁煎悎 鏌ヨ绗竴椤垫椂鑾峰彇鍊欓�夎瘝
+ if (page == 0) {
+ listRecommendWords = TaoBaoUtil.getSuguestSearch(kw);
+ if (listRecommendWords == null || listRecommendWords.size() == 0) {
+ listRecommendWords = new ArrayList<String>();
+ }
+ }
+
+ Gson gson = new GsonBuilder().create();
+ data.put("words", gson.toJson(listRecommendWords));
+
+ out.print(JsonUtil.loadTrueResult(data));
}
+
+
+ /**
+ * 鎵ц鎼滅储-鏂扮増
+ * @param kw
+ * @param page
+ * @param filter
+ * @param order
+ * @param startprice
+ * @param endprice
+ * @return
+ */
+ private JSONObject searchGoods(String kw, int page, String filter, String order, String startprice, String endprice) {
+ page = page + 1;
+ SearchFilter sf = new SearchFilter();
+ sf.setKey(SearchFilterUtil.filterSearchContent(kw));
+ sf.setPage(page);
+ sf.setSort(0);
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(startprice)) {
+ sf.setStartPrice(new BigDecimal(startprice));
+ }
+
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(endprice)) {
+ sf.setEndPrice(new BigDecimal(endprice));
+ }
+
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(order)) {
+ if (Integer.parseInt(order) == 1) {
+ sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
+ } else if (Integer.parseInt(order) == 2) {
+ sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW);
+ } else if (Integer.parseInt(order) == 3) {
+ sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH);
+ } else if (Integer.parseInt(order) == 4) {
+ sf.setSort(TaoBaoUtil.SORT_TOTAL_SALES_HIGH_TO_LOW);
+ } else if (Integer.parseInt(order) == 5) {
+ sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW);
+ } else if (Integer.parseInt(order) == 6) {
+ sf.setSort(TaoBaoUtil.SORT_TKRATE_LOW_TO_HIGH);
+ }
+ } else {
+ // 榛樿閿�閲忎粠楂樺埌浣庢帓搴�
+ sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
+ }
+
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) {
+ // 鏌ヨ娣樺疂澶╃尗
+ JSONArray array = JSONArray.fromObject(filter);
+ Set<String> params = new HashSet<String>();
+ for (int i = 0; i < array.size(); i++) {
+ // [{"type":'shoptype',id:12}]
+ String ty = array.optJSONObject(i).optString("type");
+ if ("shoptype".equalsIgnoreCase(ty)) {
+ if (array.optJSONObject(i).optInt("id") == 21) {
+ sf.setTmFlagship(false); // 涓嶇瓫锟�?
+ } else {
+ sf.setTmFlagship(true);
+ sf.setTmall(true);
+ sf.setShopTag("b2c");
+ }
+ } else if ("category".equalsIgnoreCase(ty)) {
+ sf.setCateIds(array.optJSONObject(i).optString("id"));
+ } else if ("userType".equalsIgnoreCase(ty)) {
+ // if(array.optJSONObject(i).optInt("id") == 51)
+ sf.setTmall(true);
+ // else
+ // sf.setTmall(false);
+ } else if ("baoyou".equalsIgnoreCase(ty)) {
+ // if(array.optJSONObject(i).optInt("id") == 61)
+ sf.setBaoYou(true);
+ // else
+ // sf.setBaoYou(false);
+ } else if ("quantype".equalsIgnoreCase(ty)) {
+ // if (array.optJSONObject(i).optInt("id") == 31){
+ sf.setQuan(1);
+ if (sf.isTmFlagship()) {
+ sf.setShopTag(sf.getShopTag() + ",dpyhq");
+ } else {
+ sf.setShopTag("dpyhq");
+ }
+ // }
+ // else
+ // sf.setQuan(2);
+ } else if ("hongbaotype".equalsIgnoreCase(ty)) {
+ if (array.optJSONObject(i).optInt("id") == 41)// 鏈夌孩锟�?
+ sf.setHongbao(1);
+ else// 鏃犵孩锟�?
+ sf.setHongbao(2);
+ } else if ("property".equalsIgnoreCase(ty)) {
+ String pid = (String) array.optJSONObject(i).opt("pid");
+ String id = (String) array.optJSONObject(i).opt("id");
+ boolean flag = false;
+ String str = null;
+ for (String string : params) {
+ flag = string.contains(pid + ":");
+ if (flag) {
+ str = string;
+ break;
+ }
+ }
+ if (flag) {
+ params.add(str + "," + id);
+ params.remove(str);
+ } else {
+ params.add(pid + ":" + id);
+ }
+ } else if ("fahuodi".equalsIgnoreCase(ty)) {
+ int id = array.optJSONObject(i).optInt("id");
+ sf.setProvinceId(id);
+ }else if ("materialId".equalsIgnoreCase(ty)) {
+ int id = array.optJSONObject(i).optInt("id");
+ sf.setProvinceId(id);
+ }
+ }
+ sf.setParams(params);
+ }
+ TaoBaoSearchResult result = TaoBaoUtil.search(sf);
+ if (result == null) {
+ return null;
+ }
+
+ List<TaoBaoSearchNav> navList = TaoBaoUtil.getBaseNav();
+ if (result.getNavList() != null)
+ navList.addAll(result.getNavList());
+ Gson gson = new GsonBuilder().create();
+ JSONObject data = new JSONObject();
+ data.put("nav", gson.toJson(navList));
+ List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
+ List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
+ int fq = sf.getQuan();
+ int fh = sf.getHongbao();
+ boolean ft = sf.isTmall();
+ Map<String, String> map = manageService.convertMap();
+ String proportion = map.get("hongbao_goods_proportion");
+ String fcRate = map.get("hongbao_fc_ratio");
+ if (fq == 0 && fh == 0 && !ft) {
+ if (result != null && result.getTaoBaoGoodsBriefs() != null)
+ for (TaoBaoGoodsBrief bf : result.getTaoBaoGoodsBriefs()) {
+ int count = bf.getBiz30day();
+ if (count >= 10000) { // 瀵归攢閲忔暟鎹仛澶勭悊 椤甸潰灞曠ず7.3涓�
+ double sales = count;
+ String salesCountMidea = String.format("%.1f", sales / 10000);
+ bf.setSalesCount(salesCountMidea + "涓�");
+ re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion, fcRate, ""));
+ } else {
+ bf.setSalesCount(count + "");
+ re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion, fcRate, ""));
+ }
+ }
+ } else {
+ TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra;
+ if (taoBaoGoodsBriefs != null)
+ for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) {
+ int count = taoBaoGoodsBrief.getBiz30day();
+ if (count >= 10000) {
+ double sales = count;
+ String salesCountMidea = String.format("%.1f", sales / 10000);
+ taoBaoGoodsBrief.setSalesCount(salesCountMidea + "涓�");
+ taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion,
+ fcRate, "");
+ re.add(taoBaoGoodsBriefExtra);
+ } else {
+ taoBaoGoodsBrief.setSalesCount(count + "");
+ taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion,
+ fcRate, "");
+ re.add(taoBaoGoodsBriefExtra);
+ }
+ }
+ }
+ Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
+ .excludeFieldsWithoutExposeAnnotation().create();
+ data.put("result", gson2.toJson(re));
+ data.put("count", result.getTaoBaoHead().getDocsfound());
+ return data;
+ }
+
+
+
+ /**
+ * 鎵ц鎼滅储绮鹃�夊簱
+ * @param kw
+ * @param page
+ * @param filter
+ * @param order
+ * @param startprice
+ * @param endprice
+ * @return
+ */
+ private JSONObject searchQualityGoods(String key, int page, String filter, String order, String startprice, String endprice) {
+
+ Integer hasQuan = null;
+ Integer userType = null;
+ Double start_Price = null;
+ Double end_Price= null;
+ Integer sort = null;
+
+ int provinceId = -100;
+
+ // 璧峰浠锋牸
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(startprice)) {
+ start_Price = Double.parseDouble(startprice);
+ }
+ // 缁撴潫浠锋牸
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(endprice)) {
+ end_Price = Double.parseDouble(endprice);
+ }
+
+ // 鎺掑簭
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(order)) {
+
+ if (Integer.parseInt(order) == 4) {
+ sort = 20; // 缁煎悎鏃讹細閲囩敤榛樿鏉冮噸鎺掑簭
+ } else {
+ sort =Integer.parseInt(order);
+ }
+
+ }
+
+ /* 鍏朵粬绛涢�夋潯浠� */
+ if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) {
+ // 鏌ヨ娣樺疂澶╃尗
+ JSONArray array = JSONArray.fromObject(filter);
+ for (int i = 0; i < array.size(); i++) {
+ String ty = array.optJSONObject(i).optString("type");
+
+ if ("userType".equalsIgnoreCase(ty)) {
+ userType = 1; // 澶╃尗
+ } else if ("quantype".equalsIgnoreCase(ty)) {
+ hasQuan = 1; // 鏈夊埜
+ } else if ("hongbaotype".equalsIgnoreCase(ty)) {
+
+ } else if ("fahuodi".equalsIgnoreCase(ty)) {
+ provinceId = array.optJSONObject(i).optInt("id");
+ }
+ }
+ }
+
+
+ int pageSize = Constant.PAGE_SIZE;
+
+ List<QualityFactory> listQuery = qualityGoodsService.listRecommendBykey(page * pageSize,
+ pageSize, key, hasQuan, userType, start_Price, end_Price, sort);
+
+
+ List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
+ Map<String, String> map = manageService.convertMap();
+ String proportion = map.get("hongbao_goods_proportion");
+ String fcRate = map.get("hongbao_fc_ratio");
+
+ /* 閬嶅巻鍒楄〃鏁版嵁 */
+ if (listQuery != null && listQuery.size() > 0) {
+ for (QualityFactory selectionGoods : listQuery) {
+
+ TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
+
+ if (taoBaoGoodsBrief == null) {
+ continue;
+ }
+
+ int biz30day = taoBaoGoodsBrief.getBiz30day();
+ if (biz30day >= 10000) {
+ double sales = biz30day;
+ String salesCountMidea = String.format("%.1f", sales / 10000);
+ taoBaoGoodsBrief.setSalesCount(salesCountMidea + "涓�");
+ } else {
+ taoBaoGoodsBrief.setSalesCount(biz30day + "");
+ }
+
+ // 鏀瑰彉鍥剧墖灏哄
+ String pictUrl = taoBaoGoodsBrief.getPictUrl();
+ if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
+ taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
+ }
+
+ listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion, fcRate, null));
+ }
+ }
+
+
+ long count = qualityGoodsService.countRecommendBykey(key, hasQuan, userType, start_Price, end_Price);
+
+
+ // 璁剧疆鍙戣揣鍦板潃
+ TaoBaoSearchNav nav = new TaoBaoSearchNav();
+ nav.setName("鍙戣揣鍦�");
+ nav.setFlag("address");
+ nav.setId(11110);
+ nav.setType("fahuodi");
+
+ List<TaoBaoSearchNav> navList = new ArrayList<>();
+
+ List<TaoBaoSearchNav> childNavList = new ArrayList<>();
+ List<TaoBaoProvince> provinceList = TaoBaoUtil.getTaoBaoProvinceList();
+ for (TaoBaoProvince province : provinceList) {
+ TaoBaoSearchNav childNav = new TaoBaoSearchNav();
+ childNav.setName(province.getName());
+ childNav.setId(Integer.parseInt(province.getId()));
+ childNav.setType("fahuodi-child");
+ if (Integer.parseInt(province.getId()) == provinceId)
+ childNav.setSelector(1);
+ childNavList.add(childNav);
+ }
+
+ nav.setSubIds(childNavList);
+ navList.add(nav);
+
+ Gson gson = new GsonBuilder().create();
+ Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
+ .excludeFieldsWithoutExposeAnnotation().create();
+
+ JSONObject data = new JSONObject();
+ data.put("nav", gson.toJson(navList));
+ data.put("result", gson2.toJson(listExtra));
+ data.put("count", count);
+
+ return data;
+ }
+
}
--
Gitblit v1.8.0