yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/CommonContentControllerV2.java
@@ -14,16 +14,29 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.common.CommonContentNav;
import com.yeshi.fanli.dto.common.CommonContentResult;
import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
import com.yeshi.fanli.dto.common.JDCommonContentTypeEnum;
import com.yeshi.fanli.dto.common.PDDCommonContentTypeEnum;
import com.yeshi.fanli.dto.jd.JDSearchResult;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.pdd.PDDGoodsResult;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
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.hongbao.HongBaoManageService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -38,6 +51,8 @@
@RequestMapping("api/v2/commoncontent")
public class CommonContentControllerV2 {
   @Resource
   private SwiperPictureService swiperPictureService;
   @Resource
   private HongBaoManageService hongBaoManageService;
@@ -45,6 +60,41 @@
   @Resource
   private CommonTemplateContentService commonTemplateContentService;
   @Resource
   private JDCommonTemplateContentService jdCommonTemplateContentService;
   @Resource
   private PDDCommonTemplateContentService pddCommonTemplateContentService;
   /**
    * 通用模板导航
    *
    * @param acceptData
    * @param key
    * @param out
    */
   @RequestMapping(value = "getNavList", method = RequestMethod.POST)
   public void getNavList(AcceptData acceptData, String key, Integer type, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(key)) {
         out.print(JsonUtil.loadFalseResult(1, "请传入Key"));
         return;
      }
      List<CommonContentNav> list = null;
      if (type == null || type == Constant.SOURCE_TYPE_TAOBAO) {
         list = commonTemplateContentService.getNavList(CommonContentTypeEnum.valueOf(key));
      } else if (type == Constant.SOURCE_TYPE_JD) {
         // 暂无分类
      } else if (type == Constant.SOURCE_TYPE_PDD) {
         list = pddCommonTemplateContentService.getNavList(PDDCommonContentTypeEnum.valueOf(key));
      }
      if (list == null) {
         list = new ArrayList<CommonContentNav>();
      }
      out.print(JsonUtil.loadTrueResult(new Gson().toJson(list)));
   }
   /**
    * 获取内容
@@ -56,7 +106,8 @@
    * @param out
    */
   @RequestMapping(value = "getNavGoodsList", method = RequestMethod.POST)
   public void getNavContent(AcceptData acceptData, String key, Integer page, String cid, PrintWriter out) {
   public void getNavContent(AcceptData acceptData, String key, Integer type, Integer page, String cid,
         PrintWriter out) {
      if (StringUtil.isNullOrEmpty(key)) {
         out.print(JsonUtil.loadFalseResult(1, "请传入Key"));
         return;
@@ -67,6 +118,24 @@
         return;
      }
      if (type == null || type == Constant.SOURCE_TYPE_TAOBAO) {
         getListTB(acceptData, key, page, cid, out);
         return;
      }
      if (type == Constant.SOURCE_TYPE_JD) {
         getListJD(acceptData, key, page, cid, out);
         return;
      }
      if (type == Constant.SOURCE_TYPE_PDD) {
         getListPDD(acceptData, key, page, cid, out);
         return;
      }
      out.print(JsonUtil.loadFalseResult("goodsType参数不正确"));
   }
   private void getListTB(AcceptData acceptData, String key, Integer page, String cid, PrintWriter out) {
      CommonContentResult result = commonTemplateContentService.getContentList(CommonContentTypeEnum.valueOf(key),
            cid, page, Constant.PAGE_SIZE);
@@ -82,12 +151,113 @@
      List<TaoBaoGoodsBrief> goodsList = result.getGoodsList();
      BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
      BigDecimal shareRate = hongBaoManageService.getShareRate();
      for (TaoBaoGoodsBrief taoBaoGoodsBrief : goodsList) {
         array.add(gson.toJson(GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate)));
         GoodsDetailVO vo = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, null, fanLiRate, shareRate);
         if (CommonContentTypeEnum.valueOf(key) == CommonContentTypeEnum.mianDan)// 免单商品
         {
            vo.getMoneyInfo().setFanliMoney("¥" + TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief));
            vo.getMoneyInfo().setShareMoney("¥" + TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief));
         }
         array.add(gson.toJson(vo));
      }
      root.put("goodsList", array);
      root.put("goodsCount", result.getCount());
      root.put("list", array);
      root.put("count", result.getCount());
      out.print(JsonUtil.loadTrueResult(root));
   }
   /**
    * 京东通用专题模板
    *
    * @param acceptData
    * @param key
    * @param page
    * @param cid
    * @param out
    */
   public void getListJD(AcceptData acceptData, String key, Integer page, String cid, PrintWriter out) {
      JSONObject data = new JSONObject();
      if (page == 1) {
         List<SwiperPicture> bannerList = new ArrayList<>();
         data.put("bannerList", new Gson().toJson(bannerList));
      }
      JDSearchResult result = jdCommonTemplateContentService.getContentList(JDCommonContentTypeEnum.valueOf(key), cid,
            page, Constant.PAGE_SIZE);
      JSONArray array = new JSONArray();
      long count = 0;
      if (result != null) {
         PageEntity pageEntity = result.getPageEntity();
         if (pageEntity != null) {
            count = pageEntity.getTotalCount();
         }
         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();
            for (JDGoods goods : goodsList) {
               array.add(gson.toJson(GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate)));
            }
         }
      }
      data.put("list", array);
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 拼多多通用专题模板
    *
    * @param acceptData
    * @param key
    * @param page
    * @param cid
    * @param out
    */
   public void getListPDD(AcceptData acceptData, String key, Integer page, String cid, PrintWriter out) {
      JSONObject data = new JSONObject();
      if (page == 1) {
         // 2、顶部轮播图
         List<SwiperPicture> bannerList = null;
         if (Constant.IS_TEST) {
            bannerList = swiperPictureService.getByBannerCard("index_top");
         }
         if (bannerList == null) {
            bannerList = new ArrayList<SwiperPicture>();
         }
         data.put("bannerList", new Gson().toJson(bannerList));
      }
      PDDGoodsResult result = pddCommonTemplateContentService.getContentList(PDDCommonContentTypeEnum.valueOf(key),
            cid, page, Constant.PAGE_SIZE);
      JSONArray array = new JSONArray();
      long count = 0;
      if (result != null) {
         count = result.getTotalCount();
         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();
            for (PDDGoodsDetail goods : goodsList) {
               array.add(gson.toJson(GoodsDetailVOFactory.convertPDDGoods(goods, fanLiRate, shareRate)));
            }
         }
      }
      data.put("list", array);
      data.put("count", count);
      out.print(JsonUtil.loadTrueResult(data));
   }
}