forked from wangziqi/gongxue-base
fix: release beds/lockers in batchCheckOut
The batchCheckOut method was not releasing assigned beds and lockers after checkout, leaving them orphaned as 'occupied'. Added the same release pattern used in checkOut() — using runner.manager.update() since batchCheckOut operates inside a QueryRunner transaction.
This commit is contained in:
@@ -35,6 +35,13 @@ export class DepartmentsController {
|
||||
return this.departmentsService.findTree();
|
||||
}
|
||||
|
||||
/** 获取钉钉同步的部门树,供"从部门创建班级"使用 */
|
||||
@Get('synced')
|
||||
@RequirePermission('department:view')
|
||||
findSyncedTree() {
|
||||
return this.departmentsService.findSyncedTree();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@RequirePermission('department:view')
|
||||
findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
|
||||
@@ -52,6 +52,35 @@ export class DepartmentsService {
|
||||
return roots;
|
||||
}
|
||||
|
||||
/** 获取钉钉同步的部门树(只返回 source='dingtalk' 的部门) */
|
||||
async findSyncedTree(): Promise<Department[]> {
|
||||
const all = await this.deptRepo.find({
|
||||
where: { status: 'active', source: 'dingtalk' },
|
||||
order: { sortOrder: 'ASC', name: 'ASC' },
|
||||
});
|
||||
|
||||
const byParent = new Map<number | null, Department[]>();
|
||||
for (const dept of all) {
|
||||
const key = dept.parentId ?? null;
|
||||
const list = byParent.get(key);
|
||||
if (list) {
|
||||
list.push(dept);
|
||||
} else {
|
||||
byParent.set(key, [dept]);
|
||||
}
|
||||
}
|
||||
|
||||
const attachChildren = (dept: Department): void => {
|
||||
const children = byParent.get(dept.id) ?? [];
|
||||
dept.children = children;
|
||||
for (const child of children) attachChildren(child);
|
||||
};
|
||||
|
||||
const roots = byParent.get(null) ?? [];
|
||||
for (const root of roots) attachChildren(root);
|
||||
return roots;
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<Department> {
|
||||
const dept = await this.deptRepo.findOne({ where: { id } });
|
||||
if (!dept) throw new NotFoundException('部门不存在');
|
||||
|
||||
Reference in New Issue
Block a user