Commit b3c46f5016c291edb276166cd99aa24faac2c466
1 parent
247ba669
优化图文、朋友圈、评论、频道api
Showing
3 changed files
with
127 additions
and
184 deletions
src/main/java/com/cnlive/shenhe/api/ChannelControllerApi.java
| @@ -40,36 +40,45 @@ public class ChannelControllerApi { | @@ -40,36 +40,45 @@ public class ChannelControllerApi { | ||
| 40 | public ResponseBean impotChannel(String param) { | 40 | public ResponseBean impotChannel(String param) { |
| 41 | logger.info("频道入库,param=====" + param); | 41 | logger.info("频道入库,param=====" + param); |
| 42 | JSONObject json = JSONObject.parseObject(param); | 42 | JSONObject json = JSONObject.parseObject(param); |
| 43 | + boolean yorN; | ||
| 43 | //判断是否存在 | 44 | //判断是否存在 |
| 44 | ShyChannel shyChannel = new ShyChannel(); | 45 | ShyChannel shyChannel = new ShyChannel(); |
| 45 | shyChannel.setChannel_id(json.getString("channelId")); | 46 | shyChannel.setChannel_id(json.getString("channelId")); |
| 46 | List<ShyChannel> channelList = channelService.findshyChannel(shyChannel); | 47 | List<ShyChannel> channelList = channelService.findshyChannel(shyChannel); |
| 47 | - | 48 | + shyChannel.setCreated_at(CommonUtils.getCurrentTime()); |
| 48 | Integer spId; | 49 | Integer spId; |
| 49 | try { | 50 | try { |
| 50 | spId = json.getInteger("spId"); | 51 | spId = json.getInteger("spId"); |
| 51 | } catch (Exception e) { | 52 | } catch (Exception e) { |
| 52 | spId = null; | 53 | spId = null; |
| 53 | } | 54 | } |
| 54 | - //存在则更新 | ||
| 55 | if (channelList.size() > 0) { | 55 | if (channelList.size() > 0) { |
| 56 | + // 存在则更新 | ||
| 56 | ShyChannel shyChannel1 = channelList.get(0); | 57 | ShyChannel shyChannel1 = channelList.get(0); |
| 57 | - shyChannel1.setShenhe_status(CommonConst.AUDIT_INTT); | ||
| 58 | - shyChannel1.setChannel_name(json.getString("channelName")); | ||
| 59 | - shyChannel1.setChannel_img(json.getString("face")); | ||
| 60 | - shyChannel1.setCallback(json.getString("callback")); | ||
| 61 | - shyChannel1.setSp_id(spId); | ||
| 62 | - //是否下线 0表示正常 1表示下线 | ||
| 63 | - shyChannel1.setOffline(CommonConstStates.ZHENGCHANG); | ||
| 64 | - shyChannel1.setUpdated_at(CommonUtils.getCurrentTime()); | ||
| 65 | - channelService.getShenheType(shyChannel1); | ||
| 66 | - boolean yorN = channelService.updateshyChannel(shyChannel1); | ||
| 67 | - if (yorN) { | ||
| 68 | - return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "审核请求收到成功"); | ||
| 69 | - } | ||
| 70 | - return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "审核请求收到失败(更新)"); | 58 | + yorN = saveOrUpdateChannel(shyChannel1, json, spId); |
| 59 | + logger.info("频道修改操作"); | ||
| 60 | + } else { | ||
| 61 | + // 不存在则保存 | ||
| 62 | + yorN = saveOrUpdateChannel(shyChannel, json, spId); | ||
| 63 | + logger.info("频道保存操作"); | ||
| 64 | + } | ||
| 65 | + if (yorN) { | ||
| 66 | + return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 67 | + } else { | ||
| 68 | + return new ResponseBean(ErrorEnum.ERROR); | ||
| 71 | } | 69 | } |
| 72 | - //如果不存在直接插入 | 70 | + } |
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 保存和修改频道 | ||
| 74 | + * | ||
| 75 | + * @param shyChannel | ||
| 76 | + * @param json | ||
| 77 | + * @param spId | ||
| 78 | + * @return | ||
| 79 | + */ | ||
| 80 | + private boolean saveOrUpdateChannel(ShyChannel shyChannel, JSONObject json, Integer spId) { | ||
| 81 | + // 如果不存在直接插入 存在就直接修改 | ||
| 73 | shyChannel.setShenhe_status(CommonConst.AUDIT_INTT); | 82 | shyChannel.setShenhe_status(CommonConst.AUDIT_INTT); |
| 74 | shyChannel.setChannel_name(json.getString("channelName")); | 83 | shyChannel.setChannel_name(json.getString("channelName")); |
| 75 | shyChannel.setChannel_img(json.getString("face")); | 84 | shyChannel.setChannel_img(json.getString("face")); |
| @@ -77,15 +86,12 @@ public class ChannelControllerApi { | @@ -77,15 +86,12 @@ public class ChannelControllerApi { | ||
| 77 | shyChannel.setSp_id(spId); | 86 | shyChannel.setSp_id(spId); |
| 78 | //是否下线 0表示正常 1表示下线 | 87 | //是否下线 0表示正常 1表示下线 |
| 79 | shyChannel.setOffline(CommonConstStates.ZHENGCHANG); | 88 | shyChannel.setOffline(CommonConstStates.ZHENGCHANG); |
| 80 | - shyChannel.setCreated_at(CommonUtils.getCurrentTime()); | ||
| 81 | shyChannel.setUpdated_at(CommonUtils.getCurrentTime()); | 89 | shyChannel.setUpdated_at(CommonUtils.getCurrentTime()); |
| 82 | channelService.getShenheType(shyChannel); | 90 | channelService.getShenheType(shyChannel); |
| 83 | - boolean yorN = channelService.impotChannel(shyChannel); | ||
| 84 | - if (yorN) { | ||
| 85 | - return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "审核请求收到成功"); | 91 | + if (shyChannel.getId() == null) { |
| 92 | + return channelService.impotChannel(shyChannel); | ||
| 93 | + } else { | ||
| 94 | + return channelService.updateshyChannel(shyChannel); | ||
| 86 | } | 95 | } |
| 87 | - return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "审核请求收到失败(新增)"); | ||
| 88 | } | 96 | } |
| 89 | - | ||
| 90 | - | ||
| 91 | } | 97 | } |
src/main/java/com/cnlive/shenhe/api/CommentsControllerApi.java
| @@ -38,29 +38,16 @@ public class CommentsControllerApi { | @@ -38,29 +38,16 @@ public class CommentsControllerApi { | ||
| 38 | public ResponseBean impotComment(String param) { | 38 | public ResponseBean impotComment(String param) { |
| 39 | logger.info("评论入库,param=====" + param); | 39 | logger.info("评论入库,param=====" + param); |
| 40 | JSONObject json = JSONObject.parseObject(param); | 40 | JSONObject json = JSONObject.parseObject(param); |
| 41 | + boolean yorN; | ||
| 41 | //评论类型,topic:话题 | 42 | //评论类型,topic:话题 |
| 42 | String type = json.getString("type") == null ? "else" : json.getString("type"); | 43 | String type = json.getString("type") == null ? "else" : json.getString("type"); |
| 43 | //评论的级别 | 44 | //评论的级别 |
| 44 | Integer level = json.getInteger("level") == null ? 1 : json.getInteger("level"); | 45 | Integer level = json.getInteger("level") == null ? 1 : json.getInteger("level"); |
| 45 | - String programId = json.getString("programId"); | ||
| 46 | - String originalUrl = json.getString("originalUrl"); | ||
| 47 | - String commentTitle = json.getString("commentTitle"); | ||
| 48 | - Integer commentUserId = json.getInteger("commentUserId"); | ||
| 49 | - String commentUserName = json.getString("commentUserName"); | ||
| 50 | - String commentUserAvatar = json.getString("commentUserAvatar"); | ||
| 51 | - String commentUserIp = json.getString("commentUserIP"); | ||
| 52 | - String commentContent = json.getString("commentContent"); | ||
| 53 | - String appId = json.getString("appId"); | ||
| 54 | - String platform = json.getString("platform"); | ||
| 55 | - String activityId = json.getString("activityId"); | ||
| 56 | - Boolean priority = json.getBoolean("priority"); | ||
| 57 | - String callback = json.getString("callback"); | ||
| 58 | String commentTime = json.getString("commentTime"); | 46 | String commentTime = json.getString("commentTime"); |
| 59 | Date timestamp = null; | 47 | Date timestamp = null; |
| 60 | if (CommonUtils.isNotEmpty(commentTime)) { | 48 | if (CommonUtils.isNotEmpty(commentTime)) { |
| 61 | timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd HH:mm"); | 49 | timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd HH:mm"); |
| 62 | } | 50 | } |
| 63 | - | ||
| 64 | //判断是否存在 | 51 | //判断是否存在 |
| 65 | ShyComments shyComments = new ShyComments(); | 52 | ShyComments shyComments = new ShyComments(); |
| 66 | shyComments.setActivity_id(json.getString("activityId")); | 53 | shyComments.setActivity_id(json.getString("activityId")); |
| @@ -71,59 +58,53 @@ public class CommentsControllerApi { | @@ -71,59 +58,53 @@ public class CommentsControllerApi { | ||
| 71 | spId = json.getInteger("spId"); | 58 | spId = json.getInteger("spId"); |
| 72 | } catch (Exception e) { | 59 | } catch (Exception e) { |
| 73 | } | 60 | } |
| 74 | - //存在则更新 | ||
| 75 | if (commentsList.size() > 0) { | 61 | if (commentsList.size() > 0) { |
| 62 | + //存在则更新 | ||
| 76 | ShyComments shyComments1 = commentsList.get(0); | 63 | ShyComments shyComments1 = commentsList.get(0); |
| 77 | - shyComments1.setState(CommonConst.AUDIT_INTT); | ||
| 78 | - shyComments1.setProgram_id(programId); | ||
| 79 | - shyComments1.setComment_original_url(originalUrl); | ||
| 80 | - shyComments1.setComment_title(commentTitle); | ||
| 81 | - shyComments1.setComment_user_id(commentUserId); | ||
| 82 | - shyComments1.setComment_user_name(commentUserName); | ||
| 83 | - shyComments1.setComment_user_avatar(commentUserAvatar); | ||
| 84 | - shyComments1.setComment_user_ip(commentUserIp); | ||
| 85 | - shyComments1.setComment_content(commentContent); | ||
| 86 | - shyComments1.setType(type); | ||
| 87 | - shyComments1.setLevel(level); | ||
| 88 | - shyComments1.setComment_time(timestamp); | ||
| 89 | - shyComments1.setSpid(spId); | ||
| 90 | - shyComments1.setApp_id(appId); | ||
| 91 | - shyComments1.setPlatform(platform); | ||
| 92 | - shyComments1.setActivity_id(activityId); | ||
| 93 | - shyComments1.setIs_hot(priority); | ||
| 94 | - shyComments1.setCallback(callback); | ||
| 95 | - boolean yorN = commentsService.updateshyComments1(shyComments1); | ||
| 96 | - if (yorN) { | ||
| 97 | - return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 98 | - } else { | ||
| 99 | - return new ResponseBean(ErrorEnum.ERROR); | ||
| 100 | - } | 64 | + yorN = saveOrUpdateComments(json, shyComments1, type, level, spId, timestamp); |
| 65 | + logger.info("评论修改"); | ||
| 66 | + } else { | ||
| 67 | + // 不存在就保存 | ||
| 68 | + yorN = saveOrUpdateComments(json, shyComments, type, level, spId, timestamp); | ||
| 69 | + logger.info("评论保存"); | ||
| 70 | + } | ||
| 71 | + if (yorN) { | ||
| 72 | + return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 73 | + } else { | ||
| 74 | + return new ResponseBean(ErrorEnum.ERROR); | ||
| 101 | } | 75 | } |
| 102 | - //如果不存在直接插入 | 76 | + } |
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 保存和修改 评论 | ||
| 80 | + * | ||
| 81 | + * @param json | ||
| 82 | + * @param shyComments | ||
| 83 | + * @return | ||
| 84 | + */ | ||
| 85 | + private boolean saveOrUpdateComments(JSONObject json, ShyComments shyComments, String type, Integer level, Integer spId, Date timestamp) { | ||
| 103 | shyComments.setState(CommonConst.AUDIT_INTT); | 86 | shyComments.setState(CommonConst.AUDIT_INTT); |
| 104 | - shyComments.setProgram_id(programId); | ||
| 105 | - shyComments.setComment_original_url(originalUrl); | ||
| 106 | - shyComments.setComment_title(commentTitle); | ||
| 107 | - shyComments.setComment_user_id(commentUserId); | ||
| 108 | - shyComments.setComment_user_name(commentUserName); | ||
| 109 | - shyComments.setComment_user_avatar(commentUserAvatar); | ||
| 110 | - shyComments.setComment_user_ip(commentUserIp); | ||
| 111 | - shyComments.setComment_content(commentContent); | 87 | + shyComments.setProgram_id(json.getString("programId")); |
| 88 | + shyComments.setComment_original_url(json.getString("originalUrl")); | ||
| 89 | + shyComments.setComment_title(json.getString("commentTitle")); | ||
| 90 | + shyComments.setComment_user_id(json.getInteger("commentUserId")); | ||
| 91 | + shyComments.setComment_user_name(json.getString("commentUserName")); | ||
| 92 | + shyComments.setComment_user_avatar(json.getString("commentUserAvatar")); | ||
| 93 | + shyComments.setComment_user_ip(json.getString("commentUserIP")); | ||
| 94 | + shyComments.setComment_content(json.getString("commentContent")); | ||
| 112 | shyComments.setComment_time(timestamp); | 95 | shyComments.setComment_time(timestamp); |
| 113 | shyComments.setType(type); | 96 | shyComments.setType(type); |
| 114 | shyComments.setLevel(level); | 97 | shyComments.setLevel(level); |
| 115 | shyComments.setSpid(spId); | 98 | shyComments.setSpid(spId); |
| 116 | - shyComments.setApp_id(appId); | ||
| 117 | - shyComments.setPlatform(platform); | ||
| 118 | - shyComments.setIs_hot(priority); | ||
| 119 | - shyComments.setCallback(callback); | 99 | + shyComments.setApp_id(json.getString("appId")); |
| 100 | + shyComments.setPlatform(json.getString("platform")); | ||
| 101 | + shyComments.setIs_hot(json.getBoolean("priority")); | ||
| 102 | + shyComments.setCallback(json.getString("callback")); | ||
| 120 | commentsService.getShenheType(shyComments); | 103 | commentsService.getShenheType(shyComments); |
| 121 | - boolean yorN = commentsService.impotComments(shyComments); | ||
| 122 | - if (yorN) { | ||
| 123 | - return new ResponseBean(ErrorEnum.SUCCESS); | 104 | + if (shyComments.getId() == null) { |
| 105 | + return commentsService.impotComments(shyComments); | ||
| 124 | } else { | 106 | } else { |
| 125 | - return new ResponseBean(ErrorEnum.ERROR); | 107 | + return commentsService.updateshyComments1(shyComments); |
| 126 | } | 108 | } |
| 127 | } | 109 | } |
| 128 | - | ||
| 129 | } | 110 | } |
src/main/java/com/cnlive/shenhe/api/ContentControllerApi.java
| @@ -44,76 +44,46 @@ public class ContentControllerApi { | @@ -44,76 +44,46 @@ public class ContentControllerApi { | ||
| 44 | public ResponseBean importContent(String param) { | 44 | public ResponseBean importContent(String param) { |
| 45 | logger.info("图文入库,param=====" + param); | 45 | logger.info("图文入库,param=====" + param); |
| 46 | JSONObject json = JSONObject.parseObject(param); | 46 | JSONObject json = JSONObject.parseObject(param); |
| 47 | + boolean yorN; | ||
| 47 | //判断是否存在 | 48 | //判断是否存在 |
| 48 | - ShyContent shyContent = new ShyContent(); | ||
| 49 | String contentId = json.getString("contentId"); | 49 | String contentId = json.getString("contentId"); |
| 50 | - shyContent.setContent_id(contentId); | ||
| 51 | - //图文标签 | ||
| 52 | - shyContent.setContent_tag("content"); | ||
| 53 | //图文标签 | 50 | //图文标签 |
| 54 | String contentTag = json.getString("content_tag"); | 51 | String contentTag = json.getString("content_tag"); |
| 55 | String newContentTag = StringUtils.isEmpty(contentTag) ? "content" : contentTag; | 52 | String newContentTag = StringUtils.isEmpty(contentTag) ? "content" : contentTag; |
| 53 | + | ||
| 54 | + ShyContent shyContent = new ShyContent(); | ||
| 55 | + shyContent.setContent_id(contentId); | ||
| 56 | + shyContent.setContent_tag(newContentTag); | ||
| 56 | //获取审核类型 | 57 | //获取审核类型 |
| 57 | Integer shenheType = contentService.getShenheType(json.getInteger("spId"), newContentTag); | 58 | Integer shenheType = contentService.getShenheType(json.getInteger("spId"), newContentTag); |
| 58 | List<ShyContent> contentList = contentService.findshyContent(shyContent); | 59 | List<ShyContent> contentList = contentService.findshyContent(shyContent); |
| 59 | - //存在则更新 | ||
| 60 | if (contentList.size() > 0) { | 60 | if (contentList.size() > 0) { |
| 61 | ShyContent shyContent1 = contentList.get(0); | 61 | ShyContent shyContent1 = contentList.get(0); |
| 62 | - //标题 | ||
| 63 | - shyContent1.setTitle(json.getString("title")); | ||
| 64 | - //标题图片 | ||
| 65 | - shyContent1.setTitle_image(json.getString("titleImage")); | ||
| 66 | - //审核类型 | ||
| 67 | - shyContent1.setShenhe_type(shenheType); | ||
| 68 | - //当前图文的审核状态 | ||
| 69 | - shyContent1.setContent_status(json.getInteger("contentStatus")); | ||
| 70 | - //来源 | ||
| 71 | - shyContent1.setSource(json.getString("source")); | ||
| 72 | - //作者 | ||
| 73 | - shyContent1.setAuthor(json.getString("author")); | ||
| 74 | - //图文内容 | ||
| 75 | - shyContent1.setContent_text(json.getString("content_text")); | ||
| 76 | - //图文创建时间 | ||
| 77 | - String contentTime = json.getString("contentTime"); | ||
| 78 | - if (CommonUtils.isNotEmpty(contentTime)) { | ||
| 79 | - Date timestamp = CommonUtils.getTimestamp(contentTime, "yyyy-MM-dd HH:mm:ss"); | ||
| 80 | - shyContent1.setContent_time(timestamp); | ||
| 81 | - } | ||
| 82 | - shyContent1.setCreate_date(CommonUtils.getCurrentTime()); | ||
| 83 | - //回调地址 | ||
| 84 | - shyContent1.setCallback(json.getString("callback")); | ||
| 85 | - //图文发布h5的url | ||
| 86 | - shyContent1.setContent_url(json.getString("contentUrl")); | ||
| 87 | - //图文发布pc的url | ||
| 88 | - shyContent1.setContent_pc_url(json.getString("contentPCUrl")); | ||
| 89 | - //spid | ||
| 90 | - shyContent1.setSp_id(json.getInteger("spId")); | ||
| 91 | - //图文标签 | ||
| 92 | - shyContent1.setContent_tag(newContentTag); | ||
| 93 | - //领取状态 | ||
| 94 | - shyContent1.setReceive_status(CommonConst.RECEIVE_BEFORE); | ||
| 95 | - //最后一次更新时间 | ||
| 96 | - shyContent1.setLast_update(CommonUtils.getCurrentTime()); | ||
| 97 | - boolean yorN = contentService.updateshyContent(shyContent1); | ||
| 98 | - if (yorN) { | ||
| 99 | - logger.info("图文同步接口更新成功:{}", contentId); | ||
| 100 | - return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 101 | - } else { | ||
| 102 | - return new ResponseBean(ErrorEnum.ERROR); | ||
| 103 | - } | 62 | + // 图文存在则更新 |
| 63 | + yorN = saveOrUpdateContent(json, shyContent1, shenheType); | ||
| 64 | + logger.info("图文同步接口更新操作:{}", contentId); | ||
| 65 | + } else { | ||
| 66 | + // 图文不存在就保存 | ||
| 67 | + yorN = saveOrUpdateContent(json, shyContent, shenheType); | ||
| 68 | + logger.info("图文同步接口保存操作:{}", contentId); | ||
| 69 | + } | ||
| 70 | + if (yorN) { | ||
| 71 | + return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 72 | + } else { | ||
| 73 | + return new ResponseBean(ErrorEnum.ERROR); | ||
| 104 | } | 74 | } |
| 105 | - return saveContent(json, shyContent, shenheType); | ||
| 106 | } | 75 | } |
| 107 | 76 | ||
| 108 | /** | 77 | /** |
| 109 | - * 保存操作 | 78 | + * 保存和修改 图文 家庭相册 作业作品 操作 |
| 110 | * | 79 | * |
| 111 | * @param json | 80 | * @param json |
| 112 | * @param shyContent | 81 | * @param shyContent |
| 113 | * @param shenheType | 82 | * @param shenheType |
| 83 | + * @param | ||
| 114 | * @return | 84 | * @return |
| 115 | */ | 85 | */ |
| 116 | - private ResponseBean saveContent(JSONObject json, ShyContent shyContent, Integer shenheType) { | 86 | + private boolean saveOrUpdateContent(JSONObject json, ShyContent shyContent, Integer shenheType) { |
| 117 | //如果不存在直接插入 | 87 | //如果不存在直接插入 |
| 118 | //标题 | 88 | //标题 |
| 119 | shyContent.setTitle(json.getString("title")); | 89 | shyContent.setTitle(json.getString("title")); |
| @@ -131,8 +101,6 @@ public class ContentControllerApi { | @@ -131,8 +101,6 @@ public class ContentControllerApi { | ||
| 131 | shyContent.setContent_text(json.getString("content_text")); | 101 | shyContent.setContent_text(json.getString("content_text")); |
| 132 | //创建时间 | 102 | //创建时间 |
| 133 | shyContent.setContent_time(new Date()); | 103 | shyContent.setContent_time(new Date()); |
| 134 | - String contentTag = json.getString("content_tag"); | ||
| 135 | - shyContent.setContent_tag(StringUtils.isEmpty(contentTag) ? "content" : contentTag); | ||
| 136 | shyContent.setCreate_date(CommonUtils.getCurrentTime()); | 104 | shyContent.setCreate_date(CommonUtils.getCurrentTime()); |
| 137 | //回调地址 | 105 | //回调地址 |
| 138 | shyContent.setCallback(json.getString("callback")); | 106 | shyContent.setCallback(json.getString("callback")); |
| @@ -146,12 +114,12 @@ public class ContentControllerApi { | @@ -146,12 +114,12 @@ public class ContentControllerApi { | ||
| 146 | shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE); | 114 | shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE); |
| 147 | //最后一次更新时间 | 115 | //最后一次更新时间 |
| 148 | shyContent.setLast_update(CommonUtils.getCurrentTime()); | 116 | shyContent.setLast_update(CommonUtils.getCurrentTime()); |
| 149 | - boolean yorN = contentService.impotContent(shyContent); | ||
| 150 | - if (yorN) { | ||
| 151 | - logger.info("图文同步接口保存操作成功:{}", json.getString("contentId")); | ||
| 152 | - return new ResponseBean(ErrorEnum.SUCCESS); | 117 | + if (shyContent.getId() == null) { |
| 118 | + //id 存在就插入 | ||
| 119 | + return contentService.impotContent(shyContent); | ||
| 153 | } else { | 120 | } else { |
| 154 | - return new ResponseBean(ErrorEnum.ERROR); | 121 | + // id不存在就修改 |
| 122 | + return contentService.updateshyContent(shyContent); | ||
| 155 | } | 123 | } |
| 156 | } | 124 | } |
| 157 | 125 | ||
| @@ -166,13 +134,17 @@ public class ContentControllerApi { | @@ -166,13 +134,17 @@ public class ContentControllerApi { | ||
| 166 | public ResponseBean impotMoment(@RequestBody String param) { | 134 | public ResponseBean impotMoment(@RequestBody String param) { |
| 167 | logger.info("朋友圈入库,param=====" + param); | 135 | logger.info("朋友圈入库,param=====" + param); |
| 168 | JSONObject json = JSONObject.parseObject(param); | 136 | JSONObject json = JSONObject.parseObject(param); |
| 137 | + boolean yorN; | ||
| 169 | //判断是否存在 | 138 | //判断是否存在 |
| 139 | + String momentId = json.getString("momentId"); | ||
| 170 | ShyContent shyContent = new ShyContent(); | 140 | ShyContent shyContent = new ShyContent(); |
| 171 | //朋友圈id | 141 | //朋友圈id |
| 172 | - shyContent.setContent_id(json.getString("momentId")); | 142 | + shyContent.setContent_id(momentId); |
| 173 | //朋友圈标签 | 143 | //朋友圈标签 |
| 174 | shyContent.setContent_tag("moment"); | 144 | shyContent.setContent_tag("moment"); |
| 175 | List<ShyContent> contentList = contentService.findshyContent(shyContent); | 145 | List<ShyContent> contentList = contentService.findshyContent(shyContent); |
| 146 | + //当前朋友圈内容的审核状态,先发后审 | ||
| 147 | + shyContent.setContent_status(1); | ||
| 176 | //获取审核类型 | 148 | //获取审核类型 |
| 177 | Integer shenheType = contentService.getShenheType(json.getInteger("spId"), "moment"); | 149 | Integer shenheType = contentService.getShenheType(json.getInteger("spId"), "moment"); |
| 178 | //获取生活圈内容的类型 1:图片 2:视频 3:分享 | 150 | //获取生活圈内容的类型 1:图片 2:视频 3:分享 |
| @@ -191,56 +163,39 @@ public class ContentControllerApi { | @@ -191,56 +163,39 @@ public class ContentControllerApi { | ||
| 191 | } else { | 163 | } else { |
| 192 | contentImageUrl = json.getString("contentImageUrl"); | 164 | contentImageUrl = json.getString("contentImageUrl"); |
| 193 | } | 165 | } |
| 194 | - | ||
| 195 | - //存在则更新 | ||
| 196 | if (contentList.size() > 0) { | 166 | if (contentList.size() > 0) { |
| 167 | + //朋友圈存在则更新 | ||
| 197 | ShyContent shyContent1 = contentList.get(0); | 168 | ShyContent shyContent1 = contentList.get(0); |
| 198 | - //标题 | ||
| 199 | - shyContent1.setTitle(json.getString("title")); | ||
| 200 | - //用户头像 | ||
| 201 | - shyContent1.setTitle_image(json.getString("image")); | ||
| 202 | - //审核类型 | ||
| 203 | - shyContent1.setShenhe_type(shenheType); | ||
| 204 | - //朋友圈内容创建时间 | ||
| 205 | - String contentTime = json.getString("createTime"); | ||
| 206 | - shyContent1.setContent_time(new Date(Long.parseLong(contentTime))); | ||
| 207 | - shyContent1.setCreate_date(CommonUtils.getCurrentTime()); | ||
| 208 | - //回调地址 | ||
| 209 | - shyContent1.setCallback(json.getString("callbackUrl")); | ||
| 210 | - //朋友圈分享的url | ||
| 211 | - shyContent1.setContent_url(json.getString("pageUrl")); | ||
| 212 | - //朋友圈分享的内容的url,以逗号分隔 | ||
| 213 | - shyContent1.setContent_pc_url(contentImageUrl); | ||
| 214 | - //spid | ||
| 215 | - shyContent1.setSp_id(json.getInteger("spId")); | ||
| 216 | - //用户id | ||
| 217 | - shyContent1.setAuthor(json.getString("userId")); | ||
| 218 | - //用户昵称 | ||
| 219 | - shyContent1.setSource(json.getString("nickName")); | ||
| 220 | - //关联videoId | ||
| 221 | - shyContent1.setVideo_id(json.getString("videoId")); | ||
| 222 | - //图文标签 | ||
| 223 | - shyContent1.setContent_tag("moment"); | ||
| 224 | - //领取状态 | ||
| 225 | - shyContent1.setReceive_status(CommonConst.RECEIVE_BEFORE); | ||
| 226 | - //最后一次更新时间 | ||
| 227 | - shyContent1.setLast_update(CommonUtils.getCurrentTime()); | ||
| 228 | - boolean yorN = contentService.updateshyContent(shyContent1); | ||
| 229 | - if (yorN) { | ||
| 230 | - return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 231 | - } else { | ||
| 232 | - return new ResponseBean(ErrorEnum.ERROR); | ||
| 233 | - } | 169 | + yorN = saveOrUpdateMoment(json, shyContent1, shenheType, contentImageUrl); |
| 170 | + logger.info("朋友圈接口更新操作:{}", momentId); | ||
| 171 | + } else { | ||
| 172 | + //朋友圈不存在直接保存 | ||
| 173 | + yorN = saveOrUpdateMoment(json, shyContent, shenheType, contentImageUrl); | ||
| 174 | + logger.info("朋友圈接口保存操作:{}", momentId); | ||
| 234 | } | 175 | } |
| 235 | - //如果不存在直接插入 | 176 | + if (yorN) { |
| 177 | + return new ResponseBean(ErrorEnum.SUCCESS); | ||
| 178 | + } else { | ||
| 179 | + return new ResponseBean(ErrorEnum.ERROR); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * 朋友圈 保存和修改 | ||
| 185 | + * | ||
| 186 | + * @param json | ||
| 187 | + * @param shyContent | ||
| 188 | + * @param shenheType | ||
| 189 | + * @param contentImageUrl | ||
| 190 | + * @return | ||
| 191 | + */ | ||
| 192 | + private boolean saveOrUpdateMoment(JSONObject json, ShyContent shyContent, Integer shenheType, String contentImageUrl) { | ||
| 236 | //标题 | 193 | //标题 |
| 237 | shyContent.setTitle(json.getString("title")); | 194 | shyContent.setTitle(json.getString("title")); |
| 238 | //用户头像 | 195 | //用户头像 |
| 239 | shyContent.setTitle_image(json.getString("image")); | 196 | shyContent.setTitle_image(json.getString("image")); |
| 240 | //审核类型 | 197 | //审核类型 |
| 241 | shyContent.setShenhe_type(shenheType); | 198 | shyContent.setShenhe_type(shenheType); |
| 242 | - //当前朋友圈内容的审核状态,先发后审 | ||
| 243 | - shyContent.setContent_status(1); | ||
| 244 | //创建时间 | 199 | //创建时间 |
| 245 | String contentTime = json.getString("createTime"); | 200 | String contentTime = json.getString("createTime"); |
| 246 | shyContent.setContent_time(new Date(Long.parseLong(contentTime))); | 201 | shyContent.setContent_time(new Date(Long.parseLong(contentTime))); |
| @@ -263,11 +218,12 @@ public class ContentControllerApi { | @@ -263,11 +218,12 @@ public class ContentControllerApi { | ||
| 263 | shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE); | 218 | shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE); |
| 264 | //最后一次更新时间 | 219 | //最后一次更新时间 |
| 265 | shyContent.setLast_update(CommonUtils.getCurrentTime()); | 220 | shyContent.setLast_update(CommonUtils.getCurrentTime()); |
| 266 | - boolean yorN = contentService.impotContent(shyContent); | ||
| 267 | - if (yorN) { | ||
| 268 | - return new ResponseBean(ErrorEnum.SUCCESS); | 221 | + if (shyContent.getId() == null) { |
| 222 | + //id不存在直接插入 | ||
| 223 | + return contentService.impotContent(shyContent); | ||
| 269 | } else { | 224 | } else { |
| 270 | - return new ResponseBean(ErrorEnum.ERROR); | 225 | + // id存在就修改 |
| 226 | + return contentService.updateshyContent(shyContent); | ||
| 271 | } | 227 | } |
| 272 | } | 228 | } |
| 273 | } | 229 | } |