From 58ee87fd64efdb75d16e396c3d952d3522c3a747 Mon Sep 17 00:00:00 2001
From: yj <Administrator@192>
Date: 星期三, 04 三月 2020 17:54:53 +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 | 188 ++++++++++++++++++++++++++++++----------------
1 files changed, 123 insertions(+), 65 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 0ab6a23..84c79cb 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.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -14,7 +15,6 @@
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,9 +26,11 @@
import com.yeshi.fanli.dto.jd.JDPingouInfo;
import com.yeshi.fanli.dto.jd.JDSearchResult;
import com.yeshi.fanli.dto.jd.JDShopInfo;
+import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
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;
@@ -113,7 +115,7 @@
*
* @return
*/
- public static String convertLink(String materialId, String couponUrl, String positionId, String ext1) {
+ public static String convertLink1(String materialId, String couponUrl, String positionId, String ext1) {
JSONObject json = new JSONObject();
json.put("materialId", materialId);
json.put("siteId", APP_ID);
@@ -141,21 +143,43 @@
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);
+ public static String convertLinkWithSubUnionId(String materialId, String couponUrl, String positionId,
+ String subUnionId) {
+ String log = "浜笢杞摼鍑洪敊:";
+ try {
+ JSONObject json = new JSONObject();
+ json.put("materialId", materialId);
+ json.put("siteId", APP_ID);
+ json.put("positionId", positionId);
+
+ if (!StringUtil.isNullOrEmpty(couponUrl))
+ json.put("couponUrl", couponUrl);
+
+ if (!StringUtil.isNullOrEmpty(subUnionId))
+ json.put("subUnionId", subUnionId);
+
+ // 1锛氶暱閾撅紝 2 锛氱煭閾� 锛�3锛� 闀块摼+鐭摼
+ json.put("chainType", 3);
+ JSONObject root = new JSONObject();
+ root.put("promotionCodeReq", json);
+
+ String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root);
+
+ log += json.toString() + "####" + result;
+ JSONObject resultJson = JSONObject.fromObject(result);
+ result = resultJson.optJSONObject("jd_union_open_promotion_bysubunionid_get_response").optString("result");
+ System.out.println(result);
+ if (result == null) {
+ return null;
+ }
+
+ resultJson = JSONObject.fromObject(result);
+ return resultJson.optJSONObject("data").optString("shortURL");
+ } catch (Exception e) {
+ LogHelper.error(log);
}
- return url;
+
+ return null;
}
public static JDGoods queryGoodsDetail(Long skuId) {
@@ -170,6 +194,20 @@
List<JDGoods> list = searchResult.getGoodsList();
if (list != null && list.size() > 0)
return list.get(0);
+ }
+ return null;
+ }
+
+ public static List<JDGoods> queryGoodsDetail(List<Long> skuIdList) {
+ JDFilter filter = new JDFilter();
+ filter.setPageIndex(1);
+ filter.setPageSize(20);
+ filter.setListId(skuIdList);
+ JDSearchResult searchResult = queryByKey(filter);
+ if (searchResult != null) {
+ List<JDGoods> list = searchResult.getGoodsList();
+ if (list != null && list.size() > 0)
+ return list;
}
return null;
}
@@ -292,6 +330,24 @@
return searchResult;
}
+ /**
+ * 瑙f瀽浜笢鐨勫埜淇℃伅
+ *
+ * @param json
+ * @return
+ */
+ private static JDCouponInfo parseJDCouponInfo(JSONObject json) {
+ JDCouponInfo couponInfo = new Gson().fromJson(json.toString(), JDCouponInfo.class);
+ return couponInfo;
+ }
+
+ /**
+ * 瑙f瀽浜笢鍟嗗搧淇℃伅
+ *
+ * @param json
+ * @return
+ */
+
private static JDGoods parseJDGoods(JSONObject json) {
JDGoods goods = new JDGoods();
@@ -382,45 +438,37 @@
JSONObject couponJson = JSONObject.fromObject(coupon);
JSONArray couponArray = couponJson.optJSONArray("couponList");
if (couponArray != null) {
- BigDecimal discount_temp = null;
- JDCouponInfo couponInfo = null;
+ List<JDCouponInfo> couponInfoList = new ArrayList<>();
for (int i = 0; i < couponArray.size(); i++) {
- boolean add = false;
- JSONObject jdcoupon = couponArray.optJSONObject(i);
-
- BigDecimal quota = new BigDecimal(jdcoupon.optString("quota"));
- BigDecimal sub = MoneyBigDecimalUtil.sub(price, quota);
- 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")));
- couponInfo.setPlatformType(jdcoupon.optInt("platformType"));
- couponInfo.setGetEndTime(jdcoupon.optLong("getEndTime"));
- couponInfo.setGetStartTime(jdcoupon.optLong("getStartTime"));
- couponInfo.setUseEndTime(jdcoupon.optLong("useEndTime"));
- couponInfo.setUseStartTime(jdcoupon.optLong("useStartTime"));
- couponInfo.setLink(jdcoupon.optString("link"));
- }
+ JDCouponInfo couponInfo = parseJDCouponInfo(couponArray.optJSONObject(i));
+ if (couponInfo != null)
+ couponInfoList.add(couponInfo);
}
- goods.setCouponInfo(couponInfo);
+ // 鏍规嵁娑堣垂鏉′欢鎺掑簭
+ Comparator<JDCouponInfo> cm = new Comparator<JDCouponInfo>() {
+ @Override
+ public int compare(JDCouponInfo o1, JDCouponInfo o2) {
+ return o1.getQuota().compareTo(o2.getQuota());
+ }
+ };
+ Collections.sort(couponInfoList, cm);
+ // if (couponInfoList.size() > 0) {
+ // // 璁剧疆鍒镐俊鎭负鏈�鎺ヨ繎鐨勪竴涓�
+ // for (int i = couponInfoList.size() - 1; i >= 0; i--) {
+ // if
+ // (couponInfoList.get(i).getQuota().compareTo(goods.getPrice())
+ // <= 0) {
+ // goods.setCouponInfo(couponInfoList.get(i));
+ // break;
+ // }
+ // }
+ // if (goods.getCouponInfo() == null)
+ // goods.setCouponInfo(couponInfoList.get(0));
+ // }
+ //
+ goods.setCouponInfoList(couponInfoList);
+
}
}
@@ -489,8 +537,7 @@
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"));
@@ -526,6 +573,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");
@@ -554,12 +602,12 @@
return searchResult;
}
- public static JDSearchResult getGoodsClass() {
+ public static List<GoodsClass> getGoodsClass(int parentId, int grade) {
JDSearchResult searchResult = new JDSearchResult();
- List<JDGoods> list = new ArrayList<>();
+ List<GoodsClass> list = new ArrayList<>();
JSONObject json = new JSONObject();
- json.put("parentId", 0);
- json.put("grade", 0);
+ json.put("parentId", parentId);
+ json.put("grade", grade);
JSONObject jsonDTO = new JSONObject();
jsonDTO.put("req", json);
@@ -567,7 +615,7 @@
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");
+ resultJson = resultJson.optJSONObject("jd_union_open_category_goods_get_response");
if (resultJson.optInt("code") == 0) {
result = resultJson.optString("result");
resultJson = JSONObject.fromObject(result);
@@ -576,9 +624,11 @@
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);
+ GoodsClass gc = new GoodsClass();
+ JSONObject item = array.optJSONObject(i);
+ gc.setName(item.optString("name"));
+ gc.setId(item.optLong("id"));
+ list.add(gc);
}
}
}
@@ -586,11 +636,9 @@
long totalCount = resultJson.optLong("totalCount");
PageEntity pageEntity = new PageEntity();
pageEntity.setTotalCount(totalCount);
-
searchResult.setPageEntity(pageEntity);
}
- searchResult.setGoodsList(list);
- return searchResult;
+ return list;
}
public static JDGoods getGoodsDetail(Long skuId) {
@@ -669,4 +717,14 @@
return null;
}
+ public static void test() {
+ JSONObject json = new JSONObject();
+ json.put("materialId", "https://item.jd.com/32376790478.html");
+ json.put("ext1", "437032");
+ JSONObject root = new JSONObject();
+ root.put("promotionCodeReq", json);
+ String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root);
+ System.out.println(result);
+ }
+
}
--
Gitblit v1.8.0