chore: commit oxfmt formatting changes and verify artifacts

This commit is contained in:
2026-07-02 15:55:09 +08:00
parent 34726cc46d
commit 4f4cee157a
77 changed files with 5576 additions and 1400 deletions

View File

@@ -1,4 +1,18 @@
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards, Request, Res, UseInterceptors, UploadedFile } from '@nestjs/common';
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
Query,
UseGuards,
Request,
Res,
UseInterceptors,
UploadedFile,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import type { Response } from 'express';
import { ClassroomsService } from './classrooms.service';
@@ -12,11 +26,18 @@ import * as ExcelJS from 'exceljs';
@UseGuards(JwtAuthGuard)
@Controller('classrooms')
export class ClassroomsController {
constructor(private service: ClassroomsService, private logService: OperationLogsService) {}
constructor(
private service: ClassroomsService,
private logService: OperationLogsService,
) {}
@Get()
@RequirePermission('classroom:view')
findAll(@Query('building') building?: string, @Query('roomType') roomType?: string, @Query('includeArchived') includeArchived?: string) {
findAll(
@Query('building') building?: string,
@Query('roomType') roomType?: string,
@Query('includeArchived') includeArchived?: string,
) {
return this.service.findAll({
building,
roomType,
@@ -40,9 +61,33 @@ export class ClassroomsController {
];
ws.getRow(1).font = { bold: true };
ws.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } };
ws.addRow({ name: 'A201', building: 'A座', floor: 2, roomType: '大', capacity: 60, courseType: '尊享培优班', supervisor: '张老师' });
ws.addRow({ name: 'B301', building: 'B座', floor: 3, roomType: '次大', capacity: 40, courseType: '专业课集训班', supervisor: '李老师' });
ws.addRow({ name: 'B405', building: 'B座', floor: 4, roomType: '小', capacity: 20, courseType: '', supervisor: '' });
ws.addRow({
name: 'A201',
building: 'A座',
floor: 2,
roomType: '大',
capacity: 60,
courseType: '尊享培优班',
supervisor: '张老师',
});
ws.addRow({
name: 'B301',
building: 'B座',
floor: 3,
roomType: '次大',
capacity: 40,
courseType: '专业课集训班',
supervisor: '李老师',
});
ws.addRow({
name: 'B405',
building: 'B座',
floor: 4,
roomType: '小',
capacity: 20,
courseType: '',
supervisor: '',
});
// 说明sheet
const ws2 = workbook.addWorksheet('使用说明');
@@ -56,7 +101,10 @@ export class ClassroomsController {
'5. 负责人为班主任/对接人',
].forEach((note) => ws2.addRow({ note }));
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.setHeader(
'Content-Type',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
);
res.setHeader('Content-Disposition', 'attachment; filename=classroom_template.xlsx');
await workbook.xlsx.write(res);
res.end();
@@ -73,7 +121,17 @@ export class ClassroomsController {
async create(@Body() dto: CreateClassroomDto, @Request() req: any) {
const { ipAddress, userAgent } = extractRequestInfo(req);
const result = await this.service.create(dto);
await this.logService.log({ userId: req.user?.id, username: req.user?.username, module: '教室', action: '新增教室', targetId: result.id, targetType: 'classroom', detail: dto.name, ipAddress, userAgent });
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: '教室',
action: '新增教室',
targetId: result.id,
targetType: 'classroom',
detail: dto.name,
ipAddress,
userAgent,
});
return result;
}
@@ -82,7 +140,17 @@ export class ClassroomsController {
async update(@Param('id') id: string, @Body() dto: UpdateClassroomDto, @Request() req: any) {
const { ipAddress, userAgent } = extractRequestInfo(req);
const result = await this.service.update(+id, dto);
await this.logService.log({ userId: req.user?.id, username: req.user?.username, module: '教室', action: '编辑教室', targetId: +id, targetType: 'classroom', detail: JSON.stringify(dto), ipAddress, userAgent });
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: '教室',
action: '编辑教室',
targetId: +id,
targetType: 'classroom',
detail: JSON.stringify(dto),
ipAddress,
userAgent,
});
return result;
}
@@ -91,7 +159,16 @@ export class ClassroomsController {
async remove(@Param('id') id: string, @Request() req: any) {
const { ipAddress, userAgent } = extractRequestInfo(req);
const result = await this.service.remove(+id);
await this.logService.log({ userId: req.user?.id, username: req.user?.username, module: '教室', action: '归档教室', targetId: +id, targetType: 'classroom', ipAddress, userAgent });
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: '教室',
action: '归档教室',
targetId: +id,
targetType: 'classroom',
ipAddress,
userAgent,
});
return result;
}
@@ -100,7 +177,16 @@ export class ClassroomsController {
async restore(@Param('id') id: string, @Request() req: any) {
const { ipAddress, userAgent } = extractRequestInfo(req);
const result = await this.service.restore(+id);
await this.logService.log({ userId: req.user?.id, username: req.user?.username, module: '教室', action: '恢复教室', targetId: +id, targetType: 'classroom', ipAddress, userAgent });
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: '教室',
action: '恢复教室',
targetId: +id,
targetType: 'classroom',
ipAddress,
userAgent,
});
return result;
}
@@ -126,7 +212,15 @@ export class ClassroomsController {
});
});
const result = await this.service.batchImport(rows);
await this.logService.log({ userId: req.user?.id, username: req.user?.username, module: '教室', action: '批量导入', detail: result.message, ipAddress, userAgent });
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: '教室',
action: '批量导入',
detail: result.message,
ipAddress,
userAgent,
});
return result;
}
}

View File

@@ -54,25 +54,47 @@ export class ClassroomsService {
return { message: '已恢复' };
}
async batchImport(rows: { name: string; building?: string; floor?: number; capacity?: number; roomType?: string; courseType?: string; supervisor?: string }[]) {
async batchImport(
rows: {
name: string;
building?: string;
floor?: number;
capacity?: number;
roomType?: string;
courseType?: string;
supervisor?: string;
}[],
) {
let imported = 0;
let skipped = 0;
for (const row of rows) {
if (!row.name || !row.name.trim()) { skipped++; continue; }
if (!row.name || !row.name.trim()) {
skipped++;
continue;
}
const name = row.name.trim();
const exists = await this.repo.findOne({ where: { name } });
if (exists) { skipped++; continue; }
await this.repo.save(this.repo.create({
name,
building: row.building?.trim() || undefined,
floor: row.floor || undefined,
capacity: row.capacity || 30,
roomType: row.roomType?.trim() || '大',
courseType: row.courseType?.trim() || undefined,
supervisor: row.supervisor?.trim() || undefined,
}));
if (exists) {
skipped++;
continue;
}
await this.repo.save(
this.repo.create({
name,
building: row.building?.trim() || undefined,
floor: row.floor || undefined,
capacity: row.capacity || 30,
roomType: row.roomType?.trim() || '大',
courseType: row.courseType?.trim() || undefined,
supervisor: row.supervisor?.trim() || undefined,
}),
);
imported++;
}
return { message: `成功导入 ${imported} 间教室,跳过 ${skipped} 条(重复或空行)`, imported, skipped };
return {
message: `成功导入 ${imported} 间教室,跳过 ${skipped} 条(重复或空行)`,
imported,
skipped,
};
}
}