mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 00:10:25 +08:00 
			
		
		
		
	refactor: code review
This commit is contained in:
		@@ -48,7 +48,7 @@
 | 
				
			|||||||
    "@typescript-eslint/eslint-plugin": "^6.7.4",
 | 
					    "@typescript-eslint/eslint-plugin": "^6.7.4",
 | 
				
			||||||
    "@typescript-eslint/parser": "^6.7.4",
 | 
					    "@typescript-eslint/parser": "^6.7.4",
 | 
				
			||||||
    "@vitejs/plugin-vue": "^5.0.2",
 | 
					    "@vitejs/plugin-vue": "^5.0.2",
 | 
				
			||||||
    "@vue/compiler-sfc": "^3.4.3",
 | 
					    "@vue/compiler-sfc": "^3.4.6",
 | 
				
			||||||
    "dotenv": "^16.3.1",
 | 
					    "dotenv": "^16.3.1",
 | 
				
			||||||
    "eslint": "^8.35.0",
 | 
					    "eslint": "^8.35.0",
 | 
				
			||||||
    "eslint-plugin-vue": "^9.19.2",
 | 
					    "eslint-plugin-vue": "^9.19.2",
 | 
				
			||||||
@@ -56,7 +56,7 @@
 | 
				
			|||||||
    "sass": "^1.69.0",
 | 
					    "sass": "^1.69.0",
 | 
				
			||||||
    "typescript": "^5.3.2",
 | 
					    "typescript": "^5.3.2",
 | 
				
			||||||
    "vite": "^5.0.11",
 | 
					    "vite": "^5.0.11",
 | 
				
			||||||
    "vue-eslint-parser": "^9.3.2"
 | 
					    "vue-eslint-parser": "^9.4.0"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "browserslist": [
 | 
					  "browserslist": [
 | 
				
			||||||
    "> 1%",
 | 
					    "> 1%",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -182,7 +182,7 @@ import SearchForm from '@/components/SearchForm/index.vue';
 | 
				
			|||||||
import { SearchItem } from '../SearchForm/index';
 | 
					import { SearchItem } from '../SearchForm/index';
 | 
				
			||||||
import SearchFormItem from '../SearchForm/components/SearchFormItem.vue';
 | 
					import SearchFormItem from '../SearchForm/components/SearchFormItem.vue';
 | 
				
			||||||
import SvgIcon from '@/components/svgIcon/index.vue';
 | 
					import SvgIcon from '@/components/svgIcon/index.vue';
 | 
				
			||||||
import { usePageTable } from '../../hooks/usePageTable';
 | 
					import { usePageTable } from '@/hooks/usePageTable';
 | 
				
			||||||
import { ElTable } from 'element-plus';
 | 
					import { ElTable } from 'element-plus';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const emit = defineEmits(['update:queryForm', 'update:selectionData', 'pageChange']);
 | 
					const emit = defineEmits(['update:queryForm', 'update:selectionData', 'pageChange']);
 | 
				
			||||||
@@ -316,7 +316,7 @@ onMounted(async () => {
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const calcuTableHeight = () => {
 | 
					const calcuTableHeight = () => {
 | 
				
			||||||
    const headerHeight = isShowSearch.value ? 325 : 245;
 | 
					    const headerHeight = isShowSearch.value ? 330 : 250;
 | 
				
			||||||
    state.tableMaxHeight = window.innerHeight - headerHeight + 'px';
 | 
					    state.tableMaxHeight = window.innerHeight - headerHeight + 'px';
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -840,7 +840,6 @@ defineExpose({
 | 
				
			|||||||
    .header-column-title {
 | 
					    .header-column-title {
 | 
				
			||||||
        height: 30px;
 | 
					        height: 30px;
 | 
				
			||||||
        display: flex;
 | 
					        display: flex;
 | 
				
			||||||
        align-items: center;
 | 
					 | 
				
			||||||
        justify-content: center;
 | 
					        justify-content: center;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -445,7 +445,7 @@ class DMDialect implements DbDialect {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wrapName = (name: string) => {
 | 
					    wrapName = (name: string) => {
 | 
				
			||||||
        return `"${name}"`;
 | 
					        return name;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    matchType(text: string, arr: string[]): boolean {
 | 
					    matchType(text: string, arr: string[]): boolean {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -203,7 +203,8 @@ class PostgresqlDialect implements DbDialect {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wrapName = (name: string) => {
 | 
					    wrapName = (name: string) => {
 | 
				
			||||||
        return `"${name}"`;
 | 
					        // 后端sql解析器暂不支持pgsql
 | 
				
			||||||
 | 
					        return name;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    matchType(text: string, arr: string[]): boolean {
 | 
					    matchType(text: string, arr: string[]): boolean {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,11 +23,11 @@ require (
 | 
				
			|||||||
	github.com/pkg/errors v0.9.1
 | 
						github.com/pkg/errors v0.9.1
 | 
				
			||||||
	github.com/pkg/sftp v1.13.6
 | 
						github.com/pkg/sftp v1.13.6
 | 
				
			||||||
	github.com/pquerna/otp v1.4.0
 | 
						github.com/pquerna/otp v1.4.0
 | 
				
			||||||
	github.com/redis/go-redis/v9 v9.3.0
 | 
						github.com/redis/go-redis/v9 v9.4.0
 | 
				
			||||||
	github.com/robfig/cron/v3 v3.0.1 // 定时任务
 | 
						github.com/robfig/cron/v3 v3.0.1 // 定时任务
 | 
				
			||||||
	github.com/stretchr/testify v1.8.4
 | 
						github.com/stretchr/testify v1.8.4
 | 
				
			||||||
	go.mongodb.org/mongo-driver v1.13.1 // mongo
 | 
						go.mongodb.org/mongo-driver v1.13.1 // mongo
 | 
				
			||||||
	golang.org/x/crypto v0.17.0 // ssh
 | 
						golang.org/x/crypto v0.18.0 // ssh
 | 
				
			||||||
	golang.org/x/oauth2 v0.15.0
 | 
						golang.org/x/oauth2 v0.15.0
 | 
				
			||||||
	golang.org/x/sync v0.1.0
 | 
						golang.org/x/sync v0.1.0
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
@@ -81,7 +81,7 @@ require (
 | 
				
			|||||||
	golang.org/x/exp v0.0.0-20230519143937-03e91628a987
 | 
						golang.org/x/exp v0.0.0-20230519143937-03e91628a987
 | 
				
			||||||
	golang.org/x/image v0.13.0 // indirect
 | 
						golang.org/x/image v0.13.0 // indirect
 | 
				
			||||||
	golang.org/x/net v0.19.0 // indirect
 | 
						golang.org/x/net v0.19.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.15.0 // indirect
 | 
						golang.org/x/sys v0.16.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.14.0 // indirect
 | 
						golang.org/x/text v0.14.0 // indirect
 | 
				
			||||||
	google.golang.org/appengine v1.6.7 // indirect
 | 
						google.golang.org/appengine v1.6.7 // indirect
 | 
				
			||||||
	google.golang.org/genproto v0.0.0-20230131230820-1c016267d619 // indirect
 | 
						google.golang.org/genproto v0.0.0-20230131230820-1c016267d619 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								server/initialize/terminate.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								server/initialize/terminate.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					package initialize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						dbApp "mayfly-go/internal/db/application"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 终止服务后的一些操作
 | 
				
			||||||
 | 
					func Terminate() {
 | 
				
			||||||
 | 
						closeDbTasks()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func closeDbTasks() {
 | 
				
			||||||
 | 
						restoreApp := dbApp.GetDbRestoreApp()
 | 
				
			||||||
 | 
						if restoreApp != nil {
 | 
				
			||||||
 | 
							restoreApp.Close()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						binlogApp := dbApp.GetDbBinlogApp()
 | 
				
			||||||
 | 
						if binlogApp != nil {
 | 
				
			||||||
 | 
							binlogApp.Close()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						backupApp := dbApp.GetDbBackupApp()
 | 
				
			||||||
 | 
						if backupApp != nil {
 | 
				
			||||||
 | 
							backupApp.Close()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -88,7 +88,7 @@ func (a *LdapLogin) getUser(userName string, cols ...string) (*sysentity.Account
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *LdapLogin) createUser(userName, displayName string) {
 | 
					func (a *LdapLogin) createUser(userName, displayName string) {
 | 
				
			||||||
	account := &sysentity.Account{Username: userName}
 | 
						account := &sysentity.Account{Username: userName}
 | 
				
			||||||
	account.SetBaseInfo(model.IdGenTypeNone, nil)
 | 
						account.FillBaseInfo(model.IdGenTypeNone, nil)
 | 
				
			||||||
	account.Name = displayName
 | 
						account.Name = displayName
 | 
				
			||||||
	biz.ErrIsNil(a.AccountApp.Create(context.TODO(), account))
 | 
						biz.ErrIsNil(a.AccountApp.Create(context.TODO(), account))
 | 
				
			||||||
	// 将 LADP 用户本地密码设置为空,不允许本地登录
 | 
						// 将 LADP 用户本地密码设置为空,不允许本地登录
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ func createSqlExecRecord(ctx context.Context, execSqlReq *DbSqlExecReq) *entity.
 | 
				
			|||||||
	dbSqlExecRecord.Db = execSqlReq.Db
 | 
						dbSqlExecRecord.Db = execSqlReq.Db
 | 
				
			||||||
	dbSqlExecRecord.Sql = execSqlReq.Sql
 | 
						dbSqlExecRecord.Sql = execSqlReq.Sql
 | 
				
			||||||
	dbSqlExecRecord.Remark = execSqlReq.Remark
 | 
						dbSqlExecRecord.Remark = execSqlReq.Remark
 | 
				
			||||||
	dbSqlExecRecord.SetBaseInfo(model.IdGenTypeNone, contextx.GetLoginAccount(ctx))
 | 
						dbSqlExecRecord.FillBaseInfo(model.IdGenTypeNone, contextx.GetLoginAccount(ctx))
 | 
				
			||||||
	return dbSqlExecRecord
 | 
						return dbSqlExecRecord
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
package dbm
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type DataType string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const (
 | 
					 | 
				
			||||||
	DataTypeString   DataType = "string"
 | 
					 | 
				
			||||||
	DataTypeNumber   DataType = "number"
 | 
					 | 
				
			||||||
	DataTypeDate     DataType = "date"
 | 
					 | 
				
			||||||
	DataTypeTime     DataType = "time"
 | 
					 | 
				
			||||||
	DataTypeDateTime DataType = "datetime"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
@@ -9,6 +9,16 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DataType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						DataTypeString   DataType = "string"
 | 
				
			||||||
 | 
						DataTypeNumber   DataType = "number"
 | 
				
			||||||
 | 
						DataTypeDate     DataType = "date"
 | 
				
			||||||
 | 
						DataTypeTime     DataType = "time"
 | 
				
			||||||
 | 
						DataTypeDateTime DataType = "datetime"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 数据库服务实例信息
 | 
					// 数据库服务实例信息
 | 
				
			||||||
type DbServer struct {
 | 
					type DbServer struct {
 | 
				
			||||||
	Version string  `json:"version"` // 版本信息
 | 
						Version string  `json:"version"` // 版本信息
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,11 +86,11 @@ func (br *RepoImpl[T]) Insert(ctx context.Context, e T) error {
 | 
				
			|||||||
	if db := contextx.GetDb(ctx); db != nil {
 | 
						if db := contextx.GetDb(ctx); db != nil {
 | 
				
			||||||
		return br.InsertWithDb(ctx, db, e)
 | 
							return br.InsertWithDb(ctx, db, e)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.Insert(br.setBaseInfo(ctx, e))
 | 
						return gormx.Insert(br.fillBaseInfo(ctx, e))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) InsertWithDb(ctx context.Context, db *gorm.DB, e T) error {
 | 
					func (br *RepoImpl[T]) InsertWithDb(ctx context.Context, db *gorm.DB, e T) error {
 | 
				
			||||||
	return gormx.InsertWithDb(db, br.setBaseInfo(ctx, e))
 | 
						return gormx.InsertWithDb(db, br.fillBaseInfo(ctx, e))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) BatchInsert(ctx context.Context, es []T) error {
 | 
					func (br *RepoImpl[T]) BatchInsert(ctx context.Context, es []T) error {
 | 
				
			||||||
@@ -99,7 +99,7 @@ func (br *RepoImpl[T]) BatchInsert(ctx context.Context, es []T) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, e := range es {
 | 
						for _, e := range es {
 | 
				
			||||||
		br.setBaseInfo(ctx, e)
 | 
							br.fillBaseInfo(ctx, e)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.BatchInsert(es)
 | 
						return gormx.BatchInsert(es)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -107,7 +107,7 @@ func (br *RepoImpl[T]) BatchInsert(ctx context.Context, es []T) error {
 | 
				
			|||||||
// 使用指定gorm db执行,主要用于事务执行
 | 
					// 使用指定gorm db执行,主要用于事务执行
 | 
				
			||||||
func (br *RepoImpl[T]) BatchInsertWithDb(ctx context.Context, db *gorm.DB, es []T) error {
 | 
					func (br *RepoImpl[T]) BatchInsertWithDb(ctx context.Context, db *gorm.DB, es []T) error {
 | 
				
			||||||
	for _, e := range es {
 | 
						for _, e := range es {
 | 
				
			||||||
		br.setBaseInfo(ctx, e)
 | 
							br.fillBaseInfo(ctx, e)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.BatchInsertWithDb(db, es)
 | 
						return gormx.BatchInsertWithDb(db, es)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -117,11 +117,11 @@ func (br *RepoImpl[T]) UpdateById(ctx context.Context, e T, columns ...string) e
 | 
				
			|||||||
		return br.UpdateByIdWithDb(ctx, db, e, columns...)
 | 
							return br.UpdateByIdWithDb(ctx, db, e, columns...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return gormx.UpdateById(br.setBaseInfo(ctx, e), columns...)
 | 
						return gormx.UpdateById(br.fillBaseInfo(ctx, e), columns...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) UpdateByIdWithDb(ctx context.Context, db *gorm.DB, e T, columns ...string) error {
 | 
					func (br *RepoImpl[T]) UpdateByIdWithDb(ctx context.Context, db *gorm.DB, e T, columns ...string) error {
 | 
				
			||||||
	return gormx.UpdateByIdWithDb(db, br.setBaseInfo(ctx, e), columns...)
 | 
						return gormx.UpdateByIdWithDb(db, br.fillBaseInfo(ctx, e), columns...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) Updates(cond any, udpateFields map[string]any) error {
 | 
					func (br *RepoImpl[T]) Updates(cond any, udpateFields map[string]any) error {
 | 
				
			||||||
@@ -197,10 +197,10 @@ func (br *RepoImpl[T]) GetModel() T {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 从上下文获取登录账号信息,并赋值至实体
 | 
					// 从上下文获取登录账号信息,并赋值至实体
 | 
				
			||||||
func (br *RepoImpl[T]) setBaseInfo(ctx context.Context, e T) T {
 | 
					func (br *RepoImpl[T]) fillBaseInfo(ctx context.Context, e T) T {
 | 
				
			||||||
	if la := contextx.GetLoginAccount(ctx); la != nil {
 | 
						if la := contextx.GetLoginAccount(ctx); la != nil {
 | 
				
			||||||
		// 默认使用数据库id策略, 若要改变则实体结构体自行覆盖SetBaseInfo方法。可参考 sys/entity.Resource
 | 
							// 默认使用数据库id策略, 若要改变则实体结构体自行覆盖SetBaseInfo方法。可参考 sys/entity.Resource
 | 
				
			||||||
		e.SetBaseInfo(model.IdGenTypeNone, la)
 | 
							e.FillBaseInfo(model.IdGenTypeNone, la)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return e
 | 
						return e
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,10 +24,10 @@ type ModelI interface {
 | 
				
			|||||||
	// 是否为新建该实体模型, 默认 id == 0 为新建
 | 
						// 是否为新建该实体模型, 默认 id == 0 为新建
 | 
				
			||||||
	IsCreate() bool
 | 
						IsCreate() bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 使用当前登录账号信息设置实体结构体的基础信息
 | 
						// 使用当前登录账号信息赋值实体结构体的基础信息
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	// 如创建时间,修改时间,创建者,修改者信息
 | 
						// 如创建时间,修改时间,创建者,修改者信息等
 | 
				
			||||||
	SetBaseInfo(idGenType IdGenType, account *LoginAccount)
 | 
						FillBaseInfo(idGenType IdGenType, account *LoginAccount)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type IdModel struct {
 | 
					type IdModel struct {
 | 
				
			||||||
@@ -38,7 +38,7 @@ func (m *IdModel) IsCreate() bool {
 | 
				
			|||||||
	return m.Id == 0
 | 
						return m.Id == 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *IdModel) SetBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
					func (m *IdModel) FillBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
				
			||||||
	// 存在id,则赋值
 | 
						// 存在id,则赋值
 | 
				
			||||||
	if !m.IsCreate() {
 | 
						if !m.IsCreate() {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -53,9 +53,9 @@ type DeletedModel struct {
 | 
				
			|||||||
	DeleteTime *time.Time `json:"-"`
 | 
						DeleteTime *time.Time `json:"-"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *DeletedModel) SetBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
					func (m *DeletedModel) FillBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
				
			||||||
	if m.Id == 0 {
 | 
						if m.Id == 0 {
 | 
				
			||||||
		m.IdModel.SetBaseInfo(idGenType, account)
 | 
							m.IdModel.FillBaseInfo(idGenType, account)
 | 
				
			||||||
		m.IsDeleted = ModelUndeleted
 | 
							m.IsDeleted = ModelUndeleted
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -73,7 +73,7 @@ func (m *CreateModel) SetBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m.DeletedModel.SetBaseInfo(idGenType, account)
 | 
						m.DeletedModel.FillBaseInfo(idGenType, account)
 | 
				
			||||||
	nowTime := time.Now()
 | 
						nowTime := time.Now()
 | 
				
			||||||
	m.CreateTime = &nowTime
 | 
						m.CreateTime = &nowTime
 | 
				
			||||||
	if account != nil {
 | 
						if account != nil {
 | 
				
			||||||
@@ -101,7 +101,7 @@ func (m *Model) SetBaseInfo(idGenType IdGenType, account *LoginAccount) {
 | 
				
			|||||||
	if isCreate {
 | 
						if isCreate {
 | 
				
			||||||
		m.IsDeleted = ModelUndeleted
 | 
							m.IsDeleted = ModelUndeleted
 | 
				
			||||||
		m.CreateTime = &nowTime
 | 
							m.CreateTime = &nowTime
 | 
				
			||||||
		m.IdModel.SetBaseInfo(idGenType, account)
 | 
							m.IdModel.FillBaseInfo(idGenType, account)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	m.UpdateTime = &nowTime
 | 
						m.UpdateTime = &nowTime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,14 +3,14 @@ package starter
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"mayfly-go/initialize"
 | 
						"mayfly-go/initialize"
 | 
				
			||||||
	"mayfly-go/internal/db/application"
 | 
					 | 
				
			||||||
	"mayfly-go/pkg/config"
 | 
						"mayfly-go/pkg/config"
 | 
				
			||||||
	"mayfly-go/pkg/logx"
 | 
						"mayfly-go/pkg/logx"
 | 
				
			||||||
	"mayfly-go/pkg/req"
 | 
						"mayfly-go/pkg/req"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func runWebServer(ctx context.Context) {
 | 
					func runWebServer(ctx context.Context) {
 | 
				
			||||||
@@ -41,8 +41,7 @@ func runWebServer(ctx context.Context) {
 | 
				
			|||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logx.Errorf("Failed to Shutdown HTTP Server: %v", err)
 | 
								logx.Errorf("Failed to Shutdown HTTP Server: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		closeDbTasks()
 | 
							initialize.Terminate()
 | 
				
			||||||
		// todo: close backupApp and restoreApp
 | 
					 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	confSrv := config.Conf.Server
 | 
						confSrv := config.Conf.Server
 | 
				
			||||||
@@ -59,18 +58,3 @@ func runWebServer(ctx context.Context) {
 | 
				
			|||||||
		logx.Errorf("Failed to Start HTTP Server: %v", err)
 | 
							logx.Errorf("Failed to Start HTTP Server: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func closeDbTasks() {
 | 
					 | 
				
			||||||
	restoreApp := application.GetDbRestoreApp()
 | 
					 | 
				
			||||||
	if restoreApp != nil {
 | 
					 | 
				
			||||||
		restoreApp.Close()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	binlogApp := application.GetDbBinlogApp()
 | 
					 | 
				
			||||||
	if binlogApp != nil {
 | 
					 | 
				
			||||||
		binlogApp.Close()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	backupApp := application.GetDbBackupApp()
 | 
					 | 
				
			||||||
	if backupApp != nil {
 | 
					 | 
				
			||||||
		backupApp.Close()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -234,6 +234,62 @@ CREATE TABLE `t_db_binlog_history` (
 | 
				
			|||||||
    KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE
 | 
					    KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE
 | 
				
			||||||
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 | 
					) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Table structure for t_db_data_sync_task
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					DROP TABLE IF EXISTS `t_db_data_sync_task`;
 | 
				
			||||||
 | 
					CREATE TABLE `t_db_data_sync_task`
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					    `id`                bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
 | 
				
			||||||
 | 
					    `creator_id`        bigint(20) NOT NULL COMMENT '创建人id',
 | 
				
			||||||
 | 
					    `creator`           varchar(100) NOT NULL COMMENT '创建人姓名',
 | 
				
			||||||
 | 
					    `create_time`       datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
 | 
				
			||||||
 | 
					    `update_time`       datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
 | 
				
			||||||
 | 
					    `modifier`          varchar(100) NOT NULL COMMENT '修改人姓名',
 | 
				
			||||||
 | 
					    `modifier_id`       bigint(20) NOT NULL COMMENT '修改人id',
 | 
				
			||||||
 | 
					    `task_name`         varchar(500) NOT NULL COMMENT '任务名',
 | 
				
			||||||
 | 
					    `task_cron`         varchar(50)  NOT NULL COMMENT '任务Cron表达式',
 | 
				
			||||||
 | 
					    `src_db_id`         bigint(20) NOT NULL COMMENT '源数据库ID',
 | 
				
			||||||
 | 
					    `src_db_name`       varchar(100)          DEFAULT NULL COMMENT '源数据库名',
 | 
				
			||||||
 | 
					    `src_tag_path`      varchar(200)          DEFAULT NULL COMMENT '源数据库tag路径',
 | 
				
			||||||
 | 
					    `target_db_id`      bigint(20) NOT NULL COMMENT '目标数据库ID',
 | 
				
			||||||
 | 
					    `target_db_name`    varchar(100)          DEFAULT NULL COMMENT '目标数据库名',
 | 
				
			||||||
 | 
					    `target_tag_path`   varchar(200)          DEFAULT NULL COMMENT '目标数据库tag路径',
 | 
				
			||||||
 | 
					    `target_table_name` varchar(100)          DEFAULT NULL COMMENT '目标数据库表名',
 | 
				
			||||||
 | 
					    `data_sql`          text         NOT NULL COMMENT '数据查询sql',
 | 
				
			||||||
 | 
					    `page_size`         int(11) NOT NULL COMMENT '数据同步分页大小',
 | 
				
			||||||
 | 
					    `upd_field`         varchar(100) NOT NULL DEFAULT 'id' COMMENT '更新字段,默认"id"',
 | 
				
			||||||
 | 
					    `upd_field_val`     varchar(100)          DEFAULT NULL COMMENT '当前更新值',
 | 
				
			||||||
 | 
					    `id_rule`           tinyint(2) NOT NULL DEFAULT '1' COMMENT 'id生成规则:1、MD5(时间戳+更新字段的值)。2、无(不自动生成id,选择无的时候需要指定主键ID字段是数据源哪个字段)',
 | 
				
			||||||
 | 
					    `pk_field`          varchar(100)          DEFAULT 'id' COMMENT '主键id字段名,默认"id"',
 | 
				
			||||||
 | 
					    `field_map`         text COMMENT '字段映射json',
 | 
				
			||||||
 | 
					    `is_deleted`        tinyint(8) DEFAULT '0',
 | 
				
			||||||
 | 
					    `delete_time`       datetime              DEFAULT NULL,
 | 
				
			||||||
 | 
					    `status`            tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态 1启用 2停用',
 | 
				
			||||||
 | 
					    `recent_state`      tinyint(1) NOT NULL DEFAULT '0' COMMENT '最近一次状态 0未执行 1成功 2失败',
 | 
				
			||||||
 | 
					    `task_key`          varchar(100)          DEFAULT NULL COMMENT '定时任务唯一uuid key',
 | 
				
			||||||
 | 
					    `running_state`     tinyint(1) DEFAULT '2' COMMENT '运行时状态 1运行中、2待运行、3已停止',
 | 
				
			||||||
 | 
					    PRIMARY KEY (`id`)
 | 
				
			||||||
 | 
					) COMMENT='数据同步';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Table structure for t_db_data_sync_log
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					DROP TABLE IF EXISTS `t_db_data_sync_log`;
 | 
				
			||||||
 | 
					CREATE TABLE `t_db_data_sync_log`
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					    `id`            bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
 | 
				
			||||||
 | 
					    `task_id`       bigint(20) NOT NULL COMMENT '同步任务表id',
 | 
				
			||||||
 | 
					    `create_time`   datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
 | 
				
			||||||
 | 
					    `data_sql_full` text     NOT NULL COMMENT '执行的完整sql',
 | 
				
			||||||
 | 
					    `res_num`       int(11) DEFAULT NULL COMMENT '收到数据条数',
 | 
				
			||||||
 | 
					    `err_text`      text COMMENT '错误日志',
 | 
				
			||||||
 | 
					    `status`        tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:1.成功  0.失败',
 | 
				
			||||||
 | 
					    `is_deleted`    tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 1是 0 否',
 | 
				
			||||||
 | 
					    PRIMARY KEY (`id`),
 | 
				
			||||||
 | 
					    KEY             `t_db_data_sync_log_taskid_idx` (`task_id`) USING BTREE COMMENT 't_db_data_sync_log表(taskid)普通索引'
 | 
				
			||||||
 | 
					) COMMENT='数据同步日志';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DROP TABLE IF EXISTS `t_auth_cert`;
 | 
					DROP TABLE IF EXISTS `t_auth_cert`;
 | 
				
			||||||
CREATE TABLE `t_auth_cert` (
 | 
					CREATE TABLE `t_auth_cert` (
 | 
				
			||||||
@@ -719,12 +775,18 @@ INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight
 | 
				
			|||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(132, 130, '12sSjal1/W9XKiabq/zxXM23i0/', 2, 1, '删除计划任务', 'machine:cronjob:del', 1689860102, 'null', 1, 'admin', 1, 'admin', '2023-07-20 21:35:02', '2023-07-20 21:35:02', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(132, 130, '12sSjal1/W9XKiabq/zxXM23i0/', 2, 1, '删除计划任务', 'machine:cronjob:del', 1689860102, 'null', 1, 'admin', 1, 'admin', '2023-07-20 21:35:02', '2023-07-20 21:35:02', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(131, 130, '12sSjal1/W9XKiabq/gEOqr2pD/', 2, 1, '保存计划任务', 'machine:cronjob:save', 1689860087, 'null', 1, 'admin', 1, 'admin', '2023-07-20 21:34:47', '2023-07-20 21:34:47', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(131, 130, '12sSjal1/W9XKiabq/gEOqr2pD/', 2, 1, '保存计划任务', 'machine:cronjob:save', 1689860087, 'null', 1, 'admin', 1, 'admin', '2023-07-20 21:34:47', '2023-07-20 21:34:47', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(130, 2, '12sSjal1/W9XKiabq/', 1, 1, '计划任务', '/machine/cron-job', 1689646396, '{"component":"ops/machine/cronjob/CronJobList","icon":"AlarmClock","isKeepAlive":true,"routeName":"CronJobList"}', 1, 'admin', 1, 'admin', '2023-07-18 10:13:16', '2023-07-18 10:14:06', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(130, 2, '12sSjal1/W9XKiabq/', 1, 1, '计划任务', '/machine/cron-job', 1689646396, '{"component":"ops/machine/cronjob/CronJobList","icon":"AlarmClock","isKeepAlive":true,"routeName":"CronJobList"}', 1, 'admin', 1, 'admin', '2023-07-18 10:13:16', '2023-07-18 10:14:06', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, type, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(134, 80, 'Mongo452/eggago31/3sblw1Wb/', 2, 1, '删除数据', 'mongo:data:del', 1692674964, 'null', 1, 'admin', 1, 'admin', '2023-08-22 11:29:24', '2023-08-22 11:29:24', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(134, 80, 'Mongo452/eggago31/3sblw1Wb/', 2, 1, '删除数据', 'mongo:data:del', 1692674964, 'null', 1, 'admin', 1, 'admin', '2023-08-22 11:29:24', '2023-08-22 11:29:24', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, type, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(133, 80, 'Mongo452/eggago31/xvpKk36u/', 2, 1, '保存数据', 'mongo:data:save', 1692674943, 'null', 1, 'admin', 1, 'admin', '2023-08-22 11:29:04', '2023-08-22 11:29:11', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(133, 80, 'Mongo452/eggago31/xvpKk36u/', 2, 1, '保存数据', 'mongo:data:save', 1692674943, 'null', 1, 'admin', 1, 'admin', '2023-08-22 11:29:04', '2023-08-22 11:29:11', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (135, 36, 'dbms23ax/X0f4BxT0/', 1, 1, '数据库实例', 'instances', 1693040706, '{\"component\":\"ops/db/InstanceList\",\"icon\":\"Coin\",\"isKeepAlive\":true,\"routeName\":\"InstanceList\"}', 1, 'admin', 1, 'admin', '2023-08-26 09:05:07', '2023-08-29 22:35:11', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (135, 36, 'dbms23ax/X0f4BxT0/', 1, 1, '数据库实例', 'instances', 1693040706, '{\"component\":\"ops/db/InstanceList\",\"icon\":\"Coin\",\"isKeepAlive\":true,\"routeName\":\"InstanceList\"}', 1, 'admin', 1, 'admin', '2023-08-26 09:05:07', '2023-08-29 22:35:11', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (136, 135, 'dbms23ax/X0f4BxT0/D23fUiBr/', 2, 1, '实例保存', 'db:instance:save', 1693041001, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:10:02', '2023-08-26 09:10:02', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (136, 135, 'dbms23ax/X0f4BxT0/D23fUiBr/', 2, 1, '实例保存', 'db:instance:save', 1693041001, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:10:02', '2023-08-26 09:10:02', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (137, 135, 'dbms23ax/X0f4BxT0/mJlBeTCs/', 2, 1, '基本权限', 'db:instance', 1693041055, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:10:55', '2023-08-26 09:10:55', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (137, 135, 'dbms23ax/X0f4BxT0/mJlBeTCs/', 2, 1, '基本权限', 'db:instance', 1693041055, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:10:55', '2023-08-26 09:10:55', 0, NULL);
 | 
				
			||||||
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (138, 135, 'dbms23ax/X0f4BxT0/Sgg8uPwz/', 2, 1, '实例删除', 'db:instance:del', 1693041084, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:11:24', '2023-08-26 09:11:24', 0, NULL);
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES (138, 135, 'dbms23ax/X0f4BxT0/Sgg8uPwz/', 2, 1, '实例删除', 'db:instance:del', 1693041084, 'null', 1, 'admin', 1, 'admin', '2023-08-26 09:11:24', '2023-08-26 09:11:24', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(155, 150, 'Jra0n7De/PigmSGVg/', 2, 1, '日志', 'db:sync:log', 1704266866, 'null', 12, 'liuzongyang', 12, 'liuzongyang', '2024-01-03 15:27:47', '2024-01-03 15:27:47', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(154, 150, 'Jra0n7De/VBt68CDx/', 2, 1, '启停', 'db:sync:status', 1703641364, 'null', 12, 'liuzongyang', 12, 'liuzongyang', '2023-12-27 09:42:45', '2023-12-27 09:42:45', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(153, 150, 'Jra0n7De/pLOA2UYz/', 2, 1, '删除', 'db:sync:del', 1703641342, 'null', 12, 'liuzongyang', 12, 'liuzongyang', '2023-12-27 09:42:22', '2023-12-27 09:42:22', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(152, 150, 'Jra0n7De/zvAMo2vk/', 2, 1, '编辑', 'db:sync:save', 1703641320, 'null', 12, 'liuzongyang', 12, 'liuzongyang', '2023-12-27 09:42:00', '2023-12-27 09:42:12', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(151, 150, 'Jra0n7De/uAnHZxEV/', 2, 1, '基本权限', 'db:sync', 1703641202, 'null', 12, 'liuzongyang', 12, 'liuzongyang', '2023-12-27 09:40:02', '2023-12-27 09:40:02', 0, NULL);
 | 
				
			||||||
 | 
					INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(150, 36, 'Jra0n7De/', 1, 1, '数据同步', 'sync', 1693040707, '{"component":"ops/db/SyncTaskList","icon":"Coin","isKeepAlive":true,"routeName":"SyncTaskList"}', 12, 'liuzongyang', 12, 'liuzongyang', '2023-12-22 09:51:34', '2023-12-27 10:16:57', 0, NULL);
 | 
				
			||||||
COMMIT;
 | 
					COMMIT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user