yujian
2019-05-14 efa2645b74ebfadc43ebe448370adb22aecc1ad7
fanli/src/main/java/com/yeshi/fanli/controller/admin/TaoBaoGoodsBriefAdminController.java
@@ -51,7 +51,7 @@
   @Resource
   private QualityFactoryService qualityFactoryService;
   @Resource
   private TaoBaoUnionConfigService taoBaoUnionConfigService;
@@ -62,7 +62,6 @@
   @Resource
   private TaoBaoClassService taoBaoClassService;
   /**
    * 
@@ -86,26 +85,26 @@
   public void queryOnSale(String callback, Integer pageIndex, Integer pageSize, String key, Long tbClassId,
         Integer startPrice, Integer endPrice, String startTkRate, String endTkRate, Integer sort, Integer istmall,
         Integer hasCoupon, Integer baoYou, Integer startDsr, Integer overseas, Integer needPrepay,
         Integer includePayRate30, Integer includeGoodRate, Integer includeRfdRate, Integer npxLevel,
         Integer includePayRate30, Integer includeGoodRate, Integer includeRfdRate, Integer npxLevel, String cid,
         PrintWriter out) {
      try {
         // 查询物料
         TaoBaoSearchResult result = getGoodsByWuLiao(pageIndex, pageSize, key, tbClassId, startPrice, endPrice, startTkRate, endTkRate, sort,
               istmall, hasCoupon, baoYou, startDsr, overseas, needPrepay,   includePayRate30, includeGoodRate,
               includeRfdRate, npxLevel);
         TaoBaoSearchResult result = getGoodsByWuLiao(pageIndex, pageSize, key, tbClassId, startPrice, endPrice,
               startTkRate, endTkRate, sort, istmall, hasCoupon, baoYou, startDsr, overseas, needPrepay,
               includePayRate30, includeGoodRate, includeRfdRate, npxLevel,cid);
         if (result == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未获取到淘宝商品信息"));
            return;
         }
         List<TaoBaoGoodsBrief> listTaoBaoGoods = result.getTaoBaoGoodsBriefs();
         if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未查询到淘宝商品信息"));
            return;
         }
         // 插入商品集合
         List<Long> listAuctionId = new ArrayList<Long>();
         for (TaoBaoGoodsBrief goodsBrief : listTaoBaoGoods) {
@@ -218,9 +217,10 @@
      }
   }
   /**
    *  加入精选库商品
    * 加入精选库商品
    *
    * @param callback
    * @param pageIndex
    * @param key
@@ -252,39 +252,40 @@
         }
         Gson gson2 = new Gson();
         List<Long> listTaoBaoId = gson2.fromJson(auctionIds, new TypeToken<ArrayList<Long>>() {}.getType());
         List<Long> listTaoBaoId = gson2.fromJson(auctionIds, new TypeToken<ArrayList<Long>>() {
         }.getType());
         if (listTaoBaoId == null || listTaoBaoId.size() == 0) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("请选择正确的商品入库")));
            return;
         }
         // 查询物料
         TaoBaoSearchResult result = getGoodsByWuLiao(pageIndex, pageSize, key, tbClassId, startPrice, endPrice, startTkRate, endTkRate, sort,
               istmall, hasCoupon, baoYou, startDsr, overseas, needPrepay,   includePayRate30, includeGoodRate,
               includeRfdRate, npxLevel);
         TaoBaoSearchResult result = getGoodsByWuLiao(pageIndex, pageSize, key, tbClassId, startPrice, endPrice,
               startTkRate, endTkRate, sort, istmall, hasCoupon, baoYou, startDsr, overseas, needPrepay,
               includePayRate30, includeGoodRate, includeRfdRate, npxLevel,null);
         if (result == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未获取到淘宝商品信息"));
            return;
         }
         List<TaoBaoGoodsBrief> listTaoBaoGoods = result.getTaoBaoGoodsBriefs();
         if (listTaoBaoGoods == null || listTaoBaoGoods.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未查询到淘宝商品信息"));
            return;
         }
         List<TaoBaoGoodsBrief> listAddGoods = new ArrayList<TaoBaoGoodsBrief>();
         for (TaoBaoGoodsBrief taoBaoGoodsBrief: listTaoBaoGoods) {
         for (TaoBaoGoodsBrief taoBaoGoodsBrief : listTaoBaoGoods) {
            Long auctionId = taoBaoGoodsBrief.getAuctionId();
            if (listTaoBaoId.contains(auctionId)) {
               listAddGoods.add(taoBaoGoodsBrief);
               listTaoBaoId.remove(auctionId);
            }
         }
         if (listTaoBaoId != null && listTaoBaoId.size() > 0) {
            for (Long auctionId: listTaoBaoId) {
            for (Long auctionId : listTaoBaoId) {
               /* 根据auctionId 获取淘宝商品 */
               TaoBaoGoodsBrief goodsBrief = TaoKeApiUtil.searchGoodsDetail(auctionId);
               if (goodsBrief != null) {
@@ -292,10 +293,12 @@
               }
            }
         }
         AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
         // 插入精选库
         qualityFactoryService.addBatchTaoBaoGoods(listAddGoods, lableNames, admin);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("加入成功"));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, e.getMessage()));
@@ -306,6 +309,7 @@
   /**
    * 根据条件淘宝商品查询
    *
    * @param pageIndex
    * @param pageSize
    * @param key
@@ -330,7 +334,7 @@
   public TaoBaoSearchResult getGoodsByWuLiao(Integer pageIndex, Integer pageSize, String key, Long tbClassId,
         Integer startPrice, Integer endPrice, String startTkRate, String endTkRate, Integer sort, Integer istmall,
         Integer hasCoupon, Integer baoYou, Integer startDsr, Integer overseas, Integer needPrepay,
         Integer includePayRate30, Integer includeGoodRate, Integer includeRfdRate, Integer npxLevel)
         Integer includePayRate30, Integer includeGoodRate, Integer includeRfdRate, Integer npxLevel, String cids)
         throws Exception {
      SearchFilter filter = new SearchFilter();
@@ -345,8 +349,8 @@
         GoodsClass rb = goodsClassService.getGoodsClass(tbClassId);
         if (rb == null) {
            throw new Exception("该类型已不存在,请刷新重试");
         }
         }
         // 淘宝类目id
         String taoBaoCatIds = taoBaoClassService.getTaoBaoCatIds(tbClassId);
         if (StringUtil.isNullOrEmpty(taoBaoCatIds)) {
@@ -355,6 +359,8 @@
            filter.setCateIds(taoBaoCatIds);
         }
      }
      if (!StringUtil.isNullOrEmpty(cids))
         filter.setCateIds(cids);
      // 查询条件和类目id不能同时为空
      if (StringUtil.isNullOrEmpty(key) && tbClassId == null) {
@@ -378,7 +384,8 @@
         int tkRate = (int) (Float.parseFloat(endTkRate) * 100);
         filter.setEndTkRate(tkRate);
      }
      // 排序字段 销量(total_sales)淘客佣金比率(tk_rate)累计推广量(tk_total_sales)总支出佣金(tk_total_commi)
      // 排序字段
      // 销量(total_sales)淘客佣金比率(tk_rate)累计推广量(tk_total_sales)总支出佣金(tk_total_commi)
      if (sort != null) {
         filter.setSort(sort);
      }
@@ -424,8 +431,7 @@
      if (npxLevel != null && npxLevel > 0 && npxLevel < 4) {
         filter.setNpxLevel(npxLevel);
      }
      boolean islink = false;
      Long auctionId = null;
      /* 判断是否是商品链接搜索 */