From c4cb4234fd38ba293f9406cb96eb2bf03d5bb466 Mon Sep 17 00:00:00 2001
From: "meilin.huang" <954537473@qq.com>
Date: Thu, 16 May 2024 17:26:32 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docker-compose.yaml | 2 +-
mayfly_go_web/package.json | 4 +-
mayfly_go_web/src/common/config.ts | 2 +-
.../ops/component/ResourceAuthCertEdit.vue | 5 ++
mayfly_go_web/src/views/ops/db/DbEdit.vue | 83 +++++++++++-------
mayfly_go_web/src/views/ops/db/DbList.vue | 31 +++++--
.../src/views/ops/db/InstanceDbConf.vue | 36 ++++++--
mayfly_go_web/src/views/ops/db/SqlExec.vue | 2 +-
mayfly_go_web/src/views/ops/db/api.ts | 1 +
.../views/ops/db/component/DbSelectTree.vue | 5 +-
.../ops/db/component/table/DbTablesOp.vue | 2 +-
mayfly_go_web/src/views/ops/db/db.ts | 14 +++
mayfly_go_web/src/views/ops/db/enums.ts | 5 ++
.../ops/machine/component/MachineDetail.vue | 69 +++++++++++++++
.../ops/machine/cronjob/CronJobExecList.vue | 65 ++------------
.../src/views/ops/tag/AuthCertList.vue | 13 ++-
server/internal/auth/api/account_login.go | 5 +-
server/internal/db/api/db_instance.go | 6 ++
server/internal/db/api/form/db.go | 18 ++--
server/internal/db/api/vo/db.go | 12 +--
server/internal/db/application/db.go | 2 +-
.../internal/db/application/db_data_sync.go | 2 +-
server/internal/db/application/db_instance.go | 42 +++++++--
server/internal/db/domain/entity/db.go | 20 +++--
server/internal/db/domain/entity/query.go | 2 +-
server/internal/db/router/instance.go | 3 +
.../internal/machine/api/machine_cronjob.go | 7 +-
server/internal/machine/api/machine_script.go | 7 +-
.../internal/machine/application/machine.go | 7 +-
.../machine/application/machine_cronjob.go | 46 ++++------
.../machine/application/machine_term_op.go | 4 +-
.../machine/domain/entity/machine_cronjob.go | 10 +--
.../internal/machine/domain/entity/query.go | 2 +-
.../infrastructure/persistence/machine.go | 11 +--
server/internal/machine/mcm/client.go | 15 ++--
server/internal/machine/mcm/machine.go | 1 +
server/internal/redis/application/redis.go | 6 +-
server/internal/tag/api/vo/tag_tree.go | 20 +++--
.../internal/tag/application/dto/auth_cert.go | 13 +++
.../internal/tag/application/dto/tag_tree.go | 1 +
.../tag/application/resouce_auth_cert.go | 62 ++++++-------
.../tag/domain/entity/resource_auth_cert.go | 2 +-
server/pkg/config/app.go | 2 +-
server/resources/data/mayfly-go.sqlite | Bin 311296 -> 311296 bytes
server/resources/script/sql/mayfly-go.sql | 5 +-
server/resources/script/sql/v1.8/v1.8.5.sql | 6 ++
46 files changed, 416 insertions(+), 262 deletions(-)
create mode 100644 mayfly_go_web/src/views/ops/machine/component/MachineDetail.vue
create mode 100644 server/internal/tag/application/dto/auth_cert.go
create mode 100644 server/resources/script/sql/v1.8/v1.8.5.sql
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 25b9b028..8e9718e2 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -14,7 +14,7 @@ services:
restart: always
server:
- image: ccr.ccs.tencentyun.com/mayfly/mayfly-go:v1.8.3
+ image: ccr.ccs.tencentyun.com/mayfly/mayfly-go:v1.8.5
build:
context: .
dockerfile: Dockerfile
diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json
index de33f59f..9315d4db 100644
--- a/mayfly_go_web/package.json
+++ b/mayfly_go_web/package.json
@@ -17,7 +17,7 @@
"cropperjs": "^1.6.1",
"dayjs": "^1.11.11",
"echarts": "^5.5.0",
- "element-plus": "^2.7.2",
+ "element-plus": "^2.7.3",
"js-base64": "^3.7.7",
"jsencrypt": "^3.3.2",
"lodash": "^4.17.21",
@@ -55,7 +55,7 @@
"eslint": "^8.35.0",
"eslint-plugin-vue": "^9.25.0",
"prettier": "^3.2.5",
- "sass": "^1.76.0",
+ "sass": "^1.77.1",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vue-eslint-parser": "^9.4.2"
diff --git a/mayfly_go_web/src/common/config.ts b/mayfly_go_web/src/common/config.ts
index 78856a9f..d8a58f48 100644
--- a/mayfly_go_web/src/common/config.ts
+++ b/mayfly_go_web/src/common/config.ts
@@ -15,7 +15,7 @@ const config = {
baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`,
// 系统版本
- version: 'v1.8.4',
+ version: 'v1.8.5',
};
export default config;
diff --git a/mayfly_go_web/src/views/ops/component/ResourceAuthCertEdit.vue b/mayfly_go_web/src/views/ops/component/ResourceAuthCertEdit.vue
index 927aa417..bf53e9e8 100644
--- a/mayfly_go_web/src/views/ops/component/ResourceAuthCertEdit.vue
+++ b/mayfly_go_web/src/views/ops/component/ResourceAuthCertEdit.vue
@@ -39,6 +39,11 @@
/>
+
diff --git a/mayfly_go_web/src/views/ops/db/DbEdit.vue b/mayfly_go_web/src/views/ops/db/DbEdit.vue
index 7f538f9a..810e7821 100644
--- a/mayfly_go_web/src/views/ops/db/DbEdit.vue
+++ b/mayfly_go_web/src/views/ops/db/DbEdit.vue
@@ -23,7 +23,7 @@
-
+
{{ item.name }}
@@ -39,8 +39,15 @@
+
+
+
+
+
+
全选
@@ -75,7 +83,7 @@
+
+
diff --git a/mayfly_go_web/src/views/ops/machine/cronjob/CronJobExecList.vue b/mayfly_go_web/src/views/ops/machine/cronjob/CronJobExecList.vue
index ea81941e..365e5ae9 100644
--- a/mayfly_go_web/src/views/ops/machine/cronjob/CronJobExecList.vue
+++ b/mayfly_go_web/src/views/ops/machine/cronjob/CronJobExecList.vue
@@ -13,20 +13,13 @@
ref="pageTableRef"
:page-api="cronJobApi.execList"
:lazy="true"
- :data-handler-fn="parseData"
:search-items="searchItems"
v-model:query-form="params"
:data="state.data.list"
:columns="columns"
>
-
-
-
- {{ ac.ip }}
-
- {{ ac.tagPath }}{{ ac.name }}
-
-
+
+
@@ -35,11 +28,12 @@
diff --git a/mayfly_go_web/src/views/ops/tag/AuthCertList.vue b/mayfly_go_web/src/views/ops/tag/AuthCertList.vue
index effdd803..d9a95b0e 100755
--- a/mayfly_go_web/src/views/ops/tag/AuthCertList.vue
+++ b/mayfly_go_web/src/views/ops/tag/AuthCertList.vue
@@ -11,6 +11,14 @@
添加
+
+
+ {{ data.resourceCode }}
+
+
编辑
@@ -41,6 +49,7 @@ import { SearchItem } from '@/components/SearchForm';
import { AuthCertCiphertextTypeEnum, AuthCertTypeEnum } from './enums';
import { ResourceTypeEnum, TagResourceTypeEnum } from '@/common/commonEnum';
import ResourceAuthCertEdit from '../component/ResourceAuthCertEdit.vue';
+import EnumValue from '@/common/Enum';
const pageTableRef: Ref = ref(null);
const state = reactive({
@@ -50,6 +59,7 @@ const state = reactive({
name: null,
},
searchItems: [
+ SearchItem.input('resourceCode', '资源编号'),
SearchItem.input('name', '凭证名称'),
SearchItem.select('resourceType', '资源类型').withEnum(ResourceTypeEnum),
SearchItem.select('type', '凭证类型').withEnum(AuthCertTypeEnum),
@@ -60,8 +70,7 @@ const state = reactive({
TableColumn.new('type', '凭证类型').typeTag(AuthCertTypeEnum),
TableColumn.new('username', '用户名'),
TableColumn.new('ciphertextType', '密文类型').typeTag(AuthCertCiphertextTypeEnum),
- TableColumn.new('resourceType', '资源类型').typeTag(TagResourceTypeEnum),
- TableColumn.new('resourceCode', '资源编号'),
+ TableColumn.new('resourceCode', '资源编号').isSlot().setAddWidth(30),
TableColumn.new('remark', '备注'),
TableColumn.new('creator', '创建人'),
TableColumn.new('createTime', '创建时间').isTime(),
diff --git a/server/internal/auth/api/account_login.go b/server/internal/auth/api/account_login.go
index 799867ed..008cfdba 100644
--- a/server/internal/auth/api/account_login.go
+++ b/server/internal/auth/api/account_login.go
@@ -123,9 +123,8 @@ func (a *AccountLogin) RefreshToken(rc *req.Ctx) {
biz.NotEmpty(refreshToken, "refresh_token不能为空")
accountId, username, err := req.ParseToken(refreshToken)
- if err != nil {
- panic(errorx.PermissionErr)
- }
+ biz.IsTrueBy(err == nil, errorx.PermissionErr)
+
token, refreshToken, err := req.CreateToken(accountId, username)
biz.ErrIsNil(err)
rc.ResData = collx.Kvs("token", token, "refresh_token", refreshToken)
diff --git a/server/internal/db/api/db_instance.go b/server/internal/db/api/db_instance.go
index 9bf398c7..8493cd0a 100644
--- a/server/internal/db/api/db_instance.go
+++ b/server/internal/db/api/db_instance.go
@@ -114,6 +114,12 @@ func (d *Instance) GetDatabaseNames(rc *req.Ctx) {
rc.ResData = res
}
+func (d *Instance) GetDatabaseNamesByAc(rc *req.Ctx) {
+ res, err := d.InstanceApp.GetDatabasesByAc(rc.PathParam("ac"))
+ biz.ErrIsNil(err)
+ rc.ResData = res
+}
+
// 获取数据库实例server信息
func (d *Instance) GetDbServer(rc *req.Ctx) {
instanceId := getInstanceId(rc)
diff --git a/server/internal/db/api/form/db.go b/server/internal/db/api/form/db.go
index a32053fb..823d0817 100644
--- a/server/internal/db/api/form/db.go
+++ b/server/internal/db/api/form/db.go
@@ -1,14 +1,16 @@
package form
+import "mayfly-go/internal/db/domain/entity"
+
type DbForm struct {
- Id uint64 `json:"id"`
- Code string `binding:"required" json:"code"`
- Name string `binding:"required" json:"name"`
- Database string `json:"database"`
- Remark string `json:"remark"`
- InstanceId uint64 `binding:"required" json:"instanceId"`
- AuthCertName string `json:"authCertName"`
- FlowProcdefKey string `json:"flowProcdefKey"`
+ Id uint64 `json:"id"`
+ Code string `binding:"required" json:"code"`
+ Name string `binding:"required" json:"name"`
+ GetDatabaseMode entity.DbGetDatabaseMode `json:"getDatabaseMode"` // 获取数据库方式
+ Database string `json:"database"`
+ Remark string `json:"remark"`
+ InstanceId uint64 `binding:"required" json:"instanceId"`
+ AuthCertName string `json:"authCertName"`
}
type DbSqlSaveForm struct {
diff --git a/server/internal/db/api/vo/db.go b/server/internal/db/api/vo/db.go
index 8f5d7133..abda831a 100644
--- a/server/internal/db/api/vo/db.go
+++ b/server/internal/db/api/vo/db.go
@@ -1,6 +1,7 @@
package vo
import (
+ "mayfly-go/internal/db/domain/entity"
tagentity "mayfly-go/internal/tag/domain/entity"
"time"
)
@@ -8,11 +9,12 @@ import (
type DbListVO struct {
tagentity.ResourceTags
- Id *int64 `json:"id"`
- Code string `json:"code"`
- Name *string `json:"name"`
- Database *string `json:"database"`
- Remark *string `json:"remark"`
+ Id *int64 `json:"id"`
+ Code string `json:"code"`
+ Name *string `json:"name"`
+ GetDatabaseMode entity.DbGetDatabaseMode `json:"getDatabaseMode"` // 获取数据库方式
+ Database *string `json:"database"`
+ Remark *string `json:"remark"`
InstanceId *int64 `json:"instanceId"`
AuthCertName string `json:"authCertName"`
diff --git a/server/internal/db/application/db.go b/server/internal/db/application/db.go
index f335dee7..3d76c5d8 100644
--- a/server/internal/db/application/db.go
+++ b/server/internal/db/application/db.go
@@ -194,7 +194,7 @@ func (d *dbAppImpl) GetDbConn(dbId uint64, dbName string) (*dbi.DbConn, error) {
di.Id = db.Id
checkDb := di.GetDatabase()
- if !strings.Contains(" "+db.Database+" ", " "+checkDb+" ") {
+ if db.GetDatabaseMode == entity.DbGetDatabaseModeAssign && !strings.Contains(" "+db.Database+" ", " "+checkDb+" ") {
return nil, errorx.NewBiz("未配置数据库【%s】的操作权限", dbName)
}
diff --git a/server/internal/db/application/db_data_sync.go b/server/internal/db/application/db_data_sync.go
index 33ccf4b3..6c91aa90 100644
--- a/server/internal/db/application/db_data_sync.go
+++ b/server/internal/db/application/db_data_sync.go
@@ -410,7 +410,7 @@ func (app *dataSyncAppImpl) InitCronJob() {
}()
// 修改执行中状态为待执行
- _ = app.UpdateByCond(context.TODO(), &entity.DataSyncTask{RunningState: entity.DataSyncTaskRunStateRunning}, &entity.DataSyncTask{RunningState: entity.DataSyncTaskRunStateReady})
+ _ = app.UpdateByCond(context.TODO(), &entity.DataSyncTask{RunningState: entity.DataSyncTaskRunStateReady}, &entity.DataSyncTask{RunningState: entity.DataSyncTaskRunStateRunning})
// 把所有正常任务添加到定时任务中
pageParam := &model.PageParam{
diff --git a/server/internal/db/application/db_instance.go b/server/internal/db/application/db_instance.go
index c5432ee5..96d5e196 100644
--- a/server/internal/db/application/db_instance.go
+++ b/server/internal/db/application/db_instance.go
@@ -39,6 +39,9 @@ type Instance interface {
// GetDatabases 获取数据库实例的所有数据库列表
GetDatabases(entity *entity.DbInstance, authCert *tagentity.ResourceAuthCert) ([]string, error)
+ // GetDatabasesByAc 根据授权凭证名获取所有数据库名称列表
+ GetDatabasesByAc(acName string) ([]string, error)
+
// ToDbInfo 根据实例与授权凭证返回对应的DbInfo
ToDbInfo(instance *entity.DbInstance, authCertName string, database string) (*dbi.DbInfo, error)
}
@@ -53,6 +56,8 @@ type instanceAppImpl struct {
restoreApp *DbRestoreApp `inject:"DbRestoreApp"`
}
+var _ (Instance) = (*instanceAppImpl)(nil)
+
// 注入DbInstanceRepo
func (app *instanceAppImpl) InjectDbInstanceRepo(repo repository.Instance) {
app.Repo = repo
@@ -118,7 +123,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *dto.Sa
return instanceEntity.Id, app.Tx(ctx, func(ctx context.Context) error {
return app.Insert(ctx, instanceEntity)
}, func(ctx context.Context) error {
- return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: instanceEntity.Code,
ResourceType: tagentity.TagType(resourceType),
AuthCerts: authCerts,
@@ -147,7 +152,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *dto.Sa
return oldInstance.Id, app.Tx(ctx, func(ctx context.Context) error {
return app.UpdateById(ctx, instanceEntity)
}, func(ctx context.Context) error {
- return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: oldInstance.Code,
ResourceType: tagentity.TagType(resourceType),
AuthCerts: authCerts,
@@ -205,7 +210,7 @@ func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error
return app.DeleteById(ctx, instanceId)
}, func(ctx context.Context) error {
// 删除该实例关联的授权凭证信息
- return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return app.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: instance.Code,
ResourceType: tagentity.TagType(consts.ResourceTypeDb),
})
@@ -239,16 +244,22 @@ func (app *instanceAppImpl) GetDatabases(ed *entity.DbInstance, authCert *tagent
}
}
- ed.Network = ed.GetNetwork()
- dbi := app.toDbInfoByAc(ed, authCert, "")
+ return app.getDatabases(ed, authCert)
+}
- dbConn, err := dbm.Conn(dbi)
+func (app *instanceAppImpl) GetDatabasesByAc(acName string) ([]string, error) {
+ ac, err := app.resourceAuthCertApp.GetAuthCert(acName)
if err != nil {
- return nil, err
+ return nil, errorx.NewBiz("该授权凭证不存在")
}
- defer dbConn.Close()
- return dbConn.GetMetaData().GetDbNames()
+ instance := &entity.DbInstance{Code: ac.ResourceCode}
+ err = app.GetByCond(instance)
+ if err != nil {
+ return nil, errorx.NewBiz("不存在该授权凭证对应的数据库实例信息")
+ }
+
+ return app.getDatabases(instance, ac)
}
func (app *instanceAppImpl) ToDbInfo(instance *entity.DbInstance, authCertName string, database string) (*dbi.DbInfo, error) {
@@ -260,6 +271,19 @@ func (app *instanceAppImpl) ToDbInfo(instance *entity.DbInstance, authCertName s
return app.toDbInfoByAc(instance, ac, database), nil
}
+func (app *instanceAppImpl) getDatabases(instance *entity.DbInstance, ac *tagentity.ResourceAuthCert) ([]string, error) {
+ instance.Network = instance.GetNetwork()
+ dbi := app.toDbInfoByAc(instance, ac, "")
+
+ dbConn, err := dbm.Conn(dbi)
+ if err != nil {
+ return nil, err
+ }
+ defer dbConn.Close()
+
+ return dbConn.GetMetaData().GetDbNames()
+}
+
func (app *instanceAppImpl) toDbInfoByAc(instance *entity.DbInstance, ac *tagentity.ResourceAuthCert, database string) *dbi.DbInfo {
di := new(dbi.DbInfo)
di.InstanceId = instance.Id
diff --git a/server/internal/db/domain/entity/db.go b/server/internal/db/domain/entity/db.go
index 84d922f3..bdba70ef 100644
--- a/server/internal/db/domain/entity/db.go
+++ b/server/internal/db/domain/entity/db.go
@@ -7,10 +7,18 @@ import (
type Db struct {
model.Model
- Code string `orm:"column(code)" json:"code"`
- Name string `orm:"column(name)" json:"name"`
- Database string `orm:"column(database)" json:"database"`
- Remark string `json:"remark"`
- InstanceId uint64
- AuthCertName string `json:"authCertName"`
+ Code string `orm:"column(code)" json:"code"`
+ Name string `orm:"column(name)" json:"name"`
+ GetDatabaseMode DbGetDatabaseMode `json:"getDatabaseMode"` // 获取数据库方式
+ Database string `orm:"column(database)" json:"database"`
+ Remark string `json:"remark"`
+ InstanceId uint64
+ AuthCertName string `json:"authCertName"`
}
+
+type DbGetDatabaseMode int8
+
+const (
+ DbGetDatabaseModeAuto DbGetDatabaseMode = -1 // 自动获取(根据凭证获取对应所有库名)
+ DbGetDatabaseModeAssign DbGetDatabaseMode = 1 // 指定库名
+)
diff --git a/server/internal/db/domain/entity/query.go b/server/internal/db/domain/entity/query.go
index d6013499..f88ea0ce 100644
--- a/server/internal/db/domain/entity/query.go
+++ b/server/internal/db/domain/entity/query.go
@@ -6,7 +6,7 @@ type InstanceQuery struct {
Name string `json:"name" form:"name"`
Code string `json:"code" form:"code"`
Host string `json:"host" form:"host"`
- TagPath string `json:"host" form:"tagPath"`
+ TagPath string `json:"tagPath" form:"tagPath"`
Codes []string
}
diff --git a/server/internal/db/router/instance.go b/server/internal/db/router/instance.go
index 1656ebf7..b9c7f4e3 100644
--- a/server/internal/db/router/instance.go
+++ b/server/internal/db/router/instance.go
@@ -28,6 +28,9 @@ func InitInstanceRouter(router *gin.RouterGroup) {
// 获取数据库实例的所有数据库名
req.NewPost("/databases", d.GetDatabaseNames),
+ // 根据授权凭证名获取其所有库名
+ req.NewGet("/databases/:ac", d.GetDatabaseNamesByAc),
+
req.NewGet(":instanceId/server-info", d.GetDbServer),
req.NewDelete(":instanceId", d.DeleteInstance).Log(req.NewLogSave("db-删除数据库实例")),
diff --git a/server/internal/machine/api/machine_cronjob.go b/server/internal/machine/api/machine_cronjob.go
index 5776d512..84ea1daf 100644
--- a/server/internal/machine/api/machine_cronjob.go
+++ b/server/internal/machine/api/machine_cronjob.go
@@ -8,13 +8,14 @@ import (
"mayfly-go/internal/machine/domain/entity"
tagapp "mayfly-go/internal/tag/application"
tagentity "mayfly-go/internal/tag/domain/entity"
- "strconv"
"strings"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"mayfly-go/pkg/scheduler"
"mayfly-go/pkg/utils/collx"
+
+ "github.com/may-fly/cast"
)
type MachineCronJob struct {
@@ -58,9 +59,7 @@ func (m *MachineCronJob) Delete(rc *req.Ctx) {
ids := strings.Split(idsStr, ",")
for _, v := range ids {
- value, err := strconv.Atoi(v)
- biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
- m.MachineCronJobApp.Delete(rc.MetaCtx, uint64(value))
+ m.MachineCronJobApp.Delete(rc.MetaCtx, cast.ToUint64(v))
}
}
diff --git a/server/internal/machine/api/machine_script.go b/server/internal/machine/api/machine_script.go
index f5619385..4c9a5c7e 100644
--- a/server/internal/machine/api/machine_script.go
+++ b/server/internal/machine/api/machine_script.go
@@ -11,8 +11,9 @@ import (
"mayfly-go/pkg/utils/collx"
"mayfly-go/pkg/utils/jsonx"
"mayfly-go/pkg/utils/stringx"
- "strconv"
"strings"
+
+ "github.com/may-fly/cast"
)
type MachineScript struct {
@@ -42,9 +43,7 @@ func (m *MachineScript) DeleteMachineScript(rc *req.Ctx) {
ids := strings.Split(idsStr, ",")
for _, v := range ids {
- value, err := strconv.Atoi(v)
- biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
- m.MachineScriptApp.Delete(rc.MetaCtx, uint64(value))
+ m.MachineScriptApp.Delete(rc.MetaCtx, cast.ToUint64(v))
}
}
diff --git a/server/internal/machine/application/machine.go b/server/internal/machine/application/machine.go
index 6a77868c..9aa13148 100644
--- a/server/internal/machine/application/machine.go
+++ b/server/internal/machine/application/machine.go
@@ -108,7 +108,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *dto.SaveMachine
return m.Tx(ctx, func(ctx context.Context) error {
return m.Insert(ctx, me)
}, func(ctx context.Context) error {
- return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: me.Code,
ResourceType: resourceType,
AuthCerts: authCerts,
@@ -138,7 +138,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *dto.SaveMachine
return m.Tx(ctx, func(ctx context.Context) error {
return m.UpdateById(ctx, me)
}, func(ctx context.Context) error {
- return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: oldMachine.Code,
ResourceType: resourceType,
AuthCerts: authCerts,
@@ -219,7 +219,7 @@ func (m *machineAppImpl) Delete(ctx context.Context, id uint64) error {
},
})
}, func(ctx context.Context) error {
- return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return m.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: machine.Code,
ResourceType: resourceType,
})
@@ -334,6 +334,7 @@ func (m *machineAppImpl) getMachineAndAuthCert(machineId uint64) (*entity.Machin
func (m *machineAppImpl) toMi(me *entity.Machine, authCert *tagentity.ResourceAuthCert) (*mcm.MachineInfo, error) {
mi := new(mcm.MachineInfo)
mi.Id = me.Id
+ mi.Code = me.Code
mi.Name = me.Name
mi.Ip = me.Ip
mi.Port = me.Port
diff --git a/server/internal/machine/application/machine_cronjob.go b/server/internal/machine/application/machine_cronjob.go
index 8efd9b3c..5891fd9b 100644
--- a/server/internal/machine/application/machine_cronjob.go
+++ b/server/internal/machine/application/machine_cronjob.go
@@ -8,13 +8,11 @@ import (
tagapp "mayfly-go/internal/tag/application"
tagentity "mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/base"
- "mayfly-go/pkg/biz"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/rediscli"
"mayfly-go/pkg/scheduler"
- "mayfly-go/pkg/utils/anyx"
"mayfly-go/pkg/utils/collx"
"mayfly-go/pkg/utils/stringx"
"time"
@@ -178,43 +176,35 @@ func (m *machineCronJobAppImpl) addCronJob(mcj *entity.MachineCronJob) {
}
func (m *machineCronJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineCronJob) {
- defer func() {
- if err := recover(); err != nil {
- res := anyx.ToString(err)
- m.machineCronJobExecRepo.Insert(context.TODO(), &entity.MachineCronJobExec{
- MachineId: mid,
- CronJobId: cronJob.Id,
- ExecTime: time.Now(),
- Status: entity.MachineCronJobExecStatusError,
- Res: res,
- })
- logx.Errorf("机器:[%d]执行[%s]计划任务失败: %s", mid, cronJob.Name, res)
- }
- }()
+ execRes := &entity.MachineCronJobExec{
+ CronJobId: cronJob.Id,
+ ExecTime: time.Now(),
+ }
machineCli, err := m.machineApp.GetCli(uint64(mid))
- biz.ErrIsNilAppendErr(err, "获取客户端连接失败: %s")
- res, err := machineCli.Run(cronJob.Script)
+ res := ""
if err != nil {
- if res == "" {
- res = err.Error()
- }
- logx.Errorf("机器:[%d]执行[%s]计划任务失败: %s", mid, cronJob.Name, res)
+ machine, _ := m.machineApp.GetById(mid)
+ execRes.MachineCode = machine.Code
} else {
- logx.Debugf("机器:[%d]执行[%s]计划任务成功, 执行结果: %s", mid, cronJob.Name, res)
+ execRes.MachineCode = machineCli.Info.Code
+ res, err = machineCli.Run(cronJob.Script)
+ if err != nil {
+ if res == "" {
+ res = err.Error()
+ }
+ logx.Errorf("机器:[%d]执行[%s]计划任务失败: %s", mid, cronJob.Name, res)
+ } else {
+ logx.Debugf("机器:[%d]执行[%s]计划任务成功, 执行结果: %s", mid, cronJob.Name, res)
+ }
}
+ execRes.Res = res
if cronJob.SaveExecResType == entity.SaveExecResTypeNo ||
(cronJob.SaveExecResType == entity.SaveExecResTypeOnError && err == nil) {
return
}
- execRes := &entity.MachineCronJobExec{
- MachineId: mid,
- CronJobId: cronJob.Id,
- ExecTime: time.Now(),
- Res: res,
- }
if err == nil {
execRes.Status = entity.MachineCronJobExecStatusSuccess
} else {
diff --git a/server/internal/machine/application/machine_term_op.go b/server/internal/machine/application/machine_term_op.go
index 797c5749..393ba701 100644
--- a/server/internal/machine/application/machine_term_op.go
+++ b/server/internal/machine/application/machine_term_op.go
@@ -63,8 +63,8 @@ func (m *machineTermOpAppImpl) TermConn(ctx context.Context, cli *mcm.Cli, wsCon
termOpRecord.MachineId = cli.Info.Id
termOpRecord.Username = cli.Info.Username
- // 回放文件路径为: 基础配置路径/操作日期(202301)/day/hour/randstr.cast
- recRelPath := path.Join(now.Format("200601"), fmt.Sprintf("%d", now.Day()), fmt.Sprintf("%d", now.Hour()))
+ // 回放文件路径为: 基础配置路径/机器编号/操作日期(202301)/day/hour/randstr.cast
+ recRelPath := path.Join(cli.Info.Code, now.Format("200601"), fmt.Sprintf("%d", now.Day()), fmt.Sprintf("%d", now.Hour()))
// 文件绝对路径
recAbsPath := path.Join(config.GetMachine().TerminalRecPath, recRelPath)
os.MkdirAll(recAbsPath, 0766)
diff --git a/server/internal/machine/domain/entity/machine_cronjob.go b/server/internal/machine/domain/entity/machine_cronjob.go
index 286f37a2..43ac2209 100644
--- a/server/internal/machine/domain/entity/machine_cronjob.go
+++ b/server/internal/machine/domain/entity/machine_cronjob.go
@@ -23,11 +23,11 @@ type MachineCronJob struct {
type MachineCronJobExec struct {
model.DeletedModel
- CronJobId uint64 `json:"cronJobId" form:"cronJobId"`
- MachineId uint64 `json:"machineId" form:"machineId"`
- Status int `json:"status" form:"status"` // 执行状态
- Res string `json:"res"` // 执行结果
- ExecTime time.Time `json:"execTime"`
+ CronJobId uint64 `json:"cronJobId" form:"cronJobId"`
+ MachineCode string `json:"machineCode" form:"machineCode"`
+ Status int `json:"status" form:"status"` // 执行状态
+ Res string `json:"res"` // 执行结果
+ ExecTime time.Time `json:"execTime"`
}
const (
diff --git a/server/internal/machine/domain/entity/query.go b/server/internal/machine/domain/entity/query.go
index 3cc0bc10..2a7c3622 100644
--- a/server/internal/machine/domain/entity/query.go
+++ b/server/internal/machine/domain/entity/query.go
@@ -3,7 +3,7 @@ package entity
import "time"
type MachineQuery struct {
- Ids string `json:"ids" form:"ids"`
+ Id uint64 `json:"id" form:"id"`
Code string `json:"code" form:"code"`
Name string `json:"name" form:"name"`
Status int8 `json:"status" form:"status"`
diff --git a/server/internal/machine/infrastructure/persistence/machine.go b/server/internal/machine/infrastructure/persistence/machine.go
index 152eae4a..d888f09e 100644
--- a/server/internal/machine/infrastructure/persistence/machine.go
+++ b/server/internal/machine/infrastructure/persistence/machine.go
@@ -5,10 +5,6 @@ import (
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/model"
- "mayfly-go/pkg/utils/collx"
- "strings"
-
- "github.com/may-fly/cast"
)
type machineRepoImpl struct {
@@ -22,6 +18,7 @@ func newMachineRepo() repository.Machine {
// 分页获取机器信息列表
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := model.NewCond().
+ Eq("id", condition.Id).
Eq("status", condition.Status).
Like("ip", condition.Ip).
Like("name", condition.Name).
@@ -29,11 +26,5 @@ func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pagePar
Like("code", condition.Code).
Eq("protocol", condition.Protocol)
- if condition.Ids != "" {
- qd.In("id", collx.ArrayMap[string, uint64](strings.Split(condition.Ids, ","), func(val string) uint64 {
- return cast.ToUint64(val)
- }))
- }
-
return m.PageByCondToAny(qd, pageParam, toEntity)
}
diff --git a/server/internal/machine/mcm/client.go b/server/internal/machine/mcm/client.go
index 9eee0296..22fdbf72 100644
--- a/server/internal/machine/mcm/client.go
+++ b/server/internal/machine/mcm/client.go
@@ -9,7 +9,7 @@ import (
"golang.org/x/crypto/ssh"
)
-// 机器客户端
+// Cli 机器客户端
type Cli struct {
Info *MachineInfo // 机器信息
@@ -17,7 +17,7 @@ type Cli struct {
sftpClient *sftp.Client // sftp客户端
}
-// 获取sftp client
+// GetSftpCli 获取sftp client
func (c *Cli) GetSftpCli() (*sftp.Client, error) {
if c.sshClient == nil {
return nil, errorx.NewBiz("请先进行机器客户端连接")
@@ -36,7 +36,7 @@ func (c *Cli) GetSftpCli() (*sftp.Client, error) {
return sftpclient, nil
}
-// 获取session
+// GetSession 获取session
func (c *Cli) GetSession() (*ssh.Session, error) {
if c.sshClient == nil {
return nil, errorx.NewBiz("请先进行机器客户端连接")
@@ -49,7 +49,7 @@ func (c *Cli) GetSession() (*ssh.Session, error) {
return session, nil
}
-// 执行shell
+// Run 执行shell
// @param shell shell脚本命令
// @return 返回执行成功或错误的消息
func (c *Cli) Run(shell string) (string, error) {
@@ -58,14 +58,15 @@ func (c *Cli) Run(shell string) (string, error) {
return "", err
}
defer session.Close()
- buf, err := session.CombinedOutput(shell)
+ // 将可能存在的windows换行符替换为linux格式
+ buf, err := session.CombinedOutput(strings.ReplaceAll(shell, "\r\n", "\n"))
if err != nil {
return string(buf), err
}
return string(buf), nil
}
-// 获取机器的所有状态信息
+// GetAllStats 获取机器的所有状态信息
func (c *Cli) GetAllStats() *Stats {
stats := new(Stats)
res, err := c.Run(StatsShell)
@@ -89,7 +90,7 @@ func (c *Cli) GetAllStats() *Stats {
return stats
}
-// 关闭client并从缓存中移除,如果使用隧道则也关闭
+// Close 关闭client并从缓存中移除,如果使用隧道则也关闭
func (c *Cli) Close() {
m := c.Info
logx.Debugf("close machine cli -> id=%d, name=%s, ip=%s", m.Id, m.Name, m.Ip)
diff --git a/server/internal/machine/mcm/machine.go b/server/internal/machine/mcm/machine.go
index dd03a3c0..d8ae3482 100644
--- a/server/internal/machine/mcm/machine.go
+++ b/server/internal/machine/mcm/machine.go
@@ -15,6 +15,7 @@ import (
type MachineInfo struct {
Key string `json:"key"` // 缓存key
Id uint64 `json:"id"`
+ Code string `json:"code"`
Name string `json:"name"`
Protocol int `json:"protocol"`
diff --git a/server/internal/redis/application/redis.go b/server/internal/redis/application/redis.go
index f808790d..a156c8f4 100644
--- a/server/internal/redis/application/redis.go
+++ b/server/internal/redis/application/redis.go
@@ -128,7 +128,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *dto.SaveRedis) erro
ParentTagCodePaths: tagCodePaths,
})
}, func(ctx context.Context) error {
- return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: re.Code,
ResourceType: tagentity.TagTypeRedis,
AuthCerts: []*tagentity.ResourceAuthCert{param.AuthCert},
@@ -170,7 +170,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *dto.SaveRedis) erro
ParentTagCodePaths: tagCodePaths,
})
}, func(ctx context.Context) error {
- return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: oldRedis.Code,
ResourceType: tagentity.TagTypeRedis,
AuthCerts: []*tagentity.ResourceAuthCert{param.AuthCert},
@@ -200,7 +200,7 @@ func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
},
})
}, func(ctx context.Context) error {
- return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagapp.RelateAuthCertParam{
+ return r.resourceAuthCertApp.RelateAuthCert(ctx, &tagdto.RelateAuthCert{
ResourceCode: re.Code,
ResourceType: tagentity.TagTypeRedis,
})
diff --git a/server/internal/tag/api/vo/tag_tree.go b/server/internal/tag/api/vo/tag_tree.go
index d6c54378..a0231b43 100644
--- a/server/internal/tag/api/vo/tag_tree.go
+++ b/server/internal/tag/api/vo/tag_tree.go
@@ -2,7 +2,6 @@ package vo
import (
"mayfly-go/internal/tag/application/dto"
- "mayfly-go/pkg/utils/collx"
)
type TagTreeVOS []*dto.SimpleTagTree
@@ -18,14 +17,21 @@ func (m *TagTreeVOS) ToTrees(pid uint64) []*TagTreeItem {
return ttis
}
- ttis = collx.ArrayMap(*m, func(tr *dto.SimpleTagTree) *TagTreeItem { return &TagTreeItem{SimpleTagTree: tr} })
- tagMap := collx.ArrayToMap(ttis, func(item *TagTreeItem) string {
- return item.CodePath
- })
+ tagMap := make(map[string]*TagTreeItem)
+ var roots []*TagTreeItem
+ for _, tag := range *m {
+ tti := &TagTreeItem{SimpleTagTree: tag}
+ tagMap[tag.CodePath] = tti
+ ttis = append(ttis, tti)
+ if tti.IsRoot() {
+ roots = append(roots, tti)
+ tti.Root = true
+ }
+ }
for _, node := range ttis {
// 根节点
- if node.IsRoot() {
+ if node.Root {
continue
}
parentCodePath := node.GetParentPath(0)
@@ -35,5 +41,5 @@ func (m *TagTreeVOS) ToTrees(pid uint64) []*TagTreeItem {
}
}
- return collx.ArrayFilter(ttis, func(tti *TagTreeItem) bool { return tti.IsRoot() })
+ return roots
}
diff --git a/server/internal/tag/application/dto/auth_cert.go b/server/internal/tag/application/dto/auth_cert.go
new file mode 100644
index 00000000..c95fae0c
--- /dev/null
+++ b/server/internal/tag/application/dto/auth_cert.go
@@ -0,0 +1,13 @@
+package dto
+
+import "mayfly-go/internal/tag/domain/entity"
+
+type RelateAuthCert struct {
+ ResourceCode string
+
+ // 资源标签类型
+ ResourceType entity.TagType
+
+ // 空数组则为删除该资源绑定的授权凭证
+ AuthCerts []*entity.ResourceAuthCert
+}
diff --git a/server/internal/tag/application/dto/tag_tree.go b/server/internal/tag/application/dto/tag_tree.go
index 4b3cbd22..c7b9f351 100644
--- a/server/internal/tag/application/dto/tag_tree.go
+++ b/server/internal/tag/application/dto/tag_tree.go
@@ -43,6 +43,7 @@ type SimpleTagTree struct {
CodePath string `json:"codePath"` // 标识路径,tag1/tag2/tagType1|tagCode/tagType2|yyycode/,非普通标签类型段含有标签类型
Name string `json:"name"` // 名称
Remark string `json:"remark"`
+ Root bool `json:"-" gorm:"-"`
}
func (pt *SimpleTagTree) IsRoot() bool {
diff --git a/server/internal/tag/application/resouce_auth_cert.go b/server/internal/tag/application/resouce_auth_cert.go
index f886a4bf..22225b45 100644
--- a/server/internal/tag/application/resouce_auth_cert.go
+++ b/server/internal/tag/application/resouce_auth_cert.go
@@ -12,21 +12,11 @@ import (
"mayfly-go/pkg/utils/collx"
)
-type RelateAuthCertParam struct {
- ResourceCode string
-
- // 资源标签类型
- ResourceType entity.TagType
-
- // 空数组则为删除该资源绑定的授权凭证
- AuthCerts []*entity.ResourceAuthCert
-}
-
type ResourceAuthCert interface {
base.App[*entity.ResourceAuthCert]
// RelateAuthCert 关联资源授权凭证信息
- RelateAuthCert(ctx context.Context, param *RelateAuthCertParam) error
+ RelateAuthCert(ctx context.Context, param *dto.RelateAuthCert) error
// SaveAuthCert 保存授权凭证信息
SaveAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error
@@ -64,7 +54,7 @@ func (r *resourceAuthCertAppImpl) InjectResourceAuthCertRepo(resourceAuthCertRep
r.Repo = resourceAuthCertRepo
}
-func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *RelateAuthCertParam) error {
+func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *dto.RelateAuthCert) error {
resourceCode := params.ResourceCode
resourceType := int8(params.ResourceType)
resourceAuthCerts := params.AuthCerts
@@ -92,11 +82,6 @@ func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *Re
resourceAuthCert.ResourceType = int8(resourceType)
name2AuthCert[resourceAuthCert.Name] = resourceAuthCert
- existNameAc := &entity.ResourceAuthCert{Name: resourceAuthCert.Name}
- if resourceAuthCert.Id == 0 && r.GetByCond(existNameAc) == nil && existNameAc.ResourceCode != resourceCode {
- return errorx.NewBiz("授权凭证的名称不能重复[%s]", resourceAuthCert.Name)
- }
-
// 公共授权凭证,则无需进行密文加密,密文即为公共授权凭证名
if resourceAuthCert.CiphertextType == entity.AuthCertCiphertextTypePublic {
continue
@@ -111,63 +96,66 @@ func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *Re
oldAuthCert, _ := r.ListByCond(&entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType})
// 新增、删除以及不变的授权凭证名
- var adds, dels, unmodifys []string
+ var addAcNames, delAcNames, unmodifyAcNames []string
if len(oldAuthCert) == 0 {
logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-不存在已有的授权凭证信息, 为新增资源授权凭证", resourceType, resourceCode)
- adds = collx.MapKeys(name2AuthCert)
+ addAcNames = collx.MapKeys(name2AuthCert)
} else {
oldNames := collx.ArrayMap(oldAuthCert, func(ac *entity.ResourceAuthCert) string {
return ac.Name
})
- adds, dels, unmodifys = collx.ArrayCompare[string](collx.MapKeys(name2AuthCert), oldNames)
+ addAcNames, delAcNames, unmodifyAcNames = collx.ArrayCompare[string](collx.MapKeys(name2AuthCert), oldNames)
}
addAuthCerts := make([]*entity.ResourceAuthCert, 0)
- for _, add := range adds {
- addAc := name2AuthCert[add]
+ for _, addAcName := range addAcNames {
+ addAc := name2AuthCert[addAcName]
addAc.Id = 0
+
+ existNameAc := &entity.ResourceAuthCert{Name: addAcName}
+ if r.GetByCond(existNameAc) == nil && existNameAc.ResourceCode != resourceCode {
+ return errorx.NewBiz("授权凭证的名称不能重复[%s]", addAcName)
+ }
+
addAuthCerts = append(addAuthCerts, addAc)
}
// 处理新增的授权凭证
if len(addAuthCerts) > 0 {
- logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-新增授权凭证-[%v]", resourceType, resourceCode, adds)
+ logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-新增授权凭证-[%v]", resourceType, resourceCode, addAcNames)
if err := r.BatchInsert(ctx, addAuthCerts); err != nil {
return err
}
}
- for _, del := range dels {
- logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-删除授权凭证-[%v]", resourceType, resourceCode, del)
- if err := r.DeleteByCond(ctx, &entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType, Name: del}); err != nil {
+ for _, delAcName := range delAcNames {
+ logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-删除授权凭证-[%v]", resourceType, resourceCode, delAcName)
+ if err := r.DeleteByCond(ctx, &entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType, Name: delAcName}); err != nil {
return err
}
}
- if len(unmodifys) > 0 {
+ if len(unmodifyAcNames) > 0 {
// 旧凭证名 -> 旧凭证
oldName2AuthCert := collx.ArrayToMap(oldAuthCert, func(ac *entity.ResourceAuthCert) string {
return ac.Name
})
acTagType := GetResourceAuthCertTagType(params.ResourceType)
- for _, unmodify := range unmodifys {
- unmodifyAc := name2AuthCert[unmodify]
- if unmodifyAc.Id == 0 {
- continue
- }
+ for _, unmodifyAcName := range unmodifyAcNames {
+ unmodifyAc := name2AuthCert[unmodifyAcName]
- oldAuthCert := oldName2AuthCert[unmodify]
+ oldAuthCert := oldName2AuthCert[unmodifyAcName]
if !unmodifyAc.HasChanged(oldAuthCert) {
- logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-授权凭证[%s]未发生字段变更", resourceType, resourceCode, unmodify)
+ logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-授权凭证[%s]未发生字段变更", resourceType, resourceCode, unmodifyAcName)
continue
}
// 如果修改了用户名,且该凭证关联至标签,则需要更新对应的标签名(资源授权凭证类型的标签名为username)
if oldAuthCert.Username != unmodifyAc.Username && acTagType != 0 {
- r.tagTreeApp.UpdateTagName(ctx, acTagType, unmodify, unmodifyAc.Username)
+ r.tagTreeApp.UpdateTagName(ctx, acTagType, unmodifyAcName, unmodifyAc.Username)
}
- logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-更新授权凭证-[%v]", resourceType, resourceCode, unmodify)
- if err := r.UpdateById(ctx, unmodifyAc); err != nil {
+ logx.DebugfContext(ctx, "RelateAuthCert[%d-%s]-更新授权凭证-[%v]", resourceType, resourceCode, unmodifyAcName)
+ if err := r.UpdateByCond(ctx, unmodifyAc, &entity.ResourceAuthCert{Name: unmodifyAcName, ResourceCode: resourceCode, ResourceType: resourceType}); err != nil {
return err
}
}
diff --git a/server/internal/tag/domain/entity/resource_auth_cert.go b/server/internal/tag/domain/entity/resource_auth_cert.go
index 6457f679..c508d796 100644
--- a/server/internal/tag/domain/entity/resource_auth_cert.go
+++ b/server/internal/tag/domain/entity/resource_auth_cert.go
@@ -103,7 +103,7 @@ func (m *ResourceAuthCert) HasChanged(rac *ResourceAuthCert) bool {
return true
}
return m.Username != rac.Username ||
- m.Ciphertext != rac.Ciphertext ||
+ (m.Ciphertext != "" && rac.Ciphertext != "" && m.Ciphertext != rac.Ciphertext) ||
m.CiphertextType != rac.CiphertextType ||
m.Remark != rac.Remark ||
m.Type != rac.Type ||
diff --git a/server/pkg/config/app.go b/server/pkg/config/app.go
index e99b8101..ed326d96 100644
--- a/server/pkg/config/app.go
+++ b/server/pkg/config/app.go
@@ -4,7 +4,7 @@ import "fmt"
const (
AppName = "mayfly-go"
- Version = "v1.8.4"
+ Version = "v1.8.5"
)
func GetAppInfo() string {
diff --git a/server/resources/data/mayfly-go.sqlite b/server/resources/data/mayfly-go.sqlite
index 43ae3648db3cdb1fc7dc82f8d568d62c6dce84c4..cfa3979166a0732df92679245a0c3f7cd69c3ea1 100644
GIT binary patch
delta 2000
zcmcIldu&r>6u;+ux4pOTZr#>y-PW!f?8#QT4ffzAFA-1*5=p>O$2Qr7ZDg$k5W?6)
zFevGE$39?yb3qV|aa!1wXd;Ff5)~qU_#!cYXq1?cjxlF=&F}Uu5EB0J58In_+xz{#
zbI$ksopWw$tF5)w7TzwBMdC2*6mLiw?z^OYp^08d0}mJ}RG>{J=@168i!;zoDUj9m
zz6k`WE1D<`YEq@oq84f4um$v8dx|8@a8lQWY51B>+NLi6y>!X!h=EsC{VjjL;Z(Iy7Y?PMB3I8
zX~0|veB{!DB9NXnuW+<)2Em?~2)mbss@H9dZBRC$^p^3})b+~$YPL`vtP37Hw#-`hRMK+KlA
zkqq}NKC*QFCkA3deFR#^UEOX5^51g}wE|jQ1)PpM$C(AwY2!-WTEV7Ckn)LRdU9dZyuzTi&
zq%C!|4Z%<#c5}!!JN(2-*_24@lb{lk=&>YNPTFQA&^J?|021XhsSpRGZKsXibbuEU
zVs%Ex<3KOZNQPp7c%=!ZKI{NHy_f=-Y4hS@QD3i`h}ziPw7xmS%7)!+5jVWY#Ww3XII)Zr(n24)V~v!hZ>bB0np@cFF1oZF
zi+U?ilnzAAw5uG;NXHr%jfP<|xaqDDOpx=tz>TD{K8-q#Ko+=^v{K|%N8lvNOC&f3
zqFK*ri%Peq)3F}7LON~9wD16wfRpZ!AX(mi02UzWSmB^Q?`K|<)nnOu!GQ@Zx46dy
zYm4{LZ_BX+JPPa=d@+MwJ;a8QG9t2Qb{{0Mw8kqi7cwTMke1G`#QcG<|M*p~LaeKb
z7)NfC{!2~-Bd5P9UK6(Q-{T=m*w73{!;cCh=wSqH=M8h=0qytVM)|N8_pwn`mQB5-
zm<2iN*&9l697v~UGTrOL$&jt){*@2wk+juLq96CMGMTJm|Ly}96S^vkZkUd#kfmb#
zrsIc-(A*S->RjBJNf(#n)W;~7n=7%4X9^F!guL|x--??YA|NMR6LxCzNC42%ZSomq
z{cQcaEbX9D>%8t7*F;BeVK$V~v=N+3I#w6a)9<=r(4;RC@U~&XBK-q4N1b
zp=`B0cn5Ezu4<}aFD->VRn$F-3G|~VCd0H?Ec!tdb@E?P6cD_0C`
z69deajehd0#WrhK2IFaF9Wyg#GE-iS7t$6er|%pkKA5l4@aIwD0Dar4GQnP12^|Zlb3ZADdCKghdHacphW3*+
zR^^r9ac{0}sj07S$tj*jFBGGbj2+GkoJ|+>F3?V4Rck$!`-AG*h#y4NC`Ye
z&-akUw7!?Qo};*yPxX=q1j#eN(6fJSETqfbF0ZVUDRe}W$*{WAX@8~rD=
ze%>3O%bC;F1L>BDH-t1zZY0AUr;$%~^2fF6_UDka2P)|0Fv)=hu}ID?aukk-dGEjE
Cj#0S)
delta 2023
zcmcIlYfKbZ6u#%)nc3GYJIk`n;>xl-M5GAI%SRC(_yEOPYH3V-tx&L%sBB$KwJl|N
z`KXrcI?B}|V$h-{EitY-wm%wMliD_Ez&}d=*xDccV@yF&Qd+ckXVI8GlKyCCl5;1M
zd(J)QJKy-hrQ@+QTdMKfQ6n6f?fG>bXMYGlTLOzVb6w!s_Lz^
z4c=|_+ux|4Tw>JvcsL8Bt<0#D33*_qHx#giI|PjNYYl>&nhK4|xZVk3Bwm^_q_>JG
zGu#NF9l5E{oIr={kf_uX9!%PSbf5WT-e^1WWP)@}DURBeB~)>~J@yjl}=%2&hL
zV5C*!SPqLLYk;(83rdwC1q|B3N{1kXyA6H}ykZq)(9^*#;!;XQGiiN?Q&wW{xzQBDG7#vv^2%hm*c<#_Gl<24vGP65#)3K%-aGSA4{h=*tv1h&6^xh
z!9vWJXp9ZAz@`@2zzU>wnMK)rKLxDXF3NTZ;m_fHHibyZ9?g8N$zTqH?@3aGF%jx$
zHXymo+%HIv?jijP{7v3R%DIQ=p4o2dH_bENHr`~kxo*;SFh;hmbJ0~HNQWfaUy7Y-
zFa!x$J=_VWL2vv52|0zk6Y0XE@B?XEoj|X2v7OFn^7p&Ifi3MehfXdmg#F7kkUEdC
z+De##1a-|Z*oc$a8TaJ;dMWZD!2ceJKV+SCIQB-3CI%z%_<
zQ=dy(YTUH36nh|9WohQK+1`>wKUN?O+$vL*Yxp!oMyGF>xldxEq2V$cZzCf*j*JsH
z)9{U`5
zP*{%RRr^w0i%Hv@blP2l(_pWeK)nck6~}Iyo`%dHwME-`pC}kjR>@GUuy+o6_j;
z3Y-hmqQ%ZG$8$(aY$|n~fC4%ZWD_&QM3d%(7@2mRfGcd&QBnjlC-(gnC$+vDhqwzq
z&V7dSVd)enNoTkK_BjkFgmicKc=wpE73{&l}G&0DRGzXxreSg%h{{3h4(A
za3Zakz`S~J0_!lz(aH4aFrLmbx;l(YNXzPMI`a{BLB6{35%YkVw0R7tLLU8S49_F&
zWm&ZP0nUV6l||~t>YXvn9yCCuMfjRtD2Vo6T`-PEFsTtkLI@fNmlESz!xr<%0NAbSvhB
z*erTX1E%Y&&Wn*c1?-(mlRLN!SfVMmTGhezKw4|%9G#q;413s>qTOTu-G1+m`pAv;
z^lPztO(9HYX473qNCA}4PmYik#+J%iI=QF_+7?jgBr@H6h)jh=T4?&=AyP;CI=C3>
zqlBXZWg48V5Hs~I!v?xUA?xVa5t0u@(M(D@$rFP43iV(&u>mdZBKttE4j$lEVbbD#
zk^UScd9YMX2$3vJ?^HNR$Vru};IJq59C})-VZczQ>*mjencVT}jCQV1_{T7PLC*6B
Dm#$cO
diff --git a/server/resources/script/sql/mayfly-go.sql b/server/resources/script/sql/mayfly-go.sql
index d1e946ea..022b8b7b 100644
--- a/server/resources/script/sql/mayfly-go.sql
+++ b/server/resources/script/sql/mayfly-go.sql
@@ -36,6 +36,7 @@ CREATE TABLE `t_db` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL,
`name` varchar(191) COLLATE utf8mb4_bin DEFAULT NULL,
+ `get_database_mode` tinyint NULL COMMENT '库名获取方式(-1.实时获取、1.指定库名)',
`database` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL,
`remark` varchar(191) COLLATE utf8mb4_bin DEFAULT NULL,
`instance_id` bigint unsigned NOT NULL,
@@ -464,9 +465,9 @@ DROP TABLE IF EXISTS `t_machine_cron_job_exec`;
CREATE TABLE `t_machine_cron_job_exec` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`cron_job_id` bigint DEFAULT NULL,
- `machine_id` bigint DEFAULT NULL,
+ `machine_code` varchar(36) DEFAULT NULL,
`status` tinyint DEFAULT NULL COMMENT '状态',
- `res` varchar(1000) DEFAULT NULL COMMENT '执行结果',
+ `res` varchar(4000) DEFAULT NULL COMMENT '执行结果',
`exec_time` datetime DEFAULT NULL COMMENT '执行时间',
`is_deleted` tinyint NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
diff --git a/server/resources/script/sql/v1.8/v1.8.5.sql b/server/resources/script/sql/v1.8/v1.8.5.sql
new file mode 100644
index 00000000..87d06327
--- /dev/null
+++ b/server/resources/script/sql/v1.8/v1.8.5.sql
@@ -0,0 +1,6 @@
+ALTER TABLE t_db ADD get_database_mode tinyint NULL COMMENT '库名获取方式(-1.实时获取、1.指定库名)';
+UPDATE t_db SET get_database_mode = 1;
+
+
+ALTER TABLE t_machine_cron_job_exec ADD machine_code varchar(36) NULL COMMENT '机器编号';
+ALTER TABLE t_machine_cron_job_exec DROP COLUMN machine_id;