Ejemplo n.º 1
0
 private SocialUserWeiboComment tranlateWeiboToComment(
     SocialUserWeibo dbWeibo, SocialUserWeibo soruceWeibo, int weiboType) {
   SocialUserWeiboComment myComment = new SocialUserWeiboComment();
   myComment.setCommentId(dbWeibo.getWeiboId());
   int factWeiboType = -1;
   if (DictDef.dictInt("weibo_mentions_timeline") == weiboType) {
     factWeiboType = DictDef.dictInt("comment_to_me");
   }
   if (DictDef.dictInt("weibo_user_timeline") == weiboType) { // 我的微博就是我发出的品论
     factWeiboType = DictDef.dictInt("comment_by_me");
   }
   myComment.setCommentType(factWeiboType);
   myComment.setCommentUid(dbWeibo.getWeiboUid());
   myComment.setCreateAt(dbWeibo.getCreateAt());
   myComment.setMid(dbWeibo.getMid());
   myComment.setSource(dbWeibo.getSource());
   myComment.setText(dbWeibo.getText());
   myComment.setUserDomain(dbWeibo.getUserDomain());
   myComment.setUserName(dbWeibo.getUserName());
   myComment.setUserProfileImageUrl(dbWeibo.getUserProfileImageUrl());
   myComment.setUserScreenName(dbWeibo.getUserScreenName());
   myComment.setUserVerified(dbWeibo.getUserVerified());
   if (soruceWeibo == null) {
     return myComment;
   }
   myComment.setStatusCreatedAt(soruceWeibo.getCreateAt());
   myComment.setStatusMid(soruceWeibo.getMid());
   myComment.setStatusSource(soruceWeibo.getSource());
   // myComment.setStatusSourceUrl(comment.getStatus().getSource().getUrl());
   myComment.setStatusText(soruceWeibo.getText());
   myComment.setStatusUserDomain(soruceWeibo.getUserDomain());
   myComment.setStatusUserName(soruceWeibo.getUserName());
   myComment.setStatusUserScreenName(soruceWeibo.getUserScreenName());
   myComment.setStatusUserVerified(soruceWeibo.getUserVerified());
   myComment.setStatusWeiboId(soruceWeibo.getWeiboId());
   System.out.println(soruceWeibo.getWeiboUid() + "----" + dbWeibo.getWeiboUid());
   myComment.setStatusUserUid(soruceWeibo.getWeiboUid());
   return myComment;
 }
Ejemplo n.º 2
0
  @Override
  public <T> SocialUserWeibo convertThirdToWeiboEntity(SocialUserWeibo weibo, T thirdInfo) {
    JSONObject jsonInfo = (JSONObject) thirdInfo;
    if (weibo == null) {
      weibo = new SocialUserWeibo();
      weibo.setCreateAt(new Date());
    }

    String weiboId = jsonInfo.getString("id");
    System.out.println(" weibId " + weiboId);
    weibo.setWeiboId(weiboId); // 微博唯一id
    weibo.setCreateAt(new Date(jsonInfo.getLong("timestamp") * 1000));

    weibo.setSource(jsonInfo.getString("from")); // 来源
    weibo.setSourceUrl(jsonInfo.getString("fromurl"));
    weibo.setUserDomain(jsonInfo.getString("fromurl")); // 来源

    // 微博内容
    weibo.setText(jsonInfo.getString("origtext"));
    // System.out.println(jsonInfo.getString("text") + "&&*&&&&");
    // System.out.println(jsonInfo.getString("origtext"));
    weibo.setUserVerified(jsonInfo.getInt("isvip"));

    /*	System.out.println(jsonInfo.getInt("type")  + "--source---" + jsonInfo.getString("origtext"));
    if(jsonInfo.getString("source") != null){
    	System.out.println("&&&&  99999----" + jsonInfo.getString("source"));
    }*/
    // 转发数
    weibo.setRepostsCount(jsonInfo.getInt("count"));
    // 评论数
    weibo.setCommentsCount(jsonInfo.getInt("mcount"));
    // 微博类型 type : 微博类型,1-原创发表,2-转载,3-私信,4-回复,5-空回,6-提及,7-评论

    // weibo.setWeiboType(jsonInfo.getInt("type"));
    // 用户粉丝说
    // weibo.setWeiboUidFollower(weiboUidFollower);
    // 微博userid
    weibo.setWeiboUid(jsonInfo.getString("openid"));
    weibo.setUserName(jsonInfo.getString("name")); // 发表人账号
    weibo.setUserScreenName(jsonInfo.getString("nick"));
    weibo.setUserProfileImageUrl(jsonInfo.getString("head"));
    // 图片
    Object t = jsonInfo.get("image");
    if (!judgeNull(t)) {
      JSONArray arrays = jsonInfo.getJSONArray("image");
      for (int i = 0; i < arrays.size(); i++) { // 没一条的微博
        Object infoObj = arrays.get(i);
        // System.out.println(infoObj);
        String thumbnailPic = infoObj.toString() + "/120";
        weibo.setThumbnailPic(thumbnailPic);
        if (StringTool.judgeBlank(thumbnailPic)) { // 取图片的大小
          String sizeStr = ImageUtil.queryURLImageSize(thumbnailPic);
          weibo.setThumbnailPicSize(sizeStr);
        }

        String bmiddlePic = infoObj.toString() + "/2000";
        weibo.setBmiddlePic(bmiddlePic);
        if (StringTool.judgeBlank(bmiddlePic)) { // 取图片的大小
          String sizeStr = ImageUtil.queryURLImageSize(bmiddlePic);
          weibo.setBmiddlePicSize(sizeStr);
        }

        String originalPic = infoObj.toString() + "/460";
        weibo.setOriginalPic(originalPic);
        if (StringTool.judgeBlank(originalPic)) { // 取图片的大小
          String sizeStr = ImageUtil.queryURLImageSize(originalPic);
          weibo.setOriginalPicSize(sizeStr);
        }
      }
    }

    // JSONObject source = jsonInfo.getJSONObject("source");
    /*
     * if (source.toString().equals("null")) {
     * weibo.setWeiboType(DictDef.dictInt("at_me_status"));//@我的 } else { if
     * (jsonInfo.getString("text").indexOf("@") > -1) {
     * weibo.setWeiboType(DictDef.dictInt("at_me_comment")); } else {
     * weibo.setWeiboType(DictDef.dictInt("comment_to_me")); }
     * SocialUserWeibo subWeibo =
     * socialUserWeiboService.newSocialUserWeibo();
     * subWeibo.setUserName(source.getString("name"));
     * subWeibo.setWeiboId(source.getString("id"));
     * subWeibo.setText(source.getString("text"));
     * subWeibo.setRetweetedId(weibo.getId()); }
     */

    return weibo;
  }
Ejemplo n.º 3
0
  /**
   * 将微博内容放到数据库
   *
   * @param response
   * @param ac
   * @return
   */
  private WeiboHandleResult weiboSaveDb(String response, SocialUserAccount ac, Integer weiboType) {
    WeiboHandleResult result = new WeiboHandleResult();
    JSONArray infoList = null;
    String ownerUserId = ac.getOwnUser();
    Object responseJsonObject = TencentSociaTool.getJsonDataObject(response);
    if (judgeNull(responseJsonObject) || ((JSONObject) responseJsonObject).get("info") == null) {
      result.setSuccess(false);
      return result;
    }
    infoList = ((JSONObject) responseJsonObject).getJSONArray("info");
    boolean sign = false;
    for (int i = 0; i < infoList.size(); i++) { // 没一条的微博
      JSONObject infoObj = infoList.getJSONObject(i);
      SocialUserWeibo dbWeibo = handlerNewSocialUserWeibo(ownerUserId, ac, infoObj, weiboType);
      logger.info(
          i
              + "+++timestamp:"
              + infoObj.getString("timestamp")
              + "++++++++++++++++"
              + "id:"
              + infoObj.getString("id"));
      if (i == 0) { //
        result.setPagetime(infoObj.getString("timestamp"));
        result.setLastid(infoObj.getString("id"));
      }
      String type = infoObj.getString("type");
      SocialUserWeibo soruceWeibo = null;
      JSONObject source = infoObj.getJSONObject("source");
      if (source != null && !(source.toString().equals("null"))) { // 有原帖内容
        soruceWeibo = handlerNewSocialUserWeibo(ownerUserId, ac, source, weiboType);
        soruceWeibo.setWeiboHandleType(1); // 表明为原始贴
        if (saveWeiboUserEntity(soruceWeibo)) { // 插入原帖id
          dbWeibo.setRetweetedId(soruceWeibo.getId());
        } else {
          SocialUserWeibo queryWeibo =
              socialUserWeiboService.queryByAccountAndWeiboId(
                  soruceWeibo.getUserAccountId(), soruceWeibo.getWeiboId());
          dbWeibo.setRetweetedId(queryWeibo.getId());
        }
      }

      if (type.equals("7")) { // 7-评论
        dbWeibo.setWeiboHandleType(2); // 表明为品论贴
        SocialUserWeiboComment comment = tranlateWeiboToComment(dbWeibo, soruceWeibo, weiboType);
        initWeiboCommentByAccount(comment, ac);
        socialUserWeiboCommentService.createSocialUserWeiboComment(comment);
      }

      // 插进本帖
      saveWeiboUserEntity(dbWeibo);
    }
    if (infoList != null) { // 记录数
      result.setInfoSize(infoList.size());
    }
    result.setSuccess(true);
    return result;
  }