This commit is contained in:
Superdandan 2024-06-11 23:24:26 +08:00
parent 7300ae827a
commit a1af6074d5
7 changed files with 67 additions and 34 deletions

View File

@ -1,11 +1,27 @@
package org.echo.application.`in` 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.RequestMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/cloud/folder") @RequestMapping("/cloud/folder")
class FolderController ( 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)
}
}

View File

@ -16,12 +16,12 @@ open class BaseType(
open class BaseDoc( open class BaseDoc(
@Id @Id
var id: Long, var id: Long?,
var name: String, var name: String?,
var authorId: Long, var authorId: Long?,
var createdAt: LocalDateTime, var createdAt: LocalDateTime?,
var updatedAt: LocalDateTime, var updatedAt: LocalDateTime?,
var filePath: String var filePath: String?
) )
val SUCCESS: String = "操作成功" val SUCCESS: String = "操作成功"

View File

@ -13,7 +13,7 @@ class Document(
createdAt: LocalDateTime, createdAt: LocalDateTime,
updatedAt: LocalDateTime, updatedAt: LocalDateTime,
filePath: String, filePath: String,
@MappedCollection(idColumn = "base_doc_id") @MappedCollection(idColumn = "document_id")
var fileType: BaseType, var fileType: BaseType,
val fileSize: String, val fileSize: String,
val title: String, val title: String,

View File

@ -5,8 +5,8 @@ import java.time.LocalDateTime
data class FolderParam( data class FolderParam(
val id: Long, val id: Long?,
val name: String, val name: String?,
val parentFolderId: Long?, val parentFolderId: Long?,
val color: String?, val color: String?,
val icon: String?, val icon: String?,
@ -15,6 +15,13 @@ data class FolderParam(
val permissions: String? 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 { fun FolderParam.toFolder(authorId: Long, filePath: String): Folder {
return Folder( return Folder(
id = this.id, id = this.id,
@ -34,12 +41,12 @@ fun FolderParam.toFolder(authorId: Long, filePath: String): Folder {
@Table("folder") @Table("folder")
class Folder( class Folder(
id: Long, id: Long?,
name: String, name: String?,
authorId: Long, authorId: Long?,
createdAt: LocalDateTime, createdAt: LocalDateTime?,
updatedAt: LocalDateTime, updatedAt: LocalDateTime?,
filePath: String, filePath: String?,
var parentFolderId: Long?, var parentFolderId: Long?,
var color: String?, var color: String?,
var icon: String?, var icon: String?,
@ -89,7 +96,10 @@ interface FolderRepository {
suspend fun addDocumentToFolder(folderId: Long, documentIdList: List<Long>) suspend fun addDocumentToFolder(folderId: Long, documentIdList: List<Long>)
// Remove a document from a folder // 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 // Search folders by name or tags
suspend fun searchFolders(query: String): List<Folder> suspend fun searchFolders(query: String): List<Folder>

View File

@ -1,9 +1,6 @@
package org.echo.domian package org.echo.domian
import echo.org.domain.FolderParam import echo.org.domain.*
import echo.org.domain.FolderRepository
import echo.org.domain.toFolder
import echo.org.domain.update
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -18,10 +15,12 @@ class FolderService(
val (id, username, _) = currentUser val (id, username, _) = currentUser
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
// 检查是否是编辑现有文件夹 // 检查是否是编辑现有文件夹
folderRepository.getFolderById(param.id)?.let { param.id?.let {
// 更新现有文件夹 folderRepository.getFolderById(it)?.let {
val updatedFolder = it.update(param) // 更新现有文件夹
folderRepository.saveFolder(updatedFolder) val updatedFolder = it.update(param)
folderRepository.saveFolder(updatedFolder)
}
} ?: run { } ?: run {
// 获取父文件夹路径 // 获取父文件夹路径
val parentFolderPath = param.parentFolderId?.let { 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
)
} }
} }

View File

@ -46,7 +46,8 @@ class FolderRepositoryImpl(
override suspend fun getSubfolders(folderId: Long): List<Folder>? = withContext(Dispatchers.IO) { override suspend fun getSubfolders(folderId: Long): List<Folder>? = withContext(Dispatchers.IO) {
jdbcFolderRepository.findByIdOrNull(folderId) 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) { 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) { withContext(Dispatchers.IO) {
val idList = documentIdList.toMutableList() val docIdList = documentIdList.toMutableList()
val folderIds = folderIdList.toMutableList()
val targetFolder = jdbcFolderRepository.findByIdOrNull(targetFolderId) val targetFolder = jdbcFolderRepository.findByIdOrNull(targetFolderId)
targetFolder?.let { targetFolder?.let {
jdbcDocumentRepository.findByIdIn(idList) jdbcDocumentRepository.findByIdIn(docIdList)
.let { .let {
it.forEach { doc -> it.forEach { doc ->
doc.filePath = targetFolder.filePath + File.separator + doc.name doc.filePath = targetFolder.filePath + File.separator + doc.name
@ -77,7 +80,7 @@ class FolderRepositoryImpl(
} }
jdbcDocumentRepository.saveAll(it) jdbcDocumentRepository.saveAll(it)
} }
jdbcFolderRepository.findByIdIn(idList) jdbcFolderRepository.findByIdIn(folderIds)
.let { .let {
it.forEach { doc -> it.forEach { doc ->
doc.filePath = targetFolder.filePath + File.separator + doc.name doc.filePath = targetFolder.filePath + File.separator + doc.name

View File

@ -1,5 +1,5 @@
server: server:
port: 7891 port: 8080
spring: spring:
application: application: