yj
2020-03-04 b416c2ffd263ca9d191fc1109bd72d10f8c5176d
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java
@@ -33,7 +33,6 @@
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.dynamic.CommentInfo;
import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum;
import com.yeshi.fanli.entity.dynamic.DynamicInfo;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate;
import com.yeshi.fanli.entity.dynamic.GoodsEvaluate.EvaluateEnum;
@@ -41,8 +40,10 @@
import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoLink;
import com.yeshi.fanli.exception.share.ShareGoodsException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService;
@@ -66,10 +67,12 @@
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.dynamic.ArticleVO;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
@@ -122,7 +125,7 @@
   @Resource
   private QrCodeService qrCodeService;
   @Resource
   private ConvertLinkManager convertLinkManager;
@@ -239,7 +242,7 @@
         // 2.0.7返回发圈+活动+学院+素材
         list.add(map.get(TYPE_FAQUAN));
         list.add(map.get(TYPE_HUODONG));
         // list.add(map.get(TYPE_XUEYUAN));
//         list.add(map.get(TYPE_XUEYUAN));
         list.add(map.get(TYPE_SUCAI));
      } else if (VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) {
@@ -589,97 +592,117 @@
    */
   @RequestMapping(value = "getDynamicList", method = RequestMethod.POST)
   public void getDynamicListNew(AcceptData acceptData, Integer page, Long cid, String subId, PrintWriter out) {
      int type = 1;
      if (cid == TYPE_FAQUAN){
         type = 1;
      } else if (cid == TYPE_SUCAI) {
         type = 2;
      }
      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());
            }
      try {
         int type = 1;
         if (cid == TYPE_FAQUAN){
            type = 1;
         } else if (cid == TYPE_SUCAI) {
            type = 2;
         }
      }).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());
            }
         List<GoodsEvaluate> list = goodsEvaluateService.queryMaterialsCache((page - 1) * Constant.PAGE_SIZE,
               Constant.PAGE_SIZE, type);
         if (list == null) {
            list = new ArrayList<>();
         }
      }).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) + "天前";
                  }
         GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
         gsonBuilder.registerTypeAdapter(ImgEnum.class, new JsonSerializer<ImgEnum>() {
            @Override
            public JsonElement serialize(ImgEnum value, Type theType, JsonSerializationContext context) {
               if (value == null) {
                  return new JsonPrimitive("");
               } else {
                  int timeDistance = 0;
                  for (int i = y1; i < y2; i++) {
                     if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
                        timeDistance += 366; // 闰年
                  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 {
                        timeDistance += 365; // 不是闰年
                        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) + "天前";
                  }
                  desc = timeDistance + (d2 - d1) + "天前";
                  return new JsonPrimitive(desc);
               }
               return new JsonPrimitive(desc);
               return new JsonPrimitive("");
            }
            return new JsonPrimitive("");
         });
         Gson gson = gsonBuilder.create();
         long count = goodsEvaluateService.countValidMaterials(type);
         JSONArray jsonArray = new JSONArray();
         String listStr = gson.toJson(list);
         JSONArray array = JSONArray.fromObject(listStr);
         for (int i = 0; i< array.size() ; i++) {
            Object object = array.get(i);
            JSONObject json = JSONObject.fromObject(object);
            Object shareNum = json.get("shareNum");
            if (shareNum != null) {
               int num = Integer.parseInt(shareNum.toString());
               if (num >= 10000) {
                  double sales = num;
                  String salesCountMidea = String.format("%.1f", sales / 10000);
                  json.put("shareNum", salesCountMidea + "万");
               }
            }
            jsonArray.add(json);
         }
      });
      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));
         JSONObject data = new JSONObject();
         data.put("count", count);
         data.put("list", jsonArray);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadFalseResult(1, "查询信息失败"));
         LogHelper.errorDetailInfo(e);
      }
   }
   /**
@@ -774,7 +797,7 @@
                  continue;
               }
               String jumpLink = getJumpLink(goodsVO, user,relationId, inviteCode);
               String jumpLink = getJumpLink(goodsVO, user, relationId, inviteCode);
               if (!StringUtil.isNullOrEmpty(jumpLink)) {
                  list.add(jumpLink);
               }
@@ -786,7 +809,7 @@
                  if (imgInfo.getGoodsVO() != null)
                     if (imgInfo.getGoodsVO().getGoodsId().longValue() == goodsId.longValue()
                           && imgInfo.getGoodsVO().getGoodsType() == goodsType.intValue()) {
                        String jumpLink = getJumpLink(imgInfo.getGoodsVO(), user,relationId, inviteCode);
                        String jumpLink = getJumpLink(imgInfo.getGoodsVO(), user, relationId, inviteCode);
                        if (!StringUtil.isNullOrEmpty(jumpLink)) {
                           list.add(jumpLink);
                        }
@@ -796,7 +819,7 @@
            } else if (type == 2 || type == 3) {
               for (ImgInfo imgInfo : imgs) {
                  if (imgInfo.getGoodsVO() != null) {
                     String jumpLink = getJumpLink(imgInfo.getGoodsVO(), user,relationId, inviteCode);
                     String jumpLink = getJumpLink(imgInfo.getGoodsVO(), user, relationId, inviteCode);
                     if (!StringUtil.isNullOrEmpty(jumpLink)) {
                        list.add(jumpLink);
                     }
@@ -817,7 +840,6 @@
            }
         }
      }
      Integer shareCount = goodsEvaluate.getShareNum();
      if (shareCount == null) {
@@ -839,21 +861,21 @@
      data.put("list", list);
      out.print(JsonUtil.loadTrueResult(data));
   }
   @Resource
   private ShareGoodsService shareGoodsService;
   private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user,String relationId, String inviteCode) {
   private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user, String relationId, String inviteCode) {
      String jumpLink = null;
      if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
         TaoBaoLink taoBaoLink=null;
         TaoBaoLink taoBaoLink = null;
         try {
            taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(user.getId(), goodsVO.getGoodsId(), relationId);
         } catch (ShareGoodsException e) {
            e.printStackTrace();
         }
         jumpLink =configService.get(ConfigKeyEnum.taobaoShareQrcodeText.getKey()).replace("[淘口令]", taoBaoLink.getTaoToken());
         jumpLink = ShareControllerV2.getERCodeContentNew(configService.get(ConfigKeyEnum.quickShareTBCommentText.getKey()),
               taoBaoLink.getGoods(), TaoBaoUtil.filterTaoToken(taoBaoLink.getTaoToken()));
      } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_JD) {
         JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsVO.getGoodsId());
         if (jdGoods == null) {
@@ -881,6 +903,7 @@
      return null;
   }
   /**
    * 评论复制
    * 
@@ -934,12 +957,12 @@
            }
         }
      }
      try {
         text=convertLinkManager.convertLinkFromText(text, uid, true);
         text = convertLinkManager.convertLinkFromText(text, uid, true);
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadFalseResult("转链失败"));
         out.print(JsonUtil.loadFalseResult("评论生成失败"));
         return;
      }
@@ -947,6 +970,5 @@
      data.put("text", text);
      out.print(JsonUtil.loadTrueResult(data));
   }
}
}