Skip to content

Commit 1020a59

Browse files
committed
feat: 部门
1 parent 0d4e5ac commit 1020a59

File tree

9 files changed

+562
-1
lines changed

9 files changed

+562
-1
lines changed

nestjs-mysql-api.sql

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CREATE TABLE `tenant` (
2424
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商户表';
2525

2626
-- ----------------------------
27-
-- 角色表(也可以当部门表)
27+
-- 角色表
2828
-- ----------------------------
2929
DROP TABLE IF EXISTS `role`;
3030
CREATE TABLE `role` (
@@ -42,6 +42,27 @@ CREATE TABLE `role` (
4242
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表(也可以当部门表)';
4343

4444

45+
-- ----------------------------
46+
-- 部门表
47+
-- ----------------------------
48+
DROP TABLE IF EXISTS `department`;
49+
CREATE TABLE `department` (
50+
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY key COMMENT '主键id',
51+
`title` varchar(50) NOT NULL COMMENT '部门名称',
52+
`name` varchar(50) DEFAULT NULL COMMENT '部门负责人',
53+
`mobile` varchar(50) DEFAULT NULL COMMENT '联系手机号码',
54+
`email` varchar(50) DEFAULT NULL COMMENT '电邮地址',
55+
`description` varchar(255) DEFAULT NULL COMMENT '描述',
56+
`status` tinyint(4) DEFAULT 0 COMMENT '状态0是正常,1是禁用',
57+
`sort` int(11) DEFAULT 1 COMMENT '排序',
58+
`tenant_id` int(11) default -1 COMMENT '关联到tenant表主键id',
59+
`parent_id` int(11) default -1 COMMENT '自己关联主键id',
60+
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
61+
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
62+
`deleted_at` timestamp NULL DEFAULT NULL COMMENT '软删除时间',
63+
UNIQUE KEY `UK_title_parent_id_deleted_at` (`title`,`parent_id`,`deleted_at`)
64+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='部门表';
65+
4566
-- ----------------------------
4667
-- 商户下账号表
4768
-- ----------------------------
@@ -53,6 +74,7 @@ CREATE TABLE `account` (
5374
`account_type` tinyint(4) DEFAULT 0 COMMENT '账号类型:0普通账号,1是主账号,2是超管',
5475
`tenant_id` int(11) NOT NULL COMMENT '关联到tenant表主键id',
5576
`parent_id` int(11) default "-1" COMMENT '自关联主键id',
77+
`department_id` int(11) default "-1" COMMENT '部门名称',
5678
`sort` int(11) DEFAULT 1 COMMENT '排序',
5779
`status` tinyint(4) DEFAULT 0 COMMENT '状态0是正常,1是禁用',
5880
`last_login_ip` varchar(30) COMMENT '最后登录ip地址',

src/api/api.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LoginModule } from './login/login.module';
88
import { MenusModule } from './menus/menus.module';
99
import { ResourcesModule } from './resources/resources.module';
1010
import { RoleResourcesModule } from './roleResources/role.resources.module';
11+
import { DepartmentModule } from './department/department.module';
1112

1213
@Module({
1314
imports: [
@@ -20,6 +21,7 @@ import { RoleResourcesModule } from './roleResources/role.resources.module';
2021
MenusModule,
2122
ResourcesModule,
2223
RoleResourcesModule,
24+
DepartmentModule,
2325
],
2426
})
2527
export class ApiModule {}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import {
2+
Controller,
3+
Delete,
4+
Get,
5+
Post,
6+
Put,
7+
Body,
8+
Param,
9+
ParseIntPipe,
10+
Query,
11+
} from '@nestjs/common';
12+
import { DepartmentService } from './department.service';
13+
import { DepartmentDto } from './dto/department.dto';
14+
import { CurrentUser, ICurrentUserType } from '@src/decorators';
15+
import { DepartmentPageVo, DepartmentVo } from './vo/department.vo';
16+
import { QueryDepartmentDto } from './dto/department.query';
17+
18+
@Controller('department')
19+
export class DepartmentController {
20+
constructor(private readonly departmentService: DepartmentService) {}
21+
22+
@Post()
23+
async createDepartmentApi(
24+
@Body() req: DepartmentDto,
25+
@CurrentUser('userInfo') currentUser: ICurrentUserType
26+
): Promise<string> {
27+
return await this.departmentService.createDepartmentApi(req, currentUser);
28+
}
29+
30+
@Delete(':id')
31+
async deleteDepartmentByIdApi(@Param('id', new ParseIntPipe()) id: number): Promise<string> {
32+
return await this.departmentService.deleteDepartmentByIdApi(id);
33+
}
34+
35+
@Put('/status/:id')
36+
async modifyDepartmentStatusByIdApi(
37+
@Param('id', new ParseIntPipe()) id: number
38+
): Promise<string> {
39+
return await this.departmentService.modifyDepartmentStatusByIdApi(id);
40+
}
41+
42+
@Put(':id')
43+
async modifyDepartmentByIdApi(
44+
@Param('id', new ParseIntPipe()) id: number,
45+
@Body() req: DepartmentDto,
46+
@CurrentUser('userInfo') currentUser: ICurrentUserType
47+
): Promise<string> {
48+
return await this.departmentService.modifyDepartmentByIdApi(id, req, currentUser);
49+
}
50+
51+
@Get()
52+
async getDepartmentPageApi(
53+
@Query() queryOption: QueryDepartmentDto,
54+
@CurrentUser('userInfo') currentUser: ICurrentUserType
55+
): Promise<DepartmentPageVo> {
56+
return await this.departmentService.getDepartmentPageApi(queryOption, currentUser);
57+
}
58+
59+
@Get(':id')
60+
async getDepartmentByIdApi(
61+
@Param('id', new ParseIntPipe()) id: number
62+
): Promise<DepartmentVo | undefined> {
63+
return await this.departmentService.getDepartmentByIdApi(id);
64+
}
65+
66+
@Post('delete')
67+
async batchDeleteDepartmentByIdListApi(@Body() idList: number[]): Promise<string> {
68+
return await this.departmentService.batchDeleteDepartmentByIdListApi(idList);
69+
}
70+
71+
@Post('/batchStatus')
72+
async batchModifyDepartmentStatusByIdApi(@Body() idList: number[]): Promise<string> {
73+
return await this.departmentService.batchModifyDepartmentStatusByIdApi(idList);
74+
}
75+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Module } from '@nestjs/common';
2+
import { RouterModule } from '@nestjs/core';
3+
import { TypeOrmModule } from '@nestjs/typeorm';
4+
import { ADMIN_PREFIX } from '@src/constants';
5+
import { TenantEntity } from '../tenant/entities/tenant.entity';
6+
import { DepartmentController } from './department.controller';
7+
import { DepartmentService } from './department.service';
8+
import { DepartmentEntity } from './entities/department.entity';
9+
10+
@Module({
11+
imports: [
12+
RouterModule.register([
13+
{
14+
path: ADMIN_PREFIX, // 指定项目名称
15+
module: DepartmentModule,
16+
},
17+
]),
18+
TypeOrmModule.forFeature([DepartmentEntity, TenantEntity]),
19+
],
20+
controllers: [DepartmentController],
21+
providers: [DepartmentService],
22+
})
23+
export class DepartmentModule {}

0 commit comments

Comments
 (0)