From a847e66c4fc843b98f1520b2b8072d3586ce8b81 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sun, 1 Dec 2024 02:10:40 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=89=B9=E9=87=8F=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=EF=BC=8C=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../libs/lib-server/src/basic/base-service.ts | 35 +++-- .../src/layout/components/menu/index.less | 4 + .../src/layout/components/menu/index.tsx | 2 +- .../src/layout/components/tabs/index.vue | 15 ++- .../src/router/source/modules/certd.ts | 10 ++ .../certd/mine/change-password-button.vue | 4 + .../src/views/certd/pipeline/api.ts | 16 +++ .../pipeline/components/change-group.vue | 62 +++++++++ .../src/views/certd/pipeline/crud.tsx | 77 ++++++++--- .../src/views/certd/pipeline/group/api.ts | 54 ++++++++ .../src/views/certd/pipeline/group/crud.tsx | 124 ++++++++++++++++++ .../src/views/certd/pipeline/group/index.vue | 38 ++++++ .../src/views/certd/pipeline/index.vue | 110 +++++++++++----- packages/ui/certd-server/db/transform.js | 1 + .../cname/cname-record-controller.ts | 1 + .../mine/user-settings-controller.ts | 1 + .../controller/pipeline/access-controller.ts | 1 + .../controller/pipeline/history-controller.ts | 1 + .../pipeline/notification-controller.ts | 2 +- .../pipeline/pipeline-controller.ts | 13 ++ .../pipeline/pipeline-group-controller.ts | 74 +++++++++++ .../modules/pipeline/entity/pipeline-group.ts | 33 +++++ .../src/modules/pipeline/entity/pipeline.ts | 9 +- .../service/pipeline-group-service.ts | 28 ++++ .../pipeline/service/pipeline-service.ts | 17 +++ 25 files changed, 653 insertions(+), 79 deletions(-) create mode 100644 packages/ui/certd-client/src/views/certd/pipeline/components/change-group.vue create mode 100644 packages/ui/certd-client/src/views/certd/pipeline/group/api.ts create mode 100644 packages/ui/certd-client/src/views/certd/pipeline/group/crud.tsx create mode 100644 packages/ui/certd-client/src/views/certd/pipeline/group/index.vue create mode 100644 packages/ui/certd-server/src/controller/pipeline/pipeline-group-controller.ts create mode 100644 packages/ui/certd-server/src/modules/pipeline/entity/pipeline-group.ts create mode 100644 packages/ui/certd-server/src/modules/pipeline/service/pipeline-group-service.ts diff --git a/packages/libs/lib-server/src/basic/base-service.ts b/packages/libs/lib-server/src/basic/base-service.ts index d45098bc..f4963c9a 100644 --- a/packages/libs/lib-server/src/basic/base-service.ts +++ b/packages/libs/lib-server/src/basic/base-service.ts @@ -1,6 +1,4 @@ -import { ValidateException } from './exception/index.js'; -import * as _ from 'lodash-es'; -import { PermissionException } from './exception/index.js'; +import { PermissionException, ValidateException } from './exception/index.js'; import { In, Repository, SelectQueryBuilder } from 'typeorm'; import { Inject } from '@midwayjs/core'; import { TypeORMDataSourceManager } from '@midwayjs/typeorm'; @@ -164,28 +162,27 @@ export abstract class BaseService { private buildListQuery(listReq: ListReq) { const { query, sort, buildQuery } = listReq; const qb = this.getRepository().createQueryBuilder('main'); - if (sort && sort.prop) { - qb.addOrderBy('main.' + sort.prop, sort.asc ? 'ASC' : 'DESC'); - } - qb.addOrderBy('id', 'DESC'); - //根据bean query if (query) { - let whereSql = ''; - let index = 0; - _.forEach(query, (value, key) => { - if (!value) { - return; + const keys = Object.keys(query); + for (const key of keys) { + const value = query[key]; + if (value == null) { + delete query[key]; } - if (index !== 0) { - whereSql += ' and '; + } + qb.where(query); + } + if (sort && sort.prop) { + const found = this.getRepository().metadata.columns.find(column => { + if (column.propertyName === sort.prop) { + return true; } - whereSql += ` main.${key} = :${key} `; - index++; }); - if (index > 0) { - qb.andWhere(whereSql, query); + if (found) { + qb.addOrderBy('main.' + sort.prop, sort.asc ? 'ASC' : 'DESC'); } } + qb.addOrderBy('id', 'DESC'); //自定义query if (buildQuery) { buildQuery(qb); diff --git a/packages/ui/certd-client/src/layout/components/menu/index.less b/packages/ui/certd-client/src/layout/components/menu/index.less index 9521a407..2d65332d 100644 --- a/packages/ui/certd-client/src/layout/components/menu/index.less +++ b/packages/ui/certd-client/src/layout/components/menu/index.less @@ -7,5 +7,9 @@ .menu-item-title{ display: flex; align-items: center; + .fs-icon{ + font-size: 16px !important; + min-width: 16px !important; + } } } diff --git a/packages/ui/certd-client/src/layout/components/menu/index.tsx b/packages/ui/certd-client/src/layout/components/menu/index.tsx index 719ac53e..16f97e34 100644 --- a/packages/ui/certd-client/src/layout/components/menu/index.tsx +++ b/packages/ui/certd-client/src/layout/components/menu/index.tsx @@ -91,7 +91,7 @@ export default defineComponent({ const title: any = () => { const icon = sub.icon || sub?.meta?.icon; if (icon) { - // @ts-ignore + // @ts-ignore , anticon必须要有,不然不能折叠 return (
diff --git a/packages/ui/certd-client/src/layout/components/tabs/index.vue b/packages/ui/certd-client/src/layout/components/tabs/index.vue index 28eaec94..ee92d4e5 100644 --- a/packages/ui/certd-client/src/layout/components/tabs/index.vue +++ b/packages/ui/certd-client/src/layout/components/tabs/index.vue @@ -10,13 +10,14 @@ @tab-click="handleClick" @edit="handleTabEdit" > - + + + diff --git a/packages/ui/certd-client/src/router/source/modules/certd.ts b/packages/ui/certd-client/src/router/source/modules/certd.ts index c8e18551..f19639b1 100644 --- a/packages/ui/certd-client/src/router/source/modules/certd.ts +++ b/packages/ui/certd-client/src/router/source/modules/certd.ts @@ -70,6 +70,16 @@ export const certdResources = [ auth: true } }, + { + title: "分组管理", + name: "PipelineGroupManager", + path: "/certd/pipeline/group", + component: "/certd/pipeline/group/index.vue", + meta: { + icon: "mdi:format-list-group", + auth: true + } + }, // { // title: "邮箱设置", // name: "EmailSetting", diff --git a/packages/ui/certd-client/src/views/certd/mine/change-password-button.vue b/packages/ui/certd-client/src/views/certd/mine/change-password-button.vue index d902c65f..6d176bb5 100644 --- a/packages/ui/certd-client/src/views/certd/mine/change-password-button.vue +++ b/packages/ui/certd-client/src/views/certd/mine/change-password-button.vue @@ -7,6 +7,7 @@ import { ref } from "vue"; import { CrudOptions, useColumns, useFormWrapper } from "@fast-crud/fast-crud"; import * as api from "/@/views/certd/mine/api"; import { notification } from "ant-design-vue"; +import { useUserStore } from "/@/store/modules/user"; defineProps<{ showButton: boolean; @@ -33,6 +34,7 @@ const validatePass2 = async (rule: any, value: any) => { throw new Error("两次输入密码不一致!"); } }; +const userStore = useUserStore(); const { openDialog } = useFormWrapper(); const { buildFormOptions } = useColumns(); const passwordFormOptions: CrudOptions = { @@ -46,6 +48,8 @@ const passwordFormOptions: CrudOptions = { }, async doSubmit({ form }) { await api.changePassword(form); + //重新加载用户信息 + await userStore.loadUserInfo(); }, async afterSubmit() { notification.success({ message: "修改成功" }); diff --git a/packages/ui/certd-client/src/views/certd/pipeline/api.ts b/packages/ui/certd-client/src/views/certd/pipeline/api.ts index c76ad26e..54dbec7c 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/api.ts +++ b/packages/ui/certd-client/src/views/certd/pipeline/api.ts @@ -76,6 +76,22 @@ export async function Cancel(historyId: any) { }); } +export async function BatchUpdateGroup(pipelineIds: number[], groupId: number): Promise { + return await request({ + url: apiPrefix + "/batchUpdateGroup", + method: "post", + data: { ids: pipelineIds, groupId } + }); +} + +export async function BatchDelete(pipelineIds: number[]): Promise { + return await request({ + url: apiPrefix + "/batchDelete", + method: "post", + data: { ids: pipelineIds } + }); +} + export async function GetFiles(pipelineId: number) { return await request({ url: historyApiPrefix + "/files", diff --git a/packages/ui/certd-client/src/views/certd/pipeline/components/change-group.vue b/packages/ui/certd-client/src/views/certd/pipeline/components/change-group.vue new file mode 100644 index 00000000..d5ad12ea --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/pipeline/components/change-group.vue @@ -0,0 +1,62 @@ + + diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index e357e6a7..f0bd5e3f 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -15,7 +15,7 @@ import { useModal } from "/@/use/use-modal"; import CertView from "./cert-view.vue"; import { eachStages } from "./utils"; import { createApi as createNotificationApi } from "../notification/api"; -export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOptionsProps): CreateCrudOptionsRet { +export default function ({ crudExpose, context: { certdFormRef, groupDictRef, selectedRowKeys } }: CreateCrudOptionsProps): CreateCrudOptionsRet { const router = useRouter(); const { t } = useI18n(); const lastResRef = ref(); @@ -198,6 +198,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp }; const userStore = useUserStore(); const settingStore = useSettingStore(); + return { crudOptions: { request: { @@ -206,6 +207,26 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp editRequest, delRequest }, + settings: { + plugins: { + //行选择插件,内置插件 + rowSelection: { + //是否启用本插件 + enabled: true, + order: -2, + //合并在用户配置crudOptions之前还是之后 + before: true, + props: { + multiple: true, + crossPage: false, + selectedRowKeys, + onSelectedChanged(selected) { + console.log("已选择变化:", selected); + } + } + } + } + }, actionbar: { buttons: { add: { @@ -232,9 +253,16 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp table: { scroll: { x: 1500 } }, + tabs: { + name: "groupId", + show: true + }, rowHandle: { - width: 300, + width: 200, fixed: "right", + dropdown: { + show: true + }, buttons: { play: { order: -999, @@ -275,8 +303,9 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp }, config: { order: 1, - title: "修改流水线内容", + title: "编辑流水线", type: "link", + dropdown: true, icon: "ant-design:edit-outlined", click({ row }) { router.push({ path: "/certd/pipeline/detail", query: { id: row.id, editMode: "true" } }); @@ -284,8 +313,9 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp }, edit: { order: 2, - title: "修改流水线运行配置", - icon: "ant-design:setting-outlined" + title: "修改配置/分组", + icon: "ant-design:setting-outlined", + dropdown: true }, viewCert: { order: 3, @@ -293,7 +323,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp type: "link", icon: "ph:certificate", async click({ row }) { - viewCert(row); + await viewCert(row); } }, download: { @@ -302,11 +332,12 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp title: "下载证书", icon: "ant-design:download-outlined", async click({ row }) { - downloadCert(row); + await downloadCert(row); } }, remove: { - order: 5 + order: 5, + dropdown: true } } }, @@ -495,17 +526,19 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp } } }, - - keepHistoryCount: { - title: "历史记录保持数", - type: "number", - form: { - value: 20, - helper: "历史记录保持条数,多余的会被删除" + groupId: { + title: "分组", + type: "dict-select", + search: { + show: true }, + dict: groupDictRef, column: { width: 130, - show: false + align: "center", + component: { + color: "auto" + } } }, order: { @@ -520,6 +553,18 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp value: 0 } }, + keepHistoryCount: { + title: "历史记录保持数", + type: "number", + form: { + value: 20, + helper: "历史记录保持条数,多余的会被删除" + }, + column: { + width: 130, + show: false + } + }, createTime: { title: "创建时间", type: "datetime", diff --git a/packages/ui/certd-client/src/views/certd/pipeline/group/api.ts b/packages/ui/certd-client/src/views/certd/pipeline/group/api.ts new file mode 100644 index 00000000..39df0db2 --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/pipeline/group/api.ts @@ -0,0 +1,54 @@ +import { request } from "/src/api/service"; + +export function createApi() { + const apiPrefix = "/pi/pipeline/group"; + return { + async GetList(query: any) { + return await request({ + url: apiPrefix + "/page", + method: "post", + data: query + }); + }, + + async AddObj(obj: any) { + return await request({ + url: apiPrefix + "/add", + method: "post", + data: obj + }); + }, + + async UpdateObj(obj: any) { + return await request({ + url: apiPrefix + "/update", + method: "post", + data: obj + }); + }, + + async DelObj(id: number) { + return await request({ + url: apiPrefix + "/delete", + method: "post", + params: { id } + }); + }, + + async GetObj(id: number) { + return await request({ + url: apiPrefix + "/info", + method: "post", + params: { id } + }); + }, + async ListAll() { + return await request({ + url: apiPrefix + "/all", + method: "post" + }); + } + }; +} + +export const pipelineGroupApi = createApi(); diff --git a/packages/ui/certd-client/src/views/certd/pipeline/group/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/group/crud.tsx new file mode 100644 index 00000000..378d6cea --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/pipeline/group/crud.tsx @@ -0,0 +1,124 @@ +// @ts-ignore +import { useI18n } from "vue-i18n"; +import { ref } from "vue"; +import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; +import { pipelineGroupApi } from "./api"; + +export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { + const { t } = useI18n(); + const api = pipelineGroupApi; + const pageRequest = async (query: UserPageQuery): Promise => { + return await api.GetList(query); + }; + const editRequest = async (req: EditReq) => { + const { form, row } = req; + form.id = row.id; + const res = await api.UpdateObj(form); + return res; + }; + const delRequest = async (req: DelReq) => { + const { row } = req; + return await api.DelObj(row.id); + }; + + const addRequest = async (req: AddReq) => { + const { form } = req; + const res = await api.AddObj(form); + return res; + }; + + return { + crudOptions: { + request: { + pageRequest, + addRequest, + editRequest, + delRequest + }, + form: { + labelCol: { + //固定label宽度 + span: null, + style: { + width: "100px" + } + }, + col: { + span: 22 + }, + wrapper: { + width: 600 + } + }, + rowHandle: { + width: 200, + group: { + editable: { + edit: { + text: "编辑", + order: -1, + type: "primary", + click({ row, index }) { + crudExpose.openEdit({ + index, + row + }); + } + } + } + } + }, + table: { + editable: { + enabled: true, + mode: "cell", + exclusive: true, + //排他式激活效果,将其他行的编辑状态触发保存 + exclusiveEffect: "save", //自动保存其他行编辑状态,cancel = 自动关闭其他行编辑状态 + async updateCell(opts) { + const { row, key, value } = opts; + //如果是添加,需要返回{[rowKey]:xxx},比如:{id:2} + return await api.UpdateObj({ id: row.id, [key]: value }); + } + } + }, + columns: { + id: { + title: "ID", + key: "id", + type: "number", + search: { + show: true + }, + column: { + width: 100, + editable: { + disabled: true + } + }, + form: { + show: false + } + }, + name: { + title: "分组名称", + search: { + show: true + }, + type: "text", + form: { + rules: [ + { + required: true, + message: "请输入分组名称" + } + ] + }, + column: { + width: 400 + } + } + } + } + }; +} diff --git a/packages/ui/certd-client/src/views/certd/pipeline/group/index.vue b/packages/ui/certd-client/src/views/certd/pipeline/group/index.vue new file mode 100644 index 00000000..2b1fbbbf --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/pipeline/group/index.vue @@ -0,0 +1,38 @@ + + + diff --git a/packages/ui/certd-client/src/views/certd/pipeline/index.vue b/packages/ui/certd-client/src/views/certd/pipeline/index.vue index df0da548..35a9fb7a 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/index.vue +++ b/packages/ui/certd-client/src/views/certd/pipeline/index.vue @@ -4,6 +4,13 @@
我的流水线
+
+
+ 已选择 {{ selectedRowKeys.length }} 项 + + +
+
- - + diff --git a/packages/ui/certd-server/db/transform.js b/packages/ui/certd-server/db/transform.js index 2a39b855..bc33326f 100644 --- a/packages/ui/certd-server/db/transform.js +++ b/packages/ui/certd-server/db/transform.js @@ -37,6 +37,7 @@ function transform() { let pgSql = sqliteSql.replace(/AUTOINCREMENT/g, 'GENERATED BY DEFAULT AS IDENTITY'); pgSql = pgSql.replace(/datetime/g, 'timestamp'); pgSql = pgSql.replace(/boolean DEFAULT \(0\)/g, 'boolean DEFAULT (false)'); + pgSql = pgSql.replace(/boolean.*NOT NULL DEFAULT \(0\)/g, 'boolean NOT NULL DEFAULT (false)'); pgSql = pgSql.replace(/integer/g, 'bigint'); pgSql = pgSql.replace(/last_insert_rowid\(\)/g, 'LASTVAL()'); fs.writeFileSync(`./migration-pg/${notFile}`, pgSql); diff --git a/packages/ui/certd-server/src/controller/cname/cname-record-controller.ts b/packages/ui/certd-server/src/controller/cname/cname-record-controller.ts index 9d0e55bf..ecec8ee1 100644 --- a/packages/ui/certd-server/src/controller/cname/cname-record-controller.ts +++ b/packages/ui/certd-server/src/controller/cname/cname-record-controller.ts @@ -53,6 +53,7 @@ export class CnameRecordController extends CrudController { @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); } diff --git a/packages/ui/certd-server/src/controller/mine/user-settings-controller.ts b/packages/ui/certd-server/src/controller/mine/user-settings-controller.ts index 9ab7f3f9..4fa9e951 100644 --- a/packages/ui/certd-server/src/controller/mine/user-settings-controller.ts +++ b/packages/ui/certd-server/src/controller/mine/user-settings-controller.ts @@ -38,6 +38,7 @@ export class UserSettingsController extends CrudController @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 }) diff --git a/packages/ui/certd-server/src/controller/pipeline/access-controller.ts b/packages/ui/certd-server/src/controller/pipeline/access-controller.ts index e57aa2ba..b964af88 100644 --- a/packages/ui/certd-server/src/controller/pipeline/access-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/access-controller.ts @@ -50,6 +50,7 @@ export class AccessController extends CrudController { @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 }) diff --git a/packages/ui/certd-server/src/controller/pipeline/history-controller.ts b/packages/ui/certd-server/src/controller/pipeline/history-controller.ts index dde83be4..aa73feac 100644 --- a/packages/ui/certd-server/src/controller/pipeline/history-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/history-controller.ts @@ -104,6 +104,7 @@ export class HistoryController extends CrudController { @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); } diff --git a/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts b/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts index b6adc6a6..cbaf9999 100644 --- a/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts @@ -73,7 +73,7 @@ export class NotificationController extends CrudController checkPlus(); } } - + delete bean.userId; return super.update(bean); } @Post('/info', { summary: Constants.per.authOnly }) diff --git a/packages/ui/certd-server/src/controller/pipeline/pipeline-controller.ts b/packages/ui/certd-server/src/controller/pipeline/pipeline-controller.ts index dd22c4a6..3c4ad067 100644 --- a/packages/ui/certd-server/src/controller/pipeline/pipeline-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/pipeline-controller.ts @@ -62,6 +62,7 @@ export class PipelineController extends CrudController { @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 { 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({}); + } } diff --git a/packages/ui/certd-server/src/controller/pipeline/pipeline-group-controller.ts b/packages/ui/certd-server/src/controller/pipeline/pipeline-group-controller.ts new file mode 100644 index 00000000..ec3ffc0f --- /dev/null +++ b/packages/ui/certd-server/src/controller/pipeline/pipeline-group-controller.ts @@ -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 { + @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); + } +} diff --git a/packages/ui/certd-server/src/modules/pipeline/entity/pipeline-group.ts b/packages/ui/certd-server/src/modules/pipeline/entity/pipeline-group.ts new file mode 100644 index 00000000..8ee07ed7 --- /dev/null +++ b/packages/ui/certd-server/src/modules/pipeline/entity/pipeline-group.ts @@ -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; +} diff --git a/packages/ui/certd-server/src/modules/pipeline/entity/pipeline.ts b/packages/ui/certd-server/src/modules/pipeline/entity/pipeline.ts index 50c5c0df..145f922c 100644 --- a/packages/ui/certd-server/src/modules/pipeline/entity/pipeline.ts +++ b/packages/ui/certd-server/src/modules/pipeline/entity/pipeline.ts @@ -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; diff --git a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-group-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-group-service.ts new file mode 100644 index 00000000..0dc47930 --- /dev/null +++ b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-group-service.ts @@ -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 { + @InjectEntityModel(PipelineGroupEntity) + repository: Repository; + + //@ts-ignore + getRepository() { + return this.repository; + } + + async add(bean: any) { + bean = merge( + { + favorite: false, + }, + bean + ); + return await this.repository.save(bean); + } +} diff --git a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts index 7f19190f..7d005949 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts @@ -554,4 +554,21 @@ export class PipelineService extends BaseService { 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 } + ); + } }