parent
28afd457e9
commit
d35157e124
|
@ -0,0 +1,19 @@
|
||||||
|
package cn.edu.hfut.auto.knowledge.config
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.core.convert.converter.Converter
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class SerializeConfig {
|
||||||
|
@Component
|
||||||
|
class NullableUUIDConverter : Converter<String, UUID?> {
|
||||||
|
override fun convert(source: String): UUID? {
|
||||||
|
if (source.isEmpty() || source.equals("null", true)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return UUID.fromString(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package cn.edu.hfut.auto.knowledge.controller
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckRole
|
import cn.dev33.satoken.annotation.SaCheckRole
|
||||||
import cn.edu.hfut.auto.knowledge.entity.Knowledge
|
import cn.edu.hfut.auto.knowledge.entity.Knowledge
|
||||||
|
import cn.edu.hfut.auto.knowledge.entity.KnowledgeDraft
|
||||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
||||||
import cn.edu.hfut.auto.knowledge.entity.by
|
import cn.edu.hfut.auto.knowledge.entity.by
|
||||||
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
||||||
|
@ -36,8 +37,16 @@ class KnowledgeController(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@GetMapping("/{knowledgeId}")
|
@GetMapping("/{knowledgeId}")
|
||||||
suspend fun getKnowledgeBrief(@PathVariable knowledgeId: UUID): Knowledge =
|
suspend fun getKnowledgeBrief(@PathVariable knowledgeId: UUID?): Knowledge {
|
||||||
knowledgeRepository.findNullable(knowledgeId, Knowledge.AS_PARENT_FETCHER) ?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
if (knowledgeId == null) {
|
||||||
|
return new(Knowledge::class).by {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
children()
|
||||||
|
.addAll(knowledgeRepository.findAllByParentId(null, Knowledge.BRIEF_FETCHER) as List<KnowledgeDraft>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return knowledgeRepository.findNullable(knowledgeId, Knowledge.AS_PARENT_FETCHER) ?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||||
|
}
|
||||||
|
|
||||||
@SaCheckRole("1")
|
@SaCheckRole("1")
|
||||||
@Transactional(rollbackFor = [Throwable::class])
|
@Transactional(rollbackFor = [Throwable::class])
|
||||||
|
@ -66,7 +75,7 @@ class KnowledgeController(
|
||||||
id = knowledgeResult.id
|
id = knowledgeResult.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
FileTicket(fileResult).run {
|
FileTicket(fileResult, vo.md5).run {
|
||||||
try {
|
try {
|
||||||
kafkaTemplate.send(UPLOAD_FILE_TOPIC, this).await()
|
kafkaTemplate.send(UPLOAD_FILE_TOPIC, this).await()
|
||||||
} catch (e: KafkaException) {
|
} catch (e: KafkaException) {
|
||||||
|
|
|
@ -7,9 +7,11 @@ import java.util.UUID
|
||||||
|
|
||||||
data class FileTicket(
|
data class FileTicket(
|
||||||
val ticket: String,
|
val ticket: String,
|
||||||
val id: UUID
|
val id: UUID,
|
||||||
|
val md5: String,
|
||||||
|
val size: Long
|
||||||
) {
|
) {
|
||||||
constructor(knowledgeFileAttribute: KnowledgeFileAttribute): this(
|
constructor(knowledgeFileAttribute: KnowledgeFileAttribute, md5: String): this(
|
||||||
buildString {
|
buildString {
|
||||||
knowledgeFileAttribute.run {
|
knowledgeFileAttribute.run {
|
||||||
append(id)
|
append(id)
|
||||||
|
@ -19,6 +21,8 @@ data class FileTicket(
|
||||||
}.let {
|
}.let {
|
||||||
Sha2Crypt.sha256Crypt(it.toByteArray())
|
Sha2Crypt.sha256Crypt(it.toByteArray())
|
||||||
},
|
},
|
||||||
knowledgeFileAttribute.id
|
knowledgeFileAttribute.id,
|
||||||
|
md5,
|
||||||
|
knowledgeFileAttribute.size
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ data class KnowledgeFileUploadVO(
|
||||||
val name: String,
|
val name: String,
|
||||||
val brief: String,
|
val brief: String,
|
||||||
val size: Long,
|
val size: Long,
|
||||||
val sha256: String,
|
val md5: String,
|
||||||
val tags: List<Long>,
|
val tags: List<Long>,
|
||||||
val parentId: UUID?
|
val parentId: UUID?
|
||||||
)
|
)
|
|
@ -7,4 +7,6 @@ import java.util.*
|
||||||
|
|
||||||
interface KnowledgeRepository : KRepository<Knowledge, UUID> {
|
interface KnowledgeRepository : KRepository<Knowledge, UUID> {
|
||||||
fun findByNameAndParentId(name: String, parentId: UUID?, fetcher: Fetcher<Knowledge>? = null): Knowledge?
|
fun findByNameAndParentId(name: String, parentId: UUID?, fetcher: Fetcher<Knowledge>? = null): Knowledge?
|
||||||
|
|
||||||
|
fun findAllByParentId(parentId: UUID?, fetcher: Fetcher<Knowledge>? = null): List<Knowledge>
|
||||||
}
|
}
|
Loading…
Reference in New Issue