清空
This commit is contained in:
@@ -1,131 +0,0 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
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 String avatar;
|
||||
|
||||
private String username;
|
||||
|
||||
private String realname;
|
||||
|
||||
private String avatarReply;
|
||||
|
||||
private String usernameReply;
|
||||
|
||||
private String realnameReply;
|
||||
|
||||
//下一条回复
|
||||
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<PostCustom> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package com.yaoyuan.jiscuss.common;
|
||||
|
||||
import com.yaoyuan.jiscuss.entity.custom.PostCustom;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yaoyuan2.chu
|
||||
* @Title:
|
||||
* @Package com.yaoyuan.jiscuss.common
|
||||
* @Description:
|
||||
* @date 2020/9/10 15:47
|
||||
*/
|
||||
public class PostCommonUtil {
|
||||
|
||||
|
||||
public static List<PostCustom> getNewPostsObjMap(List<Map<String, Object>> 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) {
|
||||
if (mapObj.get("content") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("content");
|
||||
content = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("content") instanceof String) {
|
||||
content = String.valueOf(mapObj.get("content"));
|
||||
}
|
||||
}
|
||||
postCustom.setContent(content);
|
||||
String avatar = "";
|
||||
if (mapObj.get("create_avatar") != null) {
|
||||
if (mapObj.get("create_avatar") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("create_avatar");
|
||||
avatar = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("create_avatar") instanceof String) {
|
||||
avatar = String.valueOf(mapObj.get("create_avatar"));
|
||||
}
|
||||
}
|
||||
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) {
|
||||
if (mapObj.get("user_avatar") instanceof Clob) {
|
||||
Clob clob = (Clob) mapObj.get("user_avatar");
|
||||
avatarReply = PostCommonUtil.clobToString(clob);
|
||||
} else if (mapObj.get("user_avatar") instanceof String) {
|
||||
avatarReply = String.valueOf(mapObj.get("user_avatar"));
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
return postCustomList;
|
||||
}
|
||||
|
||||
public static List<PostCustom> getNewPostsObjCustom(List<PostCustom> postCustomList) {
|
||||
List<PostCustom> mainList = new ArrayList<>();
|
||||
Map<String, Object> postMap = new LinkedHashMap<>();
|
||||
for (PostCustom mapObj : postCustomList) {
|
||||
if (null == mapObj.getParentId()) {
|
||||
mainList.add(mapObj);
|
||||
} else {
|
||||
List<PostCustom> tempList = new ArrayList<>();
|
||||
if (postMap.containsKey(String.valueOf(mapObj.getParentId()))) {
|
||||
tempList = (List<PostCustom>) postMap.get(String.valueOf(mapObj.getParentId()));
|
||||
tempList.add(mapObj);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()), tempList);
|
||||
} else {
|
||||
tempList.add(mapObj);
|
||||
postMap.put(String.valueOf(mapObj.getParentId()), tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<PostCustom> mainListResult = new ArrayList<>();
|
||||
for (PostCustom mapObj : mainList) {
|
||||
if (postMap.containsKey(String.valueOf(mapObj.getId()))) {
|
||||
PostCustom newObj = new PostCustom();
|
||||
BeanUtils.copyProperties(mapObj, newObj);
|
||||
newObj.setChild((List<PostCustom>) postMap.get(String.valueOf(mapObj.getId())));
|
||||
mainListResult.add(newObj);
|
||||
} else {
|
||||
mainListResult.add(mapObj);
|
||||
}
|
||||
}
|
||||
|
||||
return mainListResult;
|
||||
}
|
||||
|
||||
// Clob类型转换成String类型
|
||||
public static String clobToString(final Clob clob) {
|
||||
|
||||
if (clob == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reader is = null;
|
||||
try {
|
||||
is = clob.getCharacterStream();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BufferedReader br = new BufferedReader(is);
|
||||
|
||||
String str = null;
|
||||
try {
|
||||
str = br.readLine(); // 读取第一行
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (str != null) { // 如果没有到达流的末尾,则继续读取下一行
|
||||
sb.append(str);
|
||||
try {
|
||||
str = br.readLine();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String returnString = sb.toString();
|
||||
|
||||
return returnString;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user