admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java
@@ -17,10 +17,11 @@
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.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -86,7 +87,7 @@
   @Cacheable(value = "jdSpecialCache", key = "'specialSearch-'+#page+'-'+#cid")
   @Override
   @Transactional
   @Transactional(rollbackFor=Exception.class)
   public List<JDGoods> specialSearch(Integer page, Long cid) throws JDGoodsException {
      if (cid == null) {
         throw new JDGoodsException(1, "分类id为空");
@@ -144,7 +145,7 @@
         if (result == null) {
            return null;
         } else {
            return result.getGoodsList();
            return filterJDGoods(result.getGoodsList());
         }
      }
@@ -164,12 +165,29 @@
            list.addAll(listGoods);
         }
      }
      return list;
      return filterJDGoods(list);
   }
   /**
    * 过滤商品
    *
    * @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) {
      JDSearchResult result = null;
      String way = configService.get("jd_api_search_key");
      String way = configService.get(ConfigKeyEnum.jdApiSearchKey.getKey());
      if ("1".equals(way)) { // API搜索
         JDFilter filterAPI = new JDFilter();
         filterAPI.setPageIndex(page);
@@ -195,7 +213,9 @@
   @Override
   public JDSearchResult getIndexJDGoods(int page) {
      JDSearchResult result = null;
      String way = configService.get("jd_api_search_key");
      String way = configService.get(ConfigKeyEnum.jdApiSearchKey.getKey());
      // TODO 需要调整规则
      way = "0";
      if ("1".equals(way)) {
         JDFilter filterAPI = new JDFilter();
         filterAPI.setPageIndex(page);
@@ -206,7 +226,7 @@
         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());