forked from ITStudio_OUC/itstudio_manager
refactor: delete remain of department and users
This commit is contained in:
@@ -15,10 +15,18 @@
|
||||
- /ask-code
|
||||
- /register
|
||||
- /reset
|
||||
- /departments
|
||||
- /email
|
||||
- /finance
|
||||
- /items
|
||||
- /
|
||||
- /{id}/upload_images
|
||||
- /{id}/set_primary_image
|
||||
- /{id}/borrow
|
||||
- /{id}/return_item
|
||||
- /available
|
||||
- /in_use
|
||||
- /categories
|
||||
- /images
|
||||
- /proof-images
|
||||
- /usages
|
||||
|
||||
@@ -53,8 +61,6 @@
|
||||
| `finance/` | GET/POST/PUT/DELETE | 财务记录 CRUD 操作 |
|
||||
| `finance/{id}/upload_images/` | POST | 上传财务凭证图片 |
|
||||
| `finance/{id}/` | DELETE | 删除财务记录(发送邮件通知) |
|
||||
| `departments/` | GET/POST/PUT/DELETE | 部门 CRUD 操作 |
|
||||
| `departments/{id}/` | DELETE | 删除部门(发送邮件通知) |
|
||||
| `finance/categories/`(原 `finance_categories/`) | GET/POST/PUT/DELETE | 财务分类 CRUD 操作 |
|
||||
| `proof-images/` | GET/POST/PUT/DELETE | 财务凭证图片 CRUD 操作 |
|
||||
| `proof-images/{id}/` | DELETE | 删除凭证图片(自动删除物理文件) |
|
||||
@@ -98,8 +104,6 @@ Authorization: Bearer <token>
|
||||
[schema.sql](./schema.sql)
|
||||
|
||||
- users/account (系统用户/认证信息)
|
||||
- departments (组织/部门)
|
||||
- parent_id -> departments.id (自关联父级)
|
||||
- categories (物品类别)
|
||||
- parent_id -> categories.id (自关联父级)
|
||||
- items (物品基本信息)
|
||||
|
||||
-15
@@ -15,21 +15,6 @@ CREATE TABLE account
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci COMMENT ='系统用户/认证信息';
|
||||
|
||||
-- 部门表
|
||||
DROP TABLE IF EXISTS departments;
|
||||
CREATE TABLE departments
|
||||
(
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
code VARCHAR(50),
|
||||
parent_id BIGINT UNSIGNED,
|
||||
description TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT fk_departments_parent FOREIGN KEY (parent_id) REFERENCES departments (id) ON DELETE SET NULL
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4 COMMENT ='组织/部门';
|
||||
|
||||
-- 物品类别
|
||||
DROP TABLE IF EXISTS categories;
|
||||
CREATE TABLE categories
|
||||
|
||||
-29
@@ -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>>
|
||||
}
|
||||
-62
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user