Skip to content

Commit

Permalink
dev-0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Forge-nb committed Jul 16, 2019
1 parent a64c990 commit ddc4e30
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 127 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public String Send(HttpServletRequest request) {
try {
email.addTo(userEmail);
email.setFrom("[email protected]", "聚集地论坛");
email.setAuthentication("[email protected]", "nlqqmczegpalbagd");
email.setAuthentication("[email protected]", "rkjhrvjftpizigbg");
email.setSubject("邮箱验证");//设置发送主题
String code = RandomCode();
email.setMsg("您正在注册聚集地论坛,您的验证码为: " + code + ",有效时间三分钟。 如非本人操作,请忽略本邮件。");//设置发送内容
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/com/chinasoft/forum/controller/PostController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.chinasoft.forum.controller;

import com.alibaba.fastjson.JSON;
import com.chinasoft.forum.dal.entity.Comment;
import com.chinasoft.forum.dal.entity.Post;
import com.chinasoft.forum.dal.entity.User;
import com.chinasoft.forum.service.CommentService;
import com.chinasoft.forum.service.PostService;
import com.chinasoft.forum.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
public class PostController {

@Autowired
private CommentService commentService;

@Autowired
private UserService userService;

@Autowired
private PostService postService;

@RequestMapping("postDetail")
public String toPostDetail(ModelMap modelMap){
Integer postId=1;
Post postDetail=postService.getDetail(postId);
modelMap.put("postDetail",postDetail);
List<Comment> parentComments=commentService.findAllParentComment(postId);
User user;
for(int i=0;i<parentComments.size();i++){
user = userService.userCoookie(parentComments.get(i).getUserEmail());
parentComments.get(i).setUserNickName(user.getNickName());
}
if(parentComments.size()!=0) {
modelMap.put("parentComments", parentComments);
modelMap.put("parentCommentsNumber", parentComments.size());
}
return "postDetail";
}

@RequestMapping(value = "writeComment",method = RequestMethod.POST)
@ResponseBody
public boolean writeComment(HttpServletRequest request){
User user=(User)request.getSession().getAttribute("User");
String userEmail=user.getUserEmail();
String nickName=user.getNickName();
String content=request.getParameter("commentContent");
Comment comment=new Comment();
comment.setUserEmail(userEmail);
comment.setCommentTime(new Date());
comment.setContent(content);
comment.setPostId(1);
comment.setUserNickName(nickName);
commentService.insert(comment);
return true;
}
@RequestMapping("commentDetail")
public String commentDetail(ModelMap modelMap){
Integer parentId=1;
Integer postId=1;
List<Comment> childrenComments=commentService.findAllChildComment(parentId,postId);
User user;
for(int i=0;i<childrenComments.size();i++){
user = userService.userCoookie(childrenComments.get(i).getUserEmail());
childrenComments.get(i).setUserNickName(user.getNickName());
user=userService.userCoookie(childrenComments.get(i).getRespondentUserEmail());
childrenComments.get(i).setRespondentUserNickName(user.getNickName());
}
if(childrenComments.size()!=0) {
modelMap.put("childrenComments", childrenComments);
modelMap.put("childrenCommentsNumber", childrenComments.size());
}
return "postDetail";
}

@ResponseBody
@RequestMapping(value = "writeAction", method = RequestMethod.POST)
public String write(HttpServletRequest request){
try {
Integer section_name = Integer.parseInt(request.getParameter("section_name")); //板块
String title = request.getParameter("title"); //标题
String content = request.getParameter("content"); //内容
Boolean commentable = Boolean.parseBoolean(request.getParameter("commentable")); //是否可评论
String summary = content.replaceAll("<([^>]*)>", ""); //摘要需要先把内容正则化,然后再次判断其长度; //取摘要
if(summary.length()>=20)
summary=summary.substring(0,20);
User user= (User)request.getSession().getAttribute("User");
String author_email=user.getUserEmail();
postService.writeContent(author_email, section_name, title, summary, content, commentable, "正常", new Date());
return JSON.toJSONString("发表成功!");
} catch (NumberFormatException e) {
e.printStackTrace();
return JSON.toJSONString("发表失败!");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface CommentRepository extends JpaRepository<Comment,Integer> {

@Query(value = "select * from gpf_dev.comment where post_id=?1 order by comment_time",nativeQuery = true)
@Query(value = "select * from gpf_dev.comment where post_id=?1 and parent_comment_id is null order by comment_time",nativeQuery = true)
List<Comment> findAllParentComment(Integer postId);

List<Comment> findByParentCommentIdAndPostIdOrderByCommentTime(Integer parentCommentId,Integer postId);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/chinasoft/forum/dal/PostRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.chinasoft.forum.dal;

import com.chinasoft.forum.dal.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PostRepository extends JpaRepository<Post,String> {

List<Post> findBySectionNameOrderByLastEditTimeDesc(String sectionName);

List<Post> findBySectionNameOrderByStarNumberDesc(String sectionName);

Post findByPostId(Integer id);
}
22 changes: 22 additions & 0 deletions src/main/java/com/chinasoft/forum/dal/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class Post {

private String summary;

private Integer starNumber;

private Integer browseNumber;

private boolean commentable;

@Column(length = 10000)
Expand Down Expand Up @@ -124,6 +128,22 @@ public void setPostStatus(String postStatus) {
this.postStatus = postStatus;
}

public Integer getStarNumber() {
return starNumber;
}

public void setStarNumber(Integer starNumber) {
this.starNumber = starNumber;
}

public Integer getBrowseNumber() {
return browseNumber;
}

public void setBrowseNumber(Integer browseNumber) {
this.browseNumber = browseNumber;
}

@Override
public String toString() {
return "Post{" +
Expand All @@ -135,6 +155,8 @@ public String toString() {
", postStatus='" + postStatus + '\'' +
", title='" + title + '\'' +
", summary='" + summary + '\'' +
", starNumber=" + starNumber +
", browseNumber=" + browseNumber +
", commentable=" + commentable +
", firstImg='" + firstImg + '\'' +
'}';
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/chinasoft/forum/service/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface CommentService {
List<Comment> findAllParentComment(Integer postId);

List<Comment> findAllChildComment(Integer parentCommentId,Integer postId);

void insert(Comment comment);
}
16 changes: 16 additions & 0 deletions src/main/java/com/chinasoft/forum/service/PostService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.chinasoft.forum.service;

import com.chinasoft.forum.dal.entity.Post;

import java.util.Date;
import java.util.List;

public interface PostService {
void writeContent(String author_email, Integer section_name, String title, String summary, String content, boolean commentable, String post_status, Date lastEditTime);

List<Post> getByEdiTime(String sectionName);

List<Post> getByStarNumber(String sectionName);

Post getDetail(Integer postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.chinasoft.forum.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CommentServiceImpl implements CommentService {

@Autowired
Expand All @@ -23,4 +25,9 @@ public List<Comment> findAllParentComment(Integer postId) {
public List<Comment> findAllChildComment(Integer parentCommentId, Integer postId) {
return commentRepository.findByParentCommentIdAndPostIdOrderByCommentTime(parentCommentId,postId);
}

@Override
public void insert(Comment comment) {
commentRepository.save(comment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.chinasoft.forum.service.impl;

import com.chinasoft.forum.dal.PostRepository;
import com.chinasoft.forum.dal.entity.Post;
import com.chinasoft.forum.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {
@Autowired
private PostRepository postRepository;

public List<Post> getByEdiTime(String sectionName){
List<Post> postList=postRepository.findBySectionNameOrderByLastEditTimeDesc(sectionName);
return postList;
}

@Override
public List<Post> getByStarNumber(String sectionName) {
List<Post> postList=postRepository.findBySectionNameOrderByStarNumberDesc(sectionName);
return postList;
}

@Override
public Post getDetail(Integer postId) {
return postRepository.findByPostId(postId);
}

@Override
public void writeContent(String author_email, Integer section_name, String title, String summary, String content, boolean commentable, String post_status, Date lastEditTime) {
Post post=new Post();
post.setAuthorEmail(author_email);
post.setSectionName(section_name);
post.setTitle(title);
post.setSummary(summary);
post.setContent(content);
post.setFirstImg(content);
post.setCommentable(commentable);
post.setPostStatus(post_status);
post.setLastEditTime(lastEditTime);
postRepository.save(post);
}
}
Loading

0 comments on commit ddc4e30

Please sign in to comment.