Browse Source

对接移动端 添加后台代码判断此用户是否已经评论过该文章

huangct 8 năm trước cách đây
mục cha
commit
0033b16883

+ 14 - 0
jpress-model/src/main/java/io/jpress/model/Comment.java

@@ -20,6 +20,7 @@ import io.jpress.model.core.Table;
 import io.jpress.model.query.CommentQuery;
 import io.jpress.model.query.ContentQuery;
 import io.jpress.model.query.UserQuery;
+import io.jpress.utils.StringUtils;
 
 import java.math.BigInteger;
 
@@ -134,4 +135,17 @@ public class Comment extends BaseComment<Comment> {
 
 		return super.save();
 	}
+
+	//判断该用户是否以及评论过改uu软文
+	public boolean isUuUserReplied(String uuUserId) {
+		if (StringUtils.isBlank(uuUserId)) {
+			return true;
+		}
+		BigInteger contentId = getContentId();
+		long count = CommentQuery.me().findCountByContentIdAndUuUserId(contentId, new BigInteger(uuUserId));
+		if (count > 0) {
+			return true;
+		}
+		return false;
+	}
 }

+ 4 - 0
jpress-model/src/main/java/io/jpress/model/query/CommentQuery.java

@@ -217,4 +217,8 @@ public class CommentQuery extends JBaseQuery {
 
 		return count;
 	}
+
+	public long findCountByContentIdAndUuUserId(BigInteger contentId, BigInteger uuUserId) {
+		return DAO.doFindCount(" content_id = ? and uu_user_id=? ", contentId, uuUserId);
+	}
 }

+ 6 - 11
jpress-web-admin/src/main/java/io/jpress/admin/controller/_ContentController.java

@@ -472,29 +472,24 @@ public class _ContentController extends JBaseCRUDController<Content> {
 
 	private void pushUuHelper(Content content) {
 		Map<String, String> map = new HashMap<>();
-		String url = "http://113.105.74.140:8092/console/pushToAll";
-		String fromUserId = "10000";
+
 		JSONObject bodyJO = new JSONObject(true);
 		bodyJO.put("content", content.getTitle());
 		bodyJO.put("fromUserId", "10000");
 		bodyJO.put("fromUserName", "系统消息");
 		bodyJO.put("type", 1);
 		bodyJO.put("timeSend", "");
-		bodyJO.put("imageUrl", content.getThumbnail());
-		bodyJO.put("linkUrl", content.getUrl());
-		String body = bodyJO.toJSONString();
-
-		map.put("fromUserId", fromUserId);
-		map.put("body", body);
-
+		bodyJO.put("imageUrl", "http://192.168.253.75:8080"+content.getThumbnail());
+		bodyJO.put("linkUrl", "http://192.168.253.75:8080"+content.getUrl());
+		String body = bodyJO.toString();
+		String url = "http://113.105.74.140:8092/user/pushToAll?fromUserId=10000&body="+body;
 
 		try {
-			String response = HttpUtils.get(url, map);
+			String response = HttpUtils.post(url);
 			System.out.println(response);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-
 	}
 
 	private Content getContent() {