diff --git a/src/main/java/com/yaoyuan/jiscuss/common/PostCommonUtil.java b/src/main/java/com/yaoyuan/jiscuss/common/PostCommonUtil.java new file mode 100644 index 0000000..89b8f7a --- /dev/null +++ b/src/main/java/com/yaoyuan/jiscuss/common/PostCommonUtil.java @@ -0,0 +1,93 @@ +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.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author yaoyuan2.chu + * @Title: + * @Package com.yaoyuan.jiscuss.common + * @Description: + * @date 2020/9/10 15:47 + */ +public class PostCommonUtil { + + + public static List getNewPostsObjCustom(List postCustomList) { + List mainList = new ArrayList<>(); + Map postMap = new LinkedHashMap<>(); + for(PostCustom mapObj : postCustomList){ + if(null == mapObj.getParentId() ){ + mainList.add(mapObj); + }else{ + List tempList = new ArrayList<>(); + if(postMap.containsKey(String.valueOf(mapObj.getParentId()))){ + tempList = (List) 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 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) 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; + } +} diff --git a/src/main/java/com/yaoyuan/jiscuss/entity/custom/DiscussionCustom.java b/src/main/java/com/yaoyuan/jiscuss/entity/custom/DiscussionCustom.java new file mode 100644 index 0000000..017343d --- /dev/null +++ b/src/main/java/com/yaoyuan/jiscuss/entity/custom/DiscussionCustom.java @@ -0,0 +1,29 @@ +package com.yaoyuan.jiscuss.entity.custom; + +import com.yaoyuan.jiscuss.entity.Discussion; +import lombok.Data; + +/** + * @author yaoyuan2.chu + * @Title: + * @Package com.yaoyuan.jiscuss.entity.custom + * @Description: + * @date 2020/9/9 14:44 + */ + +@Data +public class DiscussionCustom extends Discussion { + + private String avatar; + + private String username; + + private String realname; + + private String avatarLast; + + private String usernameLast; + + private String realnameLast; + +} diff --git a/src/main/java/com/yaoyuan/jiscuss/entity/custom/PostCustom.java b/src/main/java/com/yaoyuan/jiscuss/entity/custom/PostCustom.java new file mode 100644 index 0000000..2cae7ac --- /dev/null +++ b/src/main/java/com/yaoyuan/jiscuss/entity/custom/PostCustom.java @@ -0,0 +1,35 @@ +package com.yaoyuan.jiscuss.entity.custom; + +import com.yaoyuan.jiscuss.entity.Post; +import lombok.Data; + +import javax.persistence.Column; +import java.util.List; + +/** + * @author yaoyuan2.chu + * @Title: + * @Package com.yaoyuan.jiscuss.entity.custom + * @Description: + * @date 2020/9/9 14:44 + */ +@Data +public class PostCustom extends Post { + + private String avatar; + + private String username; + + private String realname; + + private String avatarReply; + + private String usernameReply; + + private String realnameReply; + + private List child; + + + +} diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..8c943ca --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,8 @@ + _ _ + | (_) + | |_ ___ ___ _ _ ___ ___ + _ | | / __|/ __| | | / __/ __| +| |__| | \__ \ (__| |_| \__ \__ \ + \____/|_|___/\___|\__,_|___/___/ + ========================================================= + :: Spring Boot :: (v${spring-boot.version})