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:
@@ -85,6 +85,42 @@ export class ClassesController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 从钉钉同步部门创建班级 */
|
||||
@Post('from-department')
|
||||
@RequirePermission('class:create')
|
||||
async createFromDepartment(
|
||||
@Body() dto: { departmentId: number; name?: string; classType?: string },
|
||||
@Request() req: any,
|
||||
) {
|
||||
const result = await this.service.createFromDepartment(dto);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '班级管理',
|
||||
action: '从部门创建班级',
|
||||
targetId: result.id,
|
||||
targetType: 'class',
|
||||
detail: `班级${result.code} ${result.name}`,
|
||||
ipAddress: extractRequestInfo(req).ipAddress,
|
||||
userAgent: extractRequestInfo(req).userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 归档班级 */
|
||||
@Put(':id/archive')
|
||||
@RequirePermission('class:edit')
|
||||
async archive(@Param('id') id: string) {
|
||||
return this.service.archive(+id);
|
||||
}
|
||||
|
||||
/** 取消归档 */
|
||||
@Put(':id/restore')
|
||||
@RequirePermission('class:edit')
|
||||
async restore(@Param('id') id: string) {
|
||||
return this.service.restore(+id);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@RequirePermission('class:edit')
|
||||
async update(
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CommonModule } from '../common/common.module';
|
||||
import { Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord } from '../entities';
|
||||
import { Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord, Department } from '../entities';
|
||||
import { ClassesService } from './classes.service';
|
||||
import { ClassesController } from './classes.controller';
|
||||
import { OperationLogsModule } from '../operation-logs/operation-logs.module';
|
||||
import { NotificationsModule } from '../notifications/notifications.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord]), OperationLogsModule, NotificationsModule, CommonModule],
|
||||
imports: [TypeOrmModule.forFeature([Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord, Department]), OperationLogsModule, NotificationsModule, CommonModule],
|
||||
controllers: [ClassesController],
|
||||
providers: [ClassesService],
|
||||
exports: [ClassesService],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, In, Like } from 'typeorm';
|
||||
import { Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord, Classroom } from '../entities';
|
||||
import { Class, ClassStudent, ClassTeacher, ClassSchedule, AttendanceRecord, Department, Classroom } from '../entities';
|
||||
import { CreateClassDto, UpdateClassDto, QueryClassDto, AddTeacherDto, QueryClassScheduleDto, QueryClassAttendanceSummaryDto } from './dto/class.dto';
|
||||
import { CampusScope } from '../common/campus-scope';
|
||||
|
||||
@@ -23,6 +23,8 @@ export class ClassesService {
|
||||
private scheduleRepo: Repository<ClassSchedule>,
|
||||
@InjectRepository(AttendanceRecord)
|
||||
private attendanceRepo: Repository<AttendanceRecord>,
|
||||
@InjectRepository(Department)
|
||||
private deptRepo: Repository<Department>,
|
||||
private readonly scope: CampusScope,
|
||||
) {}
|
||||
|
||||
@@ -32,6 +34,8 @@ export class ClassesService {
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.classType) where.classType = query.classType;
|
||||
if (query.keyword) where.name = Like(`%${query.keyword}%`);
|
||||
// Default: hide archived, unless explicitly requested
|
||||
where.isArchived = query.isArchived ?? false;
|
||||
where = await this.scope.filter(where);
|
||||
|
||||
const classes = await this.classRepo.find({
|
||||
@@ -126,13 +130,58 @@ export class ClassesService {
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
/** 归档班级(软删除) */
|
||||
async archive(id: number) {
|
||||
const cls = await this.classRepo.findOne({ where: { id } });
|
||||
if (!cls) throw new NotFoundException('班级不存在');
|
||||
await this.classRepo.update(id, { isArchived: true });
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
/** 取消归档 */
|
||||
async restore(id: number) {
|
||||
const cls = await this.classRepo.findOne({ where: { id } });
|
||||
if (!cls) throw new NotFoundException('班级不存在');
|
||||
await this.classRepo.update(id, { isArchived: false });
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
/** 物理删除班级(已归档的才能删除) */
|
||||
async remove(id: number) {
|
||||
const cls = await this.classRepo.findOne({ where: { id } });
|
||||
if (!cls) throw new NotFoundException('班级不存在');
|
||||
if (!cls.isArchived) throw new BadRequestException('请先归档再删除');
|
||||
await this.classRepo.remove(cls);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
async createFromDepartment(dto: { departmentId: number; name?: string; classType?: string }) {
|
||||
const dept = await this.deptRepo.findOne({
|
||||
where: { id: dto.departmentId, source: 'dingtalk' },
|
||||
});
|
||||
|
||||
if (!dept) {
|
||||
throw new BadRequestException('所选部门不存在或非钉钉同步部门');
|
||||
}
|
||||
|
||||
const className = dto.name || dept.name;
|
||||
const code = `DT_${dto.departmentId}`;
|
||||
|
||||
const existing = await this.classRepo.findOne({ where: { code } });
|
||||
if (existing) {
|
||||
throw new BadRequestException(`班级"${className}"已存在(编码: ${code})`);
|
||||
}
|
||||
|
||||
const cls = this.classRepo.create({
|
||||
name: className,
|
||||
code,
|
||||
departmentId: dto.departmentId,
|
||||
classType: dto.classType || 'culture',
|
||||
status: 'enrolling',
|
||||
});
|
||||
return this.classRepo.save(cls);
|
||||
}
|
||||
|
||||
async getStudents(classId: number) {
|
||||
return this.classStudentRepo.find({
|
||||
where: { classId },
|
||||
|
||||
@@ -98,6 +98,10 @@ export class QueryClassDto {
|
||||
|
||||
@IsOptional() @IsString()
|
||||
keyword?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Boolean)
|
||||
isArchived?: boolean;
|
||||
}
|
||||
|
||||
export class AddStudentsDto {
|
||||
|
||||
Reference in New Issue
Block a user