diff --git a/src/main/java/com/lk/paopao/dto/CommentContentDto.java b/src/main/java/com/lk/paopao/dto/CommentContentDto.java new file mode 100644 index 0000000..61c15bc --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/CommentContentDto.java @@ -0,0 +1,21 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +import java.io.Serializable; + +/** + * DTO for {@link com.lk.paopao.entity.CommentContent} + */ +@Value +public class CommentContentDto implements Serializable { + Long id; + String content; + Byte type; + Integer sort; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/dto/CommentDto.java b/src/main/java/com/lk/paopao/dto/CommentDto.java new file mode 100644 index 0000000..e2e0219 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/CommentDto.java @@ -0,0 +1,29 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +import java.io.Serializable; +import java.util.List; + +/** + * DTO for {@link com.lk.paopao.entity.Comment} + */ +@Value +public class CommentDto implements Serializable { + Long id; + Long userId; + Long postId; + String ip; + String ipLoc; + Boolean isEssence; + Integer replyCount; + Integer thumbsUpCount; + Integer thumbsDownCount; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; + UserDto user; + List contents; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/dto/CommentReplyDto.java b/src/main/java/com/lk/paopao/dto/CommentReplyDto.java new file mode 100644 index 0000000..9c586cd --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/CommentReplyDto.java @@ -0,0 +1,27 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +@Value +public class CommentReplyDto { + + Long id; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; + + Long commentId; + + UserDto user; + + String content; + + String ip; + + String ipLoc; + + Integer thumbsUpCount; + Integer thumbsDownCount; +} diff --git a/src/main/java/com/lk/paopao/dto/MillisecondToSecondSerializer.java b/src/main/java/com/lk/paopao/dto/MillisecondToSecondSerializer.java new file mode 100644 index 0000000..90cf054 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/MillisecondToSecondSerializer.java @@ -0,0 +1,34 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * 将毫秒转换为秒的Json序列化器。 + * 此序列化器将数值类型的毫秒数转换为对应的秒数进行JSON序列化。 + */ +public class MillisecondToSecondSerializer extends JsonSerializer { + + /** + * 序列化方法,将输入的毫秒数转换为秒数后写入JSON生成器。 + * + * @param value 需要序列化的毫秒数,类型为Number。 + * @param gen JSON生成器,用于输出序列化后的结果。 + * @param serializers 序列化提供者,提供序列化过程所需的额外服务。 + * @throws IOException 如果在序列化过程中发生IO异常。 + */ + @Override + public void serialize(Number value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + if (value != null) { + // 将输入的毫秒数转换为秒数 + long microseconds = value.longValue(); + long seconds = TimeUnit.MILLISECONDS.toSeconds(microseconds); + // 将转换后的秒数写入JSON生成器 + gen.writeNumber(seconds); + } + } +} diff --git a/src/main/java/com/lk/paopao/dto/PostCollectionDto.java b/src/main/java/com/lk/paopao/dto/PostCollectionDto.java new file mode 100644 index 0000000..ffc41ba --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/PostCollectionDto.java @@ -0,0 +1,16 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +@Value +public class PostCollectionDto { + + Long id; + PostDto post; + UserDto user; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; +} diff --git a/src/main/java/com/lk/paopao/dto/PostContentDto.java b/src/main/java/com/lk/paopao/dto/PostContentDto.java new file mode 100644 index 0000000..f32f246 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/PostContentDto.java @@ -0,0 +1,22 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +import java.io.Serializable; + +/** + * DTO for {@link com.lk.paopao.entity.PostContent} + */ +@Value +public class PostContentDto implements Serializable { + Long id; + Long postId; + String content; + Byte type; + Integer sort; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/dto/PostDto.java b/src/main/java/com/lk/paopao/dto/PostDto.java new file mode 100644 index 0000000..b901b41 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/PostDto.java @@ -0,0 +1,37 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +import java.io.Serializable; +import java.util.List; + +/** + * DTO for {@link com.lk.paopao.entity.Post} + */ +@Value +public class PostDto implements Serializable { + Long id; + Long userId; + Long commentCount; + Long collectionCount; + Long upvoteCount; + Long shareCount; + Byte visibility; + Boolean isTop; + Boolean isEssence; + Boolean isLock; + Long latestRepliedOn; + String tags; + Long attachmentPrice; + String ip; + String ipLoc; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; + Long deletedOn; + Byte isDel; + UserDto user; + List contents; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/dto/PostStarDto.java b/src/main/java/com/lk/paopao/dto/PostStarDto.java new file mode 100644 index 0000000..4238995 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/PostStarDto.java @@ -0,0 +1,15 @@ +package com.lk.paopao.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Value; + +@Value +public class PostStarDto { + Long id; + PostDto post; + UserDto user; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long createdOn; + @JsonSerialize(using = MillisecondToSecondSerializer.class) + Long modifiedOn; +} diff --git a/src/main/java/com/lk/paopao/dto/TagDto.java b/src/main/java/com/lk/paopao/dto/TagDto.java new file mode 100644 index 0000000..25fa6ac --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/TagDto.java @@ -0,0 +1,19 @@ +package com.lk.paopao.dto; + +import lombok.Value; + +import java.io.Serializable; + +/** + * DTO for {@link com.lk.paopao.entity.Tag} + */ +@Value +public class TagDto implements Serializable { + Long id; + Long userId; + UserDto user; + String tag; + Long quoteNum; + Long createdOn; + Long modifiedOn; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/dto/rest/request/ContentInPostRequest.java b/src/main/java/com/lk/paopao/dto/rest/request/ContentInPostRequest.java new file mode 100644 index 0000000..e0e986a --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/rest/request/ContentInPostRequest.java @@ -0,0 +1,12 @@ +package com.lk.paopao.dto.rest.request; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class ContentInPostRequest { + private String content; + private Integer sort; + private Byte type; +} diff --git a/src/main/java/com/lk/paopao/dto/rest/request/PostRequest.java b/src/main/java/com/lk/paopao/dto/rest/request/PostRequest.java new file mode 100644 index 0000000..e58be93 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/rest/request/PostRequest.java @@ -0,0 +1,20 @@ +package com.lk.paopao.dto.rest.request; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Setter +@Getter +public class PostRequest { + private Long attachmentPrice; + private Byte visibility; + //帖子内容列表 + List contents; + // #标签列表 + List tags; + // @用户列表 + List users; + +} diff --git a/src/main/java/com/lk/paopao/dto/rest/response/Paged.java b/src/main/java/com/lk/paopao/dto/rest/response/Paged.java new file mode 100644 index 0000000..e7ceb85 --- /dev/null +++ b/src/main/java/com/lk/paopao/dto/rest/response/Paged.java @@ -0,0 +1,35 @@ +package com.lk.paopao.dto.rest.response; + +import lombok.Getter; + +import java.io.Serializable; +import java.util.List; + +/** + * @description 分页数据 + * @param + */ +@Getter +public class Paged implements Serializable { + + List list; + Pager pager; + + public Paged(List list, Long totalRows, Integer page, Integer pageSize){ + this.list = list; + pager = new Pager(page, pageSize, totalRows); + } + + @Getter + public class Pager implements Serializable{ + Integer page; + Integer pageSize; + Long totalRows; + + public Pager(Integer page, Integer pageSize, Long totalRows){ + this.page = page; + this.pageSize = pageSize; + this.totalRows = totalRows; + } + } +} diff --git a/src/main/java/com/lk/paopao/entity/BaseAuditingEntity.java b/src/main/java/com/lk/paopao/entity/BaseAuditingEntity.java new file mode 100644 index 0000000..3af306e --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/BaseAuditingEntity.java @@ -0,0 +1,43 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Comment; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.io.Serializable; + +@Getter +@Setter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseAuditingEntity implements Serializable { + + // 主键ID + @Comment("ID") + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Comment("创建时间") + @Column(name = "created_on", nullable = false) + @CreatedDate + private Long createdOn; + + @Comment("修改时间") + @LastModifiedDate + @Column(name = "modified_on", nullable = false) + private Long modifiedOn; + + @Comment("删除时间") + @Column(name = "deleted_on") + private Long deletedOn; + + @Comment("是否删除 0 为未删除、1 为已删除") + @Column(name = "is_del") + private byte isDel = 0; + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/Comment.java b/src/main/java/com/lk/paopao/entity/Comment.java new file mode 100644 index 0000000..6aaf595 --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/Comment.java @@ -0,0 +1,66 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.List; + +@Getter +@Setter +@org.hibernate.annotations.Comment("评论") +@Entity +@Table(name = "p_comment", indexes = { + @Index(name = "idx_comment_post_id", columnList = "post_id"), + @Index(name = "idx_comment_user_id", columnList = "user_id") +}) +@EntityListeners(AuditingEntityListener.class) +public class Comment extends BaseAuditingEntity{ + + @Version + private Long version; + + @org.hibernate.annotations.Comment("POST ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; + + @org.hibernate.annotations.Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY,mappedBy = "comment") + private List contents; + + @org.hibernate.annotations.Comment("IP地址") + @Column(name = "ip", length = 15) + private String ip; + + @org.hibernate.annotations.Comment("IP城市地址") + @Column(name = "ip_loc", length = 64) + private String ipLoc; + + @org.hibernate.annotations.Comment("是否精选") + @ColumnDefault("0") + @Column(name = "is_essence", nullable = false) + private Boolean isEssence = false; + + @org.hibernate.annotations.Comment("回复数") + @ColumnDefault("0") + @Column(name = "reply_count", nullable = false) + private Integer replyCount = 0; + + @org.hibernate.annotations.Comment("点赞数") + @ColumnDefault("0") + @Column(name = "thumbs_up_count", nullable = false) + private Integer thumbsUpCount = 0; + + @org.hibernate.annotations.Comment("点踩数") + @ColumnDefault("0") + @Column(name = "thumbs_down_count", nullable = false) + private Integer thumbsDownCount = 0; + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/CommentContent.java b/src/main/java/com/lk/paopao/entity/CommentContent.java new file mode 100644 index 0000000..a357cde --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/CommentContent.java @@ -0,0 +1,49 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@Setter +@Comment("评论内容") +@Entity +@Table(name = "p_comment_content", indexes = { + @Index(name = "idx_comment_content_comment_id", columnList = "comment_id"), + @Index(name = "idx_comment_content_user_id", columnList = "user_id"), + @Index(name = "idx_comment_content_type", columnList = "type"), + @Index(name = "idx_comment_content_sort", columnList = "sort") +}) +@EntityListeners(AuditingEntityListener.class) +public class CommentContent extends BaseAuditingEntity{ + + @Comment("评论ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "comment_id") + private com.lk.paopao.entity.Comment comment; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Comment("内容") + @ColumnDefault("") + @Column(name = "content", nullable = false, length = 4000) + private String content; + + @Comment("类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址") + @ColumnDefault("2") + @Column(name = "type", nullable = false) + private Byte type = 2; + + @Comment("排序,越小越靠前") + @ColumnDefault("100") + @Column(name = "sort", nullable = false) + private Integer sort = 100; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/CommentReply.java b/src/main/java/com/lk/paopao/entity/CommentReply.java new file mode 100644 index 0000000..3fdc5ad --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/CommentReply.java @@ -0,0 +1,53 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@Setter +@Comment("评论回复") +@Entity +@Table(name = "p_comment_reply", indexes = { + @Index(name = "idx_comment_reply_comment_id", columnList = "comment_id") +}) +@EntityListeners(AuditingEntityListener.class) +public class CommentReply extends BaseAuditingEntity{ + @Version + private Long version; + + @Comment("评论ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "comment_id", nullable = false) + private com.lk.paopao.entity.Comment comment; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Comment("内容") + @Column(name = "content", nullable = false, length = 4000) + private String content; + + @Comment("IP地址") + @Column(name = "ip", length = 15) + private String ip; + + @Comment("IP城市地址") + @Column(name = "ip_loc", length = 64) + private String ipLoc; + + @Comment("点赞数") + @ColumnDefault("0") + @Column(name = "thumbs_up_count", nullable = false) + private Integer thumbsUpCount = 0; + + @Comment("点踩数") + @ColumnDefault("0") + @Column(name = "thumbs_down_count", nullable = false) + private Integer thumbsDownCount = 0; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/Post.java b/src/main/java/com/lk/paopao/entity/Post.java new file mode 100644 index 0000000..1d080da --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/Post.java @@ -0,0 +1,93 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; + +import java.util.List; + +@Getter +@Setter +@Comment("冒泡/动态/文章") +@Entity +@Table(name = "p_post", indexes = { + @Index(name = "idx_post_user_id", columnList = "user_id"), + @Index(name = "idx_post_visibility", columnList = "visibility") +}) +public class Post extends BaseAuditingEntity{ + + @Version + private Long version; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @OneToMany(mappedBy = "post", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) + private List contents; + + @Comment("评论数") + @ColumnDefault("0") + @Column(name = "comment_count", nullable = false) + private Long commentCount = 0L; + + @Comment("收藏数") + @ColumnDefault("0") + @Column(name = "collection_count", nullable = false) + private Long collectionCount = 0L; + + @Comment("点赞数") + @ColumnDefault("0") + @Column(name = "upvote_count", nullable = false) + private Long upvoteCount = 0L; + + @Comment("分享数") + @ColumnDefault("0") + @Column(name = "share_count", nullable = false) + private Long shareCount = 0L; + + @Comment("可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开") + @ColumnDefault("50") + @Column(name = "visibility", nullable = false) + private Byte visibility; + + @Comment("是否置顶") + @ColumnDefault("0") + @Column(name = "is_top", nullable = false) + private Boolean isTop = false; + + @Comment("是否精华") + @ColumnDefault("0") + @Column(name = "is_essence", nullable = false) + private Boolean isEssence = false; + + @Comment("是否锁定") + @ColumnDefault("0") + @Column(name = "is_lock", nullable = false) + private Boolean isLock = false; + + @Comment("最新回复时间") + @Column(name = "latest_replied_on") + private Long latestRepliedOn = 0L; + + @Comment("参与的主题") + @Column(name = "tags") + private String tags; + + @Comment("附件价格(分)") + @ColumnDefault("0") + @Column(name = "attachment_price", nullable = false) + private Long attachmentPrice = 0L; + + @Comment("IP地址") + @Column(name = "ip", length = 15) + private String ip; + + @Comment("IP城市地址") + @Column(name = "ip_loc", length = 64) + private String ipLoc; + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/PostCollection.java b/src/main/java/com/lk/paopao/entity/PostCollection.java new file mode 100644 index 0000000..10cf256 --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/PostCollection.java @@ -0,0 +1,30 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Comment; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@Setter +@Comment("冒泡/文章收藏") +@Entity +@Table(name = "p_post_collection", indexes = { + @Index(name = "idx_post_collection_post_id", columnList = "post_id"), + @Index(name = "idx_post_collection_user_id", columnList = "user_id") +}) +@EntityListeners(AuditingEntityListener.class) +public class PostCollection extends BaseAuditingEntity{ + + @Comment("POST ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/PostContent.java b/src/main/java/com/lk/paopao/entity/PostContent.java new file mode 100644 index 0000000..31ff81b --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/PostContent.java @@ -0,0 +1,41 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; + +@Getter +@Setter +@Comment("冒泡/动态/文章内容") +@Entity +@Table(name = "p_post_content", indexes = { + @Index(name = "idx_post_content_post_id", columnList = "post_id"), + @Index(name = "idx_post_content_user_id", columnList = "user_id") +}) +public class PostContent extends BaseAuditingEntity{ + @Comment("冒泡/动态/文章ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Comment("内容") + @Column(name = "content", nullable = false, length = 4000) + private String content; + + @Comment("类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源,8收费资源") + @ColumnDefault("2") + @Column(name = "type", nullable = false) + private Byte type = 2; + + @Comment("排序,越小越靠前") + @ColumnDefault("100") + @Column(name = "sort", nullable = false) + private Integer sort =100; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/PostStar.java b/src/main/java/com/lk/paopao/entity/PostStar.java new file mode 100644 index 0000000..399c4e1 --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/PostStar.java @@ -0,0 +1,29 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.Comment; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@Setter +@Comment("冒泡/文章点赞") +@Entity +@Table(name = "p_post_star", indexes = { + @Index(name = "idx_post_star_post_id", columnList = "post_id"), + @Index(name = "idx_post_star_user_id", columnList = "user_id") +}) +@EntityListeners(AuditingEntityListener.class) +public class PostStar extends BaseAuditingEntity{ + + @Comment("POST ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "post_id", nullable = false) + private Post post; + + @Comment("用户ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/entity/Tag.java b/src/main/java/com/lk/paopao/entity/Tag.java new file mode 100644 index 0000000..c01d2b9 --- /dev/null +++ b/src/main/java/com/lk/paopao/entity/Tag.java @@ -0,0 +1,37 @@ +package com.lk.paopao.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Comment; +@Getter +@Setter +@Comment("标签") +@Entity +@Table(name = "p_tag", indexes = { + @Index(name = "idx_tag_user_id", columnList = "user_id"), + @Index(name = "idx_tag_quote_num", columnList = "quote_num") +}, uniqueConstraints = { + @UniqueConstraint(name = "idx_tag_tag", columnNames = {"tag"}) +}) +public class Tag extends BaseAuditingEntity{ + + @Version + private Long version; + + @Comment("创建者ID") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Comment("标签名") + @Column(name = "tag", nullable = false) + private String tag; + + @Comment("引用数") + @ColumnDefault("0") + @Column(name = "quote_num", nullable = false) + private Long quoteNum = 0L; + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/CommentContentMapper.java b/src/main/java/com/lk/paopao/mapper/CommentContentMapper.java new file mode 100644 index 0000000..924d2ad --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/CommentContentMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.dto.CommentContentDto; +import com.lk.paopao.entity.CommentContent; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface CommentContentMapper { + CommentContent toEntity(CommentContentDto commentContentDto); + + CommentContentDto toDto(CommentContent commentContent); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + CommentContent partialUpdate(CommentContentDto commentContentDto, @MappingTarget CommentContent commentContent); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/CommentMapper.java b/src/main/java/com/lk/paopao/mapper/CommentMapper.java new file mode 100644 index 0000000..7574f06 --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/CommentMapper.java @@ -0,0 +1,20 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.dto.CommentDto; +import com.lk.paopao.entity.Comment; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface CommentMapper { + Comment toEntity(CommentDto commentDto); + + @AfterMapping + default void linkContents(@MappingTarget Comment comment) { + comment.getContents().forEach(content -> content.setComment(comment)); + } + + CommentDto toDto(Comment comment); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + Comment partialUpdate(CommentDto commentDto, @MappingTarget Comment comment); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/CommentReplyMapper.java b/src/main/java/com/lk/paopao/mapper/CommentReplyMapper.java new file mode 100644 index 0000000..2f517db --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/CommentReplyMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.dto.CommentReplyDto; +import com.lk.paopao.entity.CommentReply; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface CommentReplyMapper { + CommentReply toEntity(CommentReplyDto commentReplyDto); + + CommentReplyDto toDto(CommentReply commentReply); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + CommentReply partialUpdate(CommentReplyDto commentReplyDto, @MappingTarget CommentReply commentReply); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/PostCollectionMapper.java b/src/main/java/com/lk/paopao/mapper/PostCollectionMapper.java new file mode 100644 index 0000000..593e0ea --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/PostCollectionMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.dto.PostCollectionDto; +import com.lk.paopao.entity.PostCollection; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface PostCollectionMapper { + PostCollection toEntity(PostCollectionDto postCollectionDto); + + PostCollectionDto toDto(PostCollection postCollection); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + PostCollection partialUpdate(PostCollectionDto postCollectionDto, @MappingTarget PostCollection postCollection); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/PostContentMapper.java b/src/main/java/com/lk/paopao/mapper/PostContentMapper.java new file mode 100644 index 0000000..87ddaca --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/PostContentMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.entity.PostContent; +import com.lk.paopao.dto.PostContentDto; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface PostContentMapper { + PostContent toEntity(PostContentDto postContentDto); + + PostContentDto toDto(PostContent postContent); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + PostContent partialUpdate(PostContentDto postContentDto, @MappingTarget PostContent postContent); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/PostMapper.java b/src/main/java/com/lk/paopao/mapper/PostMapper.java new file mode 100644 index 0000000..5baa9b3 --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/PostMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.entity.Post; +import com.lk.paopao.dto.PostDto; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface PostMapper { + Post toEntity(PostDto postDto); + + PostDto toDto(Post post); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + Post partialUpdate(PostDto postDto, @MappingTarget Post post); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/PostStarMapper.java b/src/main/java/com/lk/paopao/mapper/PostStarMapper.java new file mode 100644 index 0000000..965dd68 --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/PostStarMapper.java @@ -0,0 +1,15 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.dto.PostStarDto; +import com.lk.paopao.entity.PostStar; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface PostStarMapper { + PostStar toEntity(PostStarDto postStarDto); + + PostStarDto toDto(PostStar postStar); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + PostStar partialUpdate(PostStarDto postStarDto, @MappingTarget PostStar postStar); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/mapper/TagMapper.java b/src/main/java/com/lk/paopao/mapper/TagMapper.java new file mode 100644 index 0000000..f99fd6a --- /dev/null +++ b/src/main/java/com/lk/paopao/mapper/TagMapper.java @@ -0,0 +1,17 @@ +package com.lk.paopao.mapper; + +import com.lk.paopao.entity.Tag; +import com.lk.paopao.dto.TagDto; +import org.mapstruct.*; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) +public interface TagMapper { + Tag toEntity(TagDto tagDto); + + @Mapping(source = "user.id", target = "userId") + @Mapping(source = "user", target = "user") + TagDto toDto(Tag tag); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + Tag partialUpdate(TagDto tagDto, @MappingTarget Tag tag); +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/CommentContentRepository.java b/src/main/java/com/lk/paopao/repository/CommentContentRepository.java new file mode 100644 index 0000000..c91825d --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/CommentContentRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.CommentContent; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CommentContentRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/CommentReplyRepository.java b/src/main/java/com/lk/paopao/repository/CommentReplyRepository.java new file mode 100644 index 0000000..14e18a2 --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/CommentReplyRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.CommentReply; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CommentReplyRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/CommentRepository.java b/src/main/java/com/lk/paopao/repository/CommentRepository.java new file mode 100644 index 0000000..644317b --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/CommentRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.Comment; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CommentRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/PostCollectionRepository.java b/src/main/java/com/lk/paopao/repository/PostCollectionRepository.java new file mode 100644 index 0000000..708f050 --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/PostCollectionRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.PostCollection; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostCollectionRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/PostContentRepository.java b/src/main/java/com/lk/paopao/repository/PostContentRepository.java new file mode 100644 index 0000000..697348e --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/PostContentRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.PostContent; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostContentRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/PostRepository.java b/src/main/java/com/lk/paopao/repository/PostRepository.java new file mode 100644 index 0000000..b39eb71 --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/PostRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.Post; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostRepository extends JpaRepository { +} diff --git a/src/main/java/com/lk/paopao/repository/PostStarRepository.java b/src/main/java/com/lk/paopao/repository/PostStarRepository.java new file mode 100644 index 0000000..38371f9 --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/PostStarRepository.java @@ -0,0 +1,7 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.PostStar; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostStarRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/TagRepository.java b/src/main/java/com/lk/paopao/repository/TagRepository.java new file mode 100644 index 0000000..914a978 --- /dev/null +++ b/src/main/java/com/lk/paopao/repository/TagRepository.java @@ -0,0 +1,19 @@ +package com.lk.paopao.repository; + +import com.lk.paopao.entity.Tag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface TagRepository extends JpaRepository { + + @Query("SELECT t.tag FROM Tag t WHERE t.tag LIKE CONCAT('%', :key, '%') ORDER BY t.tag ASC limit 20") + List findByTagContainingOrderByTagAsc(@Param("key") String key); + + Optional findByTag(String tag); + + +} \ No newline at end of file diff --git a/src/main/java/com/lk/paopao/repository/UserRepository.java b/src/main/java/com/lk/paopao/repository/UserRepository.java index 9db57fb..9789a12 100644 --- a/src/main/java/com/lk/paopao/repository/UserRepository.java +++ b/src/main/java/com/lk/paopao/repository/UserRepository.java @@ -2,9 +2,17 @@ package com.lk.paopao.repository; import com.lk.paopao.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import java.util.List; import java.util.Optional; public interface UserRepository extends JpaRepository { Optional findByUsername(String username); + + // 或者使用@Query注解进行JPQL或SQL查询(如果声明式方法命名无法满足复杂需求) + @Query("SELECT u.username FROM User u WHERE u.username LIKE CONCAT('%', :key, '%') ORDER BY u.username ASC limit 20") + List findByUsernameContainingOrderByUsernameAsc(@Param("key") String key); + } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b2ebc94..22a2ca0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -25,7 +25,7 @@ spring: defer-datasource-initialization: true database-platform: org.hibernate.dialect.H2Dialect hibernate: - ddl-auto: update + ddl-auto: create-drop # 可选值:create-drop,create,update,none. create-drop:每次启动项目都会删除表,然后重新创建表,适合开发环境;create:每次启动项目都会创建表,适合开发环境;update:每次启动项目都会更新表,适合开发环境;none:不执行任何操作,适合生产环境。 properties: hibernate: @@ -49,6 +49,8 @@ app: methods: ["GET"] - path: "/v3/**" methods: [ "GET" ] + - path: "/h2/**" + methods: [ "GET","PUT","POST" ] - path: "/v1/auth/**" methods: [ "GET","PUT","POST"] - path: "/upload/**"