From dc5be7d38446f70e6ff86df311119c32b41fe7f8 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 28 十一月 2020 16:37:05 +0800 Subject: [PATCH] 大淘客搜索接口升级 --- fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 38 insertions(+), 13 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java index dac16bf..ad2091c 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java @@ -1,12 +1,14 @@ package com.yeshi.fanli.service.impl.jd; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; +import com.yeshi.fanli.entity.SystemEnum; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,11 +18,12 @@ import com.yeshi.fanli.dto.jd.JDSearchResult; import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.jd.JDGoods; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.exception.jd.JDGoodsException; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.jd.JDGoodsService; -import com.yeshi.fanli.tag.PageEntity; +import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; +import com.yeshi.common.entity.PageEntity; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.jd.JDApiUtil; @@ -85,8 +88,8 @@ @Cacheable(value = "jdSpecialCache", key = "'specialSearch-'+#page+'-'+#cid") @Override - @Transactional - public List<JDGoods> specialSearch(Integer page, Long cid) throws JDGoodsException { + @Transactional(rollbackFor=Exception.class) + public List<JDGoods> specialSearch(Integer page, Long cid,SystemEnum system) throws JDGoodsException { if (cid == null) { throw new JDGoodsException(1, "鍒嗙被id涓虹┖"); } @@ -143,12 +146,12 @@ if (result == null) { return null; } else { - return result.getGoodsList(); + return filterJDGoods(result.getGoodsList()); } } if (!jdcid.contains(",")) { - return search(page, Constant.PAGE_SIZE, jdcid); + return search(page, Constant.PAGE_SIZE, jdcid,system); } // 澶氫釜鍒嗙被id澶勭悊 @@ -158,17 +161,34 @@ if (i >= 3) { break; } - List<JDGoods> listGoods = search(page, 10, arrayId[i]); + List<JDGoods> listGoods = search(page, 10, arrayId[i],system); if (listGoods != null && listGoods.size() > 0) { list.addAll(listGoods); } } - return list; + return filterJDGoods(list); } - private List<JDGoods> search(int page, int pageSize, String jdcid) { + /** + * 杩囨护鍟嗗搧 + * + * @param goodsList + * @return + */ + private List<JDGoods> filterJDGoods(List<JDGoods> goodsList) { + List<Long> skuIds = new ArrayList<>(); + for (JDGoods goods : goodsList) { + skuIds.add(goods.getSkuId()); + } + List<JDGoods> newGoodsList = JDApiUtil.listGoodsDetail(skuIds); + if (newGoodsList != null && newGoodsList.size() > 0) + return newGoodsList; + return goodsList; + } + + private List<JDGoods> search(int page, int pageSize, String jdcid, SystemEnum system) { JDSearchResult result = null; - String way = configService.get("jd_api_search_key"); + String way = configService.getValue(ConfigKeyEnum.jdApiSearchKey.getKey(),system); if ("1".equals(way)) { // API鎼滅储 JDFilter filterAPI = new JDFilter(); filterAPI.setPageIndex(page); @@ -192,9 +212,11 @@ @Cacheable(value = "jdCache", key = "'getIndexJDGoods-'+#page") @Override - public JDSearchResult getIndexJDGoods(int page) { + public JDSearchResult getIndexJDGoods(int page,SystemEnum system) { JDSearchResult result = null; - String way = configService.get("jd_api_search_key"); + String way = configService.getValue(ConfigKeyEnum.jdApiSearchKey.getKey(),system); + // TODO 闇�瑕佽皟鏁磋鍒� + way = "0"; if ("1".equals(way)) { JDFilter filterAPI = new JDFilter(); filterAPI.setPageIndex(page); @@ -205,8 +227,11 @@ JDSearchFilter jdfilter = new JDSearchFilter(); jdfilter.setPageNo(page); jdfilter.setPageSize(Constant.PAGE_SIZE); - result = JDUtil.searchByKey(jdfilter); + result =JDApiUtil.getJingFenGoods(page,125); //JDUtil.searchByKey(jdfilter); } + if (result != null && result.getGoodsList() != null) + Collections.shuffle(result.getGoodsList()); + return result; } -- Gitblit v1.8.0