admin
2020-02-23 121c5ee5345d366ae4aadf7901af9b0678dbb7a8
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java
@@ -53,6 +53,7 @@
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.QrCodeService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.AESUtil;
@@ -109,6 +110,8 @@
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @Resource
   private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
@@ -517,11 +520,103 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   // //发圈测试
   public void evaluateTest(AcceptData acceptData, PrintWriter out) {
      JSONObject data = JSONObject.fromObject(configService.get("test"));
      out.print(data.toString());
   /**
    * 发圈列表
    *
    * @param acceptData
    * @param page
    * @param out
    */
   @RequestMapping(value = "evaluate2", method = RequestMethod.POST)
   public void evaluate2(AcceptData acceptData, Integer page,Integer type, PrintWriter out) {
      if(type == null) {
         type = 1;
   }
      List<GoodsEvaluate> list = goodsEvaluateService.queryMaterialsCache((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, type);
      if (list == null) {
         list = new ArrayList<>();
      }
      GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
      gsonBuilder.registerTypeAdapter(CommentInfoEnum.class, new JsonSerializer<CommentInfoEnum>() {
         @Override
         public JsonElement serialize(CommentInfoEnum value, Type theType, JsonSerializationContext context) {
            if (value == null) {
               return new JsonPrimitive(1);
            } else {
               return new JsonPrimitive(value.getDesc());
            }
         }
      }).registerTypeAdapter(ImgEnum.class, new JsonSerializer<ImgEnum>() {
         @Override
         public JsonElement serialize(ImgEnum value, Type theType, JsonSerializationContext context) {
            if (value == null) {
               return new JsonPrimitive("");
            } else {
               return new JsonPrimitive(value.getVlaue());
            }
         }
      }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
         @Override
         public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
            String desc = "";
            if (value != null) {
               // 判断是否是同一天
               Calendar calendar = Calendar.getInstance();
               calendar.setTime(value);
               int y1 = calendar.get(Calendar.YEAR);// 获取年份
               int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天
               Date nowDate = new Date();
               Calendar calendar2 = Calendar.getInstance();
               calendar2.setTime(nowDate);
               int y2 = calendar2.get(Calendar.YEAR);// 获取年份
               int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天
               long old = value.getTime();
               long now = nowDate.getTime();
               if (y1 == y2) {
                  if (d1 == d2) {
                     long cha = now - old;
                     if (cha < 1000 * 60 * 2L) {
                        desc = "刚刚";
                     } else if (cha < 1000 * 60 * 60L) {
                        desc = (cha / (1000 * 60)) + "分钟前";
                     } else {
                        desc = (cha / (1000 * 60 * 60)) + "小时前";
                     }
                  } else if (d2 - d1 == 1) {
                     desc = "昨天";
                  } else {
                     desc = (d2 - d1) + "天前";
                  }
               } else {
                  int timeDistance = 0;
                  for (int i = y1; i < y2; i++) {
                     if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
                        timeDistance += 366; // 闰年
                     } else {
                        timeDistance += 365; // 不是闰年
                     }
                  }
                  desc = timeDistance + (d2 - d1) + "天前";
               }
               return new JsonPrimitive(desc);
            }
            return new JsonPrimitive("");
         }
      });
      Gson gson = gsonBuilder.create();
      long count = goodsEvaluateService.countValidMaterials(type);
      JSONObject data = new JSONObject();
      data.put("count", count);
      data.put("list", gson.toJson(list));
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 发圈列表
@@ -531,12 +626,7 @@
    * @param out
    */
   @RequestMapping(value = "evaluate", method = RequestMethod.POST)
   public void evaluate(AcceptData acceptData, Integer page, PrintWriter out) {
      if ("1".equalsIgnoreCase(configService.get("test-open"))) {
         evaluateTest(acceptData, out);
         return;
      }
   public void evaluate(AcceptData acceptData, Integer page, Integer type, PrintWriter out) {
      long cid = 1;
      long subId = 1;
      List<DynamicInfo> listd = dynamicInfoService.queryV2(2, 74, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,
@@ -547,10 +637,7 @@
      List<GoodsEvaluate> list = new ArrayList<>();
      int p = 0;
      for (DynamicInfo info : listd) {
         p++;
         GoodsEvaluate goodsEvaluate = new GoodsEvaluate();
         goodsEvaluate.setId(info.getId());
         ActivityUser user = info.getUser();
@@ -564,7 +651,6 @@
         List<ImgInfo> imgList = new ArrayList<>();
         int i = 0;
         for (GoodsPicture goodsPicture : imgs) {
            ImgInfo imgInfo = new ImgInfo();
            GoodsDetailVO goodsVO = goodsPicture.getGoodsVO();
@@ -604,29 +690,6 @@
            // i++;
            imgList.add(imgInfo);
         }
         if (p == 1) {
            ImgInfo imgInfo = new ImgInfo();
            imgInfo.setLarge(true);
            imgInfo.setType(ImgEnum.img);
            imgInfo.setUrl(
                  "http://ec-1255749512.file.myqcloud.com/img/invite/new/10ea86eb8db94f7cbb5e68864480d5fe.jpg");
            imgInfo.setH(1334);
            imgInfo.setW(750);
            imgList.add(0, imgInfo);
            imgInfo = new ImgInfo();
            imgInfo.setType(ImgEnum.video);
            imgInfo.setLarge(true);
            imgInfo.setUrl(
                  "http://ec-1255749512.file.myqcloud.com/img/invite/new/10ea86eb8db94f7cbb5e68864480d5fe.jpg");
            imgInfo.setH(315);
            imgInfo.setW(560);
            imgInfo.setUrl("https://zzya.beva.cn/img/Fr56bczo_F8NvroeG54jLH5ey0aC.jpg");
            imgInfo.setVideoUrl("http://img.flqapp.com/resource/video.mp4");
            imgList.add(0, imgInfo);
         }
         goodsEvaluate.setImgList(imgList);
@@ -675,9 +738,7 @@
         list.add(goodsEvaluate);
      }
      // List<GoodsEvaluate> list =
      // goodsEvaluateService.queryValidEvaluateCache((page - 1) *
      // Constant.PAGE_SIZE, Constant.PAGE_SIZE);
//      List<GoodsEvaluate> list = goodsEvaluateService.queryValidEvaluateCache((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
      // if (list == null) {
      // list = new ArrayList<>();
      // }
@@ -764,8 +825,7 @@
   }
   @RequestMapping(value = "evaluateShare", method = RequestMethod.POST)
   public void evaluateShare(AcceptData acceptData, Long uid, String id, Integer type, Long goodsId, Integer goodsType,
         PrintWriter out) {
   public void evaluateShare(AcceptData acceptData, Long uid, String id, Integer type, Long goodsId, Integer goodsType, PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult("用户未登录"));
         return;
@@ -781,8 +841,8 @@
         return;
      }
      DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
      if (dynamicInfo == null) {
      GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id);
      if (goodsEvaluate == null) {
         out.print(JsonUtil.loadFalseResult("该内容已不存在"));
         return;
      }
@@ -809,52 +869,58 @@
         return;
      }
      List<GoodsPicture> imgs = dynamicInfo.getImgs();
      String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
      if (StringUtil.isNullOrEmpty(inviteCode)) {
         out.print(JsonUtil.loadFalseResult(1, "邀请码未激活"));
         return;
      }
      List<ImgInfo> imgs = goodsEvaluate.getImgList();
      if (imgs == null) {
         out.print(JsonUtil.loadFalseResult("该图片内容已不存在"));
         return;
      }
      int total = 0;
      for (GoodsPicture goodsPicture : imgs) {
         GoodsDetailVO goodsVO = goodsPicture.getGoodsVO();
         if (goodsVO != null) {
      for (ImgInfo imgInfo : imgs) {
         SimpleGoods goods = imgInfo.getGoods();
         if (goods != null) {
            total++;
         }
      }
      List<String> list = new ArrayList<>();
      for (GoodsPicture goodsPicture : imgs) {
         GoodsDetailVO goodsVO = goodsPicture.getGoodsVO();
      for (ImgInfo imgInfo : imgs) {
         GoodsDetailVO goodsVO = imgInfo.getGoodsVO();
         if (goodsVO == null && total <= 1) {
            list.add(goodsPicture.getUrl());
            list.add(imgInfo.getUrl());
            continue;
         }
         if (type == 1) {
            if (goodsVO.getGoodsId().longValue() == goodsId.longValue()
                  && goodsVO.getGoodsType() == goodsType.intValue()) {
               String jumpLink = getJumpLink(goodsVO, user);
            if (goodsVO.getGoodsId().longValue() == goodsId.longValue() && goodsVO.getGoodsType() == goodsType.intValue()) {
               String jumpLink = getJumpLink(goodsVO, user, inviteCode);
               if (!StringUtil.isNullOrEmpty(jumpLink)) {
                  list.add(jumpLink);
               }
            }
         } else {
            String jumpLink = getJumpLink(goodsVO, user);
            String jumpLink = getJumpLink(goodsVO, user, inviteCode);
            if (!StringUtil.isNullOrEmpty(jumpLink)) {
               list.add(jumpLink);
            }
         }
      }
      Integer shareCount = dynamicInfo.getShareCount();
      Integer shareCount = goodsEvaluate.getShareNum();
      if (shareCount == null) {
         shareCount = 0;
      }
      if (type == 3) {
         shareCount++;
         dynamicInfoService.updateShareCount(dynamicInfo);
         goodsEvaluateService.addShareNum(id);
      }
      if (list.size() == 0) {
@@ -868,7 +934,7 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user) {
   private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user, String inviteCode) {
      String jumpLink = null;
      if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
         String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
@@ -893,23 +959,23 @@
         jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "",
               user.getId() + "");
      } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_PDD) {
         jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsVO.getGoodsId(), PinDuoDuoApiUtil.PID_SHARE + "",
               user.getId() + "");
         jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsVO.getGoodsId(), PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + "");
      }
      FileUploadResult uploadResult = qrCodeService.drawGoodsPoster(jumpLink, user.getPortrait(), goodsVO);
      FileUploadResult uploadResult = qrCodeService.drawDynamicGoodsPoster(jumpLink, user.getPortrait(), inviteCode, goodsVO);
      if (uploadResult != null) {
         return uploadResult.getUrl();
      }
      return null;
   }
   /**
    * 评论复制
    *
    * @param acceptData
    * @param id
    * @param cid
    *            评论id
    * @param cid 评论id
    * @param out
    */
   @RequestMapping(value = "evaluateComment", method = RequestMethod.POST)
@@ -919,8 +985,8 @@
         return;
      }
      DynamicInfo dynamicInfo = dynamicInfoService.getById(id);
      if (dynamicInfo == null) {
      GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id);
      if (goodsEvaluate == null) {
         out.print(JsonUtil.loadFalseResult("该内容已不存在"));
         return;
      }
@@ -947,8 +1013,18 @@
         return;
      }
      String text = "";
      List<CommentInfo> comments = goodsEvaluate.getComments();
      if (comments != null) {
         for (CommentInfo commentInfo: comments){
            if (cid.equals(commentInfo.getId())) {
               text = commentInfo.getContent();
            }
         }
      }
      JSONObject data = new JSONObject();
      data.put("text", "安妮贝拉卡通版儿拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版");
      data.put("text", text);
      out.print(JsonUtil.loadTrueResult(data));
   }
}