From f6c334bdad31966a24dd964887238c9526544c16 Mon Sep 17 00:00:00 2001 From: John Bro <42930107+john1298308460@users.noreply.github.com> Date: Wed, 17 Jul 2024 21:35:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E5=BA=94=E7=94=A8/=E7=BD=91=E7=AB=99/?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=94=AF=E6=8C=81=E5=A4=9A=E9=80=89?= =?UTF-8?q?=20(#5849)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/cronjob_backup.go | 61 ++++++++++++-------- frontend/src/api/interface/cronjob.ts | 3 + frontend/src/views/cronjob/operate/index.vue | 43 ++++++++++++-- 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/backend/app/service/cronjob_backup.go b/backend/app/service/cronjob_backup.go index e77f94075..c3e2c77df 100644 --- a/backend/app/service/cronjob_backup.go +++ b/backend/app/service/cronjob_backup.go @@ -17,15 +17,20 @@ import ( func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time) error { var apps []model.AppInstall - if cronjob.AppID == "all" { + if strings.Contains(cronjob.AppID, "all") { apps, _ = appInstallRepo.ListBy() } else { - itemID, _ := strconv.Atoi(cronjob.AppID) - app, err := appInstallRepo.GetFirst(commonRepo.WithByID(uint(itemID))) + appIds := strings.Split(cronjob.AppID, ",") + var idItems []uint + for i := 0; i < len(appIds); i++ { + itemID, _ := strconv.Atoi(appIds[i]) + idItems = append(idItems, uint(itemID)) + } + appItems, err := appInstallRepo.ListBy(commonRepo.WithIdsIn(idItems)) if err != nil { return err } - apps = append(apps, app) + apps = appItems } accountMap, err := loadClientMap(cronjob.BackupAccounts) if err != nil { @@ -232,7 +237,7 @@ type databaseHelper struct { func loadDbsForJob(cronjob model.Cronjob) []databaseHelper { var dbs []databaseHelper - if cronjob.DBName == "all" { + if strings.Contains(cronjob.DBName, "all") { if cronjob.DBType == "mysql" || cronjob.DBType == "mariadb" { mysqlItems, _ := mysqlRepo.List() for _, mysql := range mysqlItems { @@ -254,36 +259,42 @@ func loadDbsForJob(cronjob model.Cronjob) []databaseHelper { } return dbs } - itemID, _ := strconv.Atoi(cronjob.DBName) - if cronjob.DBType == "mysql" || cronjob.DBType == "mariadb" { - mysqlItem, _ := mysqlRepo.Get(commonRepo.WithByID(uint(itemID))) - dbs = append(dbs, databaseHelper{ - DBType: cronjob.DBType, - Database: mysqlItem.MysqlName, - Name: mysqlItem.Name, - }) - } else { - pgItem, _ := postgresqlRepo.Get(commonRepo.WithByID(uint(itemID))) - dbs = append(dbs, databaseHelper{ - DBType: cronjob.DBType, - Database: pgItem.PostgresqlName, - Name: pgItem.Name, - }) + + dbNames := strings.Split(cronjob.DBName, ",") + for _, name := range dbNames { + itemID, _ := strconv.Atoi(name) + if cronjob.DBType == "mysql" || cronjob.DBType == "mariadb" { + mysqlItem, _ := mysqlRepo.Get(commonRepo.WithByID(uint(itemID))) + dbs = append(dbs, databaseHelper{ + DBType: cronjob.DBType, + Database: mysqlItem.MysqlName, + Name: mysqlItem.Name, + }) + } else { + pgItem, _ := postgresqlRepo.Get(commonRepo.WithByID(uint(itemID))) + dbs = append(dbs, databaseHelper{ + DBType: cronjob.DBType, + Database: pgItem.PostgresqlName, + Name: pgItem.Name, + }) + } } return dbs } func loadWebsForJob(cronjob model.Cronjob) []model.Website { var weblist []model.Website - if cronjob.Website == "all" { + if strings.Contains(cronjob.Website, "all") { weblist, _ = websiteRepo.List() return weblist } - itemID, _ := strconv.Atoi(cronjob.Website) - webItem, _ := websiteRepo.GetFirst(commonRepo.WithByID(uint(itemID))) - if webItem.ID != 0 { - weblist = append(weblist, webItem) + websites := strings.Split(cronjob.Website, ",") + var idItems []uint + for i := 0; i < len(websites); i++ { + itemID, _ := strconv.Atoi(websites[i]) + idItems = append(idItems, uint(itemID)) } + weblist, _ = websiteRepo.List(commonRepo.WithIdsIn(idItems)) return weblist } diff --git a/frontend/src/api/interface/cronjob.ts b/frontend/src/api/interface/cronjob.ts index ae2c033d5..bcd7c44f7 100644 --- a/frontend/src/api/interface/cronjob.ts +++ b/frontend/src/api/interface/cronjob.ts @@ -24,6 +24,9 @@ export namespace Cronjob { backupAccounts: string; defaultDownload: string; backupAccountList: Array; + appIdList: Array; + websiteList: Array; + dbNameList: Array; retainCopies: number; status: string; secret: string; diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue index 82c0964b7..bcd866402 100644 --- a/frontend/src/views/cronjob/operate/index.vue +++ b/frontend/src/views/cronjob/operate/index.vue @@ -186,9 +186,9 @@ - +
- - + + PostgreSQL - - + + Promise; } + const title = ref(''); const drawerVisible = ref(false); const dialogData = ref({ @@ -408,6 +410,15 @@ const acceptParams = (params: DialogProps): void => { if (dialogData.value.rowData.backupAccounts) { dialogData.value.rowData.backupAccountList = dialogData.value.rowData.backupAccounts.split(','); } + if (dialogData.value.rowData.appID) { + dialogData.value.rowData.appIdList = dialogData.value.rowData.appID.split(','); + } + if (dialogData.value.rowData.website) { + dialogData.value.rowData.websiteList = dialogData.value.rowData.website.split(','); + } + if (dialogData.value.rowData.dbName) { + dialogData.value.rowData.dbNameList = dialogData.value.rowData.dbName.split(','); + } dialogData.value.rowData!.command = dialogData.value.rowData!.command || 'sh'; dialogData.value.rowData!.isCustom = dialogData.value.rowData!.command !== 'sh' && @@ -718,6 +729,17 @@ const onSubmit = async (formEl: FormInstance | undefined) => { specs.push(itemSpec); } dialogData.value.rowData.backupAccounts = dialogData.value.rowData.backupAccountList.join(','); + + if (dialogData.value.rowData.appIdList) { + dialogData.value.rowData.appID = dialogData.value.rowData.appIdList.join(','); + } + if (dialogData.value.rowData.websiteList) { + dialogData.value.rowData.website = dialogData.value.rowData.websiteList.join(','); + } + if (dialogData.value.rowData.dbNameList) { + dialogData.value.rowData.dbName = dialogData.value.rowData.dbNameList.join(','); + } + dialogData.value.rowData.spec = specs.join(','); if (!formEl) return; formEl.validate(async (valid) => { @@ -750,40 +772,49 @@ defineExpose({ .specClass { width: 20% !important; margin-left: 20px; + .append { width: 20px; } } + @media only screen and (max-width: 1000px) { .specClass { width: 100% !important; margin-top: 20px; margin-left: 0; + .append { width: 43px; } } } + .specTypeClass { width: 22% !important; } + @media only screen and (max-width: 1000px) { .specTypeClass { width: 100% !important; } } + .selectClass { width: 100%; } + .tagClass { float: right; margin-right: 10px; font-size: 12px; margin-top: 5px; } + .logText { line-height: 22px; font-size: 12px; + .link { font-size: 12px; margin-top: -3px;