feat: 新增了几个知识接口
createNewKnowledgeFolder updateKnowledgeStructure deleteKnowledge starKnowledgemaster
parent
9d495a8dbc
commit
4b9264b6b9
|
@ -5,4 +5,6 @@ java -Djarmode=layertools `
|
|||
extract --destination build/extracted
|
||||
|
||||
docker build -f .\Dockerfile -t auto/aics_main:latest .
|
||||
echo 'saving...'
|
||||
docker save -o ..\docker\aics_main.tar auto/aics_main:latest
|
||||
pause
|
|
@ -4,26 +4,25 @@ import cn.dev33.satoken.annotation.SaCheckRole
|
|||
import cn.edu.hfut.auto.knowledge.config.COSClientWrapper
|
||||
import cn.edu.hfut.auto.knowledge.entity.*
|
||||
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
||||
import cn.edu.hfut.auto.knowledge.entity.vo.KnowledgeBriefVO
|
||||
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 cn.edu.hfut.auto.knowledge.util.getLoginUser
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.qcloud.cos.model.ciModel.job.DocHtmlRequest
|
||||
import kotlinx.coroutines.future.await
|
||||
import org.apache.kafka.common.KafkaException
|
||||
import org.babyfish.jimmer.kt.new
|
||||
import org.babyfish.jimmer.sql.kt.fetcher.newFetcher
|
||||
import org.springframework.kafka.core.KafkaTemplate
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
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 org.springframework.web.bind.annotation.*
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
import java.util.*
|
||||
|
||||
const val UPLOAD_FILE_TOPIC = "upload_file"
|
||||
|
||||
|
@ -33,7 +32,8 @@ class KnowledgeController(
|
|||
private val kafkaTemplate: KafkaTemplate<String, Any?>,
|
||||
private val knowledgeRepository: KnowledgeRepository,
|
||||
private val knowledgeFileAttributeRepository: KnowledgeFileAttributeRepository,
|
||||
private val cosClientWrapper: COSClientWrapper
|
||||
private val cosClientWrapper: COSClientWrapper,
|
||||
private val objectMapper: ObjectMapper
|
||||
) {
|
||||
|
||||
@GetMapping("/{knowledgeId}")
|
||||
|
@ -100,4 +100,54 @@ class KnowledgeController(
|
|||
}
|
||||
?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
suspend fun createNewKnowledgeFolder(@RequestBody vo: KnowledgeBriefVO) {
|
||||
knowledgeRepository.insert(new(Knowledge::class).by {
|
||||
name = vo.name
|
||||
vo.parentId?.let {
|
||||
parent().apply {
|
||||
id = it
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@PutMapping("/{knowledgeId}")
|
||||
suspend fun updateKnowledgeStructure(@PathVariable knowledgeId: UUID, @RequestBody vo: KnowledgeBriefVO) {
|
||||
knowledgeRepository.update(new(Knowledge::class).by {
|
||||
id = knowledgeId
|
||||
name = vo.name
|
||||
vo.parentId?.let {
|
||||
parent().apply {
|
||||
id = it
|
||||
}
|
||||
} ?: let {
|
||||
parent = null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@DeleteMapping("/{knowledgeId}")
|
||||
suspend fun deleteKnowledge(@PathVariable knowledgeId: UUID) {
|
||||
knowledgeRepository.deleteById(knowledgeId)
|
||||
}
|
||||
|
||||
@PutMapping("/{knowledgeId}/star")
|
||||
suspend fun starKnowledge(@PathVariable knowledgeId: UUID, active: Boolean) {
|
||||
val loginUserId = getLoginUser(objectMapper).id
|
||||
knowledgeRepository.findNullable(knowledgeId, newFetcher(Knowledge::class).by {
|
||||
knowledgeFileAttribute { starers() }
|
||||
})
|
||||
?.knowledgeFileAttribute
|
||||
?.let { attr ->
|
||||
knowledgeFileAttributeRepository.update(new(KnowledgeFileAttribute::class).by {
|
||||
starers = attr.starers.filterNot { it.id == loginUserId }
|
||||
if (active) {
|
||||
starers().addBy { id = loginUserId }
|
||||
}
|
||||
})
|
||||
}
|
||||
?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||
}
|
||||
}
|
|
@ -10,3 +10,8 @@ data class KnowledgeFileUploadVO(
|
|||
val tags: List<Long>,
|
||||
val parentId: UUID?
|
||||
)
|
||||
|
||||
data class KnowledgeBriefVO(
|
||||
val name: String,
|
||||
val parentId: UUID?
|
||||
)
|
Loading…
Reference in New Issue