This commit is contained in:
parent
7300ae827a
commit
a1af6074d5
|
@ -1,5 +1,10 @@
|
|||
package org.echo.application.`in`
|
||||
|
||||
import echo.org.domain.FolderParam
|
||||
import echo.org.domain.MoveParam
|
||||
import org.echo.domian.FolderService
|
||||
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
|
||||
|
||||
|
@ -7,5 +12,16 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RestController
|
||||
@RequestMapping("/cloud/folder")
|
||||
class FolderController(
|
||||
val folderService: FolderService
|
||||
) {
|
||||
|
||||
) {}
|
||||
@PostMapping("/save")
|
||||
suspend fun saveFolder(@RequestBody param: FolderParam) {
|
||||
folderService.saveFolder(param)
|
||||
}
|
||||
|
||||
@PostMapping("/move")
|
||||
suspend fun moveFolder(@RequestBody param: MoveParam) {
|
||||
folderService.moveFolder(param)
|
||||
}
|
||||
}
|
|
@ -16,12 +16,12 @@ open class BaseType(
|
|||
|
||||
open class BaseDoc(
|
||||
@Id
|
||||
var id: Long,
|
||||
var name: String,
|
||||
var authorId: Long,
|
||||
var createdAt: LocalDateTime,
|
||||
var updatedAt: LocalDateTime,
|
||||
var filePath: String
|
||||
var id: Long?,
|
||||
var name: String?,
|
||||
var authorId: Long?,
|
||||
var createdAt: LocalDateTime?,
|
||||
var updatedAt: LocalDateTime?,
|
||||
var filePath: String?
|
||||
)
|
||||
|
||||
val SUCCESS: String = "操作成功"
|
||||
|
|
|
@ -13,7 +13,7 @@ class Document(
|
|||
createdAt: LocalDateTime,
|
||||
updatedAt: LocalDateTime,
|
||||
filePath: String,
|
||||
@MappedCollection(idColumn = "base_doc_id")
|
||||
@MappedCollection(idColumn = "document_id")
|
||||
var fileType: BaseType,
|
||||
val fileSize: String,
|
||||
val title: String,
|
||||
|
|
|
@ -5,8 +5,8 @@ import java.time.LocalDateTime
|
|||
|
||||
|
||||
data class FolderParam(
|
||||
val id: Long,
|
||||
val name: String,
|
||||
val id: Long?,
|
||||
val name: String?,
|
||||
val parentFolderId: Long?,
|
||||
val color: String?,
|
||||
val icon: String?,
|
||||
|
@ -15,6 +15,13 @@ data class FolderParam(
|
|||
val permissions: String?
|
||||
)
|
||||
|
||||
data class MoveParam(
|
||||
val originFolderId: Long,
|
||||
val targetFolderId: Long,
|
||||
val documentIdList: List<Long>,
|
||||
val folderIdList: List<Long>
|
||||
)
|
||||
|
||||
fun FolderParam.toFolder(authorId: Long, filePath: String): Folder {
|
||||
return Folder(
|
||||
id = this.id,
|
||||
|
@ -34,12 +41,12 @@ fun FolderParam.toFolder(authorId: Long, filePath: String): Folder {
|
|||
|
||||
@Table("folder")
|
||||
class Folder(
|
||||
id: Long,
|
||||
name: String,
|
||||
authorId: Long,
|
||||
createdAt: LocalDateTime,
|
||||
updatedAt: LocalDateTime,
|
||||
filePath: String,
|
||||
id: Long?,
|
||||
name: String?,
|
||||
authorId: Long?,
|
||||
createdAt: LocalDateTime?,
|
||||
updatedAt: LocalDateTime?,
|
||||
filePath: String?,
|
||||
var parentFolderId: Long?,
|
||||
var color: String?,
|
||||
var icon: String?,
|
||||
|
@ -89,7 +96,10 @@ interface FolderRepository {
|
|||
suspend fun addDocumentToFolder(folderId: Long, documentIdList: List<Long>)
|
||||
|
||||
// Remove a document from a folder
|
||||
suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List<Long>)
|
||||
suspend fun moveDocument(
|
||||
originFolderId: Long, targetFolderId: Long, documentIdList: List<Long>,
|
||||
folderIdList: List<Long>
|
||||
)
|
||||
|
||||
// Search folders by name or tags
|
||||
suspend fun searchFolders(query: String): List<Folder>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package org.echo.domian
|
||||
|
||||
import echo.org.domain.FolderParam
|
||||
import echo.org.domain.FolderRepository
|
||||
import echo.org.domain.toFolder
|
||||
import echo.org.domain.update
|
||||
import echo.org.domain.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.springframework.stereotype.Service
|
||||
|
@ -18,10 +15,12 @@ class FolderService(
|
|||
val (id, username, _) = currentUser
|
||||
withContext(Dispatchers.IO) {
|
||||
// 检查是否是编辑现有文件夹
|
||||
folderRepository.getFolderById(param.id)?.let {
|
||||
param.id?.let {
|
||||
folderRepository.getFolderById(it)?.let {
|
||||
// 更新现有文件夹
|
||||
val updatedFolder = it.update(param)
|
||||
folderRepository.saveFolder(updatedFolder)
|
||||
}
|
||||
} ?: run {
|
||||
// 获取父文件夹路径
|
||||
val parentFolderPath = param.parentFolderId?.let {
|
||||
|
@ -34,7 +33,12 @@ class FolderService(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun moveFolder(param: FolderParam) {
|
||||
|
||||
suspend fun moveFolder(param: MoveParam) {
|
||||
folderRepository.moveDocument(
|
||||
param.originFolderId,
|
||||
param.targetFolderId,
|
||||
param.documentIdList,
|
||||
param.folderIdList
|
||||
)
|
||||
}
|
||||
}
|
|
@ -46,7 +46,8 @@ class FolderRepositoryImpl(
|
|||
|
||||
override suspend fun getSubfolders(folderId: Long): List<Folder>? = withContext(Dispatchers.IO) {
|
||||
jdbcFolderRepository.findByIdOrNull(folderId)
|
||||
.let { it?.let { subFolder -> jdbcFolderRepository.findByParentFolderId(subFolder.id) } }
|
||||
.let { it?.let { subFolder -> subFolder.id?.let {
|
||||
it1 -> jdbcFolderRepository.findByParentFolderId(it1) } } }
|
||||
}
|
||||
|
||||
override suspend fun getDocumentsInFolder(folderId: Long): List<Document> = withContext(Dispatchers.IO) {
|
||||
|
@ -64,12 +65,14 @@ class FolderRepositoryImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List<Long>): Unit =
|
||||
override suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List<Long>,
|
||||
folderIdList:List<Long>): Unit =
|
||||
withContext(Dispatchers.IO) {
|
||||
val idList = documentIdList.toMutableList()
|
||||
val docIdList = documentIdList.toMutableList()
|
||||
val folderIds = folderIdList.toMutableList()
|
||||
val targetFolder = jdbcFolderRepository.findByIdOrNull(targetFolderId)
|
||||
targetFolder?.let {
|
||||
jdbcDocumentRepository.findByIdIn(idList)
|
||||
jdbcDocumentRepository.findByIdIn(docIdList)
|
||||
.let {
|
||||
it.forEach { doc ->
|
||||
doc.filePath = targetFolder.filePath + File.separator + doc.name
|
||||
|
@ -77,7 +80,7 @@ class FolderRepositoryImpl(
|
|||
}
|
||||
jdbcDocumentRepository.saveAll(it)
|
||||
}
|
||||
jdbcFolderRepository.findByIdIn(idList)
|
||||
jdbcFolderRepository.findByIdIn(folderIds)
|
||||
.let {
|
||||
it.forEach { doc ->
|
||||
doc.filePath = targetFolder.filePath + File.separator + doc.name
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 7891
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
|
Loading…
Reference in New Issue