From 91ddd96c12ec25aaf6d0cb38d54288d863ab2b58 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 10 七月 2021 18:10:38 +0800 Subject: [PATCH] 礼金红包兼容 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java | 259 ++++++++++++++++++++++++++++----------------------- 1 files changed, 140 insertions(+), 119 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 25a4470..2d7b931 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 @@ -7,10 +7,12 @@ import java.util.List; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import com.yeshi.fanli.entity.SystemEnum; import com.yeshi.fanli.entity.SystemPIDInfo; +import com.yeshi.fanli.entity.bus.search.HistorySearch; import com.yeshi.fanli.exception.pdd.PDDApiException; import com.yeshi.fanli.exception.taobao.TaoBaoTokenParseException; import com.yeshi.fanli.lijin.manager.GoodsLijinMnager; @@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.yeshi.utils.HttpUtil; +import org.yeshi.utils.IPUtil; import org.yeshi.utils.JsonUtil; import com.google.gson.Gson; @@ -528,7 +531,7 @@ */ @RequestMapping(value = "searchGoods") public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter, - Integer order, Long uid, String notifyType, HttpSession session, PrintWriter out) { + Integer order, Long uid, String notifyType, HttpSession session,HttpServletRequest request, PrintWriter out) { if (goodsType == null || goodsType < 1 || goodsType > 5) { out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�")); @@ -567,18 +570,17 @@ executor.execute(new Runnable() { @Override public void run() { - StringBuffer sb = new StringBuffer(); - String link = "#$$$#"; - String platform = acceptData.getPlatform(); - String packages = acceptData.getPackages(); - String device = acceptData.getDevice(); - sb.append(platform).append(link).append(packages).append(link).append(device); - String bid = StringUtil.Md5(sb.toString()); - - // 鍔犲叆鎼滅储鍘嗗彶璁板綍 - historySearchService.addHistorySearch(searchkey, bid); + HistorySearch search = new HistorySearch(); + search.setDevice(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid()); + search.setKey(key); + search.setSystem(acceptData.getSystem()); + search.setUid(uid); + search.setGoodsType(goodsType); + search.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); + historySearchService.addHistorySearch(search); } }); + if (searchkey.startsWith("http://") || searchkey.startsWith("https://")) { JSONObject data = new JSONObject(); @@ -635,7 +637,7 @@ @RequestMapping(value = "searchGoodsTJ") public void searchGoodsTJ(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter, - Integer order, Long uid, String notifyType, HttpSession session, PrintWriter out) { + Integer order, Long uid, String notifyType, HttpSession session, HttpServletRequest request, PrintWriter out) { if (goodsType == null || goodsType < 1 || goodsType > 5) { out.print(JsonUtil.loadFalseResult(1, "璇蜂紶閫掓纭钩鍙板弬鏁�")); @@ -657,15 +659,14 @@ executor.execute(new Runnable() { @Override public void run() { - StringBuffer sb = new StringBuffer(); - String link = "#$$$#"; - String platform = acceptData.getPlatform(); - String packages = acceptData.getPackages(); - String device = acceptData.getDevice(); - sb.append(platform).append(link).append(packages).append(link).append(device); - String bid = StringUtil.Md5(sb.toString()); - // 鍔犲叆鎼滅储鍘嗗彶璁板綍 - historySearchService.addHistorySearch(searchkey, bid); + HistorySearch search = new HistorySearch(); + search.setDevice(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid()); + search.setKey(key); + search.setSystem(acceptData.getSystem()); + search.setUid(uid); + search.setGoodsType(goodsType); + search.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); + historySearchService.addHistorySearch(search); } }); @@ -748,113 +749,133 @@ goodsId = id; } } + if (goodsId == null) { + //瑙f瀽閾炬帴 + if (linkList != null && linkList.size() > 0) { + String tempGoodsId = clipboardAnalysisManager.parseTBAuctionIdFromLink(linkList.get(0)); + if (!StringUtil.isNullOrEmpty(tempGoodsId)) { + goodsId = Long.parseLong(tempGoodsId); + } + } + } + } + + //鍟嗗搧ID涓虹┖锛屼笖鏄彛浠ょ殑褰㈠紡灏变互鏈姞鍏ユ窐瀹濊仈鐩熺殑鍟嗗搧澶勭悊 + if (goodsId == null && (linkList != null && linkList.size() > 0) && TaoBaoUtil.isHaveNewVersionTaoBaoToken(key)) { + String[] ks = key.trim().split(" "); + if (ks.length > 1) + key = ks[1].trim(); } } List<TaoBaoGoodsBrief> goodsBriefList = new ArrayList<>(); int count = 0; - if (goodsId != null) { - try { - TaoBaoGoodsBrief goods = TaoKeApiUtil.searchGoodsDetail(goodsId); - goods.setCreatetime(null); - goodsBriefList.add(goods); - count = 1; - } catch (TaobaoGoodsDownException e) { - e.printStackTrace(); - } - } else { - SearchFilter sf = new SearchFilter(); - sf.setKey(SearchFilterUtil.filterSearchContent(key)); - sf.setPage(page); - sf.setPageSize(Constant.PAGE_SIZE); - - if (order != null) { - if (order == 1) { // 閿�閲忛珮鍒颁綆 - sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); - } else if (order == 2) { // 浠锋牸楂樺埌浣� - sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW); - } else if (order == 3) { // 浠锋牸浣庡埌楂� - sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH); - } else if (order == 4) { // 杩斿埄姣旈珮鍒颁綆 - sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW); - } - } - - if (!StringUtil.isNullOrEmpty(filter)) { - 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)); - } - } - - // 鎼滅储澶ф窐瀹� - List<DaTaoKeDetailV2> daTaoKeList = null; - if (page == 1) { - daTaoKeList = daTaoKeGoodsDetailV2Service.listByDtitle(key); - } - - String specialId = null; - if (uid != null) { - specialId = userExtraTaoBaoInfoService.getSpecialIdByUid(uid); - } - - // 娣樺疂api鎼滅储鍟嗗搧 - TaoBaoSearchResult result = taoBaoGoodsCacheUtil.getSearchResult(sf); // TaoBaoUtil.search(sf, specialId, null); - if (result == null) { - result = TaoBaoUtil.search(sf, specialId, null); - taoBaoGoodsCacheUtil.saveSearchResult(sf, result); - } - TaoBaoSearchResult finalResult = result; - // 鎼滅储缁撴灉缂撳瓨鍒皉edis - if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) { - ThreadUtil.run(new Runnable() { - @Override - public void run() { - // 鏇存柊鍒扮珐瀛� - for (TaoBaoGoodsBrief goods : finalResult.getTaoBaoGoodsBriefs()) - taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(goods); - } - }); - } - - List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = null; - if (result != null) { - taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs(); - } - if (taoBaoGoodsBriefs == null) { - taoBaoGoodsBriefs = new ArrayList<>(); - } - - if (daTaoKeList != null && daTaoKeList.size() > 0) { + try { + if (goodsId != null) { try { - Collections.reverse(daTaoKeList); - for (DaTaoKeDetailV2 detail : daTaoKeList) { - taoBaoGoodsBriefs.add(0, TaoBaoUtil.convert(detail)); - } - } catch (Exception e) { + TaoBaoGoodsBrief goods = TaoKeApiUtil.searchGoodsDetail(goodsId); + goods.setCreatetime(null); + goodsBriefList.add(goods); + count = 1; + } catch (TaobaoGoodsDownException e) { + e.printStackTrace(); } - } + } else { + SearchFilter sf = new SearchFilter(); + sf.setKey(SearchFilterUtil.filterSearchContent(key)); + sf.setPage(page); + sf.setPageSize(Constant.PAGE_SIZE); - count = result.getTaoBaoHead().getDocsfound(); - if (taoBaoGoodsBriefs != null) - goodsBriefList.addAll(taoBaoGoodsBriefs); + if (order != null) { + if (order == 1) { // 閿�閲忛珮鍒颁綆 + sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); + } else if (order == 2) { // 浠锋牸楂樺埌浣� + sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW); + } else if (order == 3) { // 浠锋牸浣庡埌楂� + sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH); + } else if (order == 4) { // 杩斿埄姣旈珮鍒颁綆 + sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW); + } + } + + if (!StringUtil.isNullOrEmpty(filter)) { + 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)); + } + } + + // 鎼滅储澶ф窐瀹� + List<DaTaoKeDetailV2> daTaoKeList = null; + if (page == 1) { + daTaoKeList = daTaoKeGoodsDetailV2Service.listByDtitle(key); + } + + String specialId = null; + if (uid != null) { + specialId = userExtraTaoBaoInfoService.getSpecialIdByUid(uid); + } + + // 娣樺疂api鎼滅储鍟嗗搧 + TaoBaoSearchResult result = taoBaoGoodsCacheUtil.getSearchResult(sf); // TaoBaoUtil.search(sf, specialId, null); + if (result == null) { + result = TaoBaoUtil.search(sf, specialId, null); + taoBaoGoodsCacheUtil.saveSearchResult(sf, result); + } + TaoBaoSearchResult finalResult = result; + // 鎼滅储缁撴灉缂撳瓨鍒皉edis + if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) { + ThreadUtil.run(new Runnable() { + @Override + public void run() { + // 鏇存柊鍒扮珐瀛� + for (TaoBaoGoodsBrief goods : finalResult.getTaoBaoGoodsBriefs()) + taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(goods); + } + }); + } + + List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = null; + if (result != null) { + taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs(); + } + if (taoBaoGoodsBriefs == null) { + taoBaoGoodsBriefs = new ArrayList<>(); + } + + if (daTaoKeList != null && daTaoKeList.size() > 0) { + try { + Collections.reverse(daTaoKeList); + for (DaTaoKeDetailV2 detail : daTaoKeList) { + taoBaoGoodsBriefs.add(0, TaoBaoUtil.convert(detail)); + } + } catch (Exception e) { + } + } + + count = result.getTaoBaoHead().getDocsfound(); + if (taoBaoGoodsBriefs != null) + goodsBriefList.addAll(taoBaoGoodsBriefs); + } + } catch (Exception e) { + } GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), -- Gitblit v1.8.0