perf: 流水线支持批量修改分组,批量删除

This commit is contained in:
xiaojunnuo
2024-12-01 02:10:40 +08:00
parent 0772d3b3fd
commit a847e66c4f
25 changed files with 653 additions and 79 deletions
@@ -53,6 +53,7 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean: any) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return super.update(bean);
}
@@ -38,6 +38,7 @@ export class UserSettingsController extends CrudController<UserSettingsService>
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
@@ -50,6 +50,7 @@ export class AccessController extends CrudController<AccessService> {
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
@@ -104,6 +104,7 @@ export class HistoryController extends CrudController<HistoryService> {
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
delete bean.userId;
return super.update(bean);
}
@@ -73,7 +73,7 @@ export class NotificationController extends CrudController<NotificationService>
checkPlus();
}
}
delete bean.userId;
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
@@ -62,6 +62,7 @@ export class PipelineController extends CrudController<PipelineService> {
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
delete bean.userId;
return super.update(bean);
}
@@ -109,4 +110,16 @@ export class PipelineController extends CrudController<PipelineService> {
const count = await this.service.count({ userId: this.getUserId() });
return this.ok({ count });
}
@Post('/batchDelete', { summary: Constants.per.authOnly })
async batchDelete(@Body('ids') ids: number[]) {
await this.service.batchDelete(ids, this.getUserId());
return this.ok({});
}
@Post('/batchUpdateGroup', { summary: Constants.per.authOnly })
async batchUpdateGroup(@Body('ids') ids: number[], @Body('groupId') groupId: number) {
await this.service.batchUpdateGroup(ids, groupId, this.getUserId());
return this.ok({});
}
}
@@ -0,0 +1,74 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { Constants, CrudController } from '@certd/lib-server';
import { AuthService } from '../../modules/sys/authority/service/auth-service.js';
import { PipelineGroupService } from '../../modules/pipeline/service/pipeline-group-service.js';
/**
* 通知
*/
@Provide()
@Controller('/api/pi/pipeline/group')
export class PipelineGroupController extends CrudController<PipelineGroupService> {
@Inject()
service: PipelineGroupService;
@Inject()
authService: AuthService;
getService(): PipelineGroupService {
return this.service;
}
@Post('/page', { summary: Constants.per.authOnly })
async page(@Body(ALL) body: any) {
body.query = body.query ?? {};
delete body.query.userId;
const buildQuery = qb => {
qb.andWhere('user_id = :userId', { userId: this.getUserId() });
};
const res = await this.service.page({
query: body.query,
page: body.page,
sort: body.sort,
buildQuery,
});
return this.ok(res);
}
@Post('/list', { summary: Constants.per.authOnly })
async list(@Body(ALL) body: any) {
body.userId = this.getUserId();
return await super.list(body);
}
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean: any) {
bean.userId = this.getUserId();
return await super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
delete bean.userId;
return await super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
async info(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return await super.info(id);
}
@Post('/delete', { summary: Constants.per.authOnly })
async delete(@Query('id') id: number) {
await this.service.checkUserId(id, this.getUserId());
return await super.delete(id);
}
@Post('/all', { summary: Constants.per.authOnly })
async all() {
const list: any = await this.service.find({
userId: this.getUserId(),
});
return this.ok(list);
}
}
@@ -0,0 +1,33 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity('pi_pipeline_group')
export class PipelineGroupEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'user_id', comment: '用户id' })
userId: number;
@Column({ name: 'name', comment: '分组名称' })
name: string;
@Column({ name: 'icon', comment: '图标' })
icon: string;
@Column({ name: 'favorite', comment: '收藏' })
favorite: boolean;
@Column({
name: 'create_time',
comment: '创建时间',
default: () => 'CURRENT_TIMESTAMP',
})
createTime: Date;
@Column({
name: 'update_time',
comment: '修改时间',
default: () => 'CURRENT_TIMESTAMP',
})
updateTime: Date;
}
@@ -14,13 +14,12 @@ export class PipelineEntity {
@Column({ comment: '配置', length: 40960 })
content: string;
@Column({
name: 'keep_history_count',
comment: '历史记录保持数量',
nullable: true,
})
@Column({ name: 'keep_history_count', comment: '历史记录保持数量', nullable: true })
keepHistoryCount: number;
@Column({ name: 'group_id', comment: '分组id', nullable: true })
groupId: number;
@Column({ comment: '备注', length: 100, nullable: true })
remark: string;
@@ -0,0 +1,28 @@
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { BaseService } from '@certd/lib-server';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PipelineGroupEntity } from '../entity/pipeline-group.js';
import { merge } from 'lodash-es';
@Provide()
@Scope(ScopeEnum.Singleton)
export class PipelineGroupService extends BaseService<PipelineGroupEntity> {
@InjectEntityModel(PipelineGroupEntity)
repository: Repository<PipelineGroupEntity>;
//@ts-ignore
getRepository() {
return this.repository;
}
async add(bean: any) {
bean = merge(
{
favorite: false,
},
bean
);
return await this.repository.save(bean);
}
}
@@ -554,4 +554,21 @@ export class PipelineService extends BaseService<PipelineEntity> {
return result;
}
async batchDelete(ids: number[], userId: number) {
for (const id of ids) {
await this.checkUserId(id, userId);
await this.delete(id);
}
}
async batchUpdateGroup(ids: number[], groupId: number, userId: any) {
await this.repository.update(
{
id: In(ids),
userId,
},
{ groupId }
);
}
}