refactor: delete remain of department and users

This commit is contained in:
SOR
2026-08-09 16:12:06 +08:00
parent d6e8390ed6
commit 091684357d
8 changed files with 9 additions and 173 deletions
@@ -1,29 +0,0 @@
package club.itstudio.itmanager.controller.v1
import club.itstudio.itmanager.utils.Const
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import reactor.core.publisher.Mono
@Validated
@RestController
@RequestMapping("/api/v1/departments")
class DepartmentsController {
// departments/ GET/POST/PUT/DELETE 部门 CRUD 操作
@GetMapping("", "/")
fun getDepartments(): Mono<String> = Const.INTERNAL_ERROR_MONO
@PostMapping("", "/")
fun createDepartment(): Mono<String> = Const.INTERNAL_ERROR_MONO
@PutMapping("", "/")
fun updateDepartment(): Mono<String> = Const.INTERNAL_ERROR_MONO
@DeleteMapping("", "/")
fun deleteDepartment(@RequestParam(required = false) id: String?): Mono<String> = Const.INTERNAL_ERROR_MONO
// departments/{id}/ DELETE 删除部门(发送邮件通知)
@DeleteMapping("/{id}", "/{id}/")
fun deleteById(@PathVariable("id") id: String): Mono<String> = Const.INTERNAL_ERROR_MONO
}
@@ -1,18 +0,0 @@
package club.itstudio.itmanager.controller.v1
import club.itstudio.itmanager.utils.Const
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono
@Validated
@RestController
@RequestMapping("/api/v1/users")
class UsersController {
// users/ GET 获取用户列表(只读)
@GetMapping("", "/")
fun getUsers(): Mono<String> = Const.INTERNAL_ERROR_MONO
}
@@ -1,21 +0,0 @@
package club.itstudio.itmanager.entity.dto
import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import club.itstudio.itmanager.entity.DataCopy
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.Serializable
@Serializable
@TableName("departments")
data class Department(
@TableId(type = IdType.AUTO)
val id: Long? = null,
val name: String = "",
val code: String? = null,
val parentId: Long? = null,
val description: String? = null,
val createdAt: LocalDateTime? = null,
val updatedAt: LocalDateTime? = null
) : DataCopy
@@ -1,8 +0,0 @@
package club.itstudio.itmanager.mapper
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import club.itstudio.itmanager.entity.dto.Department
import org.apache.ibatis.annotations.Mapper
@Mapper
interface DepartmentMapper : BaseMapper<Department>
@@ -1,15 +0,0 @@
package club.itstudio.itmanager.service
import com.baomidou.mybatisplus.extension.service.IService
import club.itstudio.itmanager.entity.dto.Department
import reactor.core.publisher.Mono
interface DepartmentService : IService<Department> {
fun getDepartmentById(id: Long): Mono<Department>
fun listAllDepartments(): Mono<List<Department>>
fun listByParentId(parentId: Long): Mono<List<Department>>
fun createDepartment(department: Department): Mono<Boolean>
fun updateDepartment(department: Department): Mono<Boolean>
fun deleteDepartment(id: Long): Mono<Boolean>
fun exportAllDepartments(): Mono<List<Department>>
}
@@ -1,62 +0,0 @@
package club.itstudio.itmanager.service.impl
import club.itstudio.itmanager.entity.dto.Department
import club.itstudio.itmanager.mapper.DepartmentMapper
import club.itstudio.itmanager.service.DepartmentService
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers
import java.util.NoSuchElementException
@Service
class DepartmentServiceImpl : ServiceImpl<DepartmentMapper, Department>(), DepartmentService {
private val logger = LoggerFactory.getLogger(this::class.java)
private fun <T : Any> blockingCall(block: () -> T?): Mono<T> =
Mono.fromCallable(block).subscribeOn(Schedulers.boundedElastic())
override fun getDepartmentById(id: Long): Mono<Department> =
blockingCall {
logger.info("Searching department by id")
ktQuery().eq(Department::id, id).one()
}.switchIfEmpty(Mono.error(NoSuchElementException("Department not found")))
override fun listAllDepartments(): Mono<List<Department>> =
blockingCall {
logger.info("Listing all departments")
list()
}
override fun listByParentId(parentId: Long): Mono<List<Department>> =
blockingCall {
logger.info("Searching departments by parent id")
ktQuery().eq(Department::parentId, parentId).list()
}
override fun createDepartment(department: Department): Mono<Boolean> =
blockingCall {
logger.info("Creating department")
save(department)
}
override fun updateDepartment(department: Department): Mono<Boolean> =
blockingCall {
logger.info("Updating department")
updateById(department)
}
override fun deleteDepartment(id: Long): Mono<Boolean> =
blockingCall {
logger.info("Deleting department by id")
removeById(id)
}
override fun exportAllDepartments(): Mono<List<Department>> =
blockingCall {
logger.info("Exporting all departments")
list()
}
}