From 254e76435a069b34b9d93157b34058b20ccfbad0 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Thu, 29 Jun 2023 23:35:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AE=9E=E4=BD=93=E7=B1=BB=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edu/hfut/auto/knowledge/entity/Comment.kt | 22 ++++++++++ .../hfut/auto/knowledge/entity/Knowledge.kt | 44 +++++++++++++++++++ .../entity/KnowledgeFileAttribute.kt | 30 +++++++++++++ .../cn/edu/hfut/auto/knowledge/entity/Note.kt | 39 ++++++++++++++++ .../edu/hfut/auto/knowledge/entity/Notice.kt | 24 ++++++++++ .../cn/edu/hfut/auto/knowledge/entity/Tag.kt | 14 ++++++ .../cn/edu/hfut/auto/knowledge/entity/User.kt | 14 ++++++ 7 files changed, 187 insertions(+) create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Comment.kt create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Notice.kt create mode 100644 src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Comment.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Comment.kt new file mode 100644 index 0000000..558e2f2 --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Comment.kt @@ -0,0 +1,22 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.Entity +import org.babyfish.jimmer.sql.GeneratedValue +import org.babyfish.jimmer.sql.Id +import org.babyfish.jimmer.sql.ManyToOne +import org.babyfish.jimmer.sql.meta.UUIDIdGenerator +import java.time.LocalDateTime +import java.util.* + +@Entity +interface Comment { + @Id + @GeneratedValue(generatorType = UUIDIdGenerator::class) + val id: UUID + val content: String + @ManyToOne + val author: User + @ManyToOne + val note: Note + val createTime: LocalDateTime +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt new file mode 100644 index 0000000..969ef9d --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Knowledge.kt @@ -0,0 +1,44 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.* +import org.babyfish.jimmer.sql.kt.fetcher.newFetcher +import org.babyfish.jimmer.sql.meta.UUIDIdGenerator +import java.time.LocalDateTime +import java.util.* + +@Entity +interface Knowledge { + @Id + @GeneratedValue(generatorType = UUIDIdGenerator::class) + val id: UUID + @Key + val name: String + val createTime: LocalDateTime + + @ManyToOne + @Key + val parent: Knowledge? + + @OneToMany(mappedBy = "parent") + val children: List + + @OneToOne(mappedBy = "knowledge") + val knowledgeFileAttribute: KnowledgeFileAttribute? + + companion object { + val BRIEF_FETCHER = newFetcher(Knowledge::class).by { + allScalarFields() + knowledgeFileAttribute() + } + val AS_PARENT_FETCHER = newFetcher(Knowledge::class).by { + allScalarFields() + children(BRIEF_FETCHER) + knowledgeFileAttribute() + } + val AS_CHILD_FETCHER = newFetcher(Knowledge::class).by { + allScalarFields() + parent(BRIEF_FETCHER) + knowledgeFileAttribute() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt new file mode 100644 index 0000000..8cb9e0c --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/KnowledgeFileAttribute.kt @@ -0,0 +1,30 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.* +import org.babyfish.jimmer.sql.meta.UUIDIdGenerator +import java.util.* + +@Entity +interface KnowledgeFileAttribute { + @Id + @GeneratedValue(generatorType = UUIDIdGenerator::class) + val id: UUID + val suffix: String + val size: Long + val brief: String + val pageView: Long + + @OneToOne + val knowledge: Knowledge + + @ManyToMany + @JoinTable + val tags: List + + @ManyToMany + @JoinTable(name = "knowledge_file_attribute_starer_mapping") + val starers: List + + @ManyToMany(mappedBy = "knowledgeFiles") + val notes: List +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt new file mode 100644 index 0000000..8c816e9 --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Note.kt @@ -0,0 +1,39 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.* +import org.babyfish.jimmer.sql.meta.UUIDIdGenerator +import java.time.LocalDateTime +import java.util.* + +@Entity +interface Note { + @Id + @GeneratedValue(generatorType = UUIDIdGenerator::class) + val id: UUID + val title: String + + @ManyToOne + val author: User + val createTime: LocalDateTime + val updateTime: LocalDateTime + val pageView: Long + + @OneToMany(mappedBy = "note") + val comments: List + + @ManyToMany + @JoinTable + val tags: List + + @ManyToMany + @JoinTable(name = "note_knowledge_file_mapping") + val knowledgeFiles: List + + @ManyToMany + @JoinTable(name = "note_starer_mapping") + val starers: List + + @ManyToMany + @JoinTable(name = "note_liker_mapping") + val likers: List +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Notice.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Notice.kt new file mode 100644 index 0000000..74ce10b --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Notice.kt @@ -0,0 +1,24 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.Entity +import org.babyfish.jimmer.sql.GeneratedValue +import org.babyfish.jimmer.sql.Id +import org.babyfish.jimmer.sql.ManyToOne +import org.babyfish.jimmer.sql.meta.UUIDIdGenerator +import java.time.LocalDateTime +import java.util.* + +@Entity +interface Notice { + @Id + @GeneratedValue(generatorType = UUIDIdGenerator::class) + val id: UUID + val viewed: Boolean + val createTime: LocalDateTime + @ManyToOne + val note: Note + @ManyToOne + val comment: Comment + @ManyToOne + val targetUser: User +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt new file mode 100644 index 0000000..88e3d4b --- /dev/null +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/Tag.kt @@ -0,0 +1,14 @@ +package cn.edu.hfut.auto.knowledge.entity + +import org.babyfish.jimmer.sql.Entity +import org.babyfish.jimmer.sql.GeneratedValue +import org.babyfish.jimmer.sql.GenerationType +import org.babyfish.jimmer.sql.Id + +@Entity +interface Tag { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long + val name: String +} \ No newline at end of file diff --git a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/User.kt b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/User.kt index 56faea9..e9f95ec 100644 --- a/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/User.kt +++ b/src/main/kotlin/cn/edu/hfut/auto/knowledge/entity/User.kt @@ -9,9 +9,23 @@ interface User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long + @Key val username: String + @get:JsonIgnore val password: String val level: Short + + @OneToMany(mappedBy = "author") + val notes: List + + @OneToMany(mappedBy = "targetUser") + val notices: List + + @ManyToMany(mappedBy = "starers") + val starredKnowledge: List + + @ManyToMany(mappedBy = "starers") + val starredNotes: List } \ No newline at end of file