Compare commits
No commits in common. "a2086975f4dfd1af6fb9ca2bd0ca2f417c31dadd" and "7f7e32db59374e26b8c0897a7947d05240864511" have entirely different histories.
a2086975f4
...
7f7e32db59
|
@ -35,4 +35,3 @@ out/
|
|||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
logs
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
||||
import org.springframework.boot.gradle.tasks.run.BootRun
|
||||
|
||||
plugins {
|
||||
|
@ -47,7 +46,6 @@ dependencies {
|
|||
implementation("com.lmax:disruptor:3.4.4")
|
||||
// kotlin 协程(spring 异步接口)
|
||||
val kotlinxCoroutinesVersion = "1.7.1"
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk9:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
|
@ -57,9 +55,7 @@ dependencies {
|
|||
implementation("org.babyfish.jimmer:jimmer-spring-boot-starter:0.7.104")
|
||||
ksp("org.babyfish.jimmer:jimmer-ksp:0.7.104")
|
||||
// developmentOnly("org.springframework.boot:spring-boot-docker-compose")
|
||||
implementation("org.postgresql:postgresql")
|
||||
// Kafka
|
||||
implementation("org.springframework.kafka:spring-kafka")
|
||||
runtimeOnly("org.postgresql:postgresql")
|
||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
}
|
||||
|
@ -69,10 +65,6 @@ tasks.withType<BootRun> {
|
|||
jvmArgs = jvmArgs?.toMutableList()?.plus("-Dlog4j.skipJansi=false")
|
||||
}
|
||||
|
||||
tasks.withType<BootBuildImage> {
|
||||
imageName.set("auto/aics_main")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += "-Xjsr305=strict"
|
||||
|
|
|
@ -3,7 +3,3 @@ distributionPath=wrapper/dists
|
|||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
systemProp.http.proxyHost=127.0.0.1
|
||||
systemProp.http.proxyPort=7890
|
||||
systemProp.https.proxyHost=127.0.0.1
|
||||
systemProp.https.proxyPort=7890
|
|
@ -1 +1 @@
|
|||
rootProject.name = "AicsKnowledgeBase_main"
|
||||
rootProject.name = "AicsKnowledgeBase"
|
||||
|
|
|
@ -1,30 +1,12 @@
|
|||
package cn.edu.hfut.auto.knowledge.config
|
||||
|
||||
import org.babyfish.jimmer.sql.runtime.DefaultDatabaseNamingStrategy
|
||||
import org.babyfish.jimmer.sql.runtime.ScalarProvider
|
||||
import org.postgresql.util.PGobject
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.*
|
||||
|
||||
@Configuration
|
||||
class JimmerConfig {
|
||||
@Bean
|
||||
fun databaseNamingStrategy(): DefaultDatabaseNamingStrategy =
|
||||
DefaultDatabaseNamingStrategy.LOWER_CASE
|
||||
|
||||
@Component
|
||||
class PostgresUUIDScalarProvider : ScalarProvider<UUID, PGobject>() {
|
||||
override fun toScalar(sqlValue: PGobject): UUID {
|
||||
return UUID.fromString(sqlValue.value)
|
||||
}
|
||||
|
||||
override fun toSql(scalarValue: UUID): PGobject {
|
||||
return PGobject().apply {
|
||||
type = "uuid"
|
||||
value = scalarValue.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.config
|
||||
|
||||
import org.apache.kafka.clients.producer.ProducerConfig
|
||||
import org.apache.kafka.common.serialization.StringSerializer
|
||||
import org.springframework.boot.autoconfigure.kafka.KafkaProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.kafka.core.DefaultKafkaProducerFactory
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.kafka.core.ProducerFactory
|
||||
import org.springframework.kafka.support.serializer.JsonSerializer
|
||||
|
||||
@Configuration
|
||||
class KafkaConfig(
|
||||
private val kafkaProperties: KafkaProperties
|
||||
) {
|
||||
fun anyJsonProducerFactory(): ProducerFactory<String, Any?> =
|
||||
DefaultKafkaProducerFactory(
|
||||
hashMapOf(
|
||||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to kafkaProperties.bootstrapServers,
|
||||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java,
|
||||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java
|
||||
)
|
||||
)
|
||||
|
||||
@Bean
|
||||
fun anyJsonKafkaTemplate(): KafkaTemplate<String, Any?> =
|
||||
KafkaTemplate(anyJsonProducerFactory())
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.config
|
||||
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor
|
||||
import cn.dev33.satoken.stp.StpInterface
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import cn.edu.hfut.auto.knowledge.util.getLogger
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
|
||||
|
||||
@Configuration
|
||||
class SaTokenConfig : WebMvcConfigurer {
|
||||
|
||||
override fun addInterceptors(registry: InterceptorRegistry) {
|
||||
registry.run {
|
||||
// addInterceptor(object : HandlerInterceptor {
|
||||
// override fun preHandle(
|
||||
// request: HttpServletRequest,
|
||||
// response: HttpServletResponse,
|
||||
// handler: Any
|
||||
// ): Boolean {
|
||||
// log.info("****** headers ******")
|
||||
// for (headerName in request.headerNames) {
|
||||
// log.info("{}: {}", headerName, request.getHeaders(headerName).toList().joinToString())
|
||||
// }
|
||||
// log.info("*********************")
|
||||
// return super.preHandle(request, response, handler)
|
||||
// }
|
||||
// }).addPathPatterns("/**")
|
||||
addInterceptor(SaInterceptor()).addPathPatterns("/**")
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
class StpInterfaceImpl(
|
||||
@Value("\${aics.max-permission-level}")
|
||||
private val maxPermissionLevel: Short,
|
||||
private val objectMapper: ObjectMapper
|
||||
) : StpInterface {
|
||||
private val permissionCache: HashMap<Short, List<String>> = hashMapOf()
|
||||
override fun getPermissionList(loginId: Any?, loginType: String?): List<String> {
|
||||
return getRoleList(loginId, loginType)
|
||||
}
|
||||
|
||||
override fun getRoleList(loginId: Any?, loginType: String?): List<String> {
|
||||
return (loginId as? String)
|
||||
?.let { objectMapper.readValue<User>(it).level }
|
||||
?.let { getPermissionLevelStringList(it) }
|
||||
?: mutableListOf()
|
||||
}
|
||||
|
||||
private fun getPermissionLevelStringList(userLevel: Short): List<String> {
|
||||
return permissionCache.getOrPut(userLevel) {
|
||||
(userLevel..maxPermissionLevel).map { it.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -5,20 +5,20 @@ import cn.dev33.satoken.stp.StpUtil
|
|||
import cn.edu.hfut.auto.knowledge.entity.vo.LoginVO
|
||||
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
||||
import cn.edu.hfut.auto.knowledge.exception.ErrorCode
|
||||
import cn.edu.hfut.auto.knowledge.repository.UserRepository
|
||||
import cn.edu.hfut.auto.knowledge.service.UserService
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class AuthorizeController(
|
||||
private val userRepository: UserRepository
|
||||
private val userService: UserService
|
||||
) {
|
||||
@PostMapping("/login")
|
||||
fun login(@RequestBody vo: LoginVO) {
|
||||
val user = userRepository.findByUsername(vo.username)
|
||||
val user = userService.findByUsername(vo.username)
|
||||
?.takeIf { BCrypt.checkpw(vo.password, it.password) }
|
||||
?: throw BusinessError(ErrorCode.INVALID_USERNAME_OR_PASSWORD)
|
||||
StpUtil.login(user)
|
||||
StpUtil.login(user.id)
|
||||
}
|
||||
}
|
|
@ -3,23 +3,25 @@ package cn.edu.hfut.auto.knowledge.controller
|
|||
import cn.dev33.satoken.secure.BCrypt
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import cn.edu.hfut.auto.knowledge.entity.by
|
||||
import cn.edu.hfut.auto.knowledge.repository.UserRepository
|
||||
import cn.edu.hfut.auto.knowledge.entity.vo.LoginVO
|
||||
import cn.edu.hfut.auto.knowledge.service.UserService
|
||||
import org.babyfish.jimmer.kt.new
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@Profile("dev")
|
||||
@RestController
|
||||
class DevOnlyController(
|
||||
private val userRepository: UserRepository
|
||||
private val userService: UserService
|
||||
) {
|
||||
@PostMapping("/register")
|
||||
fun register(username: String, password: String, level: Short) {
|
||||
userRepository.insert(new(User::class).by {
|
||||
this.username = username
|
||||
this.password = BCrypt.hashpw(password)
|
||||
this.level = level
|
||||
fun register(@RequestBody vo: LoginVO) {
|
||||
userService.insert(new(User::class).by {
|
||||
username = vo.username
|
||||
password = BCrypt.hashpw(vo.password)
|
||||
level = 2
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.controller
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckRole
|
||||
import cn.edu.hfut.auto.knowledge.entity.Knowledge
|
||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
||||
import cn.edu.hfut.auto.knowledge.entity.by
|
||||
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
||||
import cn.edu.hfut.auto.knowledge.entity.vo.KnowledgeFileUploadVO
|
||||
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
||||
import cn.edu.hfut.auto.knowledge.exception.ErrorCode
|
||||
import cn.edu.hfut.auto.knowledge.repository.KnowledgeFileAttributeRepository
|
||||
import cn.edu.hfut.auto.knowledge.repository.KnowledgeRepository
|
||||
import cn.edu.hfut.auto.knowledge.util.fileSuffix
|
||||
import kotlinx.coroutines.future.await
|
||||
import org.apache.kafka.common.KafkaException
|
||||
import org.babyfish.jimmer.kt.new
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.time.LocalDateTime
|
||||
|
||||
const val UPLOAD_FILE_TOPIC = "upload_file"
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/knowledge")
|
||||
class KnowledgeController(
|
||||
private val kafkaTemplate: KafkaTemplate<String, Any?>,
|
||||
private val knowledgeRepository: KnowledgeRepository,
|
||||
private val knowledgeFileAttributeRepository: KnowledgeFileAttributeRepository
|
||||
) {
|
||||
|
||||
@SaCheckRole("1")
|
||||
@Transactional(rollbackFor = [Throwable::class])
|
||||
@PostMapping("/file")
|
||||
suspend fun preUploadFile(@RequestBody vo: KnowledgeFileUploadVO): String {
|
||||
knowledgeRepository.findByNameAndParentId(vo.name, vo.parentId, Knowledge.AS_CHILD_FETCHER)?.let {
|
||||
throw BusinessError(ErrorCode.TARGET_ALREADY_EXISTS)
|
||||
}
|
||||
val knowledgeResult = knowledgeRepository.save(new(Knowledge::class).by {
|
||||
name = vo.name
|
||||
createTime = LocalDateTime.now()
|
||||
vo.parentId?.let {
|
||||
parent().apply {
|
||||
id = it
|
||||
}
|
||||
} ?: let {
|
||||
parent = null
|
||||
}
|
||||
})
|
||||
val fileResult = knowledgeFileAttributeRepository.save(new(KnowledgeFileAttribute::class).by {
|
||||
suffix = vo.name.fileSuffix
|
||||
size = vo.size
|
||||
brief = vo.brief
|
||||
pageView = 0
|
||||
knowledge().apply {
|
||||
id = knowledgeResult.id
|
||||
}
|
||||
})
|
||||
FileTicket(fileResult).run {
|
||||
try {
|
||||
kafkaTemplate.send(UPLOAD_FILE_TOPIC, this).await()
|
||||
} catch (e: KafkaException) {
|
||||
throw BusinessError(ErrorCode.MESSAGING_FAILED, cause = e)
|
||||
}
|
||||
return ticket
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
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<Knowledge>
|
||||
|
||||
@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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
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
|
||||
@Key
|
||||
val knowledge: Knowledge
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable
|
||||
val tags: List<Tag>
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "knowledge_file_attribute_starer_mapping")
|
||||
val starers: List<User>
|
||||
|
||||
@ManyToMany(mappedBy = "knowledgeFiles")
|
||||
val notes: List<Note>
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
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<Comment>
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable
|
||||
val tags: List<Tag>
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "note_knowledge_file_mapping")
|
||||
val knowledgeFiles: List<KnowledgeFileAttribute>
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "note_starer_mapping")
|
||||
val starers: List<User>
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "note_liker_mapping")
|
||||
val likers: List<User>
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -9,23 +9,9 @@ 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<Note>
|
||||
|
||||
@OneToMany(mappedBy = "targetUser")
|
||||
val notices: List<Notice>
|
||||
|
||||
@ManyToMany(mappedBy = "starers")
|
||||
val starredKnowledge: List<KnowledgeFileAttribute>
|
||||
|
||||
@ManyToMany(mappedBy = "starers")
|
||||
val starredNotes: List<Note>
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.entity.rpc
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
||||
import org.apache.commons.codec.digest.Sha2Crypt
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
data class FileTicket(
|
||||
val ticket: String,
|
||||
val id: UUID
|
||||
) {
|
||||
constructor(knowledgeFileAttribute: KnowledgeFileAttribute): this(
|
||||
buildString {
|
||||
knowledgeFileAttribute.run {
|
||||
append(id)
|
||||
append(size)
|
||||
append(LocalDateTime.now())
|
||||
}
|
||||
}.let {
|
||||
Sha2Crypt.sha256Crypt(it.toByteArray())
|
||||
},
|
||||
knowledgeFileAttribute.id
|
||||
)
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.entity.vo
|
||||
|
||||
import java.util.*
|
||||
|
||||
data class KnowledgeFileUploadVO(
|
||||
val name: String,
|
||||
val brief: String,
|
||||
val size: Long,
|
||||
val sha256: String,
|
||||
val tags: List<Long>,
|
||||
val parentId: UUID?
|
||||
)
|
|
@ -3,7 +3,7 @@ package cn.edu.hfut.auto.knowledge.exception
|
|||
import org.springframework.http.ProblemDetail
|
||||
import org.springframework.http.ResponseEntity
|
||||
|
||||
class BusinessError(val code: ErrorCode, override val message: String = code.message, override val cause: Throwable? = null) : RuntimeException() {
|
||||
class BusinessError(val code: ErrorCode, override val message: String = code.message) : RuntimeException() {
|
||||
override fun fillInStackTrace(): Throwable = this
|
||||
fun toResponseEntity(): ResponseEntity<ProblemDetail> =
|
||||
ResponseEntity(
|
||||
|
|
|
@ -3,14 +3,5 @@ package cn.edu.hfut.auto.knowledge.exception
|
|||
import org.springframework.http.HttpStatus
|
||||
|
||||
enum class ErrorCode(val code: Int, val status: HttpStatus, val message: String) {
|
||||
INVALID_USERNAME_OR_PASSWORD(200, HttpStatus.BAD_REQUEST, "用户名或密码错误"),
|
||||
|
||||
UNAUTHORIZED(300, HttpStatus.UNAUTHORIZED, "未登录或登录已过期"),
|
||||
|
||||
RESOURCE_NOT_FOUND(400, HttpStatus.NOT_FOUND, "找不到对应资源"),
|
||||
TARGET_ALREADY_EXISTS(401, HttpStatus.CONFLICT, "目标已存在"),
|
||||
|
||||
MESSAGING_FAILED(500, HttpStatus.SERVICE_UNAVAILABLE, "消息通信失败,请重试"),
|
||||
|
||||
UNKNOWN_ERROR(999, HttpStatus.INTERNAL_SERVER_ERROR, "出现未知错误")
|
||||
INVALID_USERNAME_OR_PASSWORD(200, HttpStatus.BAD_REQUEST, "用户名或密码错误")
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package cn.edu.hfut.auto.knowledge.exception
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException
|
||||
import cn.dev33.satoken.exception.NotRoleException
|
||||
import cn.edu.hfut.auto.knowledge.util.getLogger
|
||||
import org.springframework.http.ProblemDetail
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
|
@ -10,26 +7,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice
|
|||
|
||||
@RestControllerAdvice
|
||||
class ExceptionHandlerAdvice {
|
||||
private val log = getLogger()
|
||||
@ExceptionHandler(BusinessError::class)
|
||||
fun handleBusinessError(e: BusinessError): ResponseEntity<ProblemDetail> {
|
||||
e.cause?.run { log.error("BusinessError with cause: ", this) }
|
||||
return e.toResponseEntity()
|
||||
}
|
||||
|
||||
@ExceptionHandler(NotRoleException::class)
|
||||
fun handleNotRoleException(e: NotRoleException): ResponseEntity<ProblemDetail> {
|
||||
return BusinessError(ErrorCode.RESOURCE_NOT_FOUND).toResponseEntity()
|
||||
}
|
||||
|
||||
@ExceptionHandler(NotLoginException::class)
|
||||
fun handleNotLoginException(e: NotLoginException): ResponseEntity<ProblemDetail> {
|
||||
return BusinessError(ErrorCode.UNAUTHORIZED).toResponseEntity()
|
||||
}
|
||||
|
||||
@ExceptionHandler(Throwable::class)
|
||||
fun handleThrowable(e: Throwable): ResponseEntity<ProblemDetail> {
|
||||
log.error("Unknown Error: ", e)
|
||||
return BusinessError(ErrorCode.UNKNOWN_ERROR).toResponseEntity()
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.repository
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
||||
import org.babyfish.jimmer.spring.repository.KRepository
|
||||
import java.util.*
|
||||
|
||||
interface KnowledgeFileAttributeRepository : KRepository<KnowledgeFileAttribute, UUID>
|
|
@ -1,10 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.repository
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.Knowledge
|
||||
import org.babyfish.jimmer.spring.repository.KRepository
|
||||
import org.babyfish.jimmer.sql.fetcher.Fetcher
|
||||
import java.util.*
|
||||
|
||||
interface KnowledgeRepository : KRepository<Knowledge, UUID> {
|
||||
fun findByNameAndParentId(name: String, parentId: UUID?, fetcher: Fetcher<Knowledge>? = null): Knowledge?
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package cn.edu.hfut.auto.knowledge.repository
|
||||
package cn.edu.hfut.auto.knowledge.service
|
||||
|
||||
import cn.edu.hfut.auto.knowledge.entity.User
|
||||
import org.babyfish.jimmer.spring.repository.KRepository
|
||||
import org.babyfish.jimmer.sql.fetcher.Fetcher
|
||||
|
||||
interface UserRepository : KRepository<User, Long> {
|
||||
interface UserService : KRepository<User, Long> {
|
||||
fun findByUsername(username: String, fetcher: Fetcher<User>? = null): User?
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.util
|
||||
|
||||
inline val String.fileSuffix
|
||||
get() = this.substringAfterLast('.', "")
|
|
@ -1,6 +0,0 @@
|
|||
package cn.edu.hfut.auto.knowledge.util
|
||||
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
inline fun <reified T> T.getLogger(): Logger = LoggerFactory.getLogger(T::class.java)
|
|
@ -1,7 +1,7 @@
|
|||
server:
|
||||
# ssl:
|
||||
# key-store: classpath:ssl-rsa.pfx
|
||||
# key-store-password: auto
|
||||
ssl:
|
||||
key-store: classpath:ssl-rsa.pfx
|
||||
key-store-password: auto
|
||||
http2:
|
||||
enabled: true
|
||||
|
||||
|
@ -12,22 +12,13 @@ sa-token:
|
|||
spring:
|
||||
datasource:
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: jdbc:postgresql://localhost:5432/aics_knowledge?useUnicode=true
|
||||
url: jdbc:postgresql://101.34.228.45:5432/aics_knowledge?useUnicode=true
|
||||
username: aics_backend
|
||||
password: 123456
|
||||
kafka:
|
||||
bootstrap-servers:
|
||||
- "localhost:9094"
|
||||
producer:
|
||||
retries: 3
|
||||
|
||||
jimmer:
|
||||
language: kotlin
|
||||
dialect: org.babyfish.jimmer.sql.dialect.PostgresDialect
|
||||
show-sql: true
|
||||
|
||||
logging:
|
||||
config: classpath:log4j2-dev.xml
|
||||
|
||||
aics:
|
||||
max-permission-level: 3
|
|
@ -1,7 +1,7 @@
|
|||
server:
|
||||
# ssl:
|
||||
# key-store: classpath:ssl-rsa.pfx
|
||||
# key-store-password: auto
|
||||
ssl:
|
||||
key-store: classpath:ssl-rsa.pfx
|
||||
key-store-password: auto
|
||||
http2:
|
||||
enabled: true
|
||||
|
||||
|
@ -15,18 +15,9 @@ spring:
|
|||
url: jdbc:postgresql://localhost:5432/aics_knowledge?useUnicode=true
|
||||
username: aics_backend
|
||||
password: 123456
|
||||
kafka:
|
||||
bootstrap-servers:
|
||||
- "kafka:9092"
|
||||
producer:
|
||||
retries: 3
|
||||
|
||||
jimmer:
|
||||
language: kotlin
|
||||
dialect: org.babyfish.jimmer.sql.dialect.PostgresDialect
|
||||
|
||||
logging:
|
||||
config: classpath:log4j2-prod.xml
|
||||
|
||||
aics:
|
||||
max-permission-level: 3
|
|
@ -1,762 +0,0 @@
|
|||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 15.3 (Debian 15.3-1.pgdg120+1)
|
||||
-- Dumped by pg_dump version 15.3
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
DROP DATABASE IF EXISTS aics_knowledge;
|
||||
--
|
||||
-- Name: aics_knowledge; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE aics_knowledge WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.utf8';
|
||||
|
||||
|
||||
ALTER DATABASE aics_knowledge OWNER TO postgres;
|
||||
|
||||
\connect aics_knowledge
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: filetype; Type: TYPE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TYPE public.filetype AS ENUM (
|
||||
'image',
|
||||
'audio',
|
||||
'video',
|
||||
'doc',
|
||||
'ppt',
|
||||
'md',
|
||||
'pdf',
|
||||
'html',
|
||||
'other'
|
||||
);
|
||||
|
||||
|
||||
ALTER TYPE public.filetype OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: comment; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.comment (
|
||||
id uuid NOT NULL,
|
||||
content text NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
note_id uuid NOT NULL,
|
||||
create_time timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.comment OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: knowledge; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.knowledge (
|
||||
id uuid NOT NULL,
|
||||
name character varying(60) NOT NULL,
|
||||
parent_id uuid,
|
||||
create_time timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.knowledge OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.knowledge_file_attribute (
|
||||
id uuid NOT NULL,
|
||||
suffix character varying(20) NOT NULL,
|
||||
size bigint NOT NULL,
|
||||
brief text NOT NULL,
|
||||
page_view bigint NOT NULL,
|
||||
knowledge_id uuid NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.knowledge_file_attribute OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_starer_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.knowledge_file_attribute_starer_mapping (
|
||||
knowledge_file_attribute_id uuid NOT NULL,
|
||||
user_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.knowledge_file_attribute_starer_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_tag_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.knowledge_file_attribute_tag_mapping (
|
||||
knowledge_file_attribute_id uuid NOT NULL,
|
||||
tag_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.knowledge_file_attribute_tag_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: note; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.note (
|
||||
id uuid NOT NULL,
|
||||
title character varying(60) NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
create_time timestamp without time zone NOT NULL,
|
||||
update_time timestamp without time zone NOT NULL,
|
||||
page_view bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.note OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: note_knowledge_file_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.note_knowledge_file_mapping (
|
||||
note_id uuid NOT NULL,
|
||||
knowledge_file_attribute_id uuid NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.note_knowledge_file_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: note_liker_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.note_liker_mapping (
|
||||
note_id uuid NOT NULL,
|
||||
user_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.note_liker_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: note_starer_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.note_starer_mapping (
|
||||
note_id uuid NOT NULL,
|
||||
user_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.note_starer_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: note_tag_mapping; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.note_tag_mapping (
|
||||
note_id uuid NOT NULL,
|
||||
tag_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.note_tag_mapping OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: notice; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.notice (
|
||||
id uuid NOT NULL,
|
||||
viewed boolean NOT NULL,
|
||||
create_time timestamp without time zone NOT NULL,
|
||||
note_id uuid NOT NULL,
|
||||
comment_id uuid NOT NULL,
|
||||
target_user_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.notice OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: t_user; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.t_user (
|
||||
id bigint NOT NULL,
|
||||
username character varying(15) NOT NULL,
|
||||
password character(60) NOT NULL,
|
||||
level smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.t_user OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: t_user_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.t_user_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.t_user_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: t_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.t_user_id_seq OWNED BY public.t_user.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.tag (
|
||||
id bigint NOT NULL,
|
||||
name character varying(20) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.tag OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: tag_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.tag_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.tag_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: tag_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.tag_id_seq OWNED BY public.tag.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: t_user id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.t_user ALTER COLUMN id SET DEFAULT nextval('public.t_user_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag ALTER COLUMN id SET DEFAULT nextval('public.tag_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: comment; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: knowledge; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: knowledge_file_attribute; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: knowledge_file_attribute_starer_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: knowledge_file_attribute_tag_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: note; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: note_knowledge_file_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: note_liker_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: note_starer_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: note_tag_mapping; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: notice; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: t_user; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.t_user VALUES (1, 'test1', '$2a$10$Dbfl3tW/eIcjgJRrAxJNK.HODD/OJhboNWgIrFT8JnL5iGp45F2Ou', 2);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: tag; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Name: t_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.t_user_id_seq', 1, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.tag_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_tag_mapping file_tags_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_tag_mapping
|
||||
ADD CONSTRAINT file_tags_mapping_pk PRIMARY KEY (knowledge_file_attribute_id, tag_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute knowledge_file_attribute_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute
|
||||
ADD CONSTRAINT knowledge_file_attribute_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_starer_mapping knowledge_file_attribute_starer_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_starer_mapping
|
||||
ADD CONSTRAINT knowledge_file_attribute_starer_mapping_pk PRIMARY KEY (knowledge_file_attribute_id, user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge knowledge_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge
|
||||
ADD CONSTRAINT knowledge_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_knowledge_file_mapping note_knowledge_file_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_knowledge_file_mapping
|
||||
ADD CONSTRAINT note_knowledge_file_mapping_pk PRIMARY KEY (knowledge_file_attribute_id, note_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_liker_mapping note_liker_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_liker_mapping
|
||||
ADD CONSTRAINT note_liker_mapping_pk PRIMARY KEY (user_id, note_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note note_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note
|
||||
ADD CONSTRAINT note_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_starer_mapping note_starer_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_starer_mapping
|
||||
ADD CONSTRAINT note_starer_mapping_pk PRIMARY KEY (note_id, user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_tag_mapping note_tag_mapping_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_tag_mapping
|
||||
ADD CONSTRAINT note_tag_mapping_pk PRIMARY KEY (tag_id, note_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: notice notice_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notice
|
||||
ADD CONSTRAINT notice_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: t_user t_user_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.t_user
|
||||
ADD CONSTRAINT t_user_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: t_user t_user_username; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.t_user
|
||||
ADD CONSTRAINT t_user_username UNIQUE (username);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag tag_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag
|
||||
ADD CONSTRAINT tag_pk PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment_create_time_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX comment_create_time_index ON public.comment USING btree (create_time DESC);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_suffix_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX knowledge_file_attribute_suffix_index ON public.knowledge_file_attribute USING hash (suffix);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_update_time_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX note_update_time_index ON public.note USING btree (update_time DESC);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: comment comment_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.comment
|
||||
ADD CONSTRAINT comment_t_user_id_fk FOREIGN KEY (author_id) REFERENCES public.t_user(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_tag_mapping file_tags_mapping_knowledge_file_attribute_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_tag_mapping
|
||||
ADD CONSTRAINT file_tags_mapping_knowledge_file_attribute_id_fk FOREIGN KEY (knowledge_file_attribute_id) REFERENCES public.knowledge_file_attribute(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_tag_mapping file_tags_mapping_tag_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_tag_mapping
|
||||
ADD CONSTRAINT file_tags_mapping_tag_id_fk FOREIGN KEY (tag_id) REFERENCES public.tag(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute knowledge_file_attribute_knowledge_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute
|
||||
ADD CONSTRAINT knowledge_file_attribute_knowledge_id_fk FOREIGN KEY (knowledge_id) REFERENCES public.knowledge(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge knowledge_parent_knowledge_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge
|
||||
ADD CONSTRAINT knowledge_parent_knowledge_id_fk FOREIGN KEY (parent_id) REFERENCES public.knowledge(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_knowledge_file_mapping note_knowledge_file_mapping_knowledge_file_attribute_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_knowledge_file_mapping
|
||||
ADD CONSTRAINT note_knowledge_file_mapping_knowledge_file_attribute_id_fk FOREIGN KEY (knowledge_file_attribute_id) REFERENCES public.knowledge_file_attribute(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_knowledge_file_mapping note_knowledge_file_mapping_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_knowledge_file_mapping
|
||||
ADD CONSTRAINT note_knowledge_file_mapping_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_liker_mapping note_liker_mapping_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_liker_mapping
|
||||
ADD CONSTRAINT note_liker_mapping_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_liker_mapping note_liker_mapping_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_liker_mapping
|
||||
ADD CONSTRAINT note_liker_mapping_t_user_id_fk FOREIGN KEY (user_id) REFERENCES public.t_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_starer_mapping note_starer_mapping_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_starer_mapping
|
||||
ADD CONSTRAINT note_starer_mapping_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_starer_mapping note_starer_mapping_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_starer_mapping
|
||||
ADD CONSTRAINT note_starer_mapping_t_user_id_fk FOREIGN KEY (user_id) REFERENCES public.t_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note note_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note
|
||||
ADD CONSTRAINT note_t_user_id_fk FOREIGN KEY (author_id) REFERENCES public.t_user(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_tag_mapping note_tag_mapping_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_tag_mapping
|
||||
ADD CONSTRAINT note_tag_mapping_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: note_tag_mapping note_tag_mapping_tag_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.note_tag_mapping
|
||||
ADD CONSTRAINT note_tag_mapping_tag_id_fk FOREIGN KEY (tag_id) REFERENCES public.tag(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: notice notice_comment_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notice
|
||||
ADD CONSTRAINT notice_comment_id_fk FOREIGN KEY (comment_id) REFERENCES public.comment(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: notice notice_note_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notice
|
||||
ADD CONSTRAINT notice_note_id_fk FOREIGN KEY (note_id) REFERENCES public.note(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: notice notice_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notice
|
||||
ADD CONSTRAINT notice_t_user_id_fk FOREIGN KEY (target_user_id) REFERENCES public.t_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_starer_mapping starer_mapping_knowledge_file_attribute_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_starer_mapping
|
||||
ADD CONSTRAINT starer_mapping_knowledge_file_attribute_id_fk FOREIGN KEY (knowledge_file_attribute_id) REFERENCES public.knowledge_file_attribute(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: knowledge_file_attribute_starer_mapping starer_t_user_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.knowledge_file_attribute_starer_mapping
|
||||
ADD CONSTRAINT starer_t_user_id_fk FOREIGN KEY (user_id) REFERENCES public.t_user(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: DATABASE aics_knowledge; Type: ACL; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT ALL ON DATABASE aics_knowledge TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE comment; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.comment TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE knowledge; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.knowledge TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE knowledge_file_attribute; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.knowledge_file_attribute TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE knowledge_file_attribute_tag_mapping; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.knowledge_file_attribute_tag_mapping TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE note; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.note TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE notice; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.notice TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE t_user; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.t_user TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE t_user_id_seq; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.t_user_id_seq TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE tag; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.tag TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE tag_id_seq; Type: ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.tag_id_seq TO aics_backend;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
Loading…
Reference in New Issue