admin
2020-06-28 eda623f37c3260f4b4657e34a8a39798c72432b1
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -24,7 +24,14 @@
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.dto.suning.SuningCommodityInfo;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.dto.suning.SuningQueryModel;
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.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.help.AppPageNotification;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
@@ -39,6 +46,7 @@
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
import com.yeshi.fanli.service.inter.help.AppPageNotificationService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
@@ -66,9 +74,11 @@
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
import com.yeshi.fanli.util.suning.SuningApiUtil;
import com.yeshi.fanli.util.taobao.SearchFilterUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.util.vipshop.VipShopApiUtil;
import com.yeshi.fanli.vo.brand.BrandInfoVO;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
import com.yeshi.fanli.vo.common.JumpDetailContentVO;
@@ -139,9 +149,12 @@
   @Resource
   private JumpDetailV2Service jumpDetailV2Service;
   @Resource
   private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
   @Resource
   private AppPageNotificationService appPageNotificationService;
   /**
    * 粘贴板信息推荐
@@ -192,15 +205,13 @@
                  Gson gson = JsonUtil.getApiCommonGson();
                  data.put("title", "智能搜索");
                  int state = 0;
                  if (result.getFirstGoods() != null && result.getFirstGoods().getGoodsId() != null) {
                     state = 2;
                     data.put("stateDesc", "选择搜券或转链");
                     JSONObject params = new JSONObject();
                     params.put("id", result.getFirstGoods().getGoodsId()+"");
                     params.put("id", result.getFirstGoods().getGoodsId() + "");
                     params.put("from", "转链");
                     if (result.getFirstGoods().getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
                        view = new JumpDetailContentVO();
@@ -427,9 +438,9 @@
    */
   @RequestMapping(value = "searchGoods")
   public void searchGoods(AcceptData acceptData, Integer goodsType, String key, Integer page, String filter,
         Integer order, Long uid, HttpSession session, PrintWriter out) {
         Integer order, Long uid, String notifyType, HttpSession session, PrintWriter out) {
      if (goodsType == null || goodsType < 1 || goodsType > 3) {
      if (goodsType == null || goodsType < 1 || goodsType > 5) {
         out.print(JsonUtil.loadFalseResult(1, "请传递正确平台参数"));
         return;
      }
@@ -486,21 +497,49 @@
         out.print(JsonUtil.loadTrueResult(data));
         return;
      }
      AppPageNotification ap = null;
      if (page == 1) {
         ap = appPageNotificationService.getValidNotificationByTypeCache(notifyType, acceptData.getPlatform(),
               Integer.parseInt(acceptData.getVersion()));
         // 没有通知
         if (ap == null || !ap.getShow()) {
            ap = null;
         }
         // else {// 有通知
         // Gson gson = new
         // GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
         // out.print(JsonUtil.loadTrueResult(gson.toJson(ap)));
         // }
      }
      /*--------- 京东商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_JD) {
         searchJDGoods(acceptData, searchkey, page, filter, order, out);
         searchJDGoods(acceptData, searchkey, page, filter, order, ap, out);
         return;
      }
      /*-------- 拼多多商品  -------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_PDD) {
         searchPDDGoods(acceptData, searchkey, page, filter, order, out);
         searchPDDGoods(acceptData, searchkey, page, filter, order, ap, out);
         return;
      }
      /*-------- 唯品会商品 ------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_VIP) {
         searchVIPGoods(acceptData, searchkey, page, filter, order, ap, out);
         return;
      }
      /*-------- 苏宁商品 ------*/
      if (goodsType.intValue() == Constant.SOURCE_TYPE_SUNING) {
         searchSuningGoods(acceptData, searchkey, page, filter, order, ap, out);
         return;
      }
      /*-------- 淘宝商品  -------*/
      searchTaoBaoGoods(acceptData, searchkey, page, filter, order, out);
      searchTaoBaoGoods(acceptData, searchkey, page, filter, order, ap, out);
   }
   /**
@@ -515,7 +554,7 @@
    * @return
    */
   private void searchTaoBaoGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order,
         PrintWriter out) {
         AppPageNotification ap, PrintWriter out) {
      SearchFilter sf = new SearchFilter();
      sf.setKey(SearchFilterUtil.filterSearchContent(key));
      sf.setPage(page);
@@ -645,7 +684,15 @@
         }
      }
      out.print(JsonUtil.loadTrueResult(data));
      out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
   }
   private JSONObject buildSearchResult(JSONObject data, AppPageNotification ap) {
      if (ap != null && data != null) {
         Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
         data.put("notification", gson.toJson(ap));
      }
      return data;
   }
   /**
@@ -660,7 +707,7 @@
    * @return
    */
   private void searchJDGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order,
         PrintWriter out) {
         AppPageNotification ap, PrintWriter out) {
      JDSearchResult result = null;
      boolean hasCoupon = false;
@@ -821,7 +868,7 @@
      data.put("result", array);
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(data));
      out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
   }
   /**
@@ -836,7 +883,7 @@
    * @return
    */
   private void searchPDDGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order,
         PrintWriter out) {
         AppPageNotification ap, PrintWriter out) {
      PDDSearchFilter pddfilter = new PDDSearchFilter();
      pddfilter.setKw(SearchFilterUtil.filterSearchContent(key));
      pddfilter.setPage(page);
@@ -898,6 +945,189 @@
      data.put("result", array);
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(data));
      out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
   }
   /**
    * 搜索唯品会商品
    * @Title: searchVIPGoods
    * @Description:
    * @param acceptData
    * @param key
    * @param page
    * @param filter
    * @param order
    * @param out
    * void 返回类型
    * @throws
    */
   private void searchVIPGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order,
         AppPageNotification ap, PrintWriter out) {
      VIPSearchFilter searchFilter = new VIPSearchFilter();
      searchFilter.setKeyword(key);
      searchFilter.setPage(page);
      searchFilter.setPageSize(Constant.PAGE_SIZE);
      if (order != null) {
         int sort = order.intValue();
         switch (sort) {
         case 2: // 价格—desc
            searchFilter.setFieldName("price");
            searchFilter.setOrder(1);
            break;
         case 3: // 价格—asc
            searchFilter.setFieldName("price");
            searchFilter.setOrder(0);
            break;
         case 5: // 折扣—aec
            searchFilter.setFieldName("discount");
            searchFilter.setOrder(0);
            break;
         default: // 综合排序
            break;
         }
      }
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONObject jsonfilter = JSONObject.fromObject(filter);
         String minPrice = jsonfilter.optString("minPrice");
         if (!StringUtil.isNullOrEmpty(minPrice)) {
            searchFilter.setPriceStart(minPrice);
         }
         String maxPrice = jsonfilter.optString("maxPrice");
         if (!StringUtil.isNullOrEmpty(maxPrice)) {
            searchFilter.setPriceEnd(maxPrice);
         }
      }
      int count = 0;
      JSONObject data = new JSONObject();
      JSONArray array = new JSONArray();
      VIPSearchResult result = VipShopApiUtil.search(searchFilter);
      if (result != null) {
         count = result.getTotal();
         Gson gson = JsonUtil.getApiCommonGson();
         List<VIPGoodsInfo> goodsList = result.getGoodsList();
         if (goodsList != null && goodsList.size() > 0) {
            ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                  acceptData.getVersion());
            for (VIPGoodsInfo goods : goodsList) {
               GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertVIPGoods(goods, paramsDTO);
               array.add(gson.toJson(goodsDetailVO));
            }
         }
      }
      data.put("result", array);
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
   }
   /**
    * 搜索唯品会商品
    * @Title: searchVIPGoods
    * @Description:
    * @param acceptData
    * @param key
    * @param page
    * @param filter
    * @param order
    * @param out
    * void 返回类型
    * @throws
    */
   private void searchSuningGoods(AcceptData acceptData, String key, Integer page, String filter, Integer order,
         AppPageNotification ap, PrintWriter out) {
      SuningQueryModel searchFilter = new SuningQueryModel();
      searchFilter.setKeyword(key);
      searchFilter.setPageIndex(page);
      searchFilter.setSize(10);
      if (order != null) {
         if (order == 1) { // 销量高到低
            searchFilter.setSortType(2);
         } else if (order == 2) { // 价格高到低
            searchFilter.setSortType(3);
         } else if (order == 3) { // 价格低到高
            searchFilter.setSortType(4);
         } else if (order == 4) { // 返利比高到低
            searchFilter.setSortType(5);
         }
      }
      if (!StringUtil.isNullOrEmpty(filter)) {
         JSONObject jsonfilter = JSONObject.fromObject(filter);
         Boolean coupon = jsonfilter.optBoolean("coupon");
         if (coupon != null && coupon) {
            searchFilter.setCoupon(1); // 有券
         }
         Boolean snfwservice = jsonfilter.optBoolean("snfwservice");// 苏宁服务
         if (snfwservice != null && snfwservice) {
            searchFilter.setSnfwservice(1);
         }
         Boolean snhwg = jsonfilter.optBoolean("snhwg");// 苏宁国际
         if (snhwg != null && snhwg) {
            searchFilter.setSnhwg(1);
         }
         Boolean suningService = jsonfilter.optBoolean("suningService");// 苏宁自营
         if (suningService != null && suningService) {
            searchFilter.setSuningService(1);
         }
         Boolean pgSearch = jsonfilter.optBoolean("pgSearch");// 拼购
         if (pgSearch != null && pgSearch) {
            searchFilter.setPgSearch(1);
         }
         String minPrice = jsonfilter.optString("minPrice");
         if (!StringUtil.isNullOrEmpty(minPrice)) {
            searchFilter.setStartPrice(minPrice);
         }
         String maxPrice = jsonfilter.optString("maxPrice");
         if (!StringUtil.isNullOrEmpty(maxPrice)) {
            searchFilter.setEndPrice(maxPrice);
         }
      }
      JSONObject data = new JSONObject();
      JSONArray array = new JSONArray();
      List<SuningGoodsInfo> resultList = null;
      List<SuningGoodsInfo> list = SuningApiUtil.searchGoodsOld(searchFilter);
      if (list != null && list.size() > 0) {
         List<String> listId = new ArrayList<>();
         for (SuningGoodsInfo goodsInfo : list) {
            SuningCommodityInfo info = goodsInfo.getCommodityInfo();
            if (info != null) {
               listId.add(info.getCommodityCode() + "-" + info.getSupplierCode());
            }
         }
         resultList = SuningApiUtil.getGoodsDetailList(listId);
      }
      if (resultList != null) {
         Gson gson = JsonUtil.getApiCommonGson();
         if (resultList != null && resultList.size() > 0) {
            ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                  acceptData.getVersion());
            for (SuningGoodsInfo goods : resultList) {
               GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertSuningGoods(goods, paramsDTO);
               array.add(gson.toJson(goodsDetailVO));
            }
         }
      }
      data.put("result", array);
      data.put("count", 1000);
      out.print(JsonUtil.loadTrueResult(buildSearchResult(data, ap)));
   }
}