From 651f2856e9ae10aacbfb8327d967aacbb6d58333 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 12 四月 2023 18:13:58 +0800 Subject: [PATCH] 大淘客API修复/唯品会订单爬取策略修改 --- fanli/src/main/java/com/yeshi/fanli/controller/h5/H5SearchController.java | 590 ++++++++++++++++++++++++++-------------------------------- 1 files changed, 267 insertions(+), 323 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/h5/H5SearchController.java b/fanli/src/main/java/com/yeshi/fanli/controller/h5/H5SearchController.java index c2fb565..dacd0f8 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/h5/H5SearchController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/h5/H5SearchController.java @@ -1,323 +1,267 @@ -package com.yeshi.fanli.controller.h5; - -import java.io.PrintWriter; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.annotation.Resource; - -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 com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.yeshi.fanli.entity.accept.AcceptData; -import com.yeshi.fanli.entity.bus.search.HotSearch; -import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch; -import com.yeshi.fanli.entity.system.CustomerContent; -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.TaoBaoSearchNav; -import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; -import com.yeshi.fanli.service.inter.config.CustomerContentService; -import com.yeshi.fanli.service.inter.config.SuperHotSearchService; -import com.yeshi.fanli.service.inter.config.SystemClientParamsService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; -import com.yeshi.fanli.service.inter.user.HistorySearchService; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.taobao.TaoBaoUtil; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -@Controller -@RequestMapping("api/h5/v1/webSearch") -public class H5SearchController { - - @Resource - private HistorySearchService historySearchService; - - @Resource - private H5ControllerUtil h5ControllerUtil; - - @Resource - private HongBaoManageService manageService; - - @Resource - private SystemClientParamsService systemClientParamsService; - - @Resource - private SuperHotSearchService superHotSearchSerivce; - - @Resource - private CustomerContentService customerContentService; - - // 浼樻儬鍒� - /* - * public final static int quanType = 1; - * - * public final static int baoyou = 2; - * - * public final static int TMALL = 3; - */ - - /** - * - * 鏂规硶璇存槑: 鍏抽敭瀛楁彁绀哄缓璁悳绱� - * - * @author mawurui createTime 2018骞�4鏈�25鏃� 涓嬪崍3:04:52 - * @param acceptData - * @param kw - * @param out - */ - @RequestMapping(value = "suggestsearch", method = RequestMethod.GET) - public void getSugguestSearch(String callback, AcceptData acceptData, String kw, PrintWriter out) { - List<String> list = TaoBaoUtil.getSuguestSearch(kw); - if (list != null && list.size() > 0) { - JSONArray array = new JSONArray(); - int num = 0; - for (String st : list) { - array.add(st); - num = num + 1; - if (num >= 5) { - break; - } - } - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(array))); - } else { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(""))); - } - return; - } - - /** - * - * 鏂规硶璇存槑: 鎼滅储 - * - * @author mawurui createTime 2018骞�5鏈�3鏃� 涓婂崍9:53:54 - * @param acceptData - * @param kw - * @param page - * @param filter - * @param order - * @param startprice - * @param endprice - * @param fastFilter - * @param out - */ - @RequestMapping(value = "search", method = RequestMethod.GET) - public void search(String callback, AcceptData acceptData, String kw, int page, String filter, String order, - String startprice, String endprice, String fastFilter, PrintWriter out) { - /* - * System system = webControllerUtil.getSystem(acceptData); if(system == - * null){ - * out.print(JsonUtil.loadFalseResult(WebControllerUtil.NOSYSTEM)); - * 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; - } - } - JSONObject data = search(kw, page, filter, order, startprice, endprice); - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - } - - private JSONObject search(String kw, int page, String filter, String order, String startprice, String endprice) { - - SearchFilter sf = new SearchFilter(); - sf.setKey(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) == 0) { // 閿�閲� - sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); - } else if (Integer.parseInt(order) == 3) { - sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW); - } else if (Integer.parseInt(order) == 2) { - sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH); - } else if (Integer.parseInt(order) == 1) { - - } - } - /* - * else{ //榛樿閿�閲忎粠楂樺埌浣庢帓搴� sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); } - */ - - if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) { - // 鏌ヨ娣樺疂澶╃尗 - - if (Integer.parseInt(filter) == 1) { - filter = "[{\"type\": \"quantype\"}]"; - } else if (Integer.parseInt(filter) == 2) { - filter = "[{\"type\": \"baoyou\"}]"; - } else if (Integer.parseInt(filter) == 3) { - filter = "[{\"type\": \"userType\"}]"; - } else { - filter = "[]"; - } - JSONArray array = JSONArray.fromObject(filter); - Set<String> params = new HashSet<String>(); - for (int i = 0; i < array.size(); i++) { - 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); - } - } - } - sf.setParams(params); - } - TaoBaoSearchResult result = TaoBaoUtil.search(sf); - 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(); - BigDecimal proportion = manageService.getFanLiRate(); - if (fq == 0 && fh == 0 && !ft) { - for (TaoBaoGoodsBrief bf : result.getTaoBaoGoodsBriefs()) { - re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), "")); - } - } else { - TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra; - if (taoBaoGoodsBriefs != null) - for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) { - taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), - ""); - re.add(taoBaoGoodsBriefExtra); - } - } - Gson gson2 = JsonUtil.getApiCommonGson(); - data.put("result", gson2.toJson(re)); - data.put("count", result.getTaoBaoHead().getDocsfound()); - return data; - } - - /** - * - * 鏂规硶璇存槑: 鑱旂郴瀹㈡湇鎺ュ彛 - * - * @author mawurui createTime 2018骞�4鏈�10鏃� 涓婂崍9:02:41 - */ - @RequestMapping(value = "contactCustomer", method = RequestMethod.GET) - public void contactCustomerService(PrintWriter out) { - String title = "鑱旂郴瀹㈡湇"; - List<CustomerContent> contentList = customerContentService.contactCustomerService(title); - JSONObject data = new JSONObject(); - data.put("contentList", JsonUtil.getSimpleGsonWithDate().toJson(contentList)); - out.print(JsonUtil.loadTrueResult(data)); - } - - /** - * - * 鏂规硶璇存槑: 鐑棬鎼滅储 - * - * @author mawurui createTime 2018骞�5鏈�11鏃� 涓嬪崍4:32:46 - * @param acceptData - * @param out - */ - @RequestMapping(value = "getHotSearch", method = RequestMethod.GET) - public void getHotSearch(AcceptData acceptData, String callback, PrintWriter out) { - /* - * System system = xcxMiniControllerUtil.getSystem(acceptData); if - * (system == null) { - * out.print(JsonUtil.loadFalseResult(XcxMiniControllerUtil.NOSYSTEM)); - * return; } - */ - List<SuperHotSearch> superHotSearchList = superHotSearchSerivce.getSuperHotSearchBySystemId(4); // 杩斿埄鍒竌pp - if (superHotSearchList == null || superHotSearchList.size() == 0) { - out.print(JsonUtil.loadFalseResult(H5ControllerUtil.NODATA)); - return; - } - List<HotSearch> hotSearchList = new ArrayList<HotSearch>(); - for (SuperHotSearch superHotSearch : superHotSearchList) { - HotSearch hotSearch = superHotSearch.getHotSearch(); - hotSearchList.add(hotSearch); - } - - JSONObject data = new JSONObject(); - data.put("count", hotSearchList.size()); - data.put("hotSearchList", hotSearchList); - - String result = JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)); - out.print(result); - return; - } -} +package com.yeshi.fanli.controller.h5; + +import java.io.PrintWriter; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.annotation.Resource; + +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 com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.yeshi.fanli.entity.accept.AcceptData; +import com.yeshi.fanli.entity.bus.search.HotSearch; +import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch; +import com.yeshi.fanli.entity.taobao.SearchFilter; +import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; +import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBriefExtra; +import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav; +import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; +import com.yeshi.fanli.service.inter.config.CustomerContentService; +import com.yeshi.fanli.service.inter.config.SuperHotSearchService; +import com.yeshi.fanli.service.inter.config.SystemClientParamsService; +import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; +import com.yeshi.fanli.service.inter.user.HistorySearchService; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.taobao.TaoBaoUtil; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +@Controller +@RequestMapping("api/h5/v1/webSearch") +public class H5SearchController { + + @Resource + private HistorySearchService historySearchService; + + @Resource + private H5ControllerUtil h5ControllerUtil; + + @Resource + private HongBaoManageService manageService; + + @Resource + private SystemClientParamsService systemClientParamsService; + + @Resource + private SuperHotSearchService superHotSearchSerivce; + + @Resource + private CustomerContentService customerContentService; + + + + /** + * + * 鏂规硶璇存槑: 鎼滅储 + * + * @author mawurui createTime 2018骞�5鏈�3鏃� 涓婂崍9:53:54 + * @param acceptData + * @param kw + * @param page + * @param filter + * @param order + * @param startprice + * @param endprice + * @param fastFilter + * @param out + */ + @RequestMapping(value = "search", method = RequestMethod.GET) + public void search(String callback, AcceptData acceptData, String kw, int page, String filter, String order, + String startprice, String endprice, String fastFilter, PrintWriter out) { + + 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; + } + } + JSONObject data = search(acceptData, kw, page, filter, order, startprice, endprice); + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + } + + private JSONObject search(AcceptData acceptData, String kw, int page, String filter, String order, String startprice, String endprice) { + + SearchFilter sf = new SearchFilter(); + sf.setKey(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) == 0) { // 閿�閲� + sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); + } else if (Integer.parseInt(order) == 3) { + sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW); + } else if (Integer.parseInt(order) == 2) { + sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH); + } else if (Integer.parseInt(order) == 1) { + + } + } + /* + * else{ //榛樿閿�閲忎粠楂樺埌浣庢帓搴� sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); } + */ + + if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) { + // 鏌ヨ娣樺疂澶╃尗 + + if (Integer.parseInt(filter) == 1) { + filter = "[{\"type\": \"quantype\"}]"; + } else if (Integer.parseInt(filter) == 2) { + filter = "[{\"type\": \"baoyou\"}]"; + } else if (Integer.parseInt(filter) == 3) { + filter = "[{\"type\": \"userType\"}]"; + } else { + filter = "[]"; + } + JSONArray array = JSONArray.fromObject(filter); + Set<String> params = new HashSet<String>(); + for (int i = 0; i < array.size(); i++) { + 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); + } + } + } + sf.setParams(params); + } + TaoBaoSearchResult result = TaoBaoUtil.search(sf,null,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(); + BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem()); + if (fq == 0 && fh == 0 && !ft) { + for (TaoBaoGoodsBrief bf : result.getTaoBaoGoodsBriefs()) { + re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), "")); + } + } else { + TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra; + if (taoBaoGoodsBriefs != null) + for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) { + taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), + ""); + re.add(taoBaoGoodsBriefExtra); + } + } + Gson gson2 = JsonUtil.getApiCommonGson(); + data.put("result", gson2.toJson(re)); + data.put("count", result.getTaoBaoHead().getDocsfound()); + return data; + } + + + /** + * + * 鏂规硶璇存槑: 鐑棬鎼滅储 + * + * @author mawurui createTime 2018骞�5鏈�11鏃� 涓嬪崍4:32:46 + * @param acceptData + * @param out + */ + @RequestMapping(value = "getHotSearch", method = RequestMethod.GET) + public void getHotSearch(AcceptData acceptData, String callback, PrintWriter out) { + /* + * System system = xcxMiniControllerUtil.getSystem(acceptData); if + * (system == null) { + * out.print(JsonUtil.loadFalseResult(XcxMiniControllerUtil.NOSYSTEM)); + * return; } + */ + List<SuperHotSearch> superHotSearchList = superHotSearchSerivce.getSuperHotSearchBySystemId(4, null); // 鏉挎牀蹇渷app + if (superHotSearchList == null || superHotSearchList.size() == 0) { + out.print(JsonUtil.loadFalseResult(H5ControllerUtil.NODATA)); + return; + } + List<HotSearch> hotSearchList = new ArrayList<HotSearch>(); + for (SuperHotSearch superHotSearch : superHotSearchList) { + HotSearch hotSearch = superHotSearch.getHotSearch(); + hotSearchList.add(hotSearch); + } + + JSONObject data = new JSONObject(); + data.put("count", hotSearchList.size()); + data.put("hotSearchList", hotSearchList); + + String result = JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)); + out.print(result); + return; + } +} -- Gitblit v1.8.0