From a6f34b99ee20e528b766c8ed5a61bd9c5aa0e7ae Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 16 十一月 2019 18:10:33 +0800 Subject: [PATCH] 淘宝相似商品推荐接口优化,根据商品ID搜索商品基本信息优化 --- fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java | 75 +++++++++++++++++++++++++++++-------- 1 files changed, 58 insertions(+), 17 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java index e7f417b..2c0c7c7 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java @@ -28,6 +28,8 @@ import com.yeshi.fanli.dto.jd.JDShopInfo; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.jd.JDOrder; +import com.yeshi.fanli.entity.jd.JDOrderItem; +import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; @@ -37,21 +39,19 @@ import net.sf.json.JSONObject; public class JDApiUtil { - public static String APP_ID = "1774659094"; - public static String APP_KEY = "7ba8e06b7d6fde3d6bd5db4b0026ecd7"; - public static String SECRET_KEY = "fb49bc6ecac5458ba5394fc2969d7c56"; + public static String APP_ID = "1864778416"; + public static String APP_KEY = "388f5133d13a5ea290aa5c44f3ebcc00"; + public static String SECRET_KEY = "e22367fc866746d98b50d47b4c521781"; private static String SERVER_URL = "https://router.jd.com/api"; - public static long POSITION_FANLI = 1834339426L; - public static long POSITION_SHARE = 1834289924L; - public static long POSITION_COUPON = 1859510742L; + public static long POSITION_FANLI = 1869704794L; + public static long POSITION_SHARE = 1869542990L; + public static long POSITION_COUPON = 1869704796L; // 璁㈠崟鏌ヨ绫诲瀷 public static int ORDER_TYPE_CREATETIME = 1;// 涓嬪崟鏃堕棿 public static int ORDER_TYPE_FINISHTIME = 2;// 瀹屾垚鏃堕棿 public static int ORDER_TYPE_UPDATETIME = 3;// 鏇存柊鏃堕棿 - - private static String post2(String url, Map<String, String> params) { String baseUrl = url; @@ -133,6 +133,7 @@ JSONObject resultJson = JSONObject.fromObject(result); result = resultJson.optJSONObject("jd_union_open_promotion_common_get_response").optString("result"); + System.out.println(result); if (result == null) { return null; } @@ -152,9 +153,10 @@ */ public static String convertShortLink(String materialId, String couponUrl, String positionId, String ext1) { String url = convertLink(materialId, couponUrl, positionId, ext1); - if (!StringUtil.isNullOrEmpty(url)) { - url = HttpUtil.getShortLink(url); - } +//鏆傛椂娉ㄩ噴 +// if (!StringUtil.isNullOrEmpty(url)) { +// url = HttpUtil.getShortLink(url); +// } return url; } @@ -172,6 +174,19 @@ return list.get(0); } return null; + } + + /** + * 閫氳繃鍟嗗搧鎼滅储鎺ュ彛鎵归噺鑾峰彇璇︽儏 + * + * @param skuIds + * @return + */ + public static List<JDGoods> listGoodsDetail(List<Long> skuIds) { + JDFilter filter = new JDFilter(); + filter.setListId(skuIds); + JDSearchResult result = queryByKey(filter); + return result.getGoodsList(); } /** @@ -386,8 +401,8 @@ if (discount_temp == null) { add = true; discount_temp = discount; - } else if (discount_temp.compareTo(discount) > 0) { // 鍒搁潰棰濆ぇ - add = true; + } else if (discount_temp.compareTo(discount) < 0 && discount.compareTo(price) <= 0) { + add = true; // 鍒搁潰棰濆ぇ,涓斿埜鑳藉浣跨敤 } if (add) { @@ -472,14 +487,17 @@ if (!StringUtil.isNullOrEmpty(isFreeShipping)) { goods.setIsFreeShipping(Integer.parseInt(isFreeShipping)); } - + String inOrderCount = json.optString("inOrderCount"); + if (!StringUtil.isNullOrEmpty(isFreeShipping)) { + goods.setInOrderCount30Days(Long.parseLong(inOrderCount)); + } + goods.setCouponInfo(null); goods.setGoodCommentsShare(null); List<String> imageList = new ArrayList<>(); imageList.add(json.optString("imgUrl")); goods.setPicUrl(json.optString("imgUrl")); goods.setImageList(imageList); - goods.setInOrderCount30Days(0L); goods.setIsHot(null); goods.setMaterialUrl(json.optString("materialUrl")); goods.setOwner(null); @@ -510,6 +528,7 @@ jsonDTO.put("goodsReq", json); String result = baseRequest2("jd.union.open.goods.jingfen.query", null, jsonDTO); + LogHelper.test(result); System.out.println(result); JSONObject resultJson = JSONObject.fromObject(result); resultJson = resultJson.optJSONObject("jd_union_open_goods_jingfen_query_response"); @@ -606,24 +625,46 @@ json.put("orderReq", orderReq); String result = baseRequest2("jd.union.open.order.query", null, json); + System.out.println(result); JSONObject root = JSONObject.fromObject(result).optJSONObject("jd_union_open_order_query_response"); if (root.optInt("code") == 0) { boolean hasMore = root.optBoolean("hasMore"); root = JSONObject.fromObject(root.optString("result")); - if (root.optInt("code") == 200&&root.optJSONArray("data")!=null) { - + if (root.optInt("code") == 200 && root.optJSONArray("data") != null) { + String date = root.optJSONArray("data").toString(); Type typeToken = new TypeToken<List<JDOrder>>() { }.getType(); List<JDOrder> orderList = new Gson().fromJson(date, typeToken); if (orderList != null) for (JDOrder order : orderList) { + Map<Long, List<JDOrderItem>> map = new HashMap<>(); for (int i = 0; i < order.getOrderItemList().size(); i++) { + JDOrderItem orderItem = order.getOrderItemList().get(i); + if (map.get(orderItem.getSkuId()) == null) + map.put(orderItem.getSkuId(), new ArrayList<>()); + map.get(orderItem.getSkuId()).add(orderItem); + order.getOrderItemList().get(i) .setTradeId(order.getOrderId() + "-" + order.getOrderItemList().get(i).getSkuId()); order.getOrderItemList().get(i).setOrderId(order.getOrderId()); order.getOrderItemList().get(i).setOrderBy(i + 1); } + // 鏌ヨ鍟嗗搧ID鐩稿悓鐨勫瓙璁㈠崟 + for (Iterator<Long> its = map.keySet().iterator(); its.hasNext();) { + Long skuId = its.next(); + if (map.get(skuId).size() > 1) { + int skuOrderBy = 1; + for (int i = 0; i < order.getOrderItemList().size(); i++) { + JDOrderItem orderItem = order.getOrderItemList().get(i); + if (orderItem.getSkuId().longValue() == skuId) { + order.getOrderItemList().get(i).setTradeId(order.getOrderId() + "-" + + order.getOrderItemList().get(i).getSkuId() + "-" + skuOrderBy++); + } + } + } + } + } return new JDOrderResult(hasMore, orderList); } -- Gitblit v1.8.0