/** * 将微博内容放到数据库 * * @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; }
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; }