Skip to content

Commit

Permalink
feat: 补充创建者/更新者
Browse files Browse the repository at this point in the history
  • Loading branch information
haiweilian committed Apr 28, 2024
1 parent 241fa3d commit 6c2d4a7
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 32 deletions.
16 changes: 8 additions & 8 deletions sql/vivy-nest-admin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ CREATE TABLE `sys_config` (
-- Records of sys_config
-- ----------------------------
BEGIN;
INSERT INTO `sys_config` VALUES (1, '用户管理-账号初始密码', 'sys.user.initPassword', 'Aa@123456', '0', NULL, sysdate(), NULL, sysdate(), '初始化密码(Aa@123456)');
INSERT INTO `sys_config` VALUES (2, '账号管理-验证码开关', 'sys.account.enableCaptcha', 'true', '0', NULL, sysdate(), NULL, sysdate(), '是否开启验证码功能(true开启,false关闭)');
INSERT INTO `sys_config` VALUES (1, '用户管理-账号初始密码', 'sys.user.initPassword', 'Aa@123456', '0', 'admin', sysdate(), 'admin', sysdate(), '初始化密码(Aa@123456)');
INSERT INTO `sys_config` VALUES (2, '账号管理-验证码开关', 'sys.account.enableCaptcha', 'true', '0', 'admin', sysdate(), 'admin', sysdate(), '是否开启验证码功能(true开启,false关闭)');
COMMIT;

-- ----------------------------
Expand Down Expand Up @@ -667,12 +667,12 @@ CREATE TABLE `job` (
-- Records of job
-- ----------------------------
BEGIN;
INSERT INTO `job` VALUES (1, '无参数', '0', 'CallTask.noParams', NULL, '0 0 * * * ?', '0', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (2, '数字参数', '0', 'CallTask.numberParams', '1', '0 0 * * * ?', '1', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (3, '字符串参数', '0', 'CallTask.stringParams', '\'1\'', '0 0 * * * ?', '1', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (4, '布尔参数', '0', 'CallTask.booleanParams', 'true', '0 0 * * * ?', '1', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (5, '对象参数', '0', 'CallTask.objectParams', '{\"a\":1,\"b\":2}', '0 0 * * * ?', '1', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (6, '测试错误', '0', 'CallTask.errorParams', NULL, '0 0 * * * ?', '1', NULL, sysdate(), NULL, sysdate(), NULL);
INSERT INTO `job` VALUES (1, '无参数', '0', 'CallTask.noParams', NULL, '0 0 * * * ?', '0', 'admin', sysdate(), 'admin', sysdate(), NULL);
INSERT INTO `job` VALUES (2, '数字参数', '0', 'CallTask.numberParams', '1', '0 0 * * * ?', '1', 'admin', sysdate(), 'admin', sysdate(), NULL);
INSERT INTO `job` VALUES (3, '字符串参数', '0', 'CallTask.stringParams', '\'1\'', '0 0 * * * ?', '1', 'admin', sysdate(), 'admin', sysdate(), NULL);
INSERT INTO `job` VALUES (4, '布尔参数', '0', 'CallTask.booleanParams', 'true', '0 0 * * * ?', '1', 'admin', sysdate(), 'admin', sysdate(), NULL);
INSERT INTO `job` VALUES (5, '对象参数', '0', 'CallTask.objectParams', '{\"a\":1,\"b\":2}', '0 0 * * * ?', '1', 'admin', sysdate(), 'admin', sysdate(), NULL);
INSERT INTO `job` VALUES (6, '测试错误', '0', 'CallTask.errorParams', NULL, '0 0 * * * ?', '1', 'admin', sysdate(), 'admin', sysdate(), NULL);
COMMIT;

-- ----------------------------
Expand Down
7 changes: 5 additions & 2 deletions vivy-modules/vivy-system/src/modules/gen/gen/gen.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs/promises'
import * as path from 'path'
import { Injectable, StreamableFile } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { ServiceException } from '@vivy-common/core'
import { ServiceException, SecurityContext } from '@vivy-common/core'
import * as archiver from 'archiver'
import { isEmpty, isNotEmpty } from 'class-validator'
import { Pagination, paginate } from 'nestjs-typeorm-paginate'
Expand All @@ -28,7 +28,8 @@ export class GenService {
@InjectRepository(GenTableColumn)
private tableColumnRepository: Repository<GenTableColumn>,

private genMapper: GenMapper
private genMapper: GenMapper,
private securityContext: SecurityContext
) {}

/**
Expand Down Expand Up @@ -57,6 +58,7 @@ export class GenService {
* @param gen 更新信息
*/
async update(gen: UpdateGenDto): Promise<void> {
gen.updateBy = this.securityContext.getUserName()
await this.tableRepository.save(gen)
}

Expand Down Expand Up @@ -100,6 +102,7 @@ export class GenService {
async import(tableNames: string[]): Promise<void> {
const tables = await this.genMapper.selectDbTableListByNames(tableNames)
for (const table of tables) {
table.createBy = this.securityContext.getUserName()
GenUtils.initTable(table)
const columns = await this.genMapper.selectDbTableColumnsByName(table.tableName)
for (const column of columns) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { ListJobLogDto } from './dto/job-log.dto'
Expand All @@ -15,7 +15,10 @@ import { JobService } from './job.service'
@ApiBearerAuth()
@Controller('job')
export class JobController {
constructor(private jobService: JobService) {}
constructor(
private jobService: JobService,
private securityContext: SecurityContext
) {}

/**
* 定时任务列表
Expand All @@ -37,6 +40,8 @@ export class JobController {
@RequirePermissions('monitor:job:add')
async add(@Body() job: CreateJobDto): Promise<AjaxResult> {
await this.jobService.checkInvokeTargetAllowed(job.invokeTarget)

job.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.jobService.add(job))
}

Expand All @@ -49,6 +54,8 @@ export class JobController {
@RequirePermissions('monitor:job:update')
async update(@Body() job: UpdateJobDto): Promise<AjaxResult> {
await this.jobService.checkInvokeTargetAllowed(job.invokeTarget)

job.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.jobService.update(job))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { ConfigService } from './config.service'
Expand All @@ -14,7 +14,10 @@ import { ListConfigDto, CreateConfigDto, UpdateConfigDto } from './dto/config.dt
@ApiBearerAuth()
@Controller('config')
export class ConfigController {
constructor(private configService: ConfigService) {}
constructor(
private configService: ConfigService,
private securityContext: SecurityContext
) {}

/**
* 参数配置列表
Expand All @@ -39,6 +42,7 @@ export class ConfigController {
return AjaxResult.error(`新增参数配置${config.configName}失败,参数键名已存在`)
}

config.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.configService.add(config))
}

Expand All @@ -54,6 +58,7 @@ export class ConfigController {
return AjaxResult.error(`修改参数配置${config.configName}失败,参数键名已存在`)
}

config.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.configService.update(config))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { DeptService } from './dept.service'
Expand All @@ -14,7 +14,10 @@ import { CreateDeptDto, UpdateDeptDto } from './dto/dept.dto'
@ApiBearerAuth()
@Controller('dept')
export class DeptController {
constructor(private deptService: DeptService) {}
constructor(
private deptService: DeptService,
private securityContext: SecurityContext
) {}

/**
* 查询部门树结构
Expand All @@ -33,6 +36,7 @@ export class DeptController {
@Log({ title: '部门管理', operType: OperType.INSERT })
@RequirePermissions('system:dept:add')
async add(@Body() dept: CreateDeptDto): Promise<AjaxResult> {
dept.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.deptService.add(dept))
}

Expand All @@ -48,6 +52,7 @@ export class DeptController {
return AjaxResult.error(`修改部门${dept.deptName}失败,上级部门不能是自己`)
}

dept.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.deptService.update(dept))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { DictDataService } from './dict-data.service'
Expand All @@ -14,7 +14,10 @@ import { ListDictDataDto, CreateDictDataDto, UpdateDictDataDto } from './dto/dic
@ApiBearerAuth()
@Controller('dict/data')
export class DictDataController {
constructor(private dictDataService: DictDataService) {}
constructor(
private dictDataService: DictDataService,
private securityContext: SecurityContext
) {}

/**
* 查询字典数据列表
Expand Down Expand Up @@ -44,6 +47,7 @@ export class DictDataController {
return AjaxResult.error(`新增字典${dictData.dictLabel}失败,字典键值已存在`)
}

dictData.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.dictDataService.add(dictData))
}

Expand All @@ -63,6 +67,7 @@ export class DictDataController {
return AjaxResult.error(`修改字典${dictData.dictLabel}失败,字典键值已存在`)
}

dictData.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.dictDataService.update(dictData))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { DictTypeService } from './dict-type.service'
Expand All @@ -14,7 +14,10 @@ import { ListDictTypeDto, CreateDictTypeDto, UpdateDictTypeDto } from './dto/dic
@ApiBearerAuth()
@Controller('dict/type')
export class DictTypeController {
constructor(private dictTypeService: DictTypeService) {}
constructor(
private dictTypeService: DictTypeService,
private securityContext: SecurityContext
) {}

/**
* 查询字典类型列表
Expand Down Expand Up @@ -43,6 +46,7 @@ export class DictTypeController {
return AjaxResult.error(`新增字典${dictType.dictName}失败,字典名称已存在`)
}

dictType.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.dictTypeService.add(dictType))
}

Expand All @@ -62,6 +66,7 @@ export class DictTypeController {
return AjaxResult.error(`修改字典${dictType.dictName}失败,字典名称已存在`)
}

dictType.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.dictTypeService.update(dictType))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult, UserId } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { CreateMenuDto, UpdateMenuDto } from './dto/menu.dto'
Expand All @@ -14,7 +14,10 @@ import { MenuService } from './menu.service'
@ApiBearerAuth()
@Controller('menu')
export class MenuController {
constructor(private menuService: MenuService) {}
constructor(
private menuService: MenuService,
private securityContext: SecurityContext
) {}

/**
* 查询菜单树结构
Expand All @@ -33,6 +36,7 @@ export class MenuController {
@Log({ title: '菜单管理', operType: OperType.INSERT })
@RequirePermissions('system:menu:add')
async add(@Body() menu: CreateMenuDto): Promise<AjaxResult> {
menu.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.menuService.add(menu))
}

Expand All @@ -48,6 +52,7 @@ export class MenuController {
return AjaxResult.error(`修改菜单${menu.menuName}失败,上级菜单不能是自己`)
}

menu.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.menuService.update(menu))
}

Expand Down Expand Up @@ -95,8 +100,8 @@ export class MenuController {
* @returns 用户路由信息
*/
@Get('getUserRouters')
async getUserRouters(@UserId() userId: number): Promise<AjaxResult> {
const menus = await this.menuService.selectUserMenuTree(userId)
async getUserRouters(): Promise<AjaxResult> {
const menus = await this.menuService.selectUserMenuTree(this.securityContext.getUserId())
return AjaxResult.success(this.menuService.buildUmiMaxRouters(menus))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { ListNoticeDto, CreateNoticeDto, UpdateNoticeDto } from './dto/notice.dto'
Expand All @@ -14,7 +14,10 @@ import { NoticeService } from './notice.service'
@ApiBearerAuth()
@Controller('notice')
export class NoticeController {
constructor(private noticeService: NoticeService) {}
constructor(
private noticeService: NoticeService,
private securityContext: SecurityContext
) {}

/**
* 通知公告列表
Expand All @@ -35,6 +38,7 @@ export class NoticeController {
@Log({ title: '通知公告', operType: OperType.INSERT })
@RequirePermissions('system:notice:add')
async add(@Body() notice: CreateNoticeDto): Promise<AjaxResult> {
notice.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.noticeService.add(notice))
}

Expand All @@ -46,6 +50,7 @@ export class NoticeController {
@Log({ title: '通知公告', operType: OperType.UPDATE })
@RequirePermissions('system:notice:update')
async update(@Body() notice: UpdateNoticeDto): Promise<AjaxResult> {
notice.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.noticeService.update(notice))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, Post, Put, Query } from '@nestjs/common'
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { AjaxResult } from '@vivy-common/core'
import { AjaxResult, SecurityContext } from '@vivy-common/core'
import { Log, OperType } from '@vivy-common/logger'
import { RequirePermissions } from '@vivy-common/security'
import { ListPostDto, CreatePostDto, UpdatePostDto } from './dto/post.dto'
Expand All @@ -14,7 +14,10 @@ import { PostService } from './post.service'
@ApiBearerAuth()
@Controller('post')
export class PostController {
constructor(private postService: PostService) {}
constructor(
private postService: PostService,
private securityContext: SecurityContext
) {}

/**
* 岗位列表
Expand Down Expand Up @@ -43,6 +46,7 @@ export class PostController {
return AjaxResult.error(`新增岗位${post.postName}失败,岗位编码已存在`)
}

post.createBy = this.securityContext.getUserName()
return AjaxResult.success(await this.postService.add(post))
}

Expand All @@ -62,6 +66,7 @@ export class PostController {
return AjaxResult.error(`修改岗位${post.postName}失败,岗位编码已存在`)
}

post.updateBy = this.securityContext.getUserName()
return AjaxResult.success(await this.postService.update(post))
}

Expand Down
Loading

0 comments on commit 6c2d4a7

Please sign in to comment.