From 64a1ca289eda4deb422549311c4539b09fd30ba3 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期四, 07 十一月 2019 12:31:36 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div
---
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java | 421 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 274 insertions(+), 147 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 01b0b1c..15c327d 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
@@ -6,6 +6,7 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -13,6 +14,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.yeshi.utils.HttpUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@@ -26,6 +28,7 @@
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.tag.PageEntity;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
@@ -35,44 +38,20 @@
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_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 post(String url, Map<String, String> params) {
- String baseUrl = url;
- List<String> paramsList = new ArrayList<>();
- if (params != null)
- for (Iterator<String> its = params.keySet().iterator(); its.hasNext();) {
- String key = its.next();
- try {
- paramsList.add(key + "=" + URLEncoder.encode(params.get(key), "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
- baseUrl += "?" + StringUtil.concat(paramsList, "&");
- HttpClient client = new HttpClient();
- PostMethod pm = new PostMethod(baseUrl);
- try {
- client.executeMethod(pm);
- String result = pm.getResponseBodyAsString();
- return new String(result.getBytes("ISO-8859-1"), "UTF-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
private static String post2(String url, Map<String, String> params) {
String baseUrl = url;
List<String> paramsList = new ArrayList<>();
@@ -113,23 +92,6 @@
return StringUtil.Md5(SECRET_KEY + str + SECRET_KEY).toUpperCase();
}
- private static String baseRequest(String method, String accessToken, JSONObject params) {
- Map<String, String> baseMap = new HashMap<String, String>();
- baseMap.put("param_json", params.toString());
- baseMap.put("app_key", APP_KEY);
- baseMap.put("method", method);
- if (accessToken != null)
- baseMap.put("access_token", accessToken);
- baseMap.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
- baseMap.put("format", "json");
- baseMap.put("v", "1.0");
- baseMap.put("sign_method", "md5");
- baseMap.put("sign", getSign(baseMap));
- String result = post(SERVER_URL, baseMap);
- return result;
- }
-
-
private static String baseRequest2(String method, String accessToken, JSONObject params) {
Map<String, String> baseMap = new HashMap<String, String>();
baseMap.put("param_json", params.toString());
@@ -145,7 +107,7 @@
String result = post2(SERVER_URL, baseMap);
return result;
}
-
+
/**
* 杞摼
*
@@ -156,24 +118,47 @@
json.put("materialId", materialId);
json.put("siteId", APP_ID);
json.put("positionId", positionId);
-
+
if (!StringUtil.isNullOrEmpty(couponUrl))
json.put("couponUrl", couponUrl);
-
+
if (!StringUtil.isNullOrEmpty(ext1))
- json.put("ext1", ext1);
+ json.put("ext1", ext1);
JSONObject root = new JSONObject();
root.put("promotionCodeReq", json);
- String result = baseRequest("jd.union.open.promotion.common.get", null, root);
+ String result = baseRequest2("jd.union.open.promotion.common.get", null, root);
+
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;
+ }
+
resultJson = JSONObject.fromObject(result);
return resultJson.optJSONObject("data").optString("clickURL");
}
-
-
+
+ /**
+ * 杞摼鎺�-鐭繛鎺�
+ *
+ * @param materialId
+ * @param couponUrl
+ * @param positionId
+ * @param ext1
+ * @return
+ */
+ 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);
+// }
+ return url;
+ }
+
public static JDGoods queryGoodsDetail(Long skuId) {
List<Long> skuIdList = new ArrayList<>();
skuIdList.add(skuId);
@@ -189,15 +174,29 @@
}
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();
+ }
+
/**
* 鍏抽敭璇嶅晢鍝佹煡璇㈡帴鍙c�愮敵璇枫��
+ *
* @param skuIdList
* @return
*/
public static JDSearchResult queryByKey(JDFilter filter) {
JDSearchResult searchResult = new JDSearchResult();
-
+
List<JDGoods> list = new ArrayList<>();
JSONObject json = new JSONObject();
json.put("pageIndex", filter.getPageIndex());
@@ -256,16 +255,15 @@
if (filter.getShopId() != null)
json.put("shopId", filter.getShopId());
-
+
if (filter.getOwner() != null)
json.put("owner", filter.getOwner());
-
+
System.out.println(json.toString());
-
+
JSONObject jsonDTO = new JSONObject();
jsonDTO.put("goodsReqDTO", json);
-
-
+
String result = baseRequest2("jd.union.open.goods.query", null, jsonDTO);
System.out.println(result);
JSONObject resultJson = JSONObject.fromObject(result);
@@ -284,22 +282,33 @@
}
}
}
-
+
long totalCount = resultJson.optLong("totalCount");
PageEntity pageEntity = new PageEntity();
pageEntity.setTotalCount(totalCount);
-
+
searchResult.setPageEntity(pageEntity);
}
searchResult.setGoodsList(list);
return searchResult;
}
-
-
-
-
+
private static JDGoods parseJDGoods(JSONObject json) {
JDGoods goods = new JDGoods();
+
+ // 浣i噾淇℃伅
+ Object commission = json.get("commissionInfo");
+ JSONObject commissionJson = JSONObject.fromObject(commission);
+ BigDecimal commissionShare = new BigDecimal(commissionJson.optString("commissionShare"));
+ if (commissionShare.compareTo(new BigDecimal(0)) > 0) {
+ JDCommissionInfo commissionInfo = new JDCommissionInfo();
+ commissionInfo.setCommission(new BigDecimal(commissionJson.optString("commission")));
+ commissionInfo.setCommissionShare(commissionShare);
+ goods.setCommissionInfo(commissionInfo);
+ } else {
+ return null;
+ }
+
goods.setComments(json.optLong("comments"));
goods.setBrandCode(json.optString("brandCode"));
goods.setBrandName(json.optString("brandName"));
@@ -310,14 +319,12 @@
goods.setSkuId(json.optLong("skuId"));
goods.setSkuName(json.optString("skuName"));
goods.setIsHot(json.optInt("isHot"));
-
-
+
// 浠锋牸淇℃伅
Object priceInfo = json.get("priceInfo");
JSONObject priceInfoJson = JSONObject.fromObject(priceInfo);
- BigDecimal price = new BigDecimal(priceInfoJson.optString("price"));
- goods.setPrice(price);
-
+ goods.setPrice(new BigDecimal(priceInfoJson.optString("price")));
+
// 搴楅摵淇℃伅
Object shopInfo = json.get("shopInfo");
JSONObject shopInfoJson = JSONObject.fromObject(shopInfo);
@@ -325,8 +332,7 @@
jdshopInfo.setShopId(shopInfoJson.optInt("shopId"));
jdshopInfo.setShopName(shopInfoJson.optString("shopName"));
goods.setShopInfo(jdshopInfo);
-
-
+
// 鍒嗙被淇℃伅
Object category = json.get("categoryInfo");
JSONObject categoryJson = JSONObject.fromObject(category);
@@ -338,47 +344,71 @@
categoryInfo.setCid3(categoryJson.optLong("cid3"));
categoryInfo.setCid3Name(categoryJson.optString("cid3Name"));
goods.setCategoryInfo(categoryInfo);
-
-
- // 浣i噾淇℃伅
- Object commission = json.get("commissionInfo");
- JSONObject commissionJson = JSONObject.fromObject(commission);
- JDCommissionInfo commissionInfo = new JDCommissionInfo();
- commissionInfo.setCommission(new BigDecimal(commissionJson.optString("commission")));
- commissionInfo.setCommissionShare(new BigDecimal(commissionJson.optString("commissionShare")));
- goods.setCommissionInfo(commissionInfo);
-
-
+
+ // 鍥剧墖淇℃伅
+ List<String> imageList = new ArrayList<String>();
+ Object images = json.get("imageInfo");
+ JSONObject imagesJson = JSONObject.fromObject(images);
+ JSONArray imagesArray = imagesJson.optJSONArray("imageList");
+ for (int i = 0; i < imagesArray.size(); i++) {
+ imageList.add(imagesArray.optJSONObject(i).optString("url"));
+ }
+ goods.setImageList(imageList);
+
+ if (imageList.size() > 0) {
+ goods.setPicUrl(imageList.get(0));
+ }
+
+ BigDecimal price = new BigDecimal(priceInfoJson.optString("price"));
+ // 鎷艰喘淇℃伅
+ Object pinGouInfo = json.get("pinGouInfo");
+ if (pinGouInfo != null) {
+ JSONObject pinGouInfoJson = JSONObject.fromObject(pinGouInfo);
+ if (!pinGouInfoJson.isEmpty()) {
+ JDPingouInfo jdPinGouInfo = new JDPingouInfo();
+ price = new BigDecimal(pinGouInfoJson.optString("pingouPrice"));
+ jdPinGouInfo.setPingouPrice(price);
+ jdPinGouInfo.setPingouTmCount(pinGouInfoJson.optLong("pingouTmCount"));
+ jdPinGouInfo.setPingouUrl(pinGouInfoJson.optString("pingouUrl"));
+ jdPinGouInfo.setTotalCount(pinGouInfoJson.optLong("totalCount"));
+ jdPinGouInfo.setPingouEndTime(pinGouInfoJson.optLong("pingouEndTime"));
+ jdPinGouInfo.setPingouStartTime(pinGouInfoJson.optLong("pingouStartTime"));
+ goods.setPinGouInfo(jdPinGouInfo);
+ }
+ }
+
// 鍒镐俊鎭�
Object coupon = json.get("couponInfo");
if (coupon != null) {
JSONObject couponJson = JSONObject.fromObject(coupon);
JSONArray couponArray = couponJson.optJSONArray("couponList");
if (couponArray != null) {
- BigDecimal gap = null;
+ BigDecimal discount_temp = null;
JDCouponInfo couponInfo = null;
for (int i = 0; i < couponArray.size(); i++) {
boolean add = false;
JSONObject jdcoupon = couponArray.optJSONObject(i);
- if (couponInfo == null) {
- couponInfo = new JDCouponInfo();
- add = true;
- }
-
+
BigDecimal quota = new BigDecimal(jdcoupon.optString("quota"));
BigDecimal sub = MoneyBigDecimalUtil.sub(price, quota);
- if (gap == null) {
- gap = sub;
- } else if (sub.compareTo(gap) == 0) {
- BigDecimal discount = new BigDecimal(jdcoupon.optString("discount"));
- if (discount.compareTo(couponInfo.getDiscount()) > 0) {
- add = true;
- }
- } else if (sub.compareTo(gap) > 0) {
- add = true;
+ if (sub.compareTo(new BigDecimal(0)) < 0) {
+ continue; // 鍟嗗搧浠锋牸灏忎簬浼樻儬鍒镐环鏍奸檺鍒�
}
-
+
+ // 鍒搁潰棰�
+ BigDecimal discount = new BigDecimal(jdcoupon.optString("discount"));
+ if (discount_temp == null) {
+ add = true;
+ discount_temp = discount;
+ } else if (discount_temp.compareTo(discount) < 0 && discount.compareTo(price) <= 0) {
+ add = true; // 鍒搁潰棰濆ぇ,涓斿埜鑳藉浣跨敤
+ }
+
if (add) {
+ if (couponInfo == null) {
+ couponInfo = new JDCouponInfo();
+ }
+
couponInfo.setBindType(jdcoupon.optInt("bindType"));
couponInfo.setDiscount(new BigDecimal(jdcoupon.optString("discount")));
couponInfo.setQuota(new BigDecimal(jdcoupon.optString("quota")));
@@ -390,46 +420,17 @@
couponInfo.setLink(jdcoupon.optString("link"));
}
}
+
goods.setCouponInfo(couponInfo);
}
}
-
- // 鍥剧墖淇℃伅
- List<String> imageList = new ArrayList<String>();
- Object images = json.get("imageInfo");
- JSONObject imagesJson = JSONObject.fromObject(images);
- JSONArray imagesArray = imagesJson.optJSONArray("imageList");
- for (int i = 0; i < imagesArray.size(); i++) {
- imageList.add(imagesArray.optJSONObject(i).optString("url"));
- }
- goods.setImageList(imageList);
-
- if (imageList.size() > 0) {
- goods.setPicUrl(imageList.get(0));
- }
-
- // 鎷艰喘淇℃伅
- Object pinGouInfo = json.get("pinGouInfo");
- if (pinGouInfo != null) {
- JSONObject pinGouInfoJson = JSONObject.fromObject(pinGouInfo);
- if (!pinGouInfoJson.isEmpty()) {
- JDPingouInfo jdPinGouInfo = new JDPingouInfo();
- jdPinGouInfo.setPingouPrice(new BigDecimal(pinGouInfoJson.optString("pingouPrice")));
- jdPinGouInfo.setPingouTmCount(pinGouInfoJson.optLong("pingouTmCount"));
- jdPinGouInfo.setPingouUrl(pinGouInfoJson.optString("pingouUrl"));
- jdPinGouInfo.setTotalCount(pinGouInfoJson.optLong("totalCount"));
- jdPinGouInfo.setPingouEndTime(pinGouInfoJson.optLong("pingouEndTime"));
- jdPinGouInfo.setPingouStartTime(pinGouInfoJson.optLong("pingouStartTime"));
- }
- }
-
return goods;
}
-
/**
* 鑾峰彇鎺ㄥ箍鍟嗗搧淇℃伅鎺ュ彛
+ *
* @param skuIdList
* @return
*/
@@ -437,13 +438,12 @@
List<JDGoods> list = new ArrayList<>();
JSONObject json = new JSONObject();
json.put("skuIds", StringUtil.concat(skuIdList, ","));
- String result = baseRequest("jd.union.open.goods.promotiongoodsinfo.query", null, json);
+ String result = baseRequest2("jd.union.open.goods.promotiongoodsinfo.query", null, json);
JSONObject resultJson = JSONObject.fromObject(result);
resultJson = resultJson.optJSONObject("jd_union_open_goods_promotiongoodsinfo_query_response");
if (resultJson.optInt("code") == 0) {
result = resultJson.optString("result");
resultJson = JSONObject.fromObject(result);
- System.out.println(resultJson);
JSONArray array = resultJson.optJSONArray("data");
if (array != null)
for (int i = 0; i < array.size(); i++) {
@@ -457,6 +457,19 @@
private static JDGoods parseSimpleJDGoods(JSONObject json) {
JDGoods goods = new JDGoods();
+ goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
+ ? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
+
+ BigDecimal commisionRatioWl = new BigDecimal(json.optString("commisionRatioWl"));
+ if (commisionRatioWl.compareTo(new BigDecimal(0)) > 0) {
+ JDCommissionInfo commissionInfo = new JDCommissionInfo();
+ commissionInfo.setCommissionShare(new BigDecimal(json.optString("commisionRatioWl")));
+ commissionInfo.setCommission(MoneyBigDecimalUtil
+ .div(goods.getPrice().multiply(commissionInfo.getCommissionShare()), new BigDecimal(100)));
+ goods.setCommissionInfo(commissionInfo);
+ } else {
+ return null;
+ }
JDCategoryInfo categoryInfo = new JDCategoryInfo();
categoryInfo.setCid1(json.optLong("cid1"));
@@ -468,22 +481,22 @@
goods.setCategoryInfo(categoryInfo);
goods.setComments(null);
- goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
- ? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
- JDCommissionInfo commissionInfo = new JDCommissionInfo();
- commissionInfo.setCommissionShare(new BigDecimal(json.optString("commisionRatioWl")));
- commissionInfo.setCommission(MoneyBigDecimalUtil
- .div(goods.getPrice().multiply(commissionInfo.getCommissionShare()), new BigDecimal(100)));
-
- goods.setCommissionInfo(commissionInfo);
+ String isFreeShipping = json.optString("isFreeShipping");
+ 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);
@@ -500,6 +513,87 @@
return goods;
}
+ public static JDSearchResult getJingFenGoods(int pageIndex, int eliteId) {
+ JDSearchResult searchResult = new JDSearchResult();
+ List<JDGoods> list = new ArrayList<>();
+ JSONObject json = new JSONObject();
+ json.put("pageIndex", pageIndex);
+ json.put("pageSize", 20);
+ json.put("sortName", "inOrderCount30DaysSku");
+ json.put("sort", "desc");
+ json.put("eliteId", eliteId);
+
+ JSONObject jsonDTO = new JSONObject();
+ jsonDTO.put("goodsReq", json);
+
+ String result = baseRequest2("jd.union.open.goods.jingfen.query", null, jsonDTO);
+ System.out.println(result);
+ JSONObject resultJson = JSONObject.fromObject(result);
+ resultJson = resultJson.optJSONObject("jd_union_open_goods_jingfen_query_response");
+ if (resultJson.optInt("code") == 0) {
+ result = resultJson.optString("result");
+ resultJson = JSONObject.fromObject(result);
+ String message = resultJson.optString("message");
+ if ("SUCCESS".equalsIgnoreCase(message)) {
+ JSONArray array = resultJson.optJSONArray("data");
+ if (array != null) {
+ for (int i = 0; i < array.size(); i++) {
+ JDGoods goods = parseJDGoods(array.optJSONObject(i));
+ if (goods != null)
+ list.add(goods);
+ }
+ }
+ }
+
+ long totalCount = resultJson.optLong("totalCount");
+ PageEntity pageEntity = new PageEntity();
+ pageEntity.setTotalCount(totalCount);
+
+ searchResult.setPageEntity(pageEntity);
+ }
+ searchResult.setGoodsList(list);
+ return searchResult;
+ }
+
+ public static JDSearchResult getGoodsClass() {
+ JDSearchResult searchResult = new JDSearchResult();
+ List<JDGoods> list = new ArrayList<>();
+ JSONObject json = new JSONObject();
+ json.put("parentId", 0);
+ json.put("grade", 0);
+
+ JSONObject jsonDTO = new JSONObject();
+ jsonDTO.put("req", json);
+
+ String result = baseRequest2("jd.union.open.category.goods.get", null, jsonDTO);
+ System.out.println(result);
+ JSONObject resultJson = JSONObject.fromObject(result);
+ resultJson = resultJson.optJSONObject("jd_union_open_goods_jingfen_query_response");
+ if (resultJson.optInt("code") == 0) {
+ result = resultJson.optString("result");
+ resultJson = JSONObject.fromObject(result);
+ String message = resultJson.optString("message");
+ if ("SUCCESS".equalsIgnoreCase(message)) {
+ JSONArray array = resultJson.optJSONArray("data");
+ if (array != null) {
+ for (int i = 0; i < array.size(); i++) {
+ JDGoods goods = parseJDGoods(array.optJSONObject(i));
+ if (goods != null)
+ list.add(goods);
+ }
+ }
+ }
+
+ long totalCount = resultJson.optLong("totalCount");
+ PageEntity pageEntity = new PageEntity();
+ pageEntity.setTotalCount(totalCount);
+
+ searchResult.setPageEntity(pageEntity);
+ }
+ searchResult.setGoodsList(list);
+ return searchResult;
+ }
+
public static JDGoods getGoodsDetail(Long skuId) {
List<Long> skuIdList = new ArrayList<>();
skuIdList.add(skuId);
@@ -509,33 +603,66 @@
return null;
}
- public static JDOrderResult getOrder(int page, int pageSize, String time, int type) {
+ /**
+ * 鑾峰彇璁㈠崟鍒楄〃
+ *
+ * @param page
+ * @param pageSize
+ * @param time
+ * @param type
+ * 鏃堕棿绫诲瀷 1-涓嬪崟鏃堕棿 2-瀹屾垚鏃堕棿 3-鏇存柊鏃堕棿
+ * @return
+ */
+ public static JDOrderResult getOrderList(int page, int pageSize, Date time, int type) {
JSONObject json = new JSONObject();
JSONObject orderReq = new JSONObject();
orderReq.put("pageNo", page);
orderReq.put("pageSize", pageSize);
orderReq.put("type", type);
- orderReq.put("time", time);
+ orderReq.put("time", TimeUtil.getGernalTime(time.getTime(), "yyyyMMddHH"));
json.put("orderReq", orderReq);
- String result = baseRequest("jd.union.open.order.query", null, json);
+ 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) {
+ 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