parent
0e6ff7e292
commit
f9102f8761
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,54 @@ |
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common'; |
||||
import { CoreMenuService } from './core-menu.service'; |
||||
import { CreateCoreMenuDto } from './dto/create-core-menu.dto'; |
||||
import { UpdateCoreMenuDto } from './dto/update-core-menu.dto'; |
||||
import { ApiOperation, ApiProduces, ApiTags } from '@nestjs/swagger'; |
||||
import { PacInfo } from '@common/decorator/pac-info/pac-info.decorator'; |
||||
import { PacInfoType } from '@utils/myType'; |
||||
import { GetPacCoreMenuAllDto } from '@app/core-menu/dto/get-core-menu.dto'; |
||||
|
||||
@ApiTags('菜单服务') |
||||
@Controller('coremenu') |
||||
export class CoreMenuController { |
||||
constructor(private readonly coreMenuService: CoreMenuService) {} |
||||
|
||||
@ApiOperation({ |
||||
summary: '添加菜单', |
||||
description: '增加一个菜单/接口/菜单夹,可以是具体的项,也可以是一个层级', |
||||
}) |
||||
@ApiProduces('application/json') |
||||
@Post() |
||||
create(@Body() createCoreMenuDto: CreateCoreMenuDto, @PacInfo() pacInfo: PacInfoType) { |
||||
return this.coreMenuService.create(createCoreMenuDto, pacInfo); |
||||
} |
||||
|
||||
@ApiOperation({ |
||||
summary: '查菜单', |
||||
description: '查询菜单分页或者列表', |
||||
}) |
||||
@ApiProduces('application/json') |
||||
@Get() |
||||
findAll(@Query() getPacCoreMenuAllDto: GetPacCoreMenuAllDto, @PacInfo() pacInfo: PacInfoType) { |
||||
return this.coreMenuService.findAll(getPacCoreMenuAllDto, pacInfo); |
||||
} |
||||
|
||||
@ApiOperation({ |
||||
summary: '修改菜单内容', |
||||
description: '。', |
||||
}) |
||||
@ApiProduces('application/json') |
||||
@Patch(':menuId') |
||||
update(@Param('menuId') id: string, @Body() updateCoreMenuDto: UpdateCoreMenuDto, @PacInfo() pacInfo: PacInfoType) { |
||||
return this.coreMenuService.update(id, updateCoreMenuDto, pacInfo); |
||||
} |
||||
|
||||
@ApiOperation({ |
||||
summary: '删除指定菜单项', |
||||
description: '删除指定菜单项,子项存在不允许删除', |
||||
}) |
||||
@ApiProduces('application/json') |
||||
@Delete(':menuId') |
||||
remove(@Param('menuId') id: string, @PacInfo() pacInfo: PacInfoType) { |
||||
return this.coreMenuService.remove(id, pacInfo); |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
import { Module } from '@nestjs/common'; |
||||
import { CoreMenuService } from './core-menu.service'; |
||||
import { CoreMenuController } from './core-menu.controller'; |
||||
|
||||
@Module({ |
||||
controllers: [CoreMenuController], |
||||
providers: [CoreMenuService], |
||||
}) |
||||
export class CoreMenuModule {} |
@ -0,0 +1,312 @@ |
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; |
||||
import { CreateCoreMenuDto } from './dto/create-core-menu.dto'; |
||||
import { UpdateCoreMenuDto } from './dto/update-core-menu.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 { PacInfoType } from '@utils/myType'; |
||||
import { pacAuthUser, pacCoreDict, pacCoreMenu, pacCoreService } from '@entities/schema'; |
||||
import { eq, sql, isNull, asc, desc, or, like, and } from 'drizzle-orm'; |
||||
import { isExistKey, isTrueEnum } from '@utils/boolean.enum'; |
||||
import { GetPacCoreMenuAllDto } from '@app/core-menu/dto/get-core-menu.dto'; |
||||
import { likeQuery } from '@utils/likeQuery'; |
||||
|
||||
@Injectable() |
||||
export class CoreMenuService { |
||||
// 详细的菜单信息
|
||||
private readonly menuMoreDataType = { |
||||
menuId: pacCoreMenu.menuId, |
||||
pid: pacCoreMenu.pid, |
||||
haveChildren: pacCoreMenu.haveChildren, |
||||
apiPath: pacCoreMenu.apiPath, |
||||
webPath: pacCoreMenu.webPath, |
||||
webComponentPath: pacCoreMenu.webComponentPath, |
||||
menuName: pacCoreMenu.menuName, |
||||
menuDesc: pacCoreMenu.menuDesc, |
||||
menuType: pacCoreMenu.menuType, |
||||
menuTypeKey: pacCoreDict.dictKey, |
||||
menuTypeName: pacCoreDict.dictName, |
||||
menuIcon: pacCoreMenu.menuIcon, |
||||
isFrame: pacCoreMenu.isFrame, |
||||
isVisible: pacCoreMenu.isVisible, |
||||
isActivate: pacCoreMenu.isActivate, |
||||
orderNum: pacCoreMenu.orderNum, |
||||
status: pacCoreMenu.status, |
||||
serviceOf: pacCoreMenu.serviceOf, |
||||
serviceName: pacCoreService.serviceName, |
||||
createby: pacCoreMenu.createby, |
||||
createName: pacAuthUser.nickname, |
||||
createtime: pacCoreMenu.createtime, |
||||
updateby: pacCoreMenu.updateby, |
||||
updateName: pacAuthUser.nickname, |
||||
updatetime: pacCoreMenu.updatetime, |
||||
}; |
||||
|
||||
// 菜单列表数据
|
||||
private readonly menuListDataType = { |
||||
menuId: pacCoreMenu.menuId, |
||||
pid: pacCoreMenu.pid, |
||||
haveChildren: pacCoreMenu.haveChildren, |
||||
apiPath: pacCoreMenu.apiPath, |
||||
webPath: pacCoreMenu.webPath, |
||||
webComponentPath: pacCoreMenu.webComponentPath, |
||||
menuName: pacCoreMenu.menuName, |
||||
menuType: pacCoreMenu.menuType, |
||||
menuTypeKey: pacCoreDict.dictKey, |
||||
menuIcon: pacCoreMenu.menuIcon, |
||||
isFrame: pacCoreMenu.isFrame, |
||||
isVisible: pacCoreMenu.isVisible, |
||||
isActivate: pacCoreMenu.isActivate, |
||||
orderNum: pacCoreMenu.orderNum, |
||||
serviceOf: pacCoreMenu.serviceOf, |
||||
serviceName: pacCoreService.serviceName, |
||||
}; |
||||
|
||||
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-22 17:57:15 - |
||||
* */ |
||||
public async create(createCoreMenuDto: CreateCoreMenuDto, pacInfo: PacInfoType) { |
||||
// ! 加目标锁,允许同名,所以就不加锁了
|
||||
|
||||
// ? 判断是不是pac,不是的话直接退出
|
||||
if (this.config.get<number>('masterId') !== pacInfo.userId) { |
||||
throw new HttpException('没有权限添加菜单!', HttpStatus.UNAUTHORIZED); |
||||
} |
||||
|
||||
// ! 执行写入
|
||||
const newPacCoreMenu = await this.addMenuData(createCoreMenuDto, pacInfo); |
||||
|
||||
// ? 判断是否存在pid,对pid的haveChildren进行变化
|
||||
await this.haveChildrenSelfIncreasing(createCoreMenuDto.pid); |
||||
return newPacCoreMenu; |
||||
} |
||||
|
||||
/** Service |
||||
* NAME: findAll |
||||
* DESC: 获取菜单列表/分页 |
||||
* DATE: 2024-06-22 18:21:57 - |
||||
* */ |
||||
public async findAll(getPacCoreMenuAllDto: GetPacCoreMenuAllDto, pacInfo: PacInfoType) { |
||||
// ? 是否查询列表
|
||||
if (isExistKey(getPacCoreMenuAllDto, 'isList') && isTrueEnum(getPacCoreMenuAllDto['isList'])) { |
||||
// ! 返回列表数据
|
||||
return await this.getMenuList(getPacCoreMenuAllDto, pacInfo); |
||||
} else { |
||||
// ! 返回分页数据
|
||||
return await this.getMenuPage(getPacCoreMenuAllDto, pacInfo); |
||||
} |
||||
} |
||||
|
||||
public update(id: string, updateCoreMenuDto: UpdateCoreMenuDto, pacInfo: PacInfoType) { |
||||
// ! 比较权限
|
||||
if (this.config.get<number>('masterId') !== pacInfo.userId) { |
||||
throw new HttpException('没有权限删除菜单!', HttpStatus.UNAUTHORIZED); |
||||
} |
||||
|
||||
// ! 写入数据
|
||||
} |
||||
|
||||
public async remove(id: string, pacInfo: PacInfoType) { |
||||
// ! 比较权限
|
||||
if (this.config.get<number>('masterId') !== pacInfo.userId) { |
||||
throw new HttpException('没有权限删除菜单!', HttpStatus.UNAUTHORIZED); |
||||
} |
||||
|
||||
// ! 查找菜单
|
||||
const result = await this.getMore(id); |
||||
if (result.length == 0) { |
||||
throw new HttpException('未找到目标菜单!', HttpStatus.BAD_REQUEST); |
||||
} |
||||
|
||||
// ! 执行删除
|
||||
await this.deleteMenuItem(id, pacInfo); |
||||
|
||||
// ! 更改发节点的子节点数
|
||||
if (result[0].pid != 0) { |
||||
await this.haveChildrenSelfIncreasing(result[0].pid, false); |
||||
} |
||||
|
||||
return '删除菜单成功'; |
||||
} |
||||
|
||||
// DB 增加菜单
|
||||
async addMenuData(createCoreMenuDto: CreateCoreMenuDto, pacInfo: PacInfoType) { |
||||
// ! 生成雪花id,用于字典主键
|
||||
const id = await this.snowflake.generate(); |
||||
|
||||
const newMenuData = { |
||||
menuId: id, |
||||
pid: createCoreMenuDto.pid, |
||||
apiPath: createCoreMenuDto.apiPath, |
||||
webPath: createCoreMenuDto.webPath, |
||||
webComponentPath: createCoreMenuDto.webComponentPath, |
||||
menuName: createCoreMenuDto.menuName, |
||||
menuDesc: createCoreMenuDto.menuDesc, |
||||
menuType: createCoreMenuDto.menuType, |
||||
menuIcon: createCoreMenuDto.menuIcon, |
||||
isFrame: isTrueEnum(createCoreMenuDto.isFrame) ? 1 : 0, |
||||
isVisible: isTrueEnum(createCoreMenuDto.isVisible) ? 0 : 1, |
||||
isActivate: isTrueEnum(createCoreMenuDto.isActivate) ? 0 : 1, |
||||
orderNum: createCoreMenuDto.orderNum, |
||||
serviceOf: createCoreMenuDto.serviceOf, |
||||
createby: pacInfo.userId, |
||||
createtime: sql`now()` as any, |
||||
}; |
||||
|
||||
return this.mysqlService.db.insert(pacCoreMenu).values(newMenuData); |
||||
} |
||||
|
||||
// DB 更新父级子元素数量
|
||||
private async haveChildrenSelfIncreasing(menuId: string, isAdd = true) { |
||||
return this.mysqlService.db |
||||
.update(pacCoreMenu) |
||||
.set({ |
||||
haveChildren: isAdd ? sql`${pacCoreMenu.haveChildren} + 1` : sql`${pacCoreMenu.haveChildren} - 1`, |
||||
}) |
||||
.where(eq(pacCoreMenu.menuId as any, menuId)); |
||||
} |
||||
|
||||
// 查菜单数据
|
||||
private getMenuData(data: GetPacCoreMenuAllDto, pacInfo: PacInfoType, selectData = undefined) { |
||||
// ! 定义基础查询函数
|
||||
// 启用动态查询模式 $dynamic
|
||||
const query = this.mysqlService.db |
||||
.select(selectData) |
||||
.from(pacCoreMenu) |
||||
.leftJoin(pacCoreDict, eq(pacCoreMenu.menuType, pacCoreDict.dictId)) |
||||
.leftJoin(pacCoreService, eq(pacCoreMenu.serviceOf, pacCoreService.serviceKey)) |
||||
.orderBy( |
||||
isTrueEnum(data.isAsc) ? asc(pacCoreMenu.orderNum) : desc(pacCoreMenu.orderNum), |
||||
isTrueEnum(data.isAsc) ? asc(pacCoreMenu.menuId) : desc(pacCoreMenu.menuId), |
||||
) |
||||
.$dynamic(); |
||||
|
||||
// ! 条件列表
|
||||
const wl = []; |
||||
|
||||
// ? 未删除
|
||||
wl.push(isNull(pacCoreMenu.deleteby)); |
||||
|
||||
// ? 模糊查询
|
||||
wl.push( |
||||
or(like(pacCoreMenu.menuName, likeQuery(data.menuInfo)), like(pacCoreMenu.menuDesc, likeQuery(data.menuInfo))).if(isExistKey(data, 'menuInfo')), |
||||
); |
||||
|
||||
// ? 根据pid查
|
||||
wl.push(eq(pacCoreMenu.pid, data.hierarchy).if(isExistKey(data, 'hierarchy'))); |
||||
|
||||
// // ? 根据菜单类型查
|
||||
wl.push(eq(pacCoreMenu.menuType, data.menuType).if(isExistKey(data, 'menuType'))); |
||||
|
||||
// ? 根据服务名称查
|
||||
wl.push(eq(pacCoreMenu.serviceOf, data.serviceOf).if(isExistKey(data, 'serviceOf'))); |
||||
|
||||
// ? 根据是否是外部链接查
|
||||
wl.push(eq(pacCoreMenu.isFrame, isTrueEnum(data.isFrame) ? 1 : 0).if(isExistKey(data, 'isFrame'))); |
||||
|
||||
// ? 根据是否显示查
|
||||
wl.push(eq(pacCoreMenu.isVisible, isTrueEnum(data.isVisible) ? 0 : 1).if(isExistKey(data, 'isVisible'))); |
||||
|
||||
// ? 根据状态查
|
||||
wl.push(eq(pacCoreMenu.status, data.status as any).if(isExistKey(data, 'status'))); |
||||
|
||||
// ? 判断是否是pac查的
|
||||
if (this.config.get<number>('masterId') === pacInfo.userId) { |
||||
// ? 是否要按照激活查
|
||||
if (isExistKey(data, 'isActivate')) { |
||||
wl.push(eq(pacCoreMenu.isActivate, isTrueEnum(data['isActivate']) ? 0 : 1)); |
||||
} |
||||
} else { |
||||
// 非pac只能查激活的
|
||||
wl.push(eq(pacCoreMenu.isActivate, 0)); |
||||
} |
||||
|
||||
query.where(and(...wl)); |
||||
return query; |
||||
} |
||||
|
||||
// DB 查列表数据
|
||||
private getMenuList(getMenuData: GetPacCoreMenuAllDto, pacInfo: PacInfoType) { |
||||
return this.getMenuData(getMenuData, pacInfo, this.menuListDataType); |
||||
} |
||||
|
||||
// DB查分页数据
|
||||
private async getMenuPage(getPacCoreMenuAllDto: GetPacCoreMenuAllDto, pacInfo: PacInfoType) { |
||||
const offset = (getPacCoreMenuAllDto.pageNumber - 1) * getPacCoreMenuAllDto.pageSize; |
||||
|
||||
// 使用基础查询构建查询总记录数
|
||||
const totalCountQuery = this.getMenuData(getPacCoreMenuAllDto, pacInfo, { |
||||
totalCount: sql`COUNT(*)`, |
||||
}); |
||||
|
||||
// 使用基础查询构建分页查询
|
||||
const paginatedQuery = this.getMenuData(getPacCoreMenuAllDto, pacInfo, this.menuMoreDataType) |
||||
.leftJoin(pacAuthUser, eq(pacCoreMenu.createby, pacAuthUser.userId)) |
||||
.limit(getPacCoreMenuAllDto.pageSize) |
||||
.offset(offset); |
||||
|
||||
return { |
||||
total: (await totalCountQuery)[0].totalCount, |
||||
rowData: await paginatedQuery, |
||||
searchData: getPacCoreMenuAllDto, |
||||
}; |
||||
} |
||||
|
||||
// DB 删除菜单
|
||||
private deleteMenuItem(id, pacInfo: PacInfoType) { |
||||
return this.mysqlService.db |
||||
.update(pacCoreMenu) |
||||
.set({ |
||||
deletetime: sql`now()`, |
||||
deleteby: pacInfo.userId, |
||||
}) |
||||
.where(eq(pacCoreMenu.menuId, id)); |
||||
} |
||||
|
||||
// DB 获取菜单信息
|
||||
private getMore(id) { |
||||
return this.mysqlService.db |
||||
.select({ |
||||
menuId: pacCoreMenu.menuId, |
||||
pid: pacCoreMenu.pid, |
||||
}) |
||||
.from(pacCoreMenu) |
||||
.where(and(isNull(pacCoreMenu.deleteby), eq(pacCoreMenu.menuId, id))); |
||||
} |
||||
|
||||
// DB 更新菜单信息
|
||||
private async updateMenuData(id, updateCoreMenuDto: UpdateCoreMenuDto, pacInfo: PacInfoType) { |
||||
return this.mysqlService.db |
||||
.update(pacCoreMenu) |
||||
.set({ |
||||
apiPath: updateCoreMenuDto.apiPath, |
||||
webPath: updateCoreMenuDto.webPath, |
||||
webComponentPath: updateCoreMenuDto.webComponentPath, |
||||
menuName: updateCoreMenuDto.menuName, |
||||
menuDesc: updateCoreMenuDto.menuDesc, |
||||
menuType: updateCoreMenuDto.menuType, |
||||
menuIcon: updateCoreMenuDto.menuIcon, |
||||
isFrame: isTrueEnum(updateCoreMenuDto.isFrame) ? 1 : 0, |
||||
isVisible: isTrueEnum(updateCoreMenuDto.isVisible) ? 0 : 1, |
||||
isActivate: isTrueEnum(updateCoreMenuDto.isActivate) ? 0 : 1, |
||||
orderNum: updateCoreMenuDto.orderNum, |
||||
status: updateCoreMenuDto.status, |
||||
serviceOf: updateCoreMenuDto.serviceOf, |
||||
updateby: pacInfo.userId, |
||||
updatetime: sql`now()`, |
||||
}) |
||||
.where(eq(pacCoreMenu.menuId, id)); |
||||
} |
||||
} |
@ -0,0 +1,185 @@ |
||||
import { ApiProperty } from '@nestjs/swagger'; |
||||
import Trim from '@common/decorator/trim/trim.decorator'; |
||||
import {IsEnum, IsInt, IsOptional, IsString, Length, Max, Min} from 'class-validator'; |
||||
import {BooleanEnum} from "@utils/boolean.enum"; |
||||
|
||||
export class CreateCoreMenuDto { |
||||
@ApiProperty({ |
||||
description: '菜单父ID', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 32, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单关联属性应为字符串格式!' }) |
||||
@IsOptional() |
||||
readonly pid?: string = '0'; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单接口路径用:隔开', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 255, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单接口路径应为字符串格式!' }) |
||||
@Length(1, 255, { message: '请将菜单接口路径长度控制在1到255位之间!' }) |
||||
@IsOptional() |
||||
readonly apiPath: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '页面路由路径,前后不要带/,会被继承', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 255, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '页面路由路径应为字符串格式!' }) |
||||
@Length(1, 255, { message: '请将页面路由路径长度控制在1到255位之间!' }) |
||||
@IsOptional() |
||||
readonly webPath: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '页面组件路径,从前端项目指定目录读取', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 255, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '页面组件路径应为字符串格式!' }) |
||||
@Length(1, 255, { message: '请将页面组件路径长度控制在1到255位之间!' }) |
||||
@IsOptional() |
||||
readonly webComponentPath: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单接口权限名称', |
||||
type: String, |
||||
example: '控制面板', |
||||
required: true, |
||||
minLength: 1, |
||||
maxLength: 32, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单接口权限名称应为字符串格式!' }) |
||||
@Length(1, 32, { message: '菜单接口权限名称长度控制在1到32位之间!' }) |
||||
readonly menuName: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单接口权限描述', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 255, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单接口权限描述应为字符串格式!' }) |
||||
@Length(1, 255, { message: '请将菜单接口权限描述长度控制在1到255位之间!' }) |
||||
@IsOptional() |
||||
readonly menuDesc: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单类型,来自于字典', |
||||
type: String, |
||||
example: '0', |
||||
required: true, |
||||
minLength: 19, |
||||
maxLength: 19, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单类型格式不正确!' }) |
||||
@Length(19, 19, { message: '菜单类型格式不正确!' }) |
||||
readonly menuType: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单图标', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 255, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单图标应为字符串格式!' }) |
||||
@Length(1, 255, { message: '请将菜单图标长度控制在1到255位之间!' }) |
||||
@IsOptional() |
||||
readonly menuIcon: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否为外部链接', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否为外部链接参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isFrame?: BooleanEnum = BooleanEnum.FALSE; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否显示', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否显示参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isVisible?: BooleanEnum = BooleanEnum.TRUE; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否激活', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否激活参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isActivate?: BooleanEnum = BooleanEnum.TRUE; |
||||
|
||||
@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; |
||||
|
||||
@ApiProperty({ |
||||
description: '服务的唯一标识', |
||||
type: String, |
||||
example: 'CORE-PAC-AUTH', |
||||
required: false, |
||||
minLength: 2, |
||||
maxLength: 16, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '服务标识应为字符串格式!' }) |
||||
@Length(2, 16, { message: '请将服务标识长度控制在2到16位之间!' }) |
||||
@IsOptional() |
||||
readonly serviceOf: string; |
||||
} |
@ -0,0 +1,136 @@ |
||||
// | ------------------------------------------------------------
|
||||
// | @版本: version 0.1
|
||||
// | @创建人: 【Nie-hotok】
|
||||
// | @E-mail: x71291@outlook.com
|
||||
// | @所在项目: pac-auth
|
||||
// | @文件描述: get-core-menu.dto.ts -
|
||||
// | @创建时间: 2024-06-22 16:05
|
||||
// | @更新时间: 2024-06-22 16:05
|
||||
// | @修改记录:
|
||||
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
|
||||
// | =
|
||||
// | ------------------------------------------------------------
|
||||
|
||||
import { GetDto } from '@dto/get.dto'; |
||||
import { ApiProperty } from '@nestjs/swagger'; |
||||
import Trim from '@common/decorator/trim/trim.decorator'; |
||||
import { IsEnum, IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator'; |
||||
import { BooleanEnum } from '@utils/boolean.enum'; |
||||
import { Transform, Type } from 'class-transformer'; |
||||
import Int from '@common/decorator/int/int.descrator'; |
||||
|
||||
export class GetPacCoreMenuAllDto extends GetDto { |
||||
@ApiProperty({ |
||||
description: '菜单信息', |
||||
type: String, |
||||
example: '国家', |
||||
required: false, |
||||
minLength: 1, |
||||
maxLength: 128, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单信息应为字符串格式!' }) |
||||
@Length(0, 128, { message: '请将菜单信息长度控制在1到128位之间!' }) |
||||
@IsOptional() |
||||
readonly menuInfo?: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '菜单类型,来自于字典', |
||||
type: String, |
||||
example: '0', |
||||
required: false, |
||||
minLength: 19, |
||||
maxLength: 19, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '菜单类型格式不正确!' }) |
||||
@Length(19, 19, { message: '菜单类型格式不正确!' }) |
||||
@IsOptional() |
||||
readonly menuType: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '服务的唯一标识', |
||||
type: String, |
||||
example: 'CORE-PAC-AUTH', |
||||
required: false, |
||||
minLength: 2, |
||||
maxLength: 16, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '服务标识应为字符串格式!' }) |
||||
@Length(2, 16, { message: '请将服务标识长度控制在2到16位之间!' }) |
||||
@IsOptional() |
||||
readonly serviceOf: string; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否为外部链接', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否为外部链接参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isFrame?: BooleanEnum; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否显示', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否显示参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isVisible?: BooleanEnum; |
||||
|
||||
@ApiProperty({ |
||||
description: '是否激活', |
||||
type: BooleanEnum, |
||||
enum: BooleanEnum, |
||||
example: false, |
||||
required: false, |
||||
}) |
||||
@Trim() |
||||
@IsEnum(BooleanEnum, { message: '是否激活参数格式错误' }) |
||||
@IsOptional() |
||||
readonly isActivate?: BooleanEnum; |
||||
|
||||
@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; |
||||
|
||||
@ApiProperty({ |
||||
description: '字典层级id', |
||||
type: Number, |
||||
example: 0, |
||||
required: false, |
||||
minimum: 0, |
||||
maximum: 100, |
||||
}) |
||||
@Trim() |
||||
@IsString({ message: '字典层级id应为字符串格式!' }) |
||||
@Length(1, 20, { message: '字典层级id格式错误!' }) |
||||
@IsOptional() |
||||
readonly hierarchy?: string; |
||||
} |
@ -0,0 +1,25 @@ |
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'; |
||||
import { CreateCoreMenuDto } from './create-core-menu.dto'; |
||||
import { IsInt, IsOptional, Max, Min } from 'class-validator'; |
||||
|
||||
export class UpdateCoreMenuDto extends PartialType(CreateCoreMenuDto) { |
||||
@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; |
||||
} |
@ -0,0 +1 @@ |
||||
export class CoreMenu {} |
@ -0,0 +1,25 @@ |
||||
// | ------------------------------------------------------------
|
||||
// | @版本: version 0.1
|
||||
// | @创建人: 【Nie-hotok】
|
||||
// | @E-mail: x71291@outlook.com
|
||||
// | @所在项目: pac-auth
|
||||
// | @文件描述: int.descrator.ts -
|
||||
// | @创建时间: 2024-06-22 19:07
|
||||
// | @更新时间: 2024-06-22 19:07
|
||||
// | @修改记录:
|
||||
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
|
||||
// | =
|
||||
// | ------------------------------------------------------------
|
||||
import { Transform } from 'class-transformer'; |
||||
|
||||
export default function Int() { |
||||
return Transform(({ value }) => { |
||||
if (typeof value === 'string') { |
||||
if (value.trim() == '') { |
||||
return undefined; |
||||
} |
||||
return parseInt(value); |
||||
} |
||||
return value; |
||||
}); |
||||
} |
Loading…
Reference in new issue