yujian
2020-05-23 28cf328a098334b51a3e9d2d56f983fb8c862211
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/CommonContentControllerV2.java
@@ -1,7 +1,6 @@
package com.yeshi.fanli.controller.client.v2;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@@ -15,6 +14,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.dto.common.CommonContentNav;
import com.yeshi.fanli.dto.common.CommonContentResult;
import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
@@ -32,7 +32,7 @@
import com.yeshi.fanli.service.inter.goods.JDCommonTemplateContentService;
import com.yeshi.fanli.service.inter.goods.PDDCommonTemplateContentService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -40,6 +40,7 @@
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.homemodule.BannerVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -58,7 +59,7 @@
   private SwiperPictureService swiperPictureService;
   @Resource
   private HongBaoManageService hongBaoManageService;
   private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
   @Resource
   private CommonTemplateContentService commonTemplateContentService;
@@ -145,9 +146,10 @@
         // 猜你喜欢
         String idfa = acceptData.getIdfa();
         String imei = acceptData.getImei();
         result = guessLikeDeviceTB(idfa, imei, page);
         result = guessLikeDeviceTB(idfa, imei, acceptData.getUtdid(), page);
      } else {
         result = commonTemplateContentService.getContentList(type, cid, page, Constant.PAGE_SIZE);
         // 大淘客页码只能为10,50,100,200
         result = commonTemplateContentService.getContentList(type, cid, page, 10);
      }
      JSONObject root = new JSONObject();
@@ -156,25 +158,28 @@
         List<SwiperPicture> bannerList = new ArrayList<>();
         root.put("bannerList", new Gson().toJson(bannerList));
      }
      JSONArray array = new JSONArray();
      Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
      List<TaoBaoGoodsBrief> goodsList = result.getGoodsList();
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
      if (result != null)
         goodsList = result.getGoodsList();
      ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
            acceptData.getVersion());
      for (TaoBaoGoodsBrief taoBaoGoodsBrief : goodsList) {
         GoodsDetailVO vo = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate);
         GoodsDetailVO vo = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, paramsDTO);
         if (type == CommonContentTypeEnum.mianDan)// 免单商品
         {
            vo.getMoneyInfo().setFanliMoney("¥" + TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief));
            vo.getMoneyInfo().setShareMoney("¥" + TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief));
            vo.getMoneyInfo().setMaxMoney(null);
         }
         array.add(gson.toJson(vo));
      }
      root.put("list", array);
      root.put("count", result.getCount());
      root.put("count", result != null ? result.getCount() : 0);
      out.print(JsonUtil.loadTrueResult(root));
   }
@@ -207,12 +212,13 @@
         List<JDGoods> goodsList = result.getGoodsList();
         if (goodsList != null && goodsList.size() > 0) {
            BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
            BigDecimal shareRate = hongBaoManageService.getShareRate();
            Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                  .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
            ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                  acceptData.getVersion());
            for (JDGoods goods : goodsList) {
               array.add(gson.toJson(GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate)));
               array.add(gson.toJson(GoodsDetailVOFactory.convertJDGoods(goods, paramsDTO)));
            }
         }
      }
@@ -235,13 +241,14 @@
      JSONObject data = new JSONObject();
      if (page == 1) {
         // 2、顶部轮播图
         List<SwiperPicture> bannerList = null;
         List<BannerVO> bannerList = null;
         if (Constant.IS_TEST) {
            bannerList = swiperPictureService.getByBannerCard("index_top");
            bannerList = swiperPictureService.getByBannerCardAndVersion("index_top", acceptData.getPlatform(),
                  Integer.parseInt(acceptData.getVersion()));
         }
         if (bannerList == null) {
            bannerList = new ArrayList<SwiperPicture>();
            bannerList = new ArrayList<BannerVO>();
         }
         data.put("bannerList", new Gson().toJson(bannerList));
@@ -256,12 +263,13 @@
         List<PDDGoodsDetail> goodsList = result.getGoodsList();
         if (goodsList != null && goodsList.size() > 0) {
            BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
            BigDecimal shareRate = hongBaoManageService.getShareRate();
            Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                  .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
            ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                  acceptData.getVersion());
            for (PDDGoodsDetail goods : goodsList) {
               array.add(gson.toJson(GoodsDetailVOFactory.convertPDDGoods(goods, fanLiRate, shareRate)));
               array.add(gson.toJson(GoodsDetailVOFactory.convertPDDGoods(goods, paramsDTO)));
            }
         }
      }
@@ -270,18 +278,18 @@
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 猜你喜欢-淘宝设备推荐
    *
    * @param acceptData
    * @param page
    * @return
    */
   @Cacheable(value = "commonContentCache", key = "#idfa+'-'+#imei+'-'+#page")
   private CommonContentResult guessLikeDeviceTB(String idfa, String imei, Integer page) {
      TaoBaoSearchResult searchResult = TaoKeApiUtil.guessDeviceLike(page, Constant.PAGE_SIZE, imei, idfa);
      if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null
   private CommonContentResult guessLikeDeviceTB(String idfa, String imei, String utdid, Integer page) {
      TaoBaoSearchResult searchResult = TaoKeApiUtil.guessDeviceLike(page, Constant.PAGE_SIZE, imei, idfa, utdid);
      if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null
            && searchResult.getTaoBaoGoodsBriefs().size() > 0) {
         CommonContentResult result = new CommonContentResult();
         result.setCount(searchResult.getPageEntity().getTotalCount());