Browse Source

Merge remote-tracking branch 'origin/uuhelper' into uuhelper/01

hangb 8 years ago
parent
commit
c4dd574e4c

+ 1 - 1
jpress-model/src/main/java/io/jpress/model/Comment.java

@@ -151,6 +151,6 @@ public class Comment extends BaseComment<Comment> {
 
 	//判断是否处于已赞状态
 	public boolean isvoted(BigInteger commentId, BigInteger userId, BigInteger uuUserId) {
-		return VoteQuery.me().findCountVote(commentId, userId, uuUserId);
+		return VoteQuery.me().findCommentCountVote(commentId, userId, uuUserId);
 	}
 }

+ 21 - 0
jpress-model/src/main/java/io/jpress/model/Content.java

@@ -490,4 +490,25 @@ public class Content extends BaseContent<Content> implements ISortModel<Content>
 		}
 		return false;
 	}
+
+	public boolean updateVoteUpCount(String status) {
+		long count = getVoteUp();
+
+		if ("up".equals(status)) {
+			count++;
+		} else {
+			count--;
+		}
+
+		if (count < 0) {
+			count = 0;
+		}
+		setVoteUp(count);
+		return this.update();
+	}
+
+	//判断是否处于已赞状态
+	public boolean isvoted(BigInteger content, BigInteger userId, BigInteger uuUserId) {
+		return VoteQuery.me().findContentCountVote(content, userId, uuUserId);
+	}
 }

+ 8 - 0
jpress-model/src/main/java/io/jpress/model/base/BaseVote.java

@@ -141,6 +141,14 @@ public abstract class BaseVote<M extends BaseVote<M>> extends JModel<M> implemen
 		return id instanceof BigInteger ? (BigInteger)id : new BigInteger(id.toString());
 	}
 
+	public void setContentId(BigInteger contentId) {
+		set("content_id", contentId);
+	}
+
+	public BigInteger getContentId() {
+		return get("content_id");
+	}
+
 	public void setCommentId(BigInteger commentId) {
 		set("comment_id", commentId);
 	}

+ 21 - 2
jpress-model/src/main/java/io/jpress/model/query/VoteQuery.java

@@ -33,7 +33,7 @@ public class VoteQuery extends JBaseQuery {
 		return DAO.doFindCount("comment_id = ? and up=1", commentId);
 	}
 
-	public Vote findVote(BigInteger commentId, BigInteger userId, BigInteger uuUserId){
+	public Vote findCommentVote(BigInteger commentId, BigInteger userId, BigInteger uuUserId){
 		List<Vote> list = DAO.doFind("comment_id = ? and (user_id = ? or uu_user_id = ?)", commentId, userId, uuUserId);
 		Vote vote = null;
 		if (list.size() > 0) {
@@ -43,7 +43,17 @@ public class VoteQuery extends JBaseQuery {
 		return vote;
 	}
 
-	public boolean findCountVote(BigInteger commentId, BigInteger userId, BigInteger uuUserId){
+	public Vote findContentVote(BigInteger contentId, BigInteger userId, BigInteger uuUserId){
+		List<Vote> list = DAO.doFind("content_id = ? and (user_id = ? or uu_user_id = ?)", contentId, userId, uuUserId);
+		Vote vote = null;
+		if (list.size() > 0) {
+			vote = list.get(0);
+		}
+
+		return vote;
+	}
+
+	public boolean findCommentCountVote(BigInteger commentId, BigInteger userId, BigInteger uuUserId){
 		long count = DAO.doFindCount("comment_id = ? and (user_id = ? or uu_user_id = ?) and up=1 ", commentId, userId, uuUserId);
 		if (count > 0) {
 			return true;
@@ -52,4 +62,13 @@ public class VoteQuery extends JBaseQuery {
 		return false;
 	}
 
+	public boolean findContentCountVote(BigInteger contentId, BigInteger userId, BigInteger uuUserId){
+		long count = DAO.doFindCount("content_id = ? and (user_id = ? or uu_user_id = ?) and up=1 ", contentId, userId, uuUserId);
+		if (count > 0) {
+			return true;
+		}
+
+		return false;
+	}
+
 }

+ 17 - 4
jpress-web-admin/src/main/java/io/jpress/admin/controller/_ContentController.java

@@ -470,16 +470,29 @@ public class _ContentController extends JBaseCRUDController<Content> {
 
 	private void pushUuHelper(Content content) {
 		Map<String, String> map = new HashMap<>();
-
+		String requestUrlMessage = this.getRequest().getScheme() +"://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort();
 		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", "http://218.17.158.219:8038"+content.getThumbnail());
-		bodyJO.put("iconUrl", "http://218.17.158.219:8038"+content.getThumbnail());
-		bodyJO.put("linkUrl", "http://218.17.158.219:8038"+content.getUrl());
+		String imageUrl = requestUrlMessage + content.getThumbnail();
+		String iconUrl = requestUrlMessage + content.getThumbnail();
+		String linkUrl = requestUrlMessage + content.getUrl();
+		if (content.getThumbnail() == null) {
+			imageUrl = null;
+		}
+		if (content.getThumbnail() == null) {
+			iconUrl = null;
+		}
+		if (content.getUrl() == null) {
+			linkUrl = null;
+		}
+
+		bodyJO.put("imageUrl", imageUrl);
+		bodyJO.put("iconUrl", iconUrl);
+		bodyJO.put("linkUrl", linkUrl);
 		String body = bodyJO.toString();
 		String url = "http://113.105.74.140:8092/user/pushToAll?fromUserId=10000&body="+body;
 

+ 1 - 1
jpress-web-admin/src/main/webapp/WEB-INF/admin/content/edit.html

@@ -219,7 +219,7 @@ $(document).ready(function(){
     	 $('#content_slug').attr('value',params.newValue);
 	 });
 
-	<#if content?? && "uuhelper" == content.module>
+	<#if content?? && "uuhelper" == content.module && ""!=content.url>
 		window.open($("#content_url").val());
 	</#if>
 });

+ 2 - 2
jpress-web-front/src/main/java/io/jpress/front/controller/CommentController.java

@@ -309,7 +309,7 @@ public class CommentController extends BaseFrontController {
 		}
 	}
 
-	//点赞接口
+	//评论点赞接口
 	public void vote() {
 		BigInteger commentId = getParaToBigInteger("comment_id");
 		Comment comment = CommentQuery.me().findById(commentId);
@@ -322,7 +322,7 @@ public class CommentController extends BaseFrontController {
 			uuUserId = null;
 		}
 
-		Vote vote = VoteQuery.me().findVote(commentId,userId,uuUserId);
+		Vote vote = VoteQuery.me().findCommentVote(commentId,userId,uuUserId);
 		//判断此用户是否给此评论点过赞
 		if (vote != null) {
 			if (vote.getUp() == null) {

+ 76 - 0
jpress-web-front/src/main/java/io/jpress/front/controller/ContentController.java

@@ -22,8 +22,10 @@ import io.jpress.core.addon.HookInvoker;
 import io.jpress.core.cache.ActionCache;
 import io.jpress.model.Content;
 import io.jpress.model.Taxonomy;
+import io.jpress.model.Vote;
 import io.jpress.model.query.ContentQuery;
 import io.jpress.model.query.TaxonomyQuery;
+import io.jpress.model.query.VoteQuery;
 import io.jpress.router.RouterMapping;
 import io.jpress.template.TemplateManager;
 import io.jpress.template.TplModule;
@@ -34,6 +36,7 @@ import io.jpress.ui.freemarker.tag.PreviousContentTag;
 import io.jpress.utils.StringUtils;
 
 import java.math.BigInteger;
+import java.util.Date;
 import java.util.List;
 
 @RouterMapping(url = Consts.ROUTER_CONTENT)
@@ -194,4 +197,77 @@ public class ContentController extends BaseFrontController {
 		HookInvoker.contentRenderAfter(this);
 	}
 
+	//文章点赞接口
+	public void vote() {
+		BigInteger contentId = getParaToBigInteger("content_id");
+		Content content = ContentQuery.me().findById(contentId);
+		BigInteger userId = getParaToBigInteger("user_id");
+		BigInteger uuUserId = getParaToBigInteger("uu_user_id");
+		if ("0".equals(userId.toString())) {
+			userId = null;
+		}
+		if ("0".equals(uuUserId.toString())) {
+			uuUserId = null;
+		}
+
+		Vote vote = VoteQuery.me().findContentVote(contentId,userId,uuUserId);
+		//判断此用户是否给此评论点过赞
+		if (vote != null) {
+			if (vote.getUp() == null) {
+				againVoteUp(content,vote);
+			} else {
+				cancelVoteUp(content,vote);
+			}
+		} else {
+			voteUp(content,userId,uuUserId);
+		}
+	}
+
+	//新增点赞
+	private void voteUp(Content content,BigInteger userId,BigInteger uuUserId){
+		Vote vote = getModel(Vote.class);
+		vote.setContentId(content.getId());
+		vote.setUserId(userId);
+		vote.setUuUserId(uuUserId);
+		vote.setUp(true);
+		vote.setDown(null);
+		vote.setIp(getIPAddress());
+		vote.setAgent(getUserAgent());
+		vote.setStatus(Vote.STATUS_NORMAL);
+		vote.setCreated(new Date());
+
+		if (vote.save()) {
+			//更新对应文章的点赞数
+			content.updateVoteUpCount("up");
+			renderAjaxResultForSuccess();
+		} else {
+			renderAjaxResultForError();
+		}
+
+	}
+
+	//取消赞
+	private void cancelVoteUp(Content content,Vote vote){
+		vote.setUp(null);
+		if (vote.update()) {
+			//更新对应评论的点赞数
+			content.updateVoteUpCount("down");
+			renderAjaxResultForSuccess();
+		} else {
+			renderAjaxResultForError();
+		}
+	}
+
+	//再次赞
+	private void againVoteUp(Content content,Vote vote){
+		vote.setUp(true);
+		if (vote.update()) {
+			//更新对应评论的点赞数
+			content.updateVoteUpCount("up");
+			renderAjaxResultForSuccess();
+		} else {
+			renderAjaxResultForError();
+		}
+	}
+
 }

+ 22 - 4
jpress-web-template-usoftchina/src/main/webapp/templates/usoftchina/content_uuhelper.html

@@ -258,7 +258,7 @@
             <div class="readCount">
                 <div>
                     <span>阅读 <em>${content.view_count!'0'}</em></span>
-                    <span><img src="/jpress/static/jpress/admin/image/hands.png" alt=""><em>${content.vote_up!'0'}</em></span>
+                    <span><img img class="voteContent <#if content.isvoted(content.id, userId!0, userid!0)>voted</#if>" src="/jpress/static/jpress/admin/image/hands.png" alt="" onclick="voteContent(${content.id})"><em class="voteContentCount">${content.vote_up!'0'}</em></span>
                     <!--<span><img src="/jpress/static/jpress/admin/image/support.png" alt=""/><em>1</em></span>-->
                 </div>
                 <p>${(content.getMetadataByKey("copy_right"))!}</p>
@@ -283,7 +283,7 @@
                 </form>
             </#if>
             <div class="footer-section">
-                <@jp.commentPage pageSize="1">
+                <@jp.commentPage pageSize="3">
                 <#if page ??>
                     <#list page.getList() as comment>
                         <div class="message">
@@ -325,7 +325,7 @@
     jQuery('html').css('fontSize',$(window).width()/640 * 30);
 //    jQuery(window).load(function () {
 //        jQuery("img").each(function () {
-//            DrawImage(this, 100, 50);
+//            DrawImage(this, 300, 300);
 //        });
 //    });
 //    function DrawImage(ImgD, FitWidth, FitHeight) {
@@ -396,7 +396,7 @@
         }
     });
 
-    //点赞
+    //点评论
     var vote = function(commentid) {
         var imgObj = $(".votedUas"+commentid);
         var emObj = $(".em"+commentid);
@@ -414,5 +414,23 @@
         });
     }
 
+    //点文章赞
+    var voteContent = function(contentId) {
+        var imgObj = $(".voteContent");
+        var emObj = $(".voteContentCount");
+        if (imgObj.hasClass("voted")) {
+            emObj.text(""+(parseInt(emObj.text())-1));
+            imgObj.removeClass("voted");
+            imgObj.attr("src","/jpress/static/jpress/admin/image/hands.png");
+        } else {
+            emObj.text(""+(parseInt(emObj.text())+1));
+            imgObj.addClass("voted");
+            imgObj.attr("src","/jpress/static/jpress/admin/image/support.png")
+        }
+        $.get("${CPATH}/c/vote?content_id="+contentId+"&user_id="+userId+"&uu_user_id="+uuUserId, function(result){
+            console.log(result.message);
+        });
+    }
+
 </script>
 </html>