yujian
2020-01-18 f4a0f2acc63d7785eab108419a4e16f5f688cb95
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java
@@ -26,6 +26,7 @@
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;
@@ -114,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);
@@ -142,22 +143,35 @@
      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 String convertLinkWithSubUnionId(String materialId, String couponUrl, String positionId,
         String subUnionId) {
      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);
      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");
   }
   public static JDGoods queryGoodsDetail(Long skuId) {
@@ -172,6 +186,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;
   }
@@ -417,18 +445,20 @@
               }
            };
            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));
//            }
//
            // 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);
         }
@@ -564,12 +594,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);
@@ -577,7 +607,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);
@@ -586,9 +616,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);
               }
            }
         }
@@ -596,11 +628,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) {
@@ -679,4 +709,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);
   }
}