admin
2020-07-22 73a3d86a47d8da711b609cd224c63526f7d00f9b
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SearchController.java
@@ -10,49 +10,47 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.taobao.TaoBaoAuthUtil;
import org.yeshi.utils.taobao.TbImgUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
import com.yeshi.goods.facade.dto.taobao.dataoke.DaTaoKeGoodsResult;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.bus.recommend.Honest;
import com.yeshi.fanli.entity.bus.search.HotSearch;
import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.SearchFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2;
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.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.config.HotSearchService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service;
import com.yeshi.fanli.service.inter.user.HistorySearchService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.EhcacheUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil;
import com.yeshi.fanli.util.taobao.SearchFilterUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
@@ -72,19 +70,16 @@
   private ConfigService configService;
   @Resource
   private SuperHotSearchService superHotSearchSerivce;
   private HotSearchService hotSearchService;
   @Resource
   private HistorySearchService historySearchService;
   private HistorySearchService  historySearchService;
   @Resource
   private HongBaoManageService manageService;
   @Resource
   private TaoBaoUnionConfigService taoBaoUnionConfigService;
   @Resource
   private TaoKeGoodsService taoKeGoodsService;
   @Resource
   private QualityGoodsService qualityGoodsService;
@@ -96,35 +91,32 @@
   private TaoBaoShopService taoBaoShopService;
   @Resource
   private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
   private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
   /**
    * 热门搜索
    * @param acceptData
    * @param goodsType
    * @param out
    */
   @RequestMapping(value = "gethotsearch", method = RequestMethod.POST)
   public void getHotSearch(AcceptData acceptData, PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
   public void getHotSearch(AcceptData acceptData, Integer goodsType, PrintWriter out) {
      // 默认淘宝
      if (goodsType == null) {
         goodsType = Constant.SOURCE_TYPE_TAOBAO;
      }
      List<SuperHotSearch> superHotSearchList = superHotSearchSerivce
            .getSuperHotSearchBySystemIdCache(system.getId());
      if (superHotSearchList == null || superHotSearchList.size() == 0) {
      List<HotSearch> list = hotSearchService.getHotSearchCache(goodsType,acceptData.getSystem());
      if (list == null || list.size() == 0) {
         out.print(JsonUtil.loadFalseResult("没有数据"));
         return;
      }
      List<HotSearch> hotSearchList = new ArrayList<HotSearch>();
      for (SuperHotSearch superHotSearch : superHotSearchList) {
         HotSearch hotSearch = superHotSearch.getHotSearch();
         if (hotSearch != null)
            hotSearchList.add(hotSearch);
      }
      JSONObject data = new JSONObject();
      data.put("count", hotSearchList.size());
      data.put("hotSearchList", hotSearchList);
      String result = JsonUtil.loadTrueResult(data);
      out.print(result);
      return;
      data.put("count", list.size());
      data.put("hotSearchList", list);
      out.print(JsonUtil.loadTrueResult(data));
   }
   @RequestMapping("specialSearch")
@@ -156,7 +148,7 @@
      data.put("nav", gson.toJson(navList));
      List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
      List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
      BigDecimal proportion = manageService.getFanLiRate();
      BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem());
      for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) {
         re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
      }
@@ -181,7 +173,7 @@
      String bid = getHistorySearchBid(acceptData);
      historySearchService.addHistorySearch(kw, bid);
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
            acceptData.getPackages(),acceptData.getSystem());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -202,7 +194,7 @@
            filter = fastFilter;
         }
      }
      JSONObject data = search(kw, page, filter, order, startprice, endprice);
      JSONObject data = search(acceptData, kw, page, filter, order, startprice, endprice);
      out.print(JsonUtil.loadTrueResult(data));
   }
@@ -210,11 +202,11 @@
   public JSONObject searchClass(AcceptData acceptData, String kw, int page, String filter, String order,
         String startprice, String endprice, String md5) {
      java.lang.System.out.println("searchClass");
      JSONObject data = search(kw, page, filter, order, startprice, endprice);
      JSONObject data = search(acceptData, kw, page, filter, order, startprice, endprice);
      return data;
   }
   private JSONObject search(String kw, int page, String filter, String order, String startprice, String endprice) {
   private JSONObject search(AcceptData acceptData, String kw, int page, String filter, String order, String startprice, String endprice) {
      page = page + 1;
      SearchFilter sf = new SearchFilter();
@@ -314,7 +306,7 @@
         }
         sf.setParams(params);
      }
      TaoBaoSearchResult result = TaoBaoUtil.search(sf);
      TaoBaoSearchResult result = TaoBaoUtil.search(sf,null,null);
      if (result == null) {
         return null;
      }
@@ -330,7 +322,7 @@
      int fq = sf.getQuan();
      int fh = sf.getHongbao();
      boolean ft = sf.isTmall();
      BigDecimal proportion = manageService.getFanLiRate();
      BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem());
      if (fq == 0 && fh == 0 && !ft) {
         if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief bf : result.getTaoBaoGoodsBriefs()) {
@@ -463,14 +455,13 @@
      JSONObject data = null;
      if (!recommend) {
         // 淘宝接口请求
         data = searchGoods(kw, page, filter, order, startprice, endprice);
         data = searchGoods(acceptData, kw, page, filter, order, startprice, endprice,acceptData.getSystem());
      } else {
         // 推荐:精选库
         // data = searchQualityGoods(kw, page, filter, order, startprice,
         // endprice);
         data = searchDaTaoKeGoods(kw, page, filter, order, startprice, endprice);
         data = searchDaTaoKeGoods(acceptData, kw, page, filter, order, startprice, endprice);
      }
      // 获取推荐词
@@ -482,7 +473,7 @@
            listRecommendWords = new ArrayList<String>();
         }
         List<TaoBaoShopVO> listShop = taoBaoShopService.getShopByKey(kw);
         List<TaoBaoShopVO> listShop =taoBaoShopService.getShopByKey(kw,acceptData.getSystem());
         if (listShop != null && listShop.size() > 0 && listShop.get(0).getListGoods() != null
               && listShop.get(0).getListGoods().size() > 2) {
            data.put("shop", JsonUtil.getApiCommonGson().toJson(listShop.get(0)));
@@ -507,8 +498,8 @@
    * @param endprice
    * @return
    */
   private JSONObject searchGoods(String kw, int page, String filter, String order, String startprice,
         String endprice) {
   private JSONObject searchGoods(AcceptData acceptData, String kw, int page, String filter, String order, String startprice,
         String endprice,SystemEnum system) {
      page = page + 1;
      SearchFilter sf = new SearchFilter();
@@ -611,26 +602,26 @@
               int id = array.optJSONObject(i).optInt("id");
               sf.setProvinceId(id);
            } else if ("tkRate1".equalsIgnoreCase(ty)) {
               setSearchTkRate(0, sf);
               setSearchTkRate(0, sf,system);
            } else if ("tkRate2".equalsIgnoreCase(ty)) {
               setSearchTkRate(1, sf);
               setSearchTkRate(1, sf,system);
            } else if ("tkRate3".equalsIgnoreCase(ty)) {
               setSearchTkRate(2, sf);
               setSearchTkRate(2, sf,system);
            } else if ("tkRate4".equalsIgnoreCase(ty)) {
               setSearchTkRate(3, sf);
               setSearchTkRate(3, sf,system);
            } else if ("tkRate5".equalsIgnoreCase(ty)) {
               setSearchTkRate(4, sf);
               setSearchTkRate(4, sf,system);
            }
         }
         sf.setParams(params);
      }
      // 搜索大淘客
      List<DaTaoKeDetail> daTaoKeList = null;
      List<DaTaoKeDetailV2> daTaoKeList = null;
      if (page == 1)
         daTaoKeList = daTaoKeGoodsDetailService.listByDtitle(kw);
         daTaoKeList = daTaoKeGoodsDetailV2Service.listByDtitle(kw);
      TaoBaoSearchResult result = TaoBaoUtil.search(sf);
      TaoBaoSearchResult result = TaoBaoUtil.search(sf,null,null);
      if (result == null) {
         return null;
      }
@@ -680,7 +671,7 @@
      try {
         if (daTaoKeList != null && daTaoKeList.size() > 0) {
            Collections.reverse(daTaoKeList);
            for (DaTaoKeDetail detail : daTaoKeList) {
            for (DaTaoKeDetailV2 detail : daTaoKeList) {
               taoBaoGoodsBriefs.add(0, TaoBaoUtil.convert(detail));
            }
         }
@@ -690,7 +681,7 @@
      int fq = sf.getQuan();
      int fh = sf.getHongbao();
      boolean ft = sf.isTmall();
      BigDecimal proportion = manageService.getFanLiRate();
      BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem());
      if (fq == 0 && fh == 0 && !ft) {
         if (result != null && taoBaoGoodsBriefs != null)
            for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) {
@@ -735,7 +726,7 @@
   /**
    * 执行搜索精选库
    * 
    * @param kw
    * @param key
    * @param page
    * @param filter
    * @param order
@@ -743,8 +734,8 @@
    * @param endprice
    * @return
    */
   private JSONObject searchQualityGoods(String key, int page, String filter, String order, String startprice,
         String endprice) {
   private JSONObject searchQualityGoods(AcceptData acceptData, String key, int page, String filter, String order, String startprice,
                                String endprice, SystemEnum system) {
      Integer hasQuan = null;
      Integer userType = null;
@@ -793,7 +784,7 @@
               provinceId = array.optJSONObject(i).optInt("id");
            } else if ("tkRate1".equalsIgnoreCase(ty)) {
               // 获取对应参数
               String value = configService.get("tkRate_range");
               String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
               if (!StringUtil.isNullOrEmpty(value)) {
                  JSONArray tkRatearray = JSONArray.fromObject(value);
                  if (tkRatearray != null) {
@@ -809,7 +800,7 @@
               }
            } else if ("tkRate2".equalsIgnoreCase(ty)) {
               // 获取对应参数
               String value = configService.get("tkRate_range");
               String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
               if (!StringUtil.isNullOrEmpty(value)) {
                  JSONArray tkRatearray = JSONArray.fromObject(value);
                  if (tkRatearray != null) {
@@ -825,7 +816,7 @@
               }
            } else if ("tkRate3".equalsIgnoreCase(ty)) {
               // 获取对应参数
               String value = configService.get("tkRate_range");
               String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
               if (!StringUtil.isNullOrEmpty(value)) {
                  JSONArray tkRatearray = JSONArray.fromObject(value);
                  if (tkRatearray != null) {
@@ -841,7 +832,7 @@
               }
            } else if ("tkRate4".equalsIgnoreCase(ty)) {
               // 获取对应参数
               String value = configService.get("tkRate_range");
               String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
               if (!StringUtil.isNullOrEmpty(value)) {
                  JSONArray tkRatearray = JSONArray.fromObject(value);
                  if (tkRatearray != null) {
@@ -857,7 +848,7 @@
               }
            } else if ("tkRate5".equalsIgnoreCase(ty)) {
               // 获取对应参数
               String value = configService.get("tkRate_range");
               String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
               if (!StringUtil.isNullOrEmpty(value)) {
                  JSONArray tkRatearray = JSONArray.fromObject(value);
                  if (tkRatearray != null) {
@@ -881,7 +872,7 @@
            userType, start_Price, end_Price, startTkRate, endTkRate, sort);
      List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
      BigDecimal proportion = manageService.getFanLiRate();
      BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem());
      /* 遍历列表数据 */
      if (listQuery != null && listQuery.size() > 0) {
         for (QualityFactory selectionGoods : listQuery) {
@@ -950,7 +941,7 @@
      return data;
   }
   private JSONObject searchDaTaoKeGoods(String key, int page, String filter, String order, String startprice,
   private JSONObject searchDaTaoKeGoods(AcceptData acceptData, String key, int page, String filter, String order, String startprice,
         String endprice) {
      page = page + 1;
      int sort = DaTaoKeApiUtil.SORT_DEFAULT;
@@ -965,7 +956,7 @@
      }
      List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
      BigDecimal proportion = manageService.getFanLiRate();
      BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem());
      DaTaoKeGoodsResult result = DaTaoKeApiUtil.search(key, null, null, null, page, 20, sort);
      if (result != null && result.getGoodsList() != null)
@@ -993,9 +984,9 @@
    * @param i
    * @param sf
    */
   public void setSearchTkRate(int i, SearchFilter sf) {
   public void setSearchTkRate(int i, SearchFilter sf,SystemEnum system) {
      // 获取对应参数
      String value = configService.get("tkRate_range");
      String value = configService.getValue(ConfigKeyEnum.tkRateRange.getKey(),system);
      if (!StringUtil.isNullOrEmpty(value)) {