From 3e4ef41ffacd7f5fda2e81c3810cd11a6375b83c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 15 六月 2020 16:32:35 +0800 Subject: [PATCH] 好单库转链支持 --- fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java | 76 +++++++++++++++++++++++++++++++++----- 1 files changed, 66 insertions(+), 10 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java index d1874e7..3a98301 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/vipshop/VipShopApiUtil.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Type; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; @@ -17,9 +18,14 @@ import org.yeshi.utils.StringUtil; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.yeshi.fanli.dto.vip.VIPConvertResultDTO; import com.yeshi.fanli.dto.vip.VIPSearchFilter; import com.yeshi.fanli.dto.vip.VIPSearchResult; import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo; +import com.yeshi.fanli.dto.vipshop.VipShopOrderQueryModel; +import com.yeshi.fanli.dto.vipshop.VipShopQueryOrderResultDTO; +import com.yeshi.fanli.entity.vipshop.VipShopOrder; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -149,6 +155,45 @@ if (resultJson.optInt("returnCode") == 0) { resultJson = resultJson.optJSONObject("result"); int count = resultJson.optInt("total"); + + JSONArray array = resultJson.optJSONArray("goodsInfoList"); + if (array != null && array.size() > 0) { + for (int i = 0; i < array.size(); i++) { + JSONObject optJSONObject = array.optJSONObject(i); + if (optJSONObject == null) { + continue; + } + VIPGoodsInfo info = gson.fromJson(array.optJSONObject(i).toString(), VIPGoodsInfo.class); + if (info != null) + goodsList.add(info); + } + } + + return new VIPSearchResult(goodsList, count); + } + return null; + } + + + + public static VIPSearchResult getGoodsList(int channelType,int page) { + Map<String, String> taskParams = new HashMap<>(); + taskParams.put("channelType",channelType+""); + taskParams.put("page", page+ ""); + taskParams.put("pageSize", 20 + ""); + taskParams.put("requestId", System.currentTimeMillis() + "_" + UUID.randomUUID()); + + + JSONObject root = new JSONObject(); + root.put("request", JSONObject.fromObject(taskParams)); + String result = baseRequest("com.vip.adp.api.open.service.UnionGoodsService", "goodsList", root); + System.out.println(result); + List<VIPGoodsInfo> goodsList = new ArrayList<>(); + JSONObject resultJson = JSONObject.fromObject(result); + Gson gson = new Gson(); + if (resultJson.optInt("returnCode") == 0) { + resultJson = resultJson.optJSONObject("result"); + int count = resultJson.optInt("total"); JSONArray array = resultJson.optJSONArray("goodsInfoList"); for (int i = 0; i < array.size(); i++) { VIPGoodsInfo info = gson.fromJson(array.optJSONObject(i).toString(), VIPGoodsInfo.class); @@ -165,7 +210,7 @@ * * @param goodsId */ - public static String convertLink(String goodsId, String tag) { + public static VIPConvertResultDTO convertLink(String goodsId, String tag) { JSONObject taskParams = new JSONObject(); JSONArray goodsIdArray = new JSONArray(); goodsIdArray.add(goodsId); @@ -175,6 +220,11 @@ String result = baseRequest("com.vip.adp.api.open.service.UnionUrlService", "genByGoodsId", JSONObject.fromObject(taskParams)); System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + if (resultJSON.optInt("returnCode") == 0) { + String re = resultJSON.optJSONObject("result").optJSONArray("urlInfoList").optJSONObject(0).toString(); + return new Gson().fromJson(re, VIPConvertResultDTO.class); + } return null; } @@ -221,20 +271,26 @@ return goodsList.get(0); } - public static void getOrderList() { - JSONObject params = new JSONObject(); - // params.put("status", 1); - params.put("orderTimeStart", System.currentTimeMillis() - 1000 * 60 * 60L); - params.put("orderTimeEnd", System.currentTimeMillis()); - params.put("page", 1); - // params.put("pageSize", ); - // params.put("updateTimeStart", ); - // params.put("updateTimeEnd", ); + public static VipShopQueryOrderResultDTO getOrderList(VipShopOrderQueryModel query) { + JSONObject params = JSONObject.fromObject(new Gson().toJson(query)); params.put("requestId", UUID.randomUUID()); JSONObject root = new JSONObject(); root.put("queryModel", params); String result = baseRequest("com.vip.adp.api.open.service.UnionOrderService", "orderList", root); System.out.println(result); + JSONObject json = JSONObject.fromObject(result); + if (json.optInt("returnCode") == 0) { + JSONObject resultJson = json.optJSONObject("result"); + int total = resultJson.optInt("total"); + JSONArray array = JSONArray.fromObject(resultJson.optJSONArray("orderInfoList")); + if (array != null) { + Type type = new TypeToken<ArrayList<VipShopOrder>>() { + }.getType(); + List<VipShopOrder> orderList = new Gson().fromJson(array.toString(), type); + return new VipShopQueryOrderResultDTO(orderList, total); + } + } + return null; } } -- Gitblit v1.8.0