| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | */ |
| | | @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, "请传递正确平台参数")); |
| | |
| | | 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(); |
| | |
| | | |
| | | @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, "请传递正确平台参数")); |
| | |
| | | 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); |
| | | } |
| | | }); |
| | | |
| | |
| | | goodsId = id; |
| | | } |
| | | } |
| | | if (goodsId == null) { |
| | | //解析链接 |
| | | 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; |
| | | // 搜索结果缓存到redis |
| | | 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; |
| | | // 搜索结果缓存到redis |
| | | 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(), |