评论优化
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.common
|
||||
* @Description:
|
||||
* @date 2020/8/17 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Node {
|
||||
|
||||
public Node() {
|
||||
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer discussionId;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private Date time;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String content;
|
||||
|
||||
private Integer parentId;
|
||||
|
||||
private Date editTime;
|
||||
|
||||
private Integer editUserId;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private String copyright;
|
||||
|
||||
private Integer isApproved;
|
||||
|
||||
private Integer createId;
|
||||
|
||||
private Date createTime;
|
||||
//下一条回复
|
||||
private List<Node> nextNodes = new ArrayList<Node>();
|
||||
|
||||
|
||||
/**
|
||||
* 将单个node添加到链表中
|
||||
*
|
||||
* @param list
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public static boolean addNode(List<Node> list, Node node) {
|
||||
for (Node node1 : list) { //循环添加
|
||||
if (node1.getId() .equals(node.getParentId()) ) { //判断留言的上一段是都是这条留言
|
||||
node1.getNextNodes().add(node); //是,添加,返回true;
|
||||
System.out.println("添加了一个");
|
||||
return true;
|
||||
} else { //否则递归继续判断
|
||||
if (node1.getNextNodes().size() != 0) {
|
||||
if (Node.addNode(node1.getNextNodes(), node)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将查出来的lastId不为null的回复都添加到第一层Node集合中
|
||||
*
|
||||
* @param firstList
|
||||
* @param thenList
|
||||
* @return
|
||||
*/
|
||||
public static List addAllNode(List<Node> firstList, List<Posts> thenList) {
|
||||
while (thenList.size() != 0) {
|
||||
int size = thenList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(thenList.get(i), node);
|
||||
if (Node.addNode(firstList, node)) {
|
||||
thenList.remove(i);
|
||||
i--;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return firstList;
|
||||
}
|
||||
|
||||
//打印
|
||||
public static void show(List<Node> list) {
|
||||
for (Node node : list) {
|
||||
System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent());
|
||||
if (node.getNextNodes().size() != 0) {
|
||||
Node.show(node.getNextNodes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -43,7 +43,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
|
||||
"/js/**",
|
||||
"/images/**",
|
||||
"/static/**",
|
||||
"/h2-console/**"
|
||||
"/h2-console/**",
|
||||
"/druid/**"
|
||||
);
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.yaoyuan.jiscuss.common.Node;
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.*;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import com.yaoyuan.jiscuss.service.IPostsService;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -26,8 +24,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Tags;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
|
||||
@@ -48,7 +44,11 @@ public class UserPostController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IPostsService postsService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private IUsersService usersService;
|
||||
|
||||
|
||||
//首页查看主题列表(各种条件筛选,最热最新标签等)
|
||||
|
||||
|
||||
@@ -58,34 +58,34 @@ public class UserPostController extends BaseController {
|
||||
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) {
|
||||
logger.info(">>> getDiscussionsById{}",id);
|
||||
|
||||
Discussions discussions = discussionsService.findOne(id);
|
||||
Discussion discussion = discussionsService.findOne(id);
|
||||
// 获取此主题下的评论
|
||||
List<Post> posts = postsService.findOneBy(id);
|
||||
|
||||
List<Posts> posts = postsService.findOneBy(id);
|
||||
|
||||
List<Tags> tags = tagsService.findByDId(id);
|
||||
|
||||
//查询id为1且parentId为null的评论
|
||||
List<Posts> firstList = postsService.findAllByDIdAndparentIdNull(1);
|
||||
//查询id为1且parentId不为null的评论
|
||||
List<Posts> thenList = postsService.findAllByDIdAndparentIdNotNull(1);
|
||||
//新建一个Node集合。
|
||||
ArrayList<Node> nodes = new ArrayList<>();
|
||||
//将第一层评论都添加都Node集合中
|
||||
for (Posts post : firstList) {
|
||||
Node node = new Node();
|
||||
BeanUtils.copyProperties(post, node);
|
||||
nodes.add(node);
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(discussion , newdd);
|
||||
if (null != newdd.getStartUserId()){
|
||||
User startUser = usersService.findOne(newdd.getStartUserId());
|
||||
newdd.setAvatar(startUser.getAvatar());
|
||||
newdd.setRealname(startUser.getRealname());
|
||||
newdd.setUsername(startUser.getUsername());
|
||||
}
|
||||
if (null != newdd.getLastUserId()){
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
newdd.setUsernameLast(lastUser.getUsername());
|
||||
}
|
||||
//将回复添加到对应的位置
|
||||
List list = Node.addAllNode(nodes, thenList);
|
||||
System.out.println();
|
||||
//打印回复链表
|
||||
Node.show(list);
|
||||
|
||||
|
||||
List<Tag> tags = tagsService.findByDId(id);
|
||||
|
||||
map.put("discussions", discussions);
|
||||
map.put("posts", posts);
|
||||
List<PostCustom> postsObj = postsService.findPostCustomById(id);
|
||||
|
||||
map.put("tags", tags);
|
||||
|
||||
map.put("discussions", newdd);
|
||||
map.put("posts", postsObj);
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
map.put("username", user.getUsername());
|
||||
@@ -93,26 +93,27 @@ public class UserPostController extends BaseController {
|
||||
return "discussions";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//新建主题
|
||||
@PostMapping(value = "/newdiscussions")
|
||||
@ResponseBody
|
||||
public String newDiscussions(@RequestBody Discussions discussions) {
|
||||
logger.info(">>> newPost"+discussions);
|
||||
public String newDiscussions(@RequestBody Discussion discussion) {
|
||||
logger.info(">>> newPost"+ discussion);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
discussions.setLastUserId( user.getId());
|
||||
discussions.setCreateId( user.getId());
|
||||
discussion.setLastUserId( user.getId());
|
||||
discussion.setCreateId( user.getId());
|
||||
}
|
||||
discussions.setCreateTime(new Date());
|
||||
discussion.setCreateTime(new Date());
|
||||
|
||||
Discussions saveDiscussions = discussionsService.insert(discussions);
|
||||
Discussion saveDiscussion = discussionsService.insert(discussion);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
logger.info(">>>{}",saveDiscussions );
|
||||
logger.info(">>>{}", saveDiscussion);
|
||||
resultobj.put("msg", "添加成功");
|
||||
resultobj.put("flag", true);
|
||||
return resultobj.toString(); //
|
||||
@@ -127,19 +128,24 @@ public class UserPostController extends BaseController {
|
||||
//新建评论
|
||||
@PostMapping(value = "/newpost")
|
||||
@ResponseBody
|
||||
public String newPosts(@RequestBody Posts posts) {
|
||||
logger.info(">>> newpost"+posts);
|
||||
public String newPosts(@RequestBody Post post) {
|
||||
logger.info(">>> newpost"+ post);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
posts.setCreateId( user.getId());
|
||||
post.setCreateId( user.getId());
|
||||
}
|
||||
posts.setCreateTime(new Date());
|
||||
post.setCreateTime(new Date());
|
||||
if(null != post.getParentId()){
|
||||
Post temp =postsService.findOneByid(post.getParentId());
|
||||
post.setUserId(temp.getCreateId());
|
||||
|
||||
Posts savePost = postsService.insert(posts);
|
||||
}
|
||||
|
||||
Post savePost = postsService.insert(post);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
logger.info(">>>{}",savePost );
|
||||
@@ -153,22 +159,22 @@ public class UserPostController extends BaseController {
|
||||
//新建标签
|
||||
@PostMapping(value = "/newtags")
|
||||
@ResponseBody
|
||||
public String newTags(@RequestBody Tags tags) {
|
||||
logger.info(">>> newTags"+tags);
|
||||
public String newTags(@RequestBody Tag tag) {
|
||||
logger.info(">>> newTags"+ tag);
|
||||
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
|
||||
UserInfo user = getUserInfo(request);
|
||||
if(user != null){
|
||||
tags.setCreateId( user.getId());
|
||||
tag.setCreateId( user.getId());
|
||||
}
|
||||
tags.setCreateTime(new Date());
|
||||
tag.setCreateTime(new Date());
|
||||
|
||||
Tags saveTags = tagsService.insert(tags);
|
||||
Tag saveTag = tagsService.insert(tag);
|
||||
JSONObject resultobj = new JSONObject();
|
||||
|
||||
logger.info(">>>{}",saveTags );
|
||||
logger.info(">>>{}", saveTag);
|
||||
resultobj.put("msg", "添加成功");
|
||||
resultobj.put("flag", true);
|
||||
return resultobj.toString(); //
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.yaoyuan.jiscuss.controller;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Tags;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import com.yaoyuan.jiscuss.util.DelTagsUtil;
|
||||
import org.apache.catalina.mbeans.MBeanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -48,23 +48,23 @@ public class UserSystemController extends BaseController {
|
||||
logger.info(">>> index");
|
||||
logger.info(">>> tag:" + tag);
|
||||
logger.info(">>> pageNum:" + pageNum);
|
||||
List<Users> userall = usersService.getAllList();
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info(">>> 第一遍的全部用户:"+userall);
|
||||
|
||||
List<Users> useral2 = usersService.getAllList();
|
||||
List<User> useral2 = usersService.getAllList();
|
||||
logger.info(">>> 第二遍的全部用户:"+useral2);
|
||||
|
||||
int pageSiz = 10;
|
||||
int pageNumNew = pageNum - 1;
|
||||
Discussions discussions = new Discussions();
|
||||
Discussion discussion = new Discussion();
|
||||
//分页获取主题帖子
|
||||
Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussions,pageNumNew,pageSiz);
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion,pageNumNew,pageSiz);
|
||||
|
||||
List<Discussions> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<Discussions> newAllD = new ArrayList<>();
|
||||
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<DiscussionCustom> newAllD = new ArrayList<>();
|
||||
|
||||
for (Discussions dd : allDiscussions){
|
||||
Discussions newdd = new Discussions();
|
||||
for (Discussion dd : allDiscussions){
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(dd , newdd);
|
||||
String newCon = "";
|
||||
String content = DelTagsUtil.getTextFromHtml(newdd.getContent());
|
||||
@@ -74,6 +74,19 @@ public class UserSystemController extends BaseController {
|
||||
newCon = content;
|
||||
}
|
||||
newdd.setContent(newCon);
|
||||
if (null != newdd.getStartUserId()){
|
||||
User startUser = usersService.findOne(newdd.getStartUserId());
|
||||
newdd.setAvatar(startUser.getAvatar());
|
||||
newdd.setRealname(startUser.getRealname());
|
||||
newdd.setUsername(startUser.getUsername());
|
||||
}
|
||||
if (null != newdd.getLastUserId()){
|
||||
User lastUser = usersService.findOne(newdd.getLastUserId());
|
||||
newdd.setAvatarLast(lastUser.getAvatar());
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
newdd.setUsernameLast(lastUser.getUsername());
|
||||
}
|
||||
|
||||
newAllD.add(newdd);
|
||||
}
|
||||
|
||||
@@ -85,7 +98,7 @@ public class UserSystemController extends BaseController {
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tags> allTags = tagsService.getAllList();
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}",allTags);
|
||||
|
||||
System.out.println(userall.toString());
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.exception.BaseException;
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
@@ -31,10 +31,10 @@ public class RestPostController {
|
||||
|
||||
@PostMapping("/discussion")
|
||||
@ApiOperation("新增主题")
|
||||
public Discussions save(@RequestBody Discussions discussions) {
|
||||
Discussions saveDiscussions = discussionsService.insert(discussions);
|
||||
if (saveDiscussions!=null) {
|
||||
return saveDiscussions;
|
||||
public Discussion save(@RequestBody Discussion discussion) {
|
||||
Discussion saveDiscussion = discussionsService.insert(discussion);
|
||||
if (saveDiscussion !=null) {
|
||||
return saveDiscussion;
|
||||
} else {
|
||||
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
|
||||
}
|
||||
@@ -43,15 +43,15 @@ public class RestPostController {
|
||||
|
||||
@GetMapping("/discussion/{id}")
|
||||
@ApiOperation("获取主题")
|
||||
public Discussions getDiscussions(@PathVariable Integer id) {
|
||||
Discussions discussions = discussionsService.findOne(id);
|
||||
return discussions;
|
||||
public Discussion getDiscussions(@PathVariable Integer id) {
|
||||
Discussion discussion = discussionsService.findOne(id);
|
||||
return discussion;
|
||||
}
|
||||
|
||||
@GetMapping("/discussions")
|
||||
@ApiOperation("获取全部主题")
|
||||
public List<Discussions> getAllDiscussions() {
|
||||
List<Discussions> allDiscussions = discussionsService.getAllList();
|
||||
public List<Discussion> getAllDiscussions() {
|
||||
List<Discussion> allDiscussions = discussionsService.getAllList();
|
||||
logger.info("全部主题==>:{}",allDiscussions);
|
||||
return allDiscussions;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.exception.BaseException;
|
||||
import com.yaoyuan.jiscuss.response.ResponseCode;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
@@ -34,8 +34,8 @@ public class RestUserController {
|
||||
|
||||
@PostMapping("/user")
|
||||
@ApiOperation("新增用户")
|
||||
public Users save(@RequestBody Users user) {
|
||||
Users saveUser = usersService.insert(user);
|
||||
public User save(@RequestBody User user) {
|
||||
User saveUser = usersService.insert(user);
|
||||
if (saveUser!=null) {
|
||||
return saveUser;
|
||||
} else {
|
||||
@@ -58,8 +58,8 @@ public class RestUserController {
|
||||
|
||||
@PutMapping("/user/{id}")
|
||||
@ApiOperation("修改用户")
|
||||
public Users update(@RequestBody Users user, @PathVariable Integer id) {
|
||||
Users updateuser = usersService.update(user, id);
|
||||
public User update(@RequestBody User user, @PathVariable Integer id) {
|
||||
User updateuser = usersService.update(user, id);
|
||||
if (updateuser!=null) {
|
||||
return updateuser;
|
||||
} else {
|
||||
@@ -69,15 +69,15 @@ public class RestUserController {
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("获取用户")
|
||||
public Users getUser(@PathVariable Integer id) {
|
||||
Users user = usersService.findOne(id);
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
User user = usersService.findOne(id);
|
||||
return user;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("获取全部用户")
|
||||
public List<Users> getUser(Users user) {
|
||||
List<Users> userall = usersService.getAllList();
|
||||
public List<User> getUser(User user) {
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info("全部用户==>:{}",userall);
|
||||
return userall;
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ import javax.persistence.Table;
|
||||
import lombok.Data;
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussions")
|
||||
public class Discussions implements Serializable {
|
||||
@Table(name="discussion")
|
||||
public class Discussion implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
+2
-2
@@ -10,8 +10,8 @@ import javax.persistence.Table;
|
||||
import lombok.Data;
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="discussionstags")
|
||||
public class DiscussionsTags implements Serializable{
|
||||
@Table(name="discussiontag")
|
||||
public class DiscussionTag implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
+2
-2
@@ -14,8 +14,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="posts")
|
||||
public class Posts implements Serializable{
|
||||
@Table(name="post")
|
||||
public class Post implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
+2
-2
@@ -11,8 +11,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="settings")
|
||||
public class Settings implements Serializable{
|
||||
@Table(name="setting")
|
||||
public class Setting implements Serializable{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
+2
-2
@@ -14,8 +14,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="tags")
|
||||
public class Tags implements Serializable{
|
||||
@Table(name="tag")
|
||||
public class Tag implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
+5
-2
@@ -23,8 +23,8 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="users")
|
||||
public class Users implements Serializable {
|
||||
@Table(name="user")
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@@ -51,6 +51,9 @@ public class Users implements Serializable {
|
||||
|
||||
@Column(name="gender")
|
||||
private String gender;
|
||||
|
||||
@Column(name="avatar")
|
||||
private String avatar;
|
||||
|
||||
@Column(name="phone")
|
||||
private String phone;
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsRepository extends JpaRepository<Discussions,Integer> {
|
||||
public interface DiscussionsRepository extends JpaRepository<Discussion,Integer> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionsTags;
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface DiscussionsTagsRepository extends JpaRepository<DiscussionsTags,Integer> {
|
||||
public interface DiscussionsTagsRepository extends JpaRepository<DiscussionTag,Integer> {
|
||||
}
|
||||
|
||||
@@ -1,28 +1,38 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public interface PostsRepository extends JpaRepository<Posts,Integer> {
|
||||
public interface PostsRepository extends JpaRepository<Post,Integer> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dId
|
||||
* @return
|
||||
*/
|
||||
@Query("from Posts where discussionId = :dId")
|
||||
List<Posts> findOneBy(@Param("dId")Integer dId);
|
||||
@Query("from Post where discussionId = :dId")
|
||||
List<Post> findOneBy(@Param("dId")Integer dId);
|
||||
|
||||
@Query("from Posts where parentId is null and discussionId = :dId")
|
||||
List<Posts> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
@Query(value = "select p.*,u.avatar as user_avatar ,u.username as user_username ,u.realname as user_realname ," +
|
||||
"u2.avatar as create_avatar ,u2.username as create_username ,u2.realname as create_realname \n" +
|
||||
"from Post p \n" +
|
||||
"left join User u on p.user_id = u.id \n" +
|
||||
"left join User u2 on p.create_id = u2.id \n" +
|
||||
"where p.discussion_id = :dId order by p.create_time desc"
|
||||
, nativeQuery = true)
|
||||
List<Map<String, Object>> findPostCustomById(@Param("dId")Integer dId);
|
||||
|
||||
@Query("from Posts where parentId is not null and discussionId = :dId")
|
||||
List<Posts> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
@Query("from Post where parentId is null and discussionId = :dId")
|
||||
List<Post> findAllByDIdAndparentIdNull(@Param("dId")Integer dId);
|
||||
|
||||
@Query("from Post where parentId is not null and discussionId = :dId")
|
||||
List<Post> findAllByDIdAndparentIdNotNull(@Param("dId")Integer dId);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Settings;
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface SettingsRepository extends JpaRepository<Settings,Integer> {
|
||||
public interface SettingsRepository extends JpaRepository<Setting,Integer> {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.yaoyuan.jiscuss.repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.Tags;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -10,8 +9,8 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TagsRepository extends JpaRepository<Tags,Integer> {
|
||||
public interface TagsRepository extends JpaRepository<Tag,Integer> {
|
||||
|
||||
@Query(value = "FROM Tags a, DiscussionsTags b WHERE a.id = b.tagId and b.discussionId = :dId")
|
||||
List<Tags> findByDId(@Param("dId")Integer dId);
|
||||
@Query(value = "FROM Tag a, DiscussionTag b WHERE a.id = b.tagId and b.discussionId = :dId")
|
||||
List<Tag> findByDId(@Param("dId")Integer dId);
|
||||
}
|
||||
|
||||
@@ -7,33 +7,33 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface UsersRepository extends JpaRepository<Users,Integer> {
|
||||
public interface UsersRepository extends JpaRepository<User,Integer> {
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from Users where username like %:username%")
|
||||
List<Users> getByUsernameIsLike(@Param("username")String username);
|
||||
@Query("from User where username like %:username%")
|
||||
List<User> getByUsernameIsLike(@Param("username")String username);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Users getById(Integer id);
|
||||
User getById(Integer id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Query("from Users where username = :username")
|
||||
Users getByUsername(String username);
|
||||
@Query("from User where username = :username")
|
||||
User getByUsername(String username);
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -41,7 +41,7 @@ public interface UsersRepository extends JpaRepository<Users,Integer> {
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@Query("from Users where username = :username and password = :password")
|
||||
Users checkByUsernameAndPassword(String username, String password);
|
||||
@Query("from User where username = :username and password = :password")
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
|
||||
public interface IDiscussionsService {
|
||||
|
||||
List<Discussions> getAllList();
|
||||
List<Discussion> getAllList();
|
||||
|
||||
Discussions insert(Discussions discussions);
|
||||
Discussion insert(Discussion discussion);
|
||||
|
||||
Discussions findOne(Integer id);
|
||||
Discussion findOne(Integer id);
|
||||
|
||||
Page<Discussions> queryAllDiscussionsList(Discussions discussions,int pageNum,int pageSize);
|
||||
Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionsTags;
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
|
||||
public interface IDiscussionsTagsService {
|
||||
|
||||
List<DiscussionsTags> getAllList();
|
||||
List<DiscussionTag> getAllList();
|
||||
|
||||
DiscussionsTags insert(DiscussionsTags discussionsTags);
|
||||
DiscussionTag insert(DiscussionTag discussionTag);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
|
||||
public interface IPostsService {
|
||||
List<Posts> getAllList();
|
||||
List<Post> getAllList();
|
||||
|
||||
Posts insert(Posts posts);
|
||||
Post insert(Post post);
|
||||
|
||||
List<Posts> findOneBy(Integer id);
|
||||
List<Post> findOneBy(Integer id);
|
||||
|
||||
List<Posts> findAllByDIdAndparentIdNull(Integer dId);
|
||||
List<Post> findAllByDIdAndparentIdNull(Integer dId);
|
||||
|
||||
List<Posts> findAllByDIdAndparentIdNotNull(Integer dId);
|
||||
List<Post> findAllByDIdAndparentIdNotNull(Integer dId);
|
||||
|
||||
List<PostCustom> findPostCustomById(Integer id);
|
||||
|
||||
Post findOneByid(Integer parentId);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Settings;
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
|
||||
public interface ISettingsService {
|
||||
|
||||
List<Settings> getAllList();
|
||||
List<Setting> getAllList();
|
||||
|
||||
Settings insert(Settings settings);
|
||||
Setting insert(Setting setting);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.yaoyuan.jiscuss.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Tags;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
|
||||
public interface ITagsService {
|
||||
|
||||
List<Tags> getAllList();
|
||||
List<Tag> getAllList();
|
||||
|
||||
Tags insert(Tags tags);
|
||||
Tag insert(Tag tag);
|
||||
|
||||
List<Tags> findByDId(Integer id);
|
||||
List<Tag> findByDId(Integer id);
|
||||
}
|
||||
|
||||
@@ -4,29 +4,29 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
|
||||
public interface IUsersService {
|
||||
|
||||
List<Users> getAllList();
|
||||
List<User> getAllList();
|
||||
|
||||
Page<Users> queryAllUsersList(int pageNum,int pageSize);
|
||||
Page<User> queryAllUsersList(int pageNum, int pageSize);
|
||||
|
||||
List<Users> getByUsernameIsLike(String name);
|
||||
List<User> getByUsernameIsLike(String name);
|
||||
|
||||
// @Cacheable("myCache")
|
||||
Users findOne(Integer id);
|
||||
User findOne(Integer id);
|
||||
|
||||
Users insert(Users user);
|
||||
User insert(User user);
|
||||
|
||||
void remove(Integer id);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
Users getByUsername(String username);
|
||||
User getByUsername(String username);
|
||||
|
||||
Users checkByUsernameAndPassword(String username, String password);
|
||||
User checkByUsernameAndPassword(String username, String password);
|
||||
|
||||
Users update(Users user, Integer id);
|
||||
User update(User user, Integer id);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Discussions;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.repository.DiscussionsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
|
||||
@@ -19,30 +19,30 @@ public class DiscussionsServiceImpl implements IDiscussionsService {
|
||||
private DiscussionsRepository discussionsRepository;
|
||||
|
||||
@Override
|
||||
public List<Discussions> getAllList() {
|
||||
public List<Discussion> getAllList() {
|
||||
return discussionsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Discussions insert(Discussions discussions) {
|
||||
public Discussion insert(Discussion discussion) {
|
||||
|
||||
return discussionsRepository.save(discussions);
|
||||
return discussionsRepository.save(discussion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Discussions findOne(Integer id) {
|
||||
Discussions discussions = new Discussions();
|
||||
discussions.setId(id);
|
||||
public Discussion findOne(Integer id) {
|
||||
Discussion discussion = new Discussion();
|
||||
discussion.setId(id);
|
||||
return discussionsRepository.getOne(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Discussions> queryAllDiscussionsList(Discussions discussions,int pageNum, int pageSize) {
|
||||
public Page<Discussion> queryAllDiscussionsList(Discussion discussion, int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
//将匹配对象封装成Example对象
|
||||
Example<Discussions> example = Example.of(discussions);
|
||||
Example<Discussion> example = Example.of(discussion);
|
||||
|
||||
return discussionsRepository.findAll(example,pageable);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import javax.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionsTags;
|
||||
import com.yaoyuan.jiscuss.entity.DiscussionTag;
|
||||
import com.yaoyuan.jiscuss.repository.DiscussionsTagsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsTagsService;
|
||||
|
||||
@@ -18,13 +18,13 @@ public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
|
||||
private DiscussionsTagsRepository discussionsTagsRepository;
|
||||
|
||||
@Override
|
||||
public List<DiscussionsTags> getAllList() {
|
||||
public List<DiscussionTag> getAllList() {
|
||||
return discussionsTagsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscussionsTags insert(DiscussionsTags discussionsTags) {
|
||||
return discussionsTagsRepository.save(discussionsTags);
|
||||
public DiscussionTag insert(DiscussionTag discussionTag) {
|
||||
return discussionsTagsRepository.save(discussionTag);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
import com.yaoyuan.jiscuss.common.PostCommonUtil;
|
||||
import com.yaoyuan.jiscuss.entity.Discussion;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Posts;
|
||||
import com.yaoyuan.jiscuss.entity.Post;
|
||||
import com.yaoyuan.jiscuss.repository.PostsRepository;
|
||||
import com.yaoyuan.jiscuss.service.IPostsService;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
@@ -20,32 +28,86 @@ public class PostsServiceImpl implements IPostsService {
|
||||
private PostsRepository postsRepository;
|
||||
|
||||
@Override
|
||||
public List<Posts> getAllList() {
|
||||
public List<Post> getAllList() {
|
||||
return postsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Posts> findOneBy(Integer id) {
|
||||
public List<Post> findOneBy(Integer id) {
|
||||
|
||||
List<Posts> posts = postsRepository.findOneBy(id);
|
||||
List<Post> posts = postsRepository.findOneBy(id);
|
||||
return posts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Posts> findAllByDIdAndparentIdNull(Integer dId) {
|
||||
List<Posts> posts = postsRepository.findAllByDIdAndparentIdNull(dId);
|
||||
public Post findOneByid(Integer id) {
|
||||
Post post =new Post();
|
||||
post.setId(id);
|
||||
Example<Post> example = Example.of(post);
|
||||
Optional<Post> postRes = postsRepository.findOne(example);
|
||||
return postRes.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostCustom> findPostCustomById(Integer id) {
|
||||
|
||||
List<Map<String, Object>> posts = postsRepository.findPostCustomById(id);
|
||||
// List<Map<String, Object>> postsObjNew = this.getNewPostsObj(posts);
|
||||
|
||||
List<PostCustom> postCustomList = new ArrayList<>();
|
||||
for(Map<String, Object> mapObj : posts){
|
||||
PostCustom postCustom = new PostCustom();
|
||||
postCustom.setId(Integer.parseInt(String.valueOf(mapObj.get("id"))));
|
||||
postCustom.setParentId(mapObj.get("parent_id") != null ? Integer.parseInt(String.valueOf(mapObj.get("parent_id"))) : null);
|
||||
if(null != mapObj.get("create_time")){
|
||||
postCustom.setCreateTime((Date) mapObj.get("create_time"));
|
||||
}
|
||||
String content = "";
|
||||
if(mapObj.get("content") != null){
|
||||
Clob clob = (Clob) mapObj.get("content");
|
||||
content = PostCommonUtil.clobToString(clob);
|
||||
}
|
||||
postCustom.setContent(content);
|
||||
String avatar = "";
|
||||
if(mapObj.get("create_avatar") != null){
|
||||
Clob clob = (Clob) mapObj.get("create_avatar");
|
||||
avatar = PostCommonUtil.clobToString(clob);
|
||||
}
|
||||
postCustom.setAvatar(avatar);
|
||||
postCustom.setUsername(mapObj.get("create_username") != null ? String.valueOf(mapObj.get("create_username")): null);
|
||||
postCustom.setRealname(mapObj.get("create_realname") != null ? String.valueOf(mapObj.get("create_realname")): null);
|
||||
String avatarReply = "";
|
||||
if(mapObj.get("user_avatar") != null){
|
||||
Clob clob = (Clob) mapObj.get("user_avatar");
|
||||
avatarReply = PostCommonUtil.clobToString(clob);
|
||||
}
|
||||
postCustom.setAvatarReply(avatarReply);
|
||||
postCustom.setUsernameReply(mapObj.get("user_username") != null ? String.valueOf(mapObj.get("user_username")): null);
|
||||
postCustom.setRealnameReply(mapObj.get("user_realname") != null ? String.valueOf(mapObj.get("user_realname")): null);
|
||||
|
||||
postCustomList.add(postCustom);
|
||||
}
|
||||
|
||||
List<PostCustom> postCustomListNew = PostCommonUtil.getNewPostsObjCustom(postCustomList);
|
||||
|
||||
return postCustomListNew;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Post> findAllByDIdAndparentIdNull(Integer dId) {
|
||||
List<Post> posts = postsRepository.findAllByDIdAndparentIdNull(dId);
|
||||
return posts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Posts> findAllByDIdAndparentIdNotNull(Integer dId) {
|
||||
List<Posts> posts = postsRepository.findAllByDIdAndparentIdNotNull(dId);
|
||||
public List<Post> findAllByDIdAndparentIdNotNull(Integer dId) {
|
||||
List<Post> posts = postsRepository.findAllByDIdAndparentIdNotNull(dId);
|
||||
return posts;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Posts insert(Posts posts) {
|
||||
return postsRepository.save(posts);
|
||||
public Post insert(Post post) {
|
||||
return postsRepository.save(post);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import javax.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Settings;
|
||||
import com.yaoyuan.jiscuss.entity.Setting;
|
||||
import com.yaoyuan.jiscuss.repository.SettingsRepository;
|
||||
import com.yaoyuan.jiscuss.service.ISettingsService;
|
||||
|
||||
@@ -18,12 +18,12 @@ public class SettingsServiceImpl implements ISettingsService {
|
||||
private SettingsRepository settingsRepository;
|
||||
|
||||
@Override
|
||||
public List<Settings> getAllList() {
|
||||
public List<Setting> getAllList() {
|
||||
return settingsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings insert(Settings settings) {
|
||||
return settingsRepository.save(settings);
|
||||
public Setting insert(Setting setting) {
|
||||
return settingsRepository.save(setting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ import java.util.List;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Tags;
|
||||
import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import com.yaoyuan.jiscuss.repository.TagsRepository;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
|
||||
@@ -19,17 +18,17 @@ public class TagsServiceImpl implements ITagsService {
|
||||
private TagsRepository tagsRepository;
|
||||
|
||||
@Override
|
||||
public List<Tags> getAllList() {
|
||||
public List<Tag> getAllList() {
|
||||
return tagsRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tags insert(Tags tags) {
|
||||
return tagsRepository.save(tags);
|
||||
public Tag insert(Tag tag) {
|
||||
return tagsRepository.save(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tags> findByDId(Integer id) {
|
||||
public List<Tag> findByDId(Integer id) {
|
||||
return tagsRepository.findByDId(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.yaoyuan.jiscuss.service.impl;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
@@ -37,7 +35,7 @@ public class UserDetailServiceImpl implements UserDetailsService {
|
||||
@Override
|
||||
public UserInfo loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// 通过用户名从数据库获取用户信息
|
||||
Users userInfo = userInfoService.getByUsername(username);
|
||||
User userInfo = userInfoService.getByUsername(username);
|
||||
if (userInfo == null) {
|
||||
throw new UsernameNotFoundException("用户不存在");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.Users;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.repository.UsersRepository;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
*/
|
||||
@Cacheable(value = "user")
|
||||
@Override
|
||||
public List<Users> getAllList() {
|
||||
public List<User> getAllList() {
|
||||
return usersRepository.findAll();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<Users> queryAllUsersList(int pageNum,int pageSize) {
|
||||
public Page<User> queryAllUsersList(int pageNum, int pageSize) {
|
||||
Sort sort=new Sort(Sort.Direction.DESC,"id");
|
||||
@SuppressWarnings("deprecation")
|
||||
Pageable pageable=new PageRequest(pageNum,pageSize,sort);
|
||||
@@ -57,7 +57,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Users> getByUsernameIsLike(String name) {
|
||||
public List<User> getByUsernameIsLike(String name) {
|
||||
return usersRepository.getByUsernameIsLike(name);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
*/
|
||||
@Cacheable(value = "user", key = "#id")
|
||||
@Override
|
||||
public Users findOne(Integer id) {
|
||||
public User findOne(Integer id) {
|
||||
return usersRepository.getById(id);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
*/
|
||||
@CachePut(value = "user", key = "#user.id")
|
||||
@Override
|
||||
public Users insert(Users user) {
|
||||
public User insert(User user) {
|
||||
return usersRepository.save(user);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
*/
|
||||
@CachePut(value = "user", key = "#user.id")
|
||||
@Override
|
||||
public Users update(Users user, Integer id) {
|
||||
public User update(User user, Integer id) {
|
||||
return usersRepository.saveAndFlush(user);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Users getByUsername(String username) {
|
||||
public User getByUsername(String username) {
|
||||
return usersRepository.getByUsername(username);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class UsersServiceImpl implements IUsersService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Users checkByUsernameAndPassword(String username,String password) {
|
||||
public User checkByUsernameAndPassword(String username, String password) {
|
||||
return usersRepository.checkByUsernameAndPassword(username,password);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user