From d2357693d74ec048ed19e483ea29f87d823cde5f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 22 七月 2019 16:26:23 +0800 Subject: [PATCH] 资金明细添加京东,拼多多兼容 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java | 226 ++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 162 insertions(+), 64 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java index d60c3b2..ef5dd9f 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java @@ -20,6 +20,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.yeshi.fanli.dto.jd.JDFilter; import com.yeshi.fanli.dto.jd.JDSearchFilter; import com.yeshi.fanli.dto.jd.JDSearchResult; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; @@ -44,11 +45,13 @@ import com.yeshi.fanli.service.inter.user.HistorySearchService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.GsonUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.ThreadUtil; import com.yeshi.fanli.util.Utils; import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; +import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; @@ -375,16 +378,26 @@ } } - if (!StringUtil.isNullOrEmpty(filter)) { - JSONArray array = JSONArray.fromObject(filter); - for (int i = 0; i < array.size(); i++) { - String ty = array.optJSONObject(i).optString("type"); - if ("coupon".equalsIgnoreCase(ty)) { // 鏈夊埜 - sf.setQuan(1); - } else if ("tmall".equalsIgnoreCase(ty)) { // 澶╃尗 - sf.setTmall(true); - } + JSONObject jsonfilter = JSONObject.fromObject(filter); + Boolean coupon = jsonfilter.optBoolean("coupon"); + if (coupon != null && coupon) { + sf.setQuan(1); // 鏈夊埜 + } + + Boolean tmall = jsonfilter.optBoolean("tmall"); + if (tmall != null && tmall) { + sf.setTmall(true); // 澶╃尗 + } + + String minPrice = jsonfilter.optString("minPrice"); + if (!StringUtil.isNullOrEmpty(minPrice)) { + sf.setStartPrice(new BigDecimal(minPrice)); + } + + String maxPrice = jsonfilter.optString("maxPrice"); + if (!StringUtil.isNullOrEmpty(maxPrice)) { + sf.setEndPrice(new BigDecimal(maxPrice)); } } @@ -443,9 +456,9 @@ if (page == 1) { // 绗竴椤佃繑鍥炲簵閾轰俊鎭� - List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKey(key); - if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoods() != null - && listShop.get(0).getListGoods().size() > 2) { + List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKeyV2(key); + if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoodsVO() != null + && listShop.get(0).getListGoodsVO().size() > 2) { data.put("shop", JsonUtil.getApiCommonGson().toJson(listShop.get(0))); } } @@ -465,54 +478,138 @@ * @return */ private void searchJDGoods(String key, Integer page, String filter, Integer order, PrintWriter out) { - JDSearchFilter jdfilter = new JDSearchFilter(); - jdfilter.setKey(SearchFilterUtil.filterSearchContent(key)); - jdfilter.setPageNo(page); - jdfilter.setPageSize(Constant.PAGE_SIZE); + + JDSearchResult result = null; + String way = configService.get("jd_api_search_key"); + if ("1".equals(way)) { + JDFilter filterAPI = new JDFilter(); + filterAPI.setKeyword(SearchFilterUtil.filterSearchContent(key)); + filterAPI.setPageIndex(page); + filterAPI.setPageSize(Constant.PAGE_SIZE); - if (order != null) { - int sort = order.intValue(); - switch (sort) { - case 1: // 閿�閲� desc - jdfilter.setSort(JDSearchFilter.SORT_DESC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_ORDER_COUNT_30DAYS); - break; - case 2: // 浠锋牸鈥攄esc - jdfilter.setSort(JDSearchFilter.SORT_DESC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); - break; - case 3: // 浠锋牸鈥攁sc - jdfilter.setSort(JDSearchFilter.SORT_ASC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); - break; - case 4: // 杩斿埄姣斺�擠ESC - jdfilter.setSort(JDSearchFilter.SORT_DESC); - jdfilter.setSortName(JDSearchFilter.SORTNAME_COMMISSION_SHARE); - break; - default: - break; - } - } - - - if (!StringUtil.isNullOrEmpty(filter)) { - JSONArray array = JSONArray.fromObject(filter); - for (int i = 0; i < array.size(); i++) { - String ty = array.optJSONObject(i).optString("type"); - if ("coupon".equalsIgnoreCase(ty)) { - jdfilter.setHasCoupon(1); // 鏈夊埜 - } else if ("zy".equalsIgnoreCase(ty)) { - jdfilter.setIsZY(1); // 鏄惁鑷惀 - } else if ("delivery".equalsIgnoreCase(ty)) { - jdfilter.setDeliveryType(1); // 鏄惁浜笢閰嶉�� + if (order != null) { + int sort = order.intValue(); + switch (sort) { + case 1: // 閿�閲� desc + filterAPI.setSort(JDFilter.SORT_DESC); + filterAPI.setSortName(JDFilter.SORTNAME_ORDER_COUNT_30DAYS); + break; + case 2: // 浠锋牸鈥攄esc + filterAPI.setSort(JDFilter.SORT_DESC); + filterAPI.setSortName(JDFilter.SORTNAME_PRICE); + break; + case 3: // 浠锋牸鈥攁sc + filterAPI.setSort(JDFilter.SORT_ASC); + filterAPI.setSortName(JDFilter.SORTNAME_PRICE); + break; + case 4: // 杩斿埄姣斺�擠ESC + filterAPI.setSort(JDFilter.SORT_DESC); + filterAPI.setSortName(JDFilter.SORTNAME_COMMISSION_SHARE); + break; + default: + break; } } - } + + if (!StringUtil.isNullOrEmpty(filter)) { + JSONObject jsonfilter = JSONObject.fromObject(filter); + Boolean coupon = jsonfilter.optBoolean("coupon"); + if (coupon != null && coupon) { + filterAPI.setIsCoupon(1); // 鏈夊埜 + } + + Boolean zy = jsonfilter.optBoolean("zy"); + if (zy != null && zy) { + filterAPI.setOwner("g"); // 鑷惀 + } + + + String minPrice = jsonfilter.optString("minPrice"); + if (!StringUtil.isNullOrEmpty(minPrice)) { + filterAPI.setPricefrom(Double.parseDouble(minPrice)); + } + + String maxPrice = jsonfilter.optString("maxPrice"); + if (!StringUtil.isNullOrEmpty(maxPrice)) { + filterAPI.setPriceto(Double.parseDouble(maxPrice)); + } + } + + result = JDApiUtil.queryByKey(filterAPI); + } else { + // 缃戦〉鐖彇 + JDSearchFilter jdfilter = new JDSearchFilter(); + jdfilter.setKey(SearchFilterUtil.filterSearchContent(key)); + jdfilter.setPageNo(page); + jdfilter.setPageSize(Constant.PAGE_SIZE); + + if (order != null) { + int sort = order.intValue(); + switch (sort) { + case 1: // 閿�閲� desc + jdfilter.setSort(JDSearchFilter.SORT_DESC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_ORDER_COUNT_30DAYS); + break; + case 2: // 浠锋牸鈥攄esc + jdfilter.setSort(JDSearchFilter.SORT_DESC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); + break; + case 3: // 浠锋牸鈥攁sc + jdfilter.setSort(JDSearchFilter.SORT_ASC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_PRICE); + break; + case 4: // 杩斿埄姣斺�擠ESC + jdfilter.setSort(JDSearchFilter.SORT_DESC); + jdfilter.setSortName(JDSearchFilter.SORTNAME_COMMISSION_SHARE); + break; + default: + break; + } + } + + if (!StringUtil.isNullOrEmpty(filter)) { + JSONObject jsonfilter = JSONObject.fromObject(filter); + Boolean coupon = jsonfilter.optBoolean("coupon"); + if (coupon != null && coupon) { + jdfilter.setHasCoupon(1); // 鏈夊埜 + } + + Boolean zy = jsonfilter.optBoolean("zy"); + if (zy != null && zy) { + jdfilter.setIsZY(1); // 鑷惀 + } + + Boolean delivery = jsonfilter.optBoolean("delivery"); + if (delivery != null && delivery) { + jdfilter.setDeliveryType(1); // 浜笢閰嶉�� + } + + String minPrice = jsonfilter.optString("minPrice"); + if (!StringUtil.isNullOrEmpty(minPrice)) { + if(minPrice.contains(".")) { + minPrice = minPrice.replace(".", "-"); + minPrice = minPrice.split("-")[0]; + } + jdfilter.setFromPrice(Integer.parseInt(minPrice)); + } + + String maxPrice = jsonfilter.optString("maxPrice"); + if (!StringUtil.isNullOrEmpty(maxPrice)) { + if(maxPrice.contains(".")) { + maxPrice = maxPrice.replace(".", "-"); + maxPrice = maxPrice.split("-")[0]; + } + jdfilter.setToPrice(Integer.parseInt(maxPrice)); + } + } + result = JDUtil.searchByKey(jdfilter); + + } + long count = 0; JSONObject data = new JSONObject(); JSONArray array = new JSONArray(); - JDSearchResult result = JDUtil.searchByKey(jdfilter); if (result != null) { PageEntity pageEntity = result.getPageEntity(); if (pageEntity != null) { @@ -577,14 +674,15 @@ } if (!StringUtil.isNullOrEmpty(filter)) { - JSONArray array = JSONArray.fromObject(filter); - for (int i = 0; i < array.size(); i++) { - String ty = array.optJSONObject(i).optString("type"); - if ("coupon".equalsIgnoreCase(ty)) { - pddfilter.setHasCoupon(true); // 鏈夊埜 - } else if ("brand".equalsIgnoreCase(ty)) { - pddfilter.setIsBrand(true); // 鏄惁鏄搧鐗� - } + JSONObject jsonfilter = JSONObject.fromObject(filter); + Boolean coupon = jsonfilter.optBoolean("coupon"); + if (coupon != null && coupon) { + pddfilter.setHasCoupon(true); // 鏈夊埜 + } + + Boolean brand = jsonfilter.optBoolean("brand"); + if (brand != null && brand) { + pddfilter.setIsBrand(true); // 鏄惁鏄搧鐗� } } @@ -595,12 +693,12 @@ PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter); if (result != null) { count = result.getTotalCount(); + Gson gson = JsonUtil.getApiCommonGson(); List<PDDGoodsDetail> goodsList = result.getGoodsList(); if (goodsList != null && goodsList.size() > 0) { BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); BigDecimal shareRate = hongBaoManageService.getShareRate(); - Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) - .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); + for (PDDGoodsDetail goods : goodsList) { GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertPDDGoods(goods, null, fanLiRate, shareRate); @@ -608,7 +706,7 @@ } } } - + data.put("result", array); data.put("count", count); out.print(JsonUtil.loadTrueResult(data)); -- Gitblit v1.8.0