完成岗位部门,查岗位和用户关联

main
expressgy 3 months ago
parent dcbe19c36e
commit 1e05f977f6
  1. 2008
      docs/pacAuth_database_0.2.ndm2
  2. 4
      src/application/app.module.ts
  3. 8
      src/application/auth-dept/auth-dept.controller.ts
  4. 46
      src/application/auth-dept/auth-dept.service.ts
  5. 26
      src/application/auth-dept/dto/get-auth-dept.dto.ts
  6. 65
      src/application/auth-post/auth-post.controller.ts
  7. 9
      src/application/auth-post/auth-post.module.ts
  8. 301
      src/application/auth-post/auth-post.service.ts
  9. 80
      src/application/auth-post/dto/create-auth-post.dto.ts
  10. 70
      src/application/auth-post/dto/get-auth-post.dto.ts
  11. 25
      src/application/auth-post/dto/update-auth-post.dto.ts
  12. 1
      src/application/auth-post/entities/auth-post.entity.ts
  13. 6
      src/application/auth-role/auth-role.service.ts
  14. 3
      src/application/auth-role/dto/create-auth-role.dto.ts
  15. 34
      src/application/auth-user/auth-user.controller.ts
  16. 9
      src/application/auth-user/auth-user.module.ts
  17. 26
      src/application/auth-user/auth-user.service.ts
  18. 1
      src/application/auth-user/dto/create-auth-user.dto.ts
  19. 4
      src/application/auth-user/dto/update-auth-user.dto.ts
  20. 1
      src/application/auth-user/entities/auth-user.entity.ts
  21. 9
      src/application/core-dict/core-dict.service.ts
  22. 9
      src/application/core-env/core-env.service.ts
  23. 5
      src/entities/relations.ts
  24. 10
      src/entities/schema.ts

File diff suppressed because it is too large Load Diff

@ -16,6 +16,8 @@ import { CoreEnvModule } from './core-env/core-env.module';
import { CoreMenuModule } from './core-menu/core-menu.module';
import { AuthRoleModule } from './auth-role/auth-role.module';
import { AuthDeptModule } from './auth-dept/auth-dept.module';
import { AuthPostModule } from './auth-post/auth-post.module';
import { AuthUserModule } from './auth-user/auth-user.module';
@Module({
imports: [
@ -31,6 +33,8 @@ import { AuthDeptModule } from './auth-dept/auth-dept.module';
CoreMenuModule,
AuthRoleModule,
AuthDeptModule,
AuthPostModule,
AuthUserModule,
],
controllers: [AppController],
providers: [

@ -6,10 +6,8 @@ import { ApiOperation, ApiProduces, ApiTags } from '@nestjs/swagger';
import { PacInfo } from '@common/decorator/pac-info/pac-info.decorator';
import { PacInfoType } from '@utils/myType';
import { GetAuthDeptDto } from '@app/auth-dept/dto/get-auth-dept.dto';
import {
GetUserForAttDto
} from "@dto/GetUserForAtt.dto";
import {DeptLinkUserDto} from "@dto/AttLinkUser.dto";
import { GetUserForAttDto } from '@dto/GetUserForAtt.dto';
import { DeptLinkUserDto } from '@dto/AttLinkUser.dto';
@ApiTags('部门服务')
@Controller('authDept')
@ -82,7 +80,7 @@ export class AuthDeptController {
})
@ApiProduces('application/json')
@Get('/user/:pid')
findUser(@Param('pid') pid: string,@Query() getUserForAttDto: GetUserForAttDto) {
findUser(@Param('pid') pid: string, @Query() getUserForAttDto: GetUserForAttDto) {
return this.authDeptService.findUser(pid, getUserForAttDto);
}

@ -15,9 +15,7 @@ import { likeQuery } from '@utils/likeQuery';
import { alias, QueryBuilder } from 'drizzle-orm/mysql-core';
import { customDrizzleRowWithRecursive } from '@utils/customDrizzleRowWithRecursive';
import { GetUserForAttDto } from '@dto/GetUserForAtt.dto';
import {
DeptLinkUserDto
} from "@dto/AttLinkUser.dto";
import { DeptLinkUserDto } from '@dto/AttLinkUser.dto';
@Injectable()
export class AuthDeptService {
@ -154,7 +152,40 @@ export class AuthDeptService {
* DATE: 2024-06-28 11:30:50 -
* */
public async update(id: string, updateAuthDeptDto: UpdateAuthDeptDto, pacInfo: PacInfoType) {
return this.updateDept(id, updateAuthDeptDto, pacInfo.userId);
// ! 获取部门信息
const dept = await this.getDeptForDeptId(id);
// ? 不存在部门?
if (dept.length > 0) throw new HttpException('未找到目标部门信息,无法修改!', HttpStatus.BAD_REQUEST);
const pid = dept[0].pid;
// ! 加目标锁,同级,而不是全局
const lock = await this.redisService.distributedLock('DEPT' + updateAuthDeptDto.pid + '-' + updateAuthDeptDto.deptName, updateAuthDeptDto.deptName);
// ? 存在正在进行写入的部门
if (!lock) throw new HttpException('服务繁忙,部门名称重复!', HttpStatus.CONFLICT);
try {
// ! 同级查重
const result = await this.checkRepeatForDeptName(updateAuthDeptDto.deptName, updateAuthDeptDto.pid);
// ? 是否存在重复的部门
if (result.length > 0 && result[0].id != id) throw new HttpException('部门名称重复!', HttpStatus.CONFLICT);
// ! 解锁
lock();
// ! 返回结果
return await this.updateDept(id, updateAuthDeptDto, pacInfo.userId);
} catch (e) {
// ! 解锁
lock();
// ! 抛出错误
throw e;
}
}
/** Service
@ -196,7 +227,9 @@ export class AuthDeptService {
// DB 同级查重
private checkRepeatForDeptName(deptName: string, pid: string) {
return this.mysqlService.db
.select()
.select({
id: pacAuthDept.deptId,
})
.from(pacAuthDept)
.where(and(isNull(pacAuthDept.deleteby), eq(pacAuthDept.pid, pid), eq(pacAuthDept.deptName, deptName)));
}
@ -320,8 +353,6 @@ export class AuthDeptService {
// DB 查树
private getRoleTree(pid: string = '0') {
console.log(pid);
// ! 基础层级
const baseQueryBuilder = new QueryBuilder();
const baseQuery = baseQueryBuilder
@ -468,7 +499,6 @@ export class AuthDeptService {
// DB 查找部门下的账户
private async getDeptUser(deptId: string, getUserForAttDto: GetUserForAttDto) {
console.log(getUserForAttDto);
const offset = (getUserForAttDto.pageNumber - 1) * getUserForAttDto.pageSize;
// ! 使用基础查询构建查询总记录数

@ -20,7 +20,7 @@ import Int from '@common/decorator/int/int.descrator';
export class GetAuthDeptDto extends GetDto {
@ApiProperty({
description: '角色',
description: '部门',
type: String,
example: '管理员',
required: false,
@ -28,13 +28,13 @@ export class GetAuthDeptDto extends GetDto {
maxLength: 128,
})
@Trim()
@IsString({ message: '角色信息应为字符串格式!' })
@Length(0, 128, { message: '请将角色信息长度控制在1到128位之间!' })
@IsString({ message: '部门信息应为字符串格式!' })
@Length(0, 128, { message: '请将部门信息长度控制在1到128位之间!' })
@IsOptional()
readonly deptInfo?: string;
@ApiProperty({
description: '角色类型,来自于字典',
description: '部门类型,来自于字典',
type: String,
example: '0',
required: false,
@ -42,13 +42,13 @@ export class GetAuthDeptDto extends GetDto {
maxLength: 19,
})
@Trim()
@IsString({ message: '角色类型格式不正确!' })
@Length(19, 19, { message: '角色类型格式不正确!' })
@IsString({ message: '部门类型格式不正确!' })
@Length(19, 19, { message: '部门类型格式不正确!' })
@IsOptional()
readonly deptType: string;
@ApiProperty({
description: '角色状态',
description: '部门状态',
type: Number,
example: 0,
required: false,
@ -58,19 +58,19 @@ export class GetAuthDeptDto extends GetDto {
@Trim()
@Int()
@IsInt({
message: '角色状态必须是整数!',
message: '部门状态必须是整数!',
})
@Min(-100, {
message: '角色状态需要大于-100!',
message: '部门状态需要大于-100!',
})
@Max(100, {
message: '角色状态不能超过100',
message: '部门状态不能超过100',
})
@IsOptional()
readonly status?: string;
@ApiProperty({
description: '角色层级id',
description: '部门层级id',
type: Number,
example: 0,
required: false,
@ -78,8 +78,8 @@ export class GetAuthDeptDto extends GetDto {
maximum: 100,
})
@Trim()
@IsString({ message: '角色层级id应为字符串格式!' })
@Length(1, 20, { message: '角色层级id格式错误!' })
@IsString({ message: '部门层级id应为字符串格式!' })
@Length(1, 20, { message: '部门层级id格式错误!' })
@IsOptional()
readonly hierarchy?: string;
}

@ -0,0 +1,65 @@
import {Controller, Get, Post, Body, Patch, Param, Delete, Query} from '@nestjs/common';
import { AuthPostService } from './auth-post.service';
import { CreateAuthPostDto } from './dto/create-auth-post.dto';
import { UpdateAuthPostDto } from './dto/update-auth-post.dto';
import { ApiOperation, ApiProduces, ApiTags } from '@nestjs/swagger';
import { PacInfo } from '@common/decorator/pac-info/pac-info.decorator';
import { PacInfoType } from '@utils/myType';
import {GetAuthPostDto} from "@app/auth-post/dto/get-auth-post.dto";
@ApiTags('岗位服务')
@Controller('authPost')
export class AuthPostController {
constructor(private readonly authPostService: AuthPostService) {}
@ApiOperation({
summary: '添加岗位',
description: '岗位',
})
@ApiProduces('application/json')
@Post()
@Post()
create(@Body() createAuthPostDto: CreateAuthPostDto, @PacInfo() pacInfo: PacInfoType) {
return this.authPostService.create(createAuthPostDto, pacInfo);
}
@ApiOperation({
summary: '获取岗位列表',
description: '查询岗位分页或者列表',
})
@ApiProduces('application/json')
@Get()
findAll(@Query() getAuthPostDto: GetAuthPostDto) {
return this.authPostService.findAll(getAuthPostDto);
}
@ApiOperation({
summary: '获取岗位详细信息',
description: '查询岗位详细信息,目录菜单列表,数据权限范围',
})
@ApiProduces('application/json')
@Get(':id')
findOne(@Param('id') id: string) {
return this.authPostService.findOne(id);
}
@ApiOperation({
summary: '更新岗位信息',
description: '更新岗位信息',
})
@ApiProduces('application/json')
@Patch(':id')
update(@Param('id') id: string, @Body() updateAuthPostDto: UpdateAuthPostDto, @PacInfo() pacInfo: PacInfoType) {
return this.authPostService.update(id, updateAuthPostDto, pacInfo);
}
@ApiOperation({
summary: '删除目标岗位',
description: '删除目标岗位信息',
})
@ApiProduces('application/json')
@Delete(':id')
remove(@Param('id') id: string, @PacInfo() pacInfo: PacInfoType) {
return this.authPostService.remove(id, pacInfo);
}
}

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AuthPostService } from './auth-post.service';
import { AuthPostController } from './auth-post.controller';
@Module({
controllers: [AuthPostController],
providers: [AuthPostService],
})
export class AuthPostModule {}

@ -0,0 +1,301 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateAuthPostDto } from './dto/create-auth-post.dto';
import { UpdateAuthPostDto } from './dto/update-auth-post.dto';
import { LoggerService } from '@service/logger/logger.service';
import { MysqlService } from '@common/service/mysql/mysql.service';
import { RedisService } from '@common/service/redis/redis.service';
import { Snowflake } from '@service/snowflake/snowflake.service';
import { ConfigService } from '@nestjs/config';
import {pacAuthDept, pacAuthPost, pacAuthUser, pacCoreDict} from '@entities/schema';
import { and, asc, desc, eq, isNull, like, or, sql } from 'drizzle-orm';
import { PacInfoType } from '@utils/myType';
import { isExistKey, isTrueEnum } from '@utils/boolean.enum';
import { GetAuthPostDto } from '@app/auth-post/dto/get-auth-post.dto';
import { likeQuery } from '@utils/likeQuery';
import { alias } from 'drizzle-orm/mysql-core';
@Injectable()
export class AuthPostService {
// 分页数据格式
private readonly postPageType = {
postId: pacAuthPost.postId,
postKey: pacAuthPost.postKey,
postName: pacAuthPost.postName,
postType: pacAuthPost.postType,
postTypeName: pacCoreDict.dictName,
postTypeKey: pacCoreDict.dictKey,
postDesc: pacAuthPost.postDesc,
orderNum: pacAuthPost.orderNum,
status: pacAuthPost.status,
createby: pacAuthPost.createby,
createtime: pacAuthPost.createtime,
updateby: pacAuthPost.updateby,
updatetime: pacAuthPost.updatetime,
};
// 列表数据格式
private readonly postListType = {
postId: pacAuthPost.postId,
postKey: pacAuthPost.postKey,
postName: pacAuthPost.postName,
postType: pacAuthPost.postType,
postTypeName: pacCoreDict.dictName,
postTypeKey: pacCoreDict.dictKey,
orderNum: pacAuthPost.orderNum,
};
constructor(
private readonly logger: LoggerService,
private readonly mysqlService: MysqlService,
private readonly redisService: RedisService,
private readonly snowflake: Snowflake,
private readonly config: ConfigService,
) {}
/** Service
* NAME: create
* DESC: 创建岗位信息
* DATE: 2024-06-29 13:13:44 -
* */
public async create(createAuthPostDto: CreateAuthPostDto, pacInfo: PacInfoType) {
// ! 加目标锁,同级,而不是全局
const lock = await this.redisService.distributedLock('POST' + createAuthPostDto.postKey, createAuthPostDto.postKey);
// ? 存在正在进行写入的岗位
if (!lock) throw new HttpException('服务繁忙,岗位名称重复!', HttpStatus.CONFLICT);
// @ 核心逻辑
try {
// ! 查重
const result = await this.checkRepeatForPostKey(createAuthPostDto.postKey);
// ? 是否存在重复的岗位
if (result.length > 0) throw new HttpException('岗位标识重复!', HttpStatus.CONFLICT);
// ! 添加岗位数据
const newPacCoreDict = await this.addPost(createAuthPostDto, pacInfo.userId as any);
// ! 解锁
lock();
// ! 返回结果
return newPacCoreDict;
} catch (e) {
// ! 解锁
lock();
// ! 抛出错误
throw e;
}
}
/** Service
* NAME: findAll
* DESC: 获取岗位分页/
* DATE: 2024-06-29 13:13:47 -
* */
public async findAll(getAuthPostDto: GetAuthPostDto) {
if (isTrueEnum(getAuthPostDto['isList'])) {
return await this.getList(getAuthPostDto);
} else {
return await this.getPage(getAuthPostDto);
}
}
/** Service
* NAME: findOne
* DESC: 获取岗位详细信息
* DATE: 2024-06-29 13:13:49 -
* */
public findOne(id: string) {
return `This action returns a #${id} authPost`;
}
/** Service
* NAME: update
* DESC: 更新岗位信息
* DATE: 2024-06-29 13:13:52 -
* */
public async update(id: string, updateAuthPostDto: UpdateAuthPostDto, pacInfo: PacInfoType) {
return await this.updatePost(id, updateAuthPostDto, pacInfo.userId as any);
}
/** Service
* NAME: remove
* DESC: 删除岗位信息
* DATE: 2024-06-29 13:13:55 -
* */
public remove(id: string, pacInfo: PacInfoType) {
return this.deletePost(id, pacInfo.userId as any);
}
// DB 查重Key
private checkRepeatForPostKey(postKey) {
return this.mysqlService.db
.select({ id: pacAuthPost.postId })
.from(pacAuthPost)
.where(and(isNull(pacAuthPost.deleteby), eq(pacAuthPost.postKey, postKey)));
}
// DB 写入岗位信息
private async addPost(createAuthPostDto: CreateAuthPostDto, userId: string) {
// ! 生成雪花id,用于岗位主键
const id = await this.snowflake.generate();
// ! 定义写入的岗位数据
const newPostData: typeof pacAuthPost.$inferInsert = {
postId: id as any,
postKey: createAuthPostDto.postKey,
postName: createAuthPostDto.postName,
postType: createAuthPostDto.postType,
postDesc: createAuthPostDto.postDesc,
orderNum: createAuthPostDto.orderNum,
createby: userId,
createtime: sql`now()` as any,
};
return await this.mysqlService.db.insert(pacAuthPost).values(newPostData);
}
// DB 查询构建器
private queryBuilder(getAuthPostDto: GetAuthPostDto, selectData) {
// ! 定义基础查询函数
// 启用动态查询模式 $dynamic
const query = this.mysqlService.db
.select(selectData)
.from(pacAuthPost)
.orderBy(
isTrueEnum(getAuthPostDto.isAsc) ? asc(pacAuthPost.orderNum) : desc(pacAuthPost.orderNum),
isTrueEnum(getAuthPostDto.isAsc) ? asc(pacAuthPost.postId) : desc(pacAuthPost.postId),
)
.leftJoin(pacCoreDict, eq(pacAuthPost.postType, pacCoreDict.dictId))
.$dynamic();
// 查询条件集合
const wl = [];
// ? 未删除
wl.push(isNull(pacAuthPost.deleteby));
// ? 模糊查询
wl.push(
or(
like(pacAuthPost.postName, likeQuery(getAuthPostDto.postInfo)),
like(pacAuthPost.postKey, likeQuery(getAuthPostDto.postInfo)),
like(pacAuthPost.postDesc, likeQuery(getAuthPostDto.postInfo)),
).if(isExistKey(pacAuthPost, 'postInfo')),
);
// ? 按照层级查
// ? 是否查岗位类型
wl.push(eq(pacAuthPost.postType, getAuthPostDto.postType).if(isExistKey(getAuthPostDto, 'postType')));
// ? 是否查字典状态
wl.push(eq(pacAuthPost.status, getAuthPostDto.status as any).if(isExistKey(getAuthPostDto, 'status')));
query.where(and(...wl));
return query;
}
// DB 查分页
private async getPage(getAuthPostDto: GetAuthPostDto) {
const offset = (getAuthPostDto.pageNumber - 1) * getAuthPostDto.pageSize;
// ! 使用基础查询构建查询总记录数
const totalCountQuery = this.queryBuilder(getAuthPostDto, {
totalCount: sql`COUNT(*)`,
});
// ! 使用基础查询构建分页查询
// 重命名表
const userTable1 = alias(pacAuthUser, 'userTable1');
const userTable2 = alias(pacAuthUser, 'userTable2');
const paginatedQuery = this.queryBuilder(getAuthPostDto, {
...this.postPageType,
updateName: userTable1.nickname,
createName: userTable2.nickname,
})
.leftJoin(userTable2, eq(pacAuthPost.createby, userTable2.userId))
.leftJoin(userTable1, eq(pacAuthPost.updateby, userTable1.userId))
.limit(getAuthPostDto.pageSize)
.offset(offset);
return {
total: (await totalCountQuery)[0].totalCount,
rowData: await paginatedQuery,
searchData: getAuthPostDto,
};
}
// DB 查列表
private getList(getAuthPostDto: GetAuthPostDto) {
return this.queryBuilder(getAuthPostDto, this.postListType);
}
// DB 删除岗位
private deletePost(id: string, userId: string) {
// ! 删除岗位数据
return this.mysqlService.db
.update(pacAuthPost)
.set({
deletetime: sql`now()`,
deleteby: userId,
})
.where(eq(pacAuthPost.postId, id));
}
// DB 更新岗位
private async updatePost(id: string, updateAuthPostDto: UpdateAuthPostDto, userId: string) {
// ! 查岗位
const post = await this.mysqlService.db
.select()
.from(pacAuthPost)
.where(and(isNull(pacAuthPost.deleteby), eq(pacAuthPost.postId, id)));
if (post.length === 0) throw new HttpException('未找到目标岗位信息,无法修改!', HttpStatus.BAD_REQUEST);
// ! 加目标锁,同级,而不是全局
const lock = await this.redisService.distributedLock('POST' + updateAuthPostDto.postKey, updateAuthPostDto.postKey);
// ? 存在正在进行写入的岗位
if (!lock) throw new HttpException('服务繁忙,岗位标识重复!', HttpStatus.CONFLICT);
// @ 核心逻辑
try {
// ! 查重
const result = await this.checkRepeatForPostKey(updateAuthPostDto.postKey);
// ? 是否存在重复的岗位
if (result.length > 0 && result[0].id != id) throw new HttpException('岗位标识重复!', HttpStatus.CONFLICT);
// ! 添加岗位数据
const newPacCoreDict = await this.mysqlService.db
.update(pacAuthPost)
.set({
postKey: updateAuthPostDto.postKey,
postName: updateAuthPostDto.postName,
postType: updateAuthPostDto.postType,
postDesc: updateAuthPostDto.postDesc,
orderNum: updateAuthPostDto.orderNum,
status: updateAuthPostDto.status,
updateby: userId,
updatetime: sql`now()`,
})
.where(eq(pacAuthPost.postId, id));
// ! 解锁
lock();
// ! 返回结果
return newPacCoreDict;
} catch (e) {
// ! 解锁
lock();
// ! 抛出错误
throw e;
}
}
}

@ -0,0 +1,80 @@
import { ApiProperty } from '@nestjs/swagger';
import Trim from '@common/decorator/trim/trim.decorator';
import ChangeCase, { CaseType } from '@common/decorator/change-case/change-case.decorator';
import { IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator';
export class CreateAuthPostDto {
@ApiProperty({
description: '岗位标志',
type: String,
example: 'Country',
required: true,
minLength: 1,
maxLength: 32,
})
@Trim()
@ChangeCase(CaseType.constant)
@IsString({ message: '岗位标志应为字符串格式!' })
@Length(1, 32, { message: '请将岗位标志长度控制在1到32位之间!' })
readonly postKey: string;
@ApiProperty({
description: '岗位名称',
type: String,
example: '研发经理',
required: true,
minLength: 1,
maxLength: 32,
})
@Trim()
@IsString({ message: '岗位名称应为字符串格式!' })
@Length(1, 32, { message: '岗位名称长度控制在1到32位之间!' })
readonly postName: string;
@ApiProperty({
description: '岗位类型,来自于字典',
type: String,
example: '0',
required: true,
minLength: 19,
maxLength: 19,
})
@Trim()
@IsString({ message: '岗位类型格式不正确!' })
@Length(19, 19, { message: '岗位类型格式不正确!' })
readonly postType: string;
@ApiProperty({
description: '岗位描述',
type: String,
example: '0',
required: false,
minLength: 1,
maxLength: 255,
})
@Trim()
@IsString({ message: '岗位描述应为字符串格式!' })
@Length(1, 255, { message: '请将岗位描述长度控制在1到255位之间!' })
@IsOptional()
readonly postDesc: string;
@ApiProperty({
description: '排序',
type: Number,
example: 10,
required: false,
minimum: -1000,
maximum: 1000,
})
@IsOptional()
@IsInt({
message: '排序必须是整数!',
})
@Min(-1000, {
message: '排序不能小于-1000!',
})
@Max(1000, {
message: '排序不能超过1000',
})
readonly orderNum?: number = 0;
}

@ -0,0 +1,70 @@
// | ------------------------------------------------------------
// | @版本: version 0.1
// | @创建人: 【Nie-x7129】
// | @E-mail: x71291@outlook.com
// | @所在项目: pac-auth
// | @文件描述: get-auth-dept.dto.ts -
// | @创建时间: 2024-06-28 11:20
// | @更新时间: 2024-06-28 11:20
// | @修改记录:
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
// | =
// | ------------------------------------------------------------
import { GetDto } from '@dto/get.dto';
import { ApiProperty } from '@nestjs/swagger';
import Trim from '@common/decorator/trim/trim.decorator';
import { IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator';
import Int from '@common/decorator/int/int.descrator';
export class GetAuthPostDto extends GetDto {
@ApiProperty({
description: '岗位',
type: String,
example: '管理员',
required: false,
minLength: 1,
maxLength: 128,
})
@Trim()
@IsString({ message: '岗位信息应为字符串格式!' })
@Length(0, 128, { message: '请将岗位信息长度控制在1到128位之间!' })
@IsOptional()
readonly postInfo?: string;
@ApiProperty({
description: '岗位类型,来自于字典',
type: String,
example: '0',
required: false,
minLength: 19,
maxLength: 19,
})
@Trim()
@IsString({ message: '岗位类型格式不正确!' })
@Length(19, 19, { message: '岗位类型格式不正确!' })
@IsOptional()
readonly postType: string;
@ApiProperty({
description: '岗位状态',
type: Number,
example: 0,
required: false,
minimum: -100,
maximum: 100,
})
@Trim()
@Int()
@IsInt({
message: '岗位状态必须是整数!',
})
@Min(-100, {
message: '岗位状态需要大于-100!',
})
@Max(100, {
message: '岗位状态不能超过100',
})
@IsOptional()
readonly status?: string;
}

@ -0,0 +1,25 @@
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { CreateAuthPostDto } from './create-auth-post.dto';
import { IsInt, IsOptional, Max, Min } from 'class-validator';
export class UpdateAuthPostDto extends PartialType(CreateAuthPostDto) {
@ApiProperty({
description: '状态',
type: Number,
example: 10,
required: false,
minimum: -100,
maximum: 100,
})
@IsOptional()
@IsInt({
message: '状态必须是整数!',
})
@Min(-1000, {
message: '状态不能小于-100!',
})
@Max(1000, {
message: '状态不能超过100',
})
readonly status: number;
}

@ -24,7 +24,7 @@ import { GetUserForAttDto } from '@dto/GetUserForAtt.dto';
import { likeQuery } from '@utils/likeQuery';
import { alias, QueryBuilder } from 'drizzle-orm/mysql-core';
import { customDrizzleRowWithRecursive } from '@utils/customDrizzleRowWithRecursive';
import {RoleLinkUserDto} from "@dto/AttLinkUser.dto";
import { RoleLinkUserDto } from '@dto/AttLinkUser.dto';
@Injectable()
export class AuthRoleService {
@ -198,7 +198,7 @@ export class AuthRoleService {
const checkRepeat = await this.getRoleForRoleKey(updateAuthRoleDto.roleKey);
// ? 是否存在重复的角色
if (checkRepeat.length > 0 && checkRepeat[0].roleId != roleId) throw new HttpException('角色标识重复!', HttpStatus.CONFLICT);
if (checkRepeat.length > 0 && checkRepeat[0].id != roleId) throw new HttpException('角色标识重复!', HttpStatus.CONFLICT);
// ! 修改角色数据
const result = await this.updateRole(roleId, updateAuthRoleDto, pacInfo.userId as any).catch((e) => {
@ -262,7 +262,7 @@ export class AuthRoleService {
// DB 通过roleKey查找角色信息
private getRoleForRoleKey(key: string) {
return this.mysqlService.db
.select()
.select({ id: pacAuthRole.roleId })
.from(pacAuthRole)
.where(and(isNull(pacAuthRole.deleteby), eq(pacAuthRole.roleKey, key)));
}

@ -49,14 +49,13 @@ export class CreateAuthRoleDto {
description: '角色类型,来自于字典',
type: String,
example: '0',
required: false,
required: true,
minLength: 19,
maxLength: 19,
})
@Trim()
@IsString({ message: '角色类型格式不正确!' })
@Length(19, 19, { message: '角色类型格式不正确!' })
@IsOptional()
readonly roleType: string;
@ApiProperty({

@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { AuthUserService } from './auth-user.service';
import { CreateAuthUserDto } from './dto/create-auth-user.dto';
import { UpdateAuthUserDto } from './dto/update-auth-user.dto';
@Controller('auth-user')
export class AuthUserController {
constructor(private readonly authUserService: AuthUserService) {}
@Post()
create(@Body() createAuthUserDto: CreateAuthUserDto) {
return this.authUserService.create(createAuthUserDto);
}
@Get()
findAll() {
return this.authUserService.findAll();
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.authUserService.findOne(+id);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateAuthUserDto: UpdateAuthUserDto) {
return this.authUserService.update(+id, updateAuthUserDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.authUserService.remove(+id);
}
}

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AuthUserService } from './auth-user.service';
import { AuthUserController } from './auth-user.controller';
@Module({
controllers: [AuthUserController],
providers: [AuthUserService],
})
export class AuthUserModule {}

@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateAuthUserDto } from './dto/create-auth-user.dto';
import { UpdateAuthUserDto } from './dto/update-auth-user.dto';
@Injectable()
export class AuthUserService {
create(createAuthUserDto: CreateAuthUserDto) {
return 'This action adds a new authUser';
}
findAll() {
return `This action returns all authUser`;
}
findOne(id: number) {
return `This action returns a #${id} authUser`;
}
update(id: number, updateAuthUserDto: UpdateAuthUserDto) {
return `This action updates a #${id} authUser`;
}
remove(id: number) {
return `This action removes a #${id} authUser`;
}
}

@ -0,0 +1 @@
export class CreateAuthUserDto {}

@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateAuthUserDto } from './create-auth-user.dto';
export class UpdateAuthUserDto extends PartialType(CreateAuthUserDto) {}

@ -172,7 +172,7 @@ export class CoreDictService {
const checkRepeat = await this.getDictDataForDictKey(updateCoreDictDto.dictKey);
// ? 判断是否存在重名的字典,但是不包括自己
if (checkRepeat.length > 0 && checkRepeat[0].dictId != dictId) {
if (checkRepeat.length > 0 && checkRepeat[0].id != dictId) {
throw new HttpException('服务繁忙,字典标识重复!', HttpStatus.CONFLICT);
}
@ -232,7 +232,12 @@ export class CoreDictService {
// DB 根据serviceKey查找服务数据 可用于查重
private async getDictDataForDictKey(dictKey: string) {
return await this.mysqlService.db.select().from(pacCoreDict).where(eq(pacCoreDict.dictKey, dictKey));
return await this.mysqlService.db
.select({
id: pacCoreDict.dictId,
})
.from(pacCoreDict)
.where(eq(pacCoreDict.dictKey, dictKey));
}
// DB 写入Dict数据

@ -174,7 +174,7 @@ export class CoreEnvService {
const checkRepeat = await this.getEnvForEnvKey(updateCoreEnvDto.envKey);
// ? 判断是否存在重名的环境变量,但是不包括自己
if (checkRepeat.length > 0 && checkRepeat[0].envId != envId) {
if (checkRepeat.length > 0 && checkRepeat[0].id != envId) {
throw new HttpException('环境变量标识重复!', HttpStatus.CONFLICT);
}
@ -235,7 +235,12 @@ export class CoreEnvService {
// DB 通过EnvKey获取env信息,主要用于查重
private getEnvForEnvKey(envKey: string) {
return this.mysqlService.db.select().from(pacCoreEnv).where(eq(pacCoreEnv.envKey, envKey));
return this.mysqlService.db
.select({
id: pacCoreEnv.envId,
})
.from(pacCoreEnv)
.where(eq(pacCoreEnv.envKey, envKey));
}
// DB 添加Env数据

@ -1,2 +1,3 @@
import { relations } from 'drizzle-orm/relations';
import {} from './schema';
import { relations } from "drizzle-orm/relations";
import { } from "./schema";

@ -3,6 +3,7 @@ import { sql } from 'drizzle-orm';
import { bigintString } from '@entities/customType';
const bigint = bigintString;
export const pacAuthDept = mysqlTable(
'pac_auth_dept',
{
@ -121,17 +122,18 @@ export const pacAuthPost = mysqlTable(
'pac_auth_post',
{
index: int('index').autoincrement().notNull(),
postId: int('post_id').notNull(),
postId: bigint('post_id', { mode: 'number' }).notNull(),
postKey: varchar('post_key', { length: 255 }).notNull(),
postName: varchar('post_name', { length: 255 }),
postType: bigint('post_type', { mode: 'number' }).notNull(),
postDesc: varchar('post_desc', { length: 255 }),
orderNum: int('order_num').default(0).notNull(),
status: int('status').default(0).notNull(),
createby: int('createby').notNull(),
createby: bigint('createby', { mode: 'number' }).notNull(),
createtime: datetime('createtime', { mode: 'string' }).notNull(),
updateby: int('updateby'),
updateby: bigint('updateby', { mode: 'number' }),
updatetime: datetime('updatetime', { mode: 'string' }),
deleteby: int('deleteby'),
deleteby: bigint('deleteby', { mode: 'number' }),
deletetime: datetime('deletetime', { mode: 'string' }),
},
(table) => {

Loading…
Cancel
Save