feat: 恭学教育基地管理系统初始提交

- 后端: NestJS 11 + TypeORM + JWT认证 + SQLite/MySQL
- 前端: React 19 + Ant Design 6 + Vite 8 + ECharts
- 功能模块: 数据面板、学生管理、宿舍管理、入住管理、费用录入、账单管理、教室管理、押金管理、操作日志、账号管理
- 支持Docker一键部署
This commit is contained in:
陈浩
2026-06-06 17:26:10 +08:00
commit 78676a124a
123 changed files with 26403 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { IsOptional, IsString, IsNotEmpty, IsEnum } from 'class-validator';
export class CreateTenantDto {
@IsString()
@IsNotEmpty()
name: string;
@IsOptional()
@IsString()
contact?: string;
@IsOptional()
@IsString()
phone?: string;
@IsOptional()
@IsString()
color?: string;
@IsOptional()
@IsString()
notes?: string;
}
export class UpdateTenantDto {
@IsOptional()
@IsString()
name?: string;
@IsOptional()
@IsString()
contact?: string;
@IsOptional()
@IsString()
phone?: string;
@IsOptional()
@IsString()
color?: string;
@IsOptional()
@IsString()
notes?: string;
@IsOptional()
@IsEnum(['active', 'archived'])
status?: string;
}

View File

@@ -0,0 +1,46 @@
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards, Request } from '@nestjs/common';
import { TenantsService } from './tenants.service';
import { CreateTenantDto, UpdateTenantDto } from './dto/tenant.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { OperationLogsService } from '../operation-logs/operation-logs.service';
import { extractRequestInfo } from '../common/request-utils';
@UseGuards(JwtAuthGuard)
@Controller('tenants')
export class TenantsController {
constructor(private service: TenantsService, private logService: OperationLogsService) {}
@Get()
findAll(@Query('includeArchived') includeArchived?: string) {
return this.service.findAll({ includeArchived: includeArchived === 'true' });
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.service.findOne(+id);
}
@Post()
async create(@Body() dto: CreateTenantDto, @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: 'tenant', detail: dto.name, ipAddress, userAgent });
return result;
}
@Put(':id')
async update(@Param('id') id: string, @Body() dto: UpdateTenantDto, @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: 'tenant', detail: JSON.stringify(dto), ipAddress, userAgent });
return result;
}
@Delete(':id')
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: 'tenant', ipAddress, userAgent });
return result;
}
}

View File

@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Tenant } from '../entities/tenant.entity';
import { TenantsService } from './tenants.service';
import { TenantsController } from './tenants.controller';
import { OperationLogsModule } from '../operation-logs/operation-logs.module';
@Module({
imports: [TypeOrmModule.forFeature([Tenant]), OperationLogsModule],
controllers: [TenantsController],
providers: [TenantsService],
exports: [TenantsService],
})
export class TenantsModule {}

View File

@@ -0,0 +1,50 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Not } from 'typeorm';
import { Tenant } from '../entities/tenant.entity';
import { CreateTenantDto, UpdateTenantDto } from './dto/tenant.dto';
// 预设色板(避开红绿盲敏感色,保证差异度)
const COLOR_PALETTE = [
'#ff7875', '#ffa940', '#ffc53d', '#73d13d', '#36cfc9',
'#40a9ff', '#597ef7', '#9254de', '#f759ab', '#8c8c8c',
];
@Injectable()
export class TenantsService {
constructor(@InjectRepository(Tenant) private repo: Repository<Tenant>) {}
async findAll(query?: { includeArchived?: boolean }) {
const where: any = {};
if (!query?.includeArchived) where.status = Not('archived');
return this.repo.find({ where, order: { createdAt: 'DESC' } });
}
async findOne(id: number) {
const tenant = await this.repo.findOne({ where: { id } });
if (!tenant) throw new NotFoundException('租赁方不存在');
return tenant;
}
async create(dto: CreateTenantDto) {
// 颜色未指定则自动分配(按当前租赁方数量取模)
let color = dto.color;
if (!color) {
const total = await this.repo.count();
color = COLOR_PALETTE[total % COLOR_PALETTE.length];
}
return this.repo.save(this.repo.create({ ...dto, color }));
}
async update(id: number, dto: UpdateTenantDto) {
await this.findOne(id);
await this.repo.update(id, dto);
return this.repo.findOne({ where: { id } });
}
async remove(id: number) {
await this.findOne(id);
await this.repo.update(id, { status: 'archived' });
return { message: '已归档' };
}
}