mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	refactor: base.repo与app重构优化
This commit is contained in:
		@@ -33,7 +33,7 @@
 | 
				
			|||||||
    "sql-formatter": "^15.0.2",
 | 
					    "sql-formatter": "^15.0.2",
 | 
				
			||||||
    "trzsz": "^1.1.5",
 | 
					    "trzsz": "^1.1.5",
 | 
				
			||||||
    "uuid": "^9.0.1",
 | 
					    "uuid": "^9.0.1",
 | 
				
			||||||
    "vue": "^3.4.25",
 | 
					    "vue": "^3.4.26",
 | 
				
			||||||
    "vue-router": "^4.3.2",
 | 
					    "vue-router": "^4.3.2",
 | 
				
			||||||
    "xterm": "^5.3.0",
 | 
					    "xterm": "^5.3.0",
 | 
				
			||||||
    "xterm-addon-fit": "^0.8.0",
 | 
					    "xterm-addon-fit": "^0.8.0",
 | 
				
			||||||
@@ -56,7 +56,7 @@
 | 
				
			|||||||
    "prettier": "^3.2.5",
 | 
					    "prettier": "^3.2.5",
 | 
				
			||||||
    "sass": "^1.75.0",
 | 
					    "sass": "^1.75.0",
 | 
				
			||||||
    "typescript": "^5.4.5",
 | 
					    "typescript": "^5.4.5",
 | 
				
			||||||
    "vite": "^5.2.10",
 | 
					    "vite": "^5.2.11",
 | 
				
			||||||
    "vue-eslint-parser": "^9.4.2"
 | 
					    "vue-eslint-parser": "^9.4.2"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "browserslist": [
 | 
					  "browserslist": [
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -171,7 +171,7 @@ func (a *Oauth2Login) doLoginAction(rc *req.Ctx, userId string, oauth *config.Oa
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 进行登录
 | 
						// 进行登录
 | 
				
			||||||
	account, err := a.AccountApp.GetById(new(sysentity.Account), accountId, "Id", "Name", "Username", "Password", "Status", "LastLoginTime", "LastLoginIp", "OtpSecret")
 | 
						account, err := a.AccountApp.GetById(accountId, "Id", "Name", "Username", "Password", "Status", "LastLoginTime", "LastLoginIp", "OtpSecret")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取用户信息失败: %s")
 | 
						biz.ErrIsNilAppendErr(err, "获取用户信息失败: %s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	clientIp := getIpAndRegion(rc)
 | 
						clientIp := getIpAndRegion(rc)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -84,8 +84,6 @@ func (d *Db) DeleteDb(rc *req.Ctx) {
 | 
				
			|||||||
		dbId := cast.ToUint64(v)
 | 
							dbId := cast.ToUint64(v)
 | 
				
			||||||
		biz.NotBlank(dbId, "存在错误dbId")
 | 
							biz.NotBlank(dbId, "存在错误dbId")
 | 
				
			||||||
		biz.ErrIsNil(d.DbApp.Delete(ctx, dbId))
 | 
							biz.ErrIsNil(d.DbApp.Delete(ctx, dbId))
 | 
				
			||||||
		// 删除该库的sql执行记录
 | 
					 | 
				
			||||||
		d.DbSqlExecApp.DeleteBy(ctx, &entity.DbSqlExec{DbId: dbId})
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -282,7 +280,7 @@ func (d *Db) DumpSql(rc *req.Ctx) {
 | 
				
			|||||||
	needData := dumpType == "2" || dumpType == "3"
 | 
						needData := dumpType == "2" || dumpType == "3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	la := rc.GetLoginAccount()
 | 
						la := rc.GetLoginAccount()
 | 
				
			||||||
	db, err := d.DbApp.GetById(new(entity.Db), dbId)
 | 
						db, err := d.DbApp.GetById(dbId)
 | 
				
			||||||
	biz.ErrIsNil(err, "该数据库不存在")
 | 
						biz.ErrIsNil(err, "该数据库不存在")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(d.TagApp.CanAccess(la.Id, d.TagApp.ListTagPathByTypeAndCode(consts.ResourceTypeDb, db.Code)...), "%s")
 | 
						biz.ErrIsNilAppendErr(d.TagApp.CanAccess(la.Id, d.TagApp.ListTagPathByTypeAndCode(consts.ResourceTypeDb, db.Code)...), "%s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ type DbBackup struct {
 | 
				
			|||||||
func (d *DbBackup) GetPageList(rc *req.Ctx) {
 | 
					func (d *DbBackup) GetPageList(rc *req.Ctx) {
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
						biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "db_instance_id", "database")
 | 
						db, err := d.dbApp.GetById(dbId, "db_instance_id", "database")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	queryCond, page := req.BindQueryAndPage[*entity.DbBackupQuery](rc, new(entity.DbBackupQuery))
 | 
						queryCond, page := req.BindQueryAndPage[*entity.DbBackupQuery](rc, new(entity.DbBackupQuery))
 | 
				
			||||||
@@ -49,7 +49,7 @@ func (d *DbBackup) Create(rc *req.Ctx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
						biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "instanceId")
 | 
						db, err := d.dbApp.GetById(dbId, "instanceId")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
	jobs := make([]*entity.DbBackup, 0, len(dbNames))
 | 
						jobs := make([]*entity.DbBackup, 0, len(dbNames))
 | 
				
			||||||
	for _, dbName := range dbNames {
 | 
						for _, dbName := range dbNames {
 | 
				
			||||||
@@ -134,7 +134,7 @@ func (d *DbBackup) Start(rc *req.Ctx) {
 | 
				
			|||||||
// @router /api/dbs/:dbId/db-names-without-backup [GET]
 | 
					// @router /api/dbs/:dbId/db-names-without-backup [GET]
 | 
				
			||||||
func (d *DbBackup) GetDbNamesWithoutBackup(rc *req.Ctx) {
 | 
					func (d *DbBackup) GetDbNamesWithoutBackup(rc *req.Ctx) {
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "instance_id", "database")
 | 
						db, err := d.dbApp.GetById(dbId, "instance_id", "database")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
	dbNames := strings.Fields(db.Database)
 | 
						dbNames := strings.Fields(db.Database)
 | 
				
			||||||
	dbNamesWithoutBackup, err := d.backupApp.GetDbNamesWithoutBackup(db.InstanceId, dbNames)
 | 
						dbNamesWithoutBackup, err := d.backupApp.GetDbNamesWithoutBackup(db.InstanceId, dbNames)
 | 
				
			||||||
@@ -147,7 +147,7 @@ func (d *DbBackup) GetDbNamesWithoutBackup(rc *req.Ctx) {
 | 
				
			|||||||
func (d *DbBackup) GetHistoryPageList(rc *req.Ctx) {
 | 
					func (d *DbBackup) GetHistoryPageList(rc *req.Ctx) {
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
						biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "db_instance_id", "database")
 | 
						db, err := d.dbApp.GetById(dbId, "db_instance_id", "database")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	backupHistoryCond, page := req.BindQueryAndPage[*entity.DbBackupHistoryQuery](rc, new(entity.DbBackupHistoryQuery))
 | 
						backupHistoryCond, page := req.BindQueryAndPage[*entity.DbBackupHistoryQuery](rc, new(entity.DbBackupHistoryQuery))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,7 +64,7 @@ func (d *DataSyncTask) ChangeStatus(rc *req.Ctx) {
 | 
				
			|||||||
	_ = d.DataSyncTaskApp.UpdateById(rc.MetaCtx, task)
 | 
						_ = d.DataSyncTaskApp.UpdateById(rc.MetaCtx, task)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if task.Status == entity.DataSyncTaskStatusEnable {
 | 
						if task.Status == entity.DataSyncTaskStatusEnable {
 | 
				
			||||||
		task, err := d.DataSyncTaskApp.GetById(new(entity.DataSyncTask), task.Id)
 | 
							task, err := d.DataSyncTaskApp.GetById(task.Id)
 | 
				
			||||||
		biz.ErrIsNil(err, "该任务不存在")
 | 
							biz.ErrIsNil(err, "该任务不存在")
 | 
				
			||||||
		d.DataSyncTaskApp.AddCronJob(rc.MetaCtx, task)
 | 
							d.DataSyncTaskApp.AddCronJob(rc.MetaCtx, task)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@@ -92,7 +92,7 @@ func (d *DataSyncTask) Stop(rc *req.Ctx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *DataSyncTask) GetTask(rc *req.Ctx) {
 | 
					func (d *DataSyncTask) GetTask(rc *req.Ctx) {
 | 
				
			||||||
	taskId := d.getTaskId(rc)
 | 
						taskId := d.getTaskId(rc)
 | 
				
			||||||
	dbEntity, _ := d.DataSyncTaskApp.GetById(new(entity.DataSyncTask), taskId)
 | 
						dbEntity, _ := d.DataSyncTaskApp.GetById(taskId)
 | 
				
			||||||
	rc.ResData = dbEntity
 | 
						rc.ResData = dbEntity
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,7 +83,7 @@ func (d *Instance) SaveInstance(rc *req.Ctx) {
 | 
				
			|||||||
// @router /api/instances/:instance [GET]
 | 
					// @router /api/instances/:instance [GET]
 | 
				
			||||||
func (d *Instance) GetInstance(rc *req.Ctx) {
 | 
					func (d *Instance) GetInstance(rc *req.Ctx) {
 | 
				
			||||||
	dbId := getInstanceId(rc)
 | 
						dbId := getInstanceId(rc)
 | 
				
			||||||
	dbEntity, err := d.InstanceApp.GetById(new(entity.DbInstance), dbId)
 | 
						dbEntity, err := d.InstanceApp.GetById(dbId)
 | 
				
			||||||
	biz.ErrIsNil(err, "获取数据库实例错误")
 | 
						biz.ErrIsNil(err, "获取数据库实例错误")
 | 
				
			||||||
	rc.ResData = dbEntity
 | 
						rc.ResData = dbEntity
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ type DbRestore struct {
 | 
				
			|||||||
func (d *DbRestore) GetPageList(rc *req.Ctx) {
 | 
					func (d *DbRestore) GetPageList(rc *req.Ctx) {
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
						biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "db_instance_id", "database")
 | 
						db, err := d.dbApp.GetById(dbId, "db_instance_id", "database")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var restores []vo.DbRestore
 | 
						var restores []vo.DbRestore
 | 
				
			||||||
@@ -43,7 +43,7 @@ func (d *DbRestore) Create(rc *req.Ctx) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
						biz.IsTrue(dbId > 0, "无效的 dbId: %v", dbId)
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "instanceId")
 | 
						db, err := d.dbApp.GetById(dbId, "instanceId")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	job := &entity.DbRestore{
 | 
						job := &entity.DbRestore{
 | 
				
			||||||
@@ -123,7 +123,7 @@ func (d *DbRestore) Disable(rc *req.Ctx) {
 | 
				
			|||||||
// @router /api/dbs/:dbId/db-names-without-backup [GET]
 | 
					// @router /api/dbs/:dbId/db-names-without-backup [GET]
 | 
				
			||||||
func (d *DbRestore) GetDbNamesWithoutRestore(rc *req.Ctx) {
 | 
					func (d *DbRestore) GetDbNamesWithoutRestore(rc *req.Ctx) {
 | 
				
			||||||
	dbId := uint64(rc.PathParamInt("dbId"))
 | 
						dbId := uint64(rc.PathParamInt("dbId"))
 | 
				
			||||||
	db, err := d.dbApp.GetById(new(entity.Db), dbId, "instance_id", "database")
 | 
						db, err := d.dbApp.GetById(dbId, "instance_id", "database")
 | 
				
			||||||
	biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
						biz.ErrIsNilAppendErr(err, "获取数据库信息失败: %v")
 | 
				
			||||||
	dbNames := strings.Fields(db.Database)
 | 
						dbNames := strings.Fields(db.Database)
 | 
				
			||||||
	dbNamesWithoutRestore, err := d.restoreApp.GetDbNamesWithoutRestore(db.InstanceId, dbNames)
 | 
						dbNamesWithoutRestore, err := d.restoreApp.GetDbNamesWithoutRestore(db.InstanceId, dbNames)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,8 +43,7 @@ func (d *DbSql) GetSqlNames(rc *req.Ctx) {
 | 
				
			|||||||
	// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
 | 
						// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
 | 
				
			||||||
	dbSql := &entity.DbSql{Type: 1, DbId: dbId, Db: dbName}
 | 
						dbSql := &entity.DbSql{Type: 1, DbId: dbId, Db: dbName}
 | 
				
			||||||
	dbSql.CreatorId = rc.GetLoginAccount().Id
 | 
						dbSql.CreatorId = rc.GetLoginAccount().Id
 | 
				
			||||||
	var sqls []entity.DbSql
 | 
						sqls, _ := d.DbSqlApp.ListByCond(model.NewModelCond(dbSql).Columns("id", "name"))
 | 
				
			||||||
	d.DbSqlApp.ListByCond(model.NewModelCond(dbSql).Columns("id", "name"), &sqls)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ResData = sqls
 | 
						rc.ResData = sqls
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,6 +48,7 @@ type dbAppImpl struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	dbSqlRepo           repository.DbSql        `inject:"DbSqlRepo"`
 | 
						dbSqlRepo           repository.DbSql        `inject:"DbSqlRepo"`
 | 
				
			||||||
	dbInstanceApp       Instance                `inject:"DbInstanceApp"`
 | 
						dbInstanceApp       Instance                `inject:"DbInstanceApp"`
 | 
				
			||||||
 | 
						dbSqlExecApp        DbSqlExec               `inject:"DbSqlExecApp"`
 | 
				
			||||||
	tagApp              tagapp.TagTree          `inject:"TagTreeApp"`
 | 
						tagApp              tagapp.TagTree          `inject:"TagTreeApp"`
 | 
				
			||||||
	resourceAuthCertApp tagapp.ResourceAuthCert `inject:"ResourceAuthCertApp"`
 | 
						resourceAuthCertApp tagapp.ResourceAuthCert `inject:"ResourceAuthCertApp"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -103,7 +104,7 @@ func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dbId := dbEntity.Id
 | 
						dbId := dbEntity.Id
 | 
				
			||||||
	old, err := d.GetById(new(entity.Db), dbId)
 | 
						old, err := d.GetById(dbId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该数据库不存在")
 | 
							return errorx.NewBiz("该数据库不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -142,7 +143,7 @@ func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	db, err := d.GetById(new(entity.Db), id)
 | 
						db, err := d.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该数据库不存在")
 | 
							return errorx.NewBiz("该数据库不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -159,6 +160,8 @@ func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			|||||||
		func(ctx context.Context) error {
 | 
							func(ctx context.Context) error {
 | 
				
			||||||
			// 删除该库下用户保存的所有sql信息
 | 
								// 删除该库下用户保存的所有sql信息
 | 
				
			||||||
			return d.dbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: id})
 | 
								return d.dbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: id})
 | 
				
			||||||
 | 
							}, func(ctx context.Context) error {
 | 
				
			||||||
 | 
								return d.dbSqlExecApp.DeleteBy(ctx, &entity.DbSqlExec{DbId: id})
 | 
				
			||||||
		}, func(ctx context.Context) error {
 | 
							}, func(ctx context.Context) error {
 | 
				
			||||||
			return d.tagApp.DeleteTagByParam(ctx, &tagapp.DelResourceTagParam{
 | 
								return d.tagApp.DeleteTagByParam(ctx, &tagapp.DelResourceTagParam{
 | 
				
			||||||
				ResourceCode: db.Code,
 | 
									ResourceCode: db.Code,
 | 
				
			||||||
@@ -169,12 +172,12 @@ func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbAppImpl) GetDbConn(dbId uint64, dbName string) (*dbi.DbConn, error) {
 | 
					func (d *dbAppImpl) GetDbConn(dbId uint64, dbName string) (*dbi.DbConn, error) {
 | 
				
			||||||
	return dbm.GetDbConn(dbId, dbName, func() (*dbi.DbInfo, error) {
 | 
						return dbm.GetDbConn(dbId, dbName, func() (*dbi.DbInfo, error) {
 | 
				
			||||||
		db, err := d.GetById(new(entity.Db), dbId)
 | 
							db, err := d.GetById(dbId)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, errorx.NewBiz("数据库信息不存在")
 | 
								return nil, errorx.NewBiz("数据库信息不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		instance, err := d.dbInstanceApp.GetById(new(entity.DbInstance), db.InstanceId)
 | 
							instance, err := d.dbInstanceApp.GetById(db.InstanceId)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, errorx.NewBiz("数据库实例不存在")
 | 
								return nil, errorx.NewBiz("数据库实例不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -205,9 +208,8 @@ func (d *dbAppImpl) GetDbConnByInstanceId(instanceId uint64) (*dbi.DbConn, error
 | 
				
			|||||||
		return conn, nil
 | 
							return conn, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var dbs []*entity.Db
 | 
						dbs, err := d.ListByCond(&entity.Db{InstanceId: instanceId}, "id", "database")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
	if err := d.ListByCond(model.NewModelCond(&entity.Db{InstanceId: instanceId}).Columns("id", "database"), &dbs); err != nil {
 | 
					 | 
				
			||||||
		return nil, errorx.NewBiz("获取数据库列表失败")
 | 
							return nil, errorx.NewBiz("获取数据库列表失败")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(dbs) == 0 {
 | 
						if len(dbs) == 0 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,21 +63,18 @@ func (app *DbBackupApp) Init() error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *DbBackupApp) prune(ctx context.Context) error {
 | 
					func (app *DbBackupApp) prune(ctx context.Context) error {
 | 
				
			||||||
	var jobs []*entity.DbBackup
 | 
						jobs, err := app.backupRepo.SelectByCond(map[string]any{})
 | 
				
			||||||
	if err := app.backupRepo.ListByCond(map[string]any{}, &jobs); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, job := range jobs {
 | 
						for _, job := range jobs {
 | 
				
			||||||
		if ctx.Err() != nil {
 | 
							if ctx.Err() != nil {
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		var histories []*entity.DbBackupHistory
 | 
					 | 
				
			||||||
		historyCond := map[string]any{
 | 
							historyCond := map[string]any{
 | 
				
			||||||
			"db_backup_id": job.Id,
 | 
								"db_backup_id": job.Id,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := app.backupHistoryRepo.SelectByCond(historyCond, &histories); err != nil {
 | 
							histories, _ := app.backupHistoryRepo.SelectByCond(historyCond)
 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		expiringTime := time.Now().Add(-math.MaxInt64)
 | 
							expiringTime := time.Now().Add(-math.MaxInt64)
 | 
				
			||||||
		if job.MaxSaveDays > 0 {
 | 
							if job.MaxSaveDays > 0 {
 | 
				
			||||||
			expiringTime = time.Now().Add(-time.Hour * 24 * time.Duration(job.MaxSaveDays+1))
 | 
								expiringTime = time.Now().Add(-time.Hour * 24 * time.Duration(job.MaxSaveDays+1))
 | 
				
			||||||
@@ -160,8 +157,8 @@ func (app *DbBackupApp) Enable(ctx context.Context, jobId uint64) error {
 | 
				
			|||||||
	defer app.mutex.Unlock()
 | 
						defer app.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := app.backupRepo
 | 
						repo := app.backupRepo
 | 
				
			||||||
	job := &entity.DbBackup{}
 | 
						job, err := repo.GetById(jobId)
 | 
				
			||||||
	if err := repo.GetById(job, jobId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if job.IsEnabled() {
 | 
						if job.IsEnabled() {
 | 
				
			||||||
@@ -183,8 +180,8 @@ func (app *DbBackupApp) Disable(ctx context.Context, jobId uint64) error {
 | 
				
			|||||||
	defer app.mutex.Unlock()
 | 
						defer app.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := app.backupRepo
 | 
						repo := app.backupRepo
 | 
				
			||||||
	job := &entity.DbBackup{}
 | 
						job, err := repo.GetById(jobId)
 | 
				
			||||||
	if err := repo.GetById(job, jobId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !job.IsEnabled() {
 | 
						if !job.IsEnabled() {
 | 
				
			||||||
@@ -202,8 +199,8 @@ func (app *DbBackupApp) StartNow(ctx context.Context, jobId uint64) error {
 | 
				
			|||||||
	app.mutex.Lock()
 | 
						app.mutex.Lock()
 | 
				
			||||||
	defer app.mutex.Unlock()
 | 
						defer app.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	job := &entity.DbBackup{}
 | 
						job, err := app.backupRepo.GetById(jobId)
 | 
				
			||||||
	if err := app.backupRepo.GetById(job, jobId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !job.IsEnabled() {
 | 
						if !job.IsEnabled() {
 | 
				
			||||||
@@ -267,8 +264,8 @@ func (app *DbBackupApp) DeleteHistory(ctx context.Context, historyId uint64) (re
 | 
				
			|||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return errRestoringBackupHistory
 | 
							return errRestoringBackupHistory
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	job := &entity.DbBackupHistory{}
 | 
						job, err := app.backupHistoryRepo.GetById(historyId)
 | 
				
			||||||
	if err := app.backupHistoryRepo.GetById(job, historyId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conn, err := app.dbApp.GetDbConnByInstanceId(job.DbInstanceId)
 | 
						conn, err := app.dbApp.GetDbConnByInstanceId(job.DbInstanceId)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,8 +75,8 @@ func (app *DbBinlogApp) fetchBinlog(ctx context.Context) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *DbBinlogApp) pruneBinlog(ctx context.Context) error {
 | 
					func (app *DbBinlogApp) pruneBinlog(ctx context.Context) error {
 | 
				
			||||||
	var jobs []*entity.DbBinlog
 | 
						jobs, err := app.binlogRepo.SelectByCond(map[string]any{})
 | 
				
			||||||
	if err := app.binlogRepo.SelectByCond(map[string]any{}, &jobs); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logx.Error("DbBinlogApp: 获取 BINLOG 同步任务失败: ", err.Error())
 | 
							logx.Error("DbBinlogApp: 获取 BINLOG 同步任务失败: ", err.Error())
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,7 +78,7 @@ func (app *dataSyncAppImpl) Save(ctx context.Context, taskEntity *entity.DataSyn
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	task, err := app.GetById(new(entity.DataSyncTask), taskEntity.Id)
 | 
						task, err := app.GetById(taskEntity.Id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -112,7 +112,7 @@ func (app *dataSyncAppImpl) AddCronJob(ctx context.Context, taskEntity *entity.D
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *dataSyncAppImpl) RemoveCronJobById(taskId uint64) {
 | 
					func (app *dataSyncAppImpl) RemoveCronJobById(taskId uint64) {
 | 
				
			||||||
	task, err := app.GetById(new(entity.DataSyncTask), taskId)
 | 
						task, err := app.GetById(taskId)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		scheduler.RemoveByKey(task.TaskKey)
 | 
							scheduler.RemoveByKey(task.TaskKey)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -127,7 +127,7 @@ func (app *dataSyncAppImpl) changeRunningState(id uint64, state int8) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (app *dataSyncAppImpl) RunCronJob(ctx context.Context, id uint64) error {
 | 
					func (app *dataSyncAppImpl) RunCronJob(ctx context.Context, id uint64) error {
 | 
				
			||||||
	// 查询最新的任务信息
 | 
						// 查询最新的任务信息
 | 
				
			||||||
	task, err := app.GetById(new(entity.DataSyncTask), id)
 | 
						task, err := app.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("任务不存在")
 | 
							return errorx.NewBiz("任务不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -369,7 +369,7 @@ func (app *dataSyncAppImpl) srcData2TargetDb(srcRes []map[string]any, fieldMap [
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 运行过程中,判断状态是否为已关闭,是则结束运行,否则继续运行
 | 
						// 运行过程中,判断状态是否为已关闭,是则结束运行,否则继续运行
 | 
				
			||||||
	taskParam, _ := app.GetById(new(entity.DataSyncTask), task.Id)
 | 
						taskParam, _ := app.GetById(task.Id)
 | 
				
			||||||
	if taskParam.RunningState == entity.DataSyncTaskRunStateStop {
 | 
						if taskParam.RunningState == entity.DataSyncTaskRunStateStop {
 | 
				
			||||||
		return errorx.NewBiz("该任务已被手动终止")
 | 
							return errorx.NewBiz("该任务已被手动终止")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -142,7 +142,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *SaveDb
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// 根据host等未查到旧数据,则需要根据id重新获取,因为后续需要使用到code
 | 
							// 根据host等未查到旧数据,则需要根据id重新获取,因为后续需要使用到code
 | 
				
			||||||
		oldInstance, err = app.GetById(new(entity.DbInstance), instanceEntity.Id)
 | 
							oldInstance, err = app.GetById(instanceEntity.Id)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return 0, errorx.NewBiz("该数据库实例不存在")
 | 
								return 0, errorx.NewBiz("该数据库实例不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -170,7 +170,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *SaveDb
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error {
 | 
					func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error {
 | 
				
			||||||
	instance, err := app.GetById(new(entity.DbInstance), instanceId, "name")
 | 
						instance, err := app.GetById(instanceId, "name")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("获取数据库实例错误,数据库实例ID为: %d", instance.Id)
 | 
							return errorx.NewBiz("获取数据库实例错误,数据库实例ID为: %d", instance.Id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -201,18 +201,9 @@ func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error
 | 
				
			|||||||
		biz.ErrIsNil(err, "删除数据库实例失败: %v", err)
 | 
							biz.ErrIsNil(err, "删除数据库实例失败: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	db := &entity.Db{
 | 
						dbs, _ := app.dbApp.ListByCond(&entity.Db{
 | 
				
			||||||
		InstanceId: instanceId,
 | 
							InstanceId: instanceId,
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
	err = app.dbApp.GetByCond(db)
 | 
					 | 
				
			||||||
	switch {
 | 
					 | 
				
			||||||
	case err == nil:
 | 
					 | 
				
			||||||
		biz.ErrNotNil(err, "不能删除数据库实例【%s】,请先删除关联的数据库资源。", instance.Name)
 | 
					 | 
				
			||||||
	case errors.Is(err, gorm.ErrRecordNotFound):
 | 
					 | 
				
			||||||
		break
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		biz.ErrIsNil(err, "删除数据库实例失败: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return app.Tx(ctx, func(ctx context.Context) error {
 | 
						return app.Tx(ctx, func(ctx context.Context) error {
 | 
				
			||||||
		return app.DeleteById(ctx, instanceId)
 | 
							return app.DeleteById(ctx, instanceId)
 | 
				
			||||||
@@ -227,6 +218,14 @@ func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error
 | 
				
			|||||||
			ResourceCode: instance.Code,
 | 
								ResourceCode: instance.Code,
 | 
				
			||||||
			ResourceType: tagentity.TagType(consts.ResourceTypeDb),
 | 
								ResourceType: tagentity.TagType(consts.ResourceTypeDb),
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
						}, func(ctx context.Context) error {
 | 
				
			||||||
 | 
							// 删除所有库配置
 | 
				
			||||||
 | 
							for _, db := range dbs {
 | 
				
			||||||
 | 
								if err := app.dbApp.Delete(ctx, db.Id); err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -285,10 +284,10 @@ func (m *instanceAppImpl) genDbInstanceResourceTag(me *entity.DbInstance, authCe
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var dbs []*entity.Db
 | 
						dbs, err := m.dbApp.ListByCond(&entity.Db{
 | 
				
			||||||
	if err := m.dbApp.ListByCond(&entity.Db{
 | 
					 | 
				
			||||||
		InstanceId: me.Id,
 | 
							InstanceId: me.Id,
 | 
				
			||||||
	}, &dbs); err != nil {
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		logx.Errorf("获取实例关联的数据库失败: %v", err)
 | 
							logx.Errorf("获取实例关联的数据库失败: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,8 +78,8 @@ func (app *DbRestoreApp) Enable(ctx context.Context, jobId uint64) error {
 | 
				
			|||||||
	defer app.mutex.Unlock()
 | 
						defer app.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := app.restoreRepo
 | 
						repo := app.restoreRepo
 | 
				
			||||||
	job := &entity.DbRestore{}
 | 
						job, err := repo.GetById(jobId)
 | 
				
			||||||
	if err := repo.GetById(job, jobId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if job.IsEnabled() {
 | 
						if job.IsEnabled() {
 | 
				
			||||||
@@ -101,8 +101,8 @@ func (app *DbRestoreApp) Disable(ctx context.Context, jobId uint64) error {
 | 
				
			|||||||
	defer app.mutex.Unlock()
 | 
						defer app.mutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	repo := app.restoreRepo
 | 
						repo := app.restoreRepo
 | 
				
			||||||
	job := &entity.DbRestore{}
 | 
						job, err := repo.GetById(jobId)
 | 
				
			||||||
	if err := repo.GetById(job, jobId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !job.IsEnabled() {
 | 
						if !job.IsEnabled() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,8 +4,6 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"golang.org/x/sync/singleflight"
 | 
					 | 
				
			||||||
	"gorm.io/gorm"
 | 
					 | 
				
			||||||
	"mayfly-go/internal/db/dbm/dbi"
 | 
						"mayfly-go/internal/db/dbm/dbi"
 | 
				
			||||||
	"mayfly-go/internal/db/domain/entity"
 | 
						"mayfly-go/internal/db/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/db/domain/repository"
 | 
						"mayfly-go/internal/db/domain/repository"
 | 
				
			||||||
@@ -14,6 +12,9 @@ import (
 | 
				
			|||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"golang.org/x/sync/singleflight"
 | 
				
			||||||
 | 
						"gorm.io/gorm"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -173,8 +174,8 @@ func (s *dbScheduler) restore(ctx context.Context, dbProgram dbi.DbProgram, rest
 | 
				
			|||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		backupHistory := &entity.DbBackupHistory{}
 | 
							backupHistory, err := s.backupHistoryRepo.GetById(restore.DbBackupHistoryId)
 | 
				
			||||||
		if err := s.backupHistoryRepo.GetById(backupHistory, restore.DbBackupHistoryId); err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
								if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
				err = errors.New("备份历史已删除")
 | 
									err = errors.New("备份历史已删除")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,7 +56,7 @@ type DbSqlExec interface {
 | 
				
			|||||||
	Exec(ctx context.Context, execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error)
 | 
						Exec(ctx context.Context, execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据条件删除sql执行记录
 | 
						// 根据条件删除sql执行记录
 | 
				
			||||||
	DeleteBy(ctx context.Context, condition *entity.DbSqlExec)
 | 
						DeleteBy(ctx context.Context, condition *entity.DbSqlExec) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 分页获取
 | 
						// 分页获取
 | 
				
			||||||
	GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
						GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
				
			||||||
@@ -196,8 +196,8 @@ func (d *dbSqlExecAppImpl) FlowBizHandle(ctx context.Context, bizHandleParam *fl
 | 
				
			|||||||
	return d.dbSqlExecRepo.UpdateById(ctx, dbSqlExec)
 | 
						return d.dbSqlExecRepo.UpdateById(ctx, dbSqlExec)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbSqlExecAppImpl) DeleteBy(ctx context.Context, condition *entity.DbSqlExec) {
 | 
					func (d *dbSqlExecAppImpl) DeleteBy(ctx context.Context, condition *entity.DbSqlExec) error {
 | 
				
			||||||
	d.dbSqlExecRepo.DeleteByCond(ctx, condition)
 | 
						return d.dbSqlExecRepo.DeleteByCond(ctx, condition)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,7 +87,7 @@ func (app *dbTransferAppImpl) CreateLog(ctx context.Context, taskId uint64) (uin
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *dbTransferAppImpl) Run(ctx context.Context, taskId uint64, logId uint64) {
 | 
					func (app *dbTransferAppImpl) Run(ctx context.Context, taskId uint64, logId uint64) {
 | 
				
			||||||
	task, err := app.GetById(new(entity.DbTransferTask), taskId)
 | 
						task, err := app.GetById(taskId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logx.Errorf("创建DBMS-执行数据迁移日志失败:%v", err)
 | 
							logx.Errorf("创建DBMS-执行数据迁移日志失败:%v", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -150,7 +150,7 @@ func (app *dbTransferAppImpl) Run(ctx context.Context, taskId uint64, logId uint
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *dbTransferAppImpl) Stop(ctx context.Context, taskId uint64) error {
 | 
					func (app *dbTransferAppImpl) Stop(ctx context.Context, taskId uint64) error {
 | 
				
			||||||
	task, err := app.GetById(new(entity.DbTransferTask), taskId)
 | 
						task, err := app.GetById(taskId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("任务不存在")
 | 
							return errorx.NewBiz("任务不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,4 @@ type DbBackup interface {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// GetPageList 分页获取数据库任务列表
 | 
						// GetPageList 分页获取数据库任务列表
 | 
				
			||||||
	GetPageList(condition *entity.DbBackupQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
						GetPageList(condition *entity.DbBackupQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	ListByCond(cond any, listModels any, cols ...string) error
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ func NewDbBackupRepo() repository.DbBackup {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbBackupRepoImpl) GetDbNamesWithoutBackup(instanceId uint64, dbNames []string) ([]string, error) {
 | 
					func (d *dbBackupRepoImpl) GetDbNamesWithoutBackup(instanceId uint64, dbNames []string) ([]string, error) {
 | 
				
			||||||
	var dbNamesWithBackup []string
 | 
						var dbNamesWithBackup []string
 | 
				
			||||||
	err := global.Db.Model(d.GetModel()).
 | 
						err := global.Db.Model(d.NewModel()).
 | 
				
			||||||
		Where("db_instance_id = ?", instanceId).
 | 
							Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
		Where("repeated = ?", true).
 | 
							Where("repeated = ?", true).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -41,7 +41,7 @@ func (d *dbBackupRepoImpl) GetDbNamesWithoutBackup(instanceId uint64, dbNames []
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbBackupRepoImpl) ListDbInstances(enabled bool, repeated bool, instanceIds *[]uint64) error {
 | 
					func (d *dbBackupRepoImpl) ListDbInstances(enabled bool, repeated bool, instanceIds *[]uint64) error {
 | 
				
			||||||
	return global.Db.Model(d.GetModel()).
 | 
						return global.Db.Model(d.NewModel()).
 | 
				
			||||||
		Where("enabled = ?", enabled).
 | 
							Where("enabled = ?", enabled).
 | 
				
			||||||
		Where("repeated = ?", repeated).
 | 
							Where("repeated = ?", repeated).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -51,7 +51,7 @@ func (d *dbBackupRepoImpl) ListDbInstances(enabled bool, repeated bool, instance
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbBackupRepoImpl) ListToDo(jobs any) error {
 | 
					func (d *dbBackupRepoImpl) ListToDo(jobs any) error {
 | 
				
			||||||
	db := global.Db.Model(d.GetModel())
 | 
						db := global.Db.Model(d.NewModel())
 | 
				
			||||||
	err := db.Where("enabled = ?", true).
 | 
						err := db.Where("enabled = ?", true).
 | 
				
			||||||
		Where(db.Where("repeated = ?", true).Or("last_status <> ?", entity.DbJobSuccess)).
 | 
							Where(db.Where("repeated = ?", true).Or("last_status <> ?", entity.DbJobSuccess)).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -70,7 +70,7 @@ func (d *dbBackupRepoImpl) GetPageList(condition *entity.DbBackupQuery, pagePara
 | 
				
			|||||||
		Eq0("repeated", condition.Repeated).
 | 
							Eq0("repeated", condition.Repeated).
 | 
				
			||||||
		In0("db_name", condition.InDbNames).
 | 
							In0("db_name", condition.InDbNames).
 | 
				
			||||||
		Like("db_name", condition.DbName)
 | 
							Like("db_name", condition.DbName)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// AddJob 添加数据库任务
 | 
					// AddJob 添加数据库任务
 | 
				
			||||||
@@ -91,7 +91,3 @@ func (d *dbBackupRepoImpl) UpdateEnabled(ctx context.Context, jobId uint64, enab
 | 
				
			|||||||
		"enabled_desc": desc,
 | 
							"enabled_desc": desc,
 | 
				
			||||||
	}, cond)
 | 
						}, cond)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func (d *dbBackupRepoImpl) ListByCond(cond any, listModels any, cols ...string) error {
 | 
					 | 
				
			||||||
	return d.dbJobBaseImpl.SelectByCond(model.NewModelCond(cond).Columns(cols...), listModels)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,11 +29,11 @@ func (repo *dbBackupHistoryRepoImpl) GetPageList(condition *entity.DbBackupHisto
 | 
				
			|||||||
		In0("db_name", condition.InDbNames).
 | 
							In0("db_name", condition.InDbNames).
 | 
				
			||||||
		Eq("db_backup_id", condition.DbBackupId).
 | 
							Eq("db_backup_id", condition.DbBackupId).
 | 
				
			||||||
		Eq("db_name", condition.DbName)
 | 
							Eq("db_name", condition.DbName)
 | 
				
			||||||
	return repo.PageByCond(qd, pageParam, toEntity)
 | 
						return repo.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (repo *dbBackupHistoryRepoImpl) GetHistories(backupHistoryIds []uint64, toEntity any) error {
 | 
					func (repo *dbBackupHistoryRepoImpl) GetHistories(backupHistoryIds []uint64, toEntity any) error {
 | 
				
			||||||
	return global.Db.Model(repo.GetModel()).
 | 
						return global.Db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("id in ?", backupHistoryIds).
 | 
							Where("id in ?", backupHistoryIds).
 | 
				
			||||||
		Where("deleting = false").
 | 
							Where("deleting = false").
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -44,7 +44,7 @@ func (repo *dbBackupHistoryRepoImpl) GetHistories(backupHistoryIds []uint64, toE
 | 
				
			|||||||
func (repo *dbBackupHistoryRepoImpl) GetLatestHistoryForBinlog(instanceId uint64, dbName string, bi *entity.BinlogInfo) (*entity.DbBackupHistory, error) {
 | 
					func (repo *dbBackupHistoryRepoImpl) GetLatestHistoryForBinlog(instanceId uint64, dbName string, bi *entity.BinlogInfo) (*entity.DbBackupHistory, error) {
 | 
				
			||||||
	history := &entity.DbBackupHistory{}
 | 
						history := &entity.DbBackupHistory{}
 | 
				
			||||||
	db := global.Db
 | 
						db := global.Db
 | 
				
			||||||
	err := db.Model(repo.GetModel()).
 | 
						err := db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("db_instance_id = ?", instanceId).
 | 
							Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
		Where("db_name = ?", dbName).
 | 
							Where("db_name = ?", dbName).
 | 
				
			||||||
		Where(db.Where("binlog_sequence < ?", bi.Sequence).
 | 
							Where(db.Where("binlog_sequence < ?", bi.Sequence).
 | 
				
			||||||
@@ -63,7 +63,7 @@ func (repo *dbBackupHistoryRepoImpl) GetLatestHistoryForBinlog(instanceId uint64
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (repo *dbBackupHistoryRepoImpl) GetEarliestHistoryForBinlog(instanceId uint64) (*entity.DbBackupHistory, bool, error) {
 | 
					func (repo *dbBackupHistoryRepoImpl) GetEarliestHistoryForBinlog(instanceId uint64) (*entity.DbBackupHistory, bool, error) {
 | 
				
			||||||
	history := &entity.DbBackupHistory{}
 | 
						history := &entity.DbBackupHistory{}
 | 
				
			||||||
	db := global.Db.Model(repo.GetModel())
 | 
						db := global.Db.Model(repo.NewModel())
 | 
				
			||||||
	err := db.Where("db_instance_id = ?", instanceId).
 | 
						err := db.Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
		Where("binlog_sequence > 0").
 | 
							Where("binlog_sequence > 0").
 | 
				
			||||||
		Where("deleting = false").
 | 
							Where("deleting = false").
 | 
				
			||||||
@@ -81,7 +81,7 @@ func (repo *dbBackupHistoryRepoImpl) GetEarliestHistoryForBinlog(instanceId uint
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (repo *dbBackupHistoryRepoImpl) UpdateDeleting(deleting bool, backupHistoryId ...uint64) (bool, error) {
 | 
					func (repo *dbBackupHistoryRepoImpl) UpdateDeleting(deleting bool, backupHistoryId ...uint64) (bool, error) {
 | 
				
			||||||
	db := global.Db.Model(repo.GetModel()).
 | 
						db := global.Db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("id in ?", backupHistoryId).
 | 
							Where("id in ?", backupHistoryId).
 | 
				
			||||||
		Where("restoring = false").
 | 
							Where("restoring = false").
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -96,7 +96,7 @@ func (repo *dbBackupHistoryRepoImpl) UpdateDeleting(deleting bool, backupHistory
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (repo *dbBackupHistoryRepoImpl) UpdateRestoring(restoring bool, backupHistoryId ...uint64) (bool, error) {
 | 
					func (repo *dbBackupHistoryRepoImpl) UpdateRestoring(restoring bool, backupHistoryId ...uint64) (bool, error) {
 | 
				
			||||||
	db := global.Db.Model(repo.GetModel()).
 | 
						db := global.Db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("id in ?", backupHistoryId).
 | 
							Where("id in ?", backupHistoryId).
 | 
				
			||||||
		Where("deleting = false").
 | 
							Where("deleting = false").
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -111,7 +111,7 @@ func (repo *dbBackupHistoryRepoImpl) UpdateRestoring(restoring bool, backupHisto
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (repo *dbBackupHistoryRepoImpl) ZeroBinlogInfo(backupHistoryId uint64) error {
 | 
					func (repo *dbBackupHistoryRepoImpl) ZeroBinlogInfo(backupHistoryId uint64) error {
 | 
				
			||||||
	return global.Db.Model(repo.GetModel()).
 | 
						return global.Db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("id = ?", backupHistoryId).
 | 
							Where("id = ?", backupHistoryId).
 | 
				
			||||||
		Where("restoring = false").
 | 
							Where("restoring = false").
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,8 +42,8 @@ func (repo *dbBinlogHistoryRepoImpl) GetHistories(instanceId uint64, start, targ
 | 
				
			|||||||
		Ge("sequence", start.Sequence).
 | 
							Ge("sequence", start.Sequence).
 | 
				
			||||||
		Le("sequence", target.Sequence).
 | 
							Le("sequence", target.Sequence).
 | 
				
			||||||
		OrderByAsc("sequence")
 | 
							OrderByAsc("sequence")
 | 
				
			||||||
	var histories []*entity.DbBinlogHistory
 | 
						histories, err := repo.SelectByCond(qc)
 | 
				
			||||||
	if err := repo.SelectByCond(qc, &histories); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(histories) == 0 {
 | 
						if len(histories) == 0 {
 | 
				
			||||||
@@ -121,7 +121,7 @@ func (repo *dbBinlogHistoryRepoImpl) InsertWithBinlogFiles(ctx context.Context,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (repo *dbBinlogHistoryRepoImpl) GetHistoriesBeforeSequence(ctx context.Context, instanceId uint64, binlogSeq int64, histories *[]*entity.DbBinlogHistory) error {
 | 
					func (repo *dbBinlogHistoryRepoImpl) GetHistoriesBeforeSequence(ctx context.Context, instanceId uint64, binlogSeq int64, histories *[]*entity.DbBinlogHistory) error {
 | 
				
			||||||
	return global.Db.Model(repo.GetModel()).
 | 
						return global.Db.Model(repo.NewModel()).
 | 
				
			||||||
		Where("db_instance_id = ?", instanceId).
 | 
							Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
		Where("sequence < ?", binlogSeq).
 | 
							Where("sequence < ?", binlogSeq).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ func (d *dataSyncTaskRepoImpl) GetTaskList(condition *entity.DataSyncTaskQuery,
 | 
				
			|||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Like("task_name", condition.Name).
 | 
							Like("task_name", condition.Name).
 | 
				
			||||||
		Eq("status", condition.Status)
 | 
							Eq("status", condition.Status)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type dataSyncLogRepoImpl struct {
 | 
					type dataSyncLogRepoImpl struct {
 | 
				
			||||||
@@ -31,7 +31,7 @@ type dataSyncLogRepoImpl struct {
 | 
				
			|||||||
func (d *dataSyncLogRepoImpl) GetTaskLogList(condition *entity.DataSyncLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (d *dataSyncLogRepoImpl) GetTaskLogList(condition *entity.DataSyncLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Eq("task_id", condition.TaskId)
 | 
							Eq("task_id", condition.TaskId)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newDataSyncLogRepo() repository.DataSyncLog {
 | 
					func newDataSyncLogRepo() repository.DataSyncLog {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,7 +58,7 @@ func addJob[T entity.DbJob](ctx context.Context, repo dbJobBaseImpl[T], jobs any
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var res []string
 | 
							var res []string
 | 
				
			||||||
		err := db.Model(repo.GetModel()).Select("db_name").
 | 
							err := db.Model(repo.NewModel()).Select("db_name").
 | 
				
			||||||
			Where("db_instance_id = ?", instanceId).
 | 
								Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
			Where("db_name in ?", dbNames).
 | 
								Where("db_name in ?", dbNames).
 | 
				
			||||||
			Where("repeated = true").
 | 
								Where("repeated = true").
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ func NewDbRestoreRepo() repository.DbRestore {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbRestoreRepoImpl) GetDbNamesWithoutRestore(instanceId uint64, dbNames []string) ([]string, error) {
 | 
					func (d *dbRestoreRepoImpl) GetDbNamesWithoutRestore(instanceId uint64, dbNames []string) ([]string, error) {
 | 
				
			||||||
	var dbNamesWithRestore []string
 | 
						var dbNamesWithRestore []string
 | 
				
			||||||
	err := global.Db.Model(d.GetModel()).
 | 
						err := global.Db.Model(d.NewModel()).
 | 
				
			||||||
		Where("db_instance_id = ?", instanceId).
 | 
							Where("db_instance_id = ?", instanceId).
 | 
				
			||||||
		Where("repeated = ?", true).
 | 
							Where("repeated = ?", true).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -42,7 +42,7 @@ func (d *dbRestoreRepoImpl) GetDbNamesWithoutRestore(instanceId uint64, dbNames
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRestoreRepoImpl) ListToDo(jobs any) error {
 | 
					func (d *dbRestoreRepoImpl) ListToDo(jobs any) error {
 | 
				
			||||||
	db := global.Db.Model(d.GetModel())
 | 
						db := global.Db.Model(d.NewModel())
 | 
				
			||||||
	err := db.Where("enabled = ?", true).
 | 
						err := db.Where("enabled = ?", true).
 | 
				
			||||||
		Where(db.Where("repeated = ?", true).Or("last_status <> ?", entity.DbJobSuccess)).
 | 
							Where(db.Where("repeated = ?", true).Or("last_status <> ?", entity.DbJobSuccess)).
 | 
				
			||||||
		Scopes(gormx.UndeleteScope).
 | 
							Scopes(gormx.UndeleteScope).
 | 
				
			||||||
@@ -61,11 +61,11 @@ func (d *dbRestoreRepoImpl) GetPageList(condition *entity.DbRestoreQuery, pagePa
 | 
				
			|||||||
		Eq0("repeated", condition.Repeated).
 | 
							Eq0("repeated", condition.Repeated).
 | 
				
			||||||
		In0("db_name", condition.InDbNames).
 | 
							In0("db_name", condition.InDbNames).
 | 
				
			||||||
		Like("db_name", condition.DbName)
 | 
							Like("db_name", condition.DbName)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *dbRestoreRepoImpl) GetEnabledRestores(toEntity any, backupHistoryId ...uint64) error {
 | 
					func (d *dbRestoreRepoImpl) GetEnabledRestores(toEntity any, backupHistoryId ...uint64) error {
 | 
				
			||||||
	return global.Db.Model(d.GetModel()).
 | 
						return global.Db.Model(d.NewModel()).
 | 
				
			||||||
		Select("id", "db_backup_history_id", "last_status", "last_result", "last_time").
 | 
							Select("id", "db_backup_history_id", "last_status", "last_result", "last_time").
 | 
				
			||||||
		Where("db_backup_history_id in ?", backupHistoryId).
 | 
							Where("db_backup_history_id in ?", backupHistoryId).
 | 
				
			||||||
		Where("enabled = true").
 | 
							Where("enabled = true").
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,6 @@ func (d *dbRestoreHistoryRepoImpl) GetDbRestoreHistories(condition *entity.DbRes
 | 
				
			|||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Eq("id", condition.Id).
 | 
							Eq("id", condition.Id).
 | 
				
			||||||
		Eq("db_backup_id", condition.DbRestoreId)
 | 
							Eq("db_backup_id", condition.DbRestoreId)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,5 +25,5 @@ func (d *dbSqlExecRepoImpl) GetPageList(condition *entity.DbSqlExecQuery, pagePa
 | 
				
			|||||||
		Eq("flow_biz_key", condition.FlowBizKey).
 | 
							Eq("flow_biz_key", condition.FlowBizKey).
 | 
				
			||||||
		In("status", condition.Status).
 | 
							In("status", condition.Status).
 | 
				
			||||||
		RLike("db", condition.Db).OrderBy(orderBy...)
 | 
							RLike("db", condition.Db).OrderBy(orderBy...)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,5 +20,5 @@ func (d *dbTransferTaskRepoImpl) GetTaskList(condition *entity.DbTransferTaskQue
 | 
				
			|||||||
	qd := model.NewCond()
 | 
						qd := model.NewCond()
 | 
				
			||||||
	//Like("task_name", condition.Name).
 | 
						//Like("task_name", condition.Name).
 | 
				
			||||||
	//Eq("status", condition.Status)
 | 
						//Eq("status", condition.Status)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,5 +23,5 @@ func (d *instanceRepoImpl) GetInstanceList(condition *entity.InstanceQuery, page
 | 
				
			|||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		Like("code", condition.Code).
 | 
							Like("code", condition.Code).
 | 
				
			||||||
		In("code", condition.Codes)
 | 
							In("code", condition.Codes)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,19 +40,19 @@ func (p *Procinst) ProcinstCancel(rc *req.Ctx) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *Procinst) GetProcinstDetail(rc *req.Ctx) {
 | 
					func (p *Procinst) GetProcinstDetail(rc *req.Ctx) {
 | 
				
			||||||
	pi, err := p.ProcinstApp.GetById(new(entity.Procinst), uint64(rc.PathParamInt("id")))
 | 
						pi, err := p.ProcinstApp.GetById(uint64(rc.PathParamInt("id")))
 | 
				
			||||||
	biz.ErrIsNil(err, "流程实例不存在")
 | 
						biz.ErrIsNil(err, "流程实例不存在")
 | 
				
			||||||
	pivo := new(vo.ProcinstVO)
 | 
						pivo := new(vo.ProcinstVO)
 | 
				
			||||||
	structx.Copy(pivo, pi)
 | 
						structx.Copy(pivo, pi)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 流程定义信息
 | 
						// 流程定义信息
 | 
				
			||||||
	procdef, _ := p.ProcdefApp.GetById(new(entity.Procdef), pi.ProcdefId)
 | 
						procdef, _ := p.ProcdefApp.GetById(pi.ProcdefId)
 | 
				
			||||||
	pivo.Procdef = procdef
 | 
						pivo.Procdef = procdef
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 流程实例任务信息
 | 
						// 流程实例任务信息
 | 
				
			||||||
	instTasks := new([]*entity.ProcinstTask)
 | 
						instTasks, err := p.ProcinstTaskRepo.SelectByCond(&entity.ProcinstTask{ProcinstId: pi.Id})
 | 
				
			||||||
	biz.ErrIsNil(p.ProcinstTaskRepo.SelectByCond(&entity.ProcinstTask{ProcinstId: pi.Id}, instTasks))
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
	pivo.ProcinstTasks = *instTasks
 | 
						pivo.ProcinstTasks = instTasks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rc.ResData = pivo
 | 
						rc.ResData = pivo
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -69,9 +69,8 @@ func (p *Procinst) GetTasks(rc *req.Ctx) {
 | 
				
			|||||||
	biz.ErrIsNil(err)
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	instIds := collx.ArrayMap[*vo.ProcinstTask, uint64](*taskVos, func(val *vo.ProcinstTask) uint64 { return val.ProcinstId })
 | 
						instIds := collx.ArrayMap[*vo.ProcinstTask, uint64](*taskVos, func(val *vo.ProcinstTask) uint64 { return val.ProcinstId })
 | 
				
			||||||
	insts := new([]*entity.Procinst)
 | 
						insts, _ := p.ProcinstApp.GetByIds(instIds)
 | 
				
			||||||
	p.ProcinstApp.GetByIds(insts, instIds)
 | 
						instId2Inst := collx.ArrayToMap[*entity.Procinst, uint64](insts, func(val *entity.Procinst) uint64 { return val.Id })
 | 
				
			||||||
	instId2Inst := collx.ArrayToMap[*entity.Procinst, uint64](*insts, func(val *entity.Procinst) uint64 { return val.Id })
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 赋值任务对应的流程实例
 | 
						// 赋值任务对应的流程实例
 | 
				
			||||||
	for _, task := range *taskVos {
 | 
						for _, task := range *taskVos {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,7 +86,7 @@ func (p *procinstAppImpl) StartProc(ctx context.Context, procdefKey string, reqP
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *procinstAppImpl) CancelProc(ctx context.Context, procinstId uint64) error {
 | 
					func (p *procinstAppImpl) CancelProc(ctx context.Context, procinstId uint64) error {
 | 
				
			||||||
	procinst, err := p.GetById(new(entity.Procinst), procinstId)
 | 
						procinst, err := p.GetById(procinstId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("流程不存在")
 | 
							return errorx.NewBiz("流程不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -122,11 +122,8 @@ func (p *procinstAppImpl) CompleteTask(ctx context.Context, instTaskId uint64, r
 | 
				
			|||||||
	instTask.Remark = remark
 | 
						instTask.Remark = remark
 | 
				
			||||||
	instTask.SetEnd()
 | 
						instTask.SetEnd()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	procinst := new(entity.Procinst)
 | 
						procinst, _ := p.GetById(instTask.ProcinstId)
 | 
				
			||||||
	p.GetById(procinst, instTask.ProcinstId)
 | 
						procdef, _ := p.procdefApp.GetById(procinst.ProcdefId)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	procdef := new(entity.Procdef)
 | 
					 | 
				
			||||||
	p.procdefApp.GetById(procdef, procinst.ProcdefId)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 获取下一实例审批任务
 | 
						// 获取下一实例审批任务
 | 
				
			||||||
	task := p.getNextTask(procdef, instTask.TaskKey)
 | 
						task := p.getNextTask(procdef, instTask.TaskKey)
 | 
				
			||||||
@@ -163,8 +160,7 @@ func (p *procinstAppImpl) RejectTask(ctx context.Context, instTaskId uint64, rem
 | 
				
			|||||||
	instTask.Remark = remark
 | 
						instTask.Remark = remark
 | 
				
			||||||
	instTask.SetEnd()
 | 
						instTask.SetEnd()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	procinst := new(entity.Procinst)
 | 
						procinst, _ := p.GetById(instTask.ProcinstId)
 | 
				
			||||||
	p.GetById(procinst, instTask.ProcinstId)
 | 
					 | 
				
			||||||
	// 更新流程实例为终止状态,无法重新提交
 | 
						// 更新流程实例为终止状态,无法重新提交
 | 
				
			||||||
	procinst.Status = entity.ProcinstStatusTerminated
 | 
						procinst.Status = entity.ProcinstStatusTerminated
 | 
				
			||||||
	procinst.BizStatus = entity.ProcinstBizStatusNo
 | 
						procinst.BizStatus = entity.ProcinstBizStatusNo
 | 
				
			||||||
@@ -189,8 +185,7 @@ func (p *procinstAppImpl) BackTask(ctx context.Context, instTaskId uint64, remar
 | 
				
			|||||||
	instTask.Status = entity.ProcinstTaskStatusBack
 | 
						instTask.Status = entity.ProcinstTaskStatusBack
 | 
				
			||||||
	instTask.Remark = remark
 | 
						instTask.Remark = remark
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	procinst := new(entity.Procinst)
 | 
						procinst, _ := p.GetById(instTask.ProcinstId)
 | 
				
			||||||
	p.GetById(procinst, instTask.ProcinstId)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 更新流程实例为挂起状态,等待重新提交
 | 
						// 更新流程实例为挂起状态,等待重新提交
 | 
				
			||||||
	procinst.Status = entity.ProcinstStatusSuspended
 | 
						procinst.Status = entity.ProcinstStatusSuspended
 | 
				
			||||||
@@ -207,9 +202,8 @@ func (p *procinstAppImpl) BackTask(ctx context.Context, instTaskId uint64, remar
 | 
				
			|||||||
// 取消处理中的流程实例任务
 | 
					// 取消处理中的流程实例任务
 | 
				
			||||||
func (p *procinstAppImpl) cancelInstTasks(ctx context.Context, procinstId uint64, cancelReason string) error {
 | 
					func (p *procinstAppImpl) cancelInstTasks(ctx context.Context, procinstId uint64, cancelReason string) error {
 | 
				
			||||||
	// 流程实例任务信息
 | 
						// 流程实例任务信息
 | 
				
			||||||
	instTasks := new([]*entity.ProcinstTask)
 | 
						instTasks, _ := p.procinstTaskRepo.SelectByCond(&entity.ProcinstTask{ProcinstId: procinstId, Status: entity.ProcinstTaskStatusProcess})
 | 
				
			||||||
	p.procinstTaskRepo.SelectByCond(&entity.ProcinstTask{ProcinstId: procinstId, Status: entity.ProcinstTaskStatusProcess}, instTasks)
 | 
						for _, instTask := range instTasks {
 | 
				
			||||||
	for _, instTask := range *instTasks {
 | 
					 | 
				
			||||||
		instTask.Status = entity.ProcinstTaskStatusCanceled
 | 
							instTask.Status = entity.ProcinstTaskStatusCanceled
 | 
				
			||||||
		instTask.Remark = cancelReason
 | 
							instTask.Remark = cancelReason
 | 
				
			||||||
		instTask.SetEnd()
 | 
							instTask.SetEnd()
 | 
				
			||||||
@@ -250,8 +244,8 @@ func (p *procinstAppImpl) triggerProcinstStatusChangeEvent(ctx context.Context,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 获取并校验实例任务
 | 
					// 获取并校验实例任务
 | 
				
			||||||
func (p *procinstAppImpl) getAndValidInstTask(ctx context.Context, instTaskId uint64) (*entity.ProcinstTask, error) {
 | 
					func (p *procinstAppImpl) getAndValidInstTask(ctx context.Context, instTaskId uint64) (*entity.ProcinstTask, error) {
 | 
				
			||||||
	instTask := new(entity.ProcinstTask)
 | 
						instTask, err := p.procinstTaskRepo.GetById(instTaskId)
 | 
				
			||||||
	if err := p.procinstTaskRepo.GetById(instTask, instTaskId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, errorx.NewBiz("流程实例任务不存在")
 | 
							return nil, errorx.NewBiz("流程实例任务不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,5 +19,5 @@ func (p *procdefImpl) GetPageList(condition *entity.Procdef, pageParam *model.Pa
 | 
				
			|||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		Like("def_key", condition.DefKey)
 | 
							Like("def_key", condition.DefKey)
 | 
				
			||||||
	return p.PageByCond(qd, pageParam, toEntity)
 | 
						return p.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ func newProcinstRepo() repository.Procinst {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (p *procinstImpl) GetPageList(condition *entity.ProcinstQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (p *procinstImpl) GetPageList(condition *entity.ProcinstQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewModelCond(condition)
 | 
						qd := model.NewModelCond(condition)
 | 
				
			||||||
	return p.PageByCond(qd, pageParam, toEntity)
 | 
						return p.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//-----------procinst task--------------
 | 
					//-----------procinst task--------------
 | 
				
			||||||
@@ -32,5 +32,5 @@ func newProcinstTaskRepo() repository.ProcinstTask {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (p *procinstTaskImpl) GetPageList(condition *entity.ProcinstTaskQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (p *procinstTaskImpl) GetPageList(condition *entity.ProcinstTaskQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewModelCond(condition)
 | 
						qd := model.NewModelCond(condition)
 | 
				
			||||||
	return p.PageByCond(qd, pageParam, toEntity)
 | 
						return p.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -218,7 +218,7 @@ func (m *Machine) MachineTermOpRecords(rc *req.Ctx) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *Machine) MachineTermOpRecord(rc *req.Ctx) {
 | 
					func (m *Machine) MachineTermOpRecord(rc *req.Ctx) {
 | 
				
			||||||
	termOp, err := m.MachineTermOpApp.GetById(new(entity.MachineTermOp), uint64(rc.PathParamInt("recId")))
 | 
						termOp, err := m.MachineTermOpApp.GetById(uint64(rc.PathParamInt("recId")))
 | 
				
			||||||
	biz.ErrIsNil(err)
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bytes, err := os.ReadFile(path.Join(config.GetMachine().TerminalRecPath, termOp.RecordFilePath))
 | 
						bytes, err := os.ReadFile(path.Join(config.GetMachine().TerminalRecPath, termOp.RecordFilePath))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ func (m *MachineCmdConf) MachineCmdConfs(rc *req.Ctx) {
 | 
				
			|||||||
	cond := req.BindQuery(rc, new(entity.MachineCmdConf))
 | 
						cond := req.BindQuery(rc, new(entity.MachineCmdConf))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var vos []*vo.MachineCmdConfVO
 | 
						var vos []*vo.MachineCmdConfVO
 | 
				
			||||||
	err := m.MachineCmdConfApp.ListByCond(cond, &vos)
 | 
						err := m.MachineCmdConfApp.ListByCondToAny(cond, &vos)
 | 
				
			||||||
	biz.ErrIsNil(err)
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m.TagTreeRelateApp.FillTagInfo(tagentity.TagRelateTypeMachineCmd, collx.ArrayMap(vos, func(mvo *vo.MachineCmdConfVO) tagentity.IRelateTag {
 | 
						m.TagTreeRelateApp.FillTagInfo(tagentity.TagRelateTypeMachineCmd, collx.ArrayMap(vos, func(mvo *vo.MachineCmdConfVO) tagentity.IRelateTag {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,7 +51,7 @@ func (m *MachineScript) DeleteMachineScript(rc *req.Ctx) {
 | 
				
			|||||||
func (m *MachineScript) RunMachineScript(rc *req.Ctx) {
 | 
					func (m *MachineScript) RunMachineScript(rc *req.Ctx) {
 | 
				
			||||||
	scriptId := GetMachineScriptId(rc)
 | 
						scriptId := GetMachineScriptId(rc)
 | 
				
			||||||
	ac := GetMachineAc(rc)
 | 
						ac := GetMachineAc(rc)
 | 
				
			||||||
	ms, err := m.MachineScriptApp.GetById(new(entity.MachineScript), scriptId, "MachineId", "Name", "Script")
 | 
						ms, err := m.MachineScriptApp.GetById(scriptId, "MachineId", "Name", "Script")
 | 
				
			||||||
	biz.ErrIsNil(err, "该脚本不存在")
 | 
						biz.ErrIsNil(err, "该脚本不存在")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	script := ms.Script
 | 
						script := ms.Script
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -132,7 +132,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachinePara
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	// 如果调整了ssh username等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
						// 如果调整了ssh username等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
				
			||||||
	if oldMachine.Code == "" {
 | 
						if oldMachine.Code == "" {
 | 
				
			||||||
		oldMachine, _ = m.GetById(new(entity.Machine), me.Id)
 | 
							oldMachine, _ = m.GetById(me.Id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 关闭连接
 | 
						// 关闭连接
 | 
				
			||||||
@@ -201,7 +201,7 @@ func (m *machineAppImpl) ChangeStatus(ctx context.Context, id uint64, status int
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 根据条件获取机器信息
 | 
					// 根据条件获取机器信息
 | 
				
			||||||
func (m *machineAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (m *machineAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	machine, err := m.GetById(new(entity.Machine), id)
 | 
						machine, err := m.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("机器信息不存在")
 | 
							return errorx.NewBiz("机器信息不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -266,9 +266,8 @@ func (m *machineAppImpl) GetSshTunnelMachine(machineId int) (*mcm.SshTunnelMachi
 | 
				
			|||||||
func (m *machineAppImpl) TimerUpdateStats() {
 | 
					func (m *machineAppImpl) TimerUpdateStats() {
 | 
				
			||||||
	logx.Debug("开始定时收集并缓存服务器状态信息...")
 | 
						logx.Debug("开始定时收集并缓存服务器状态信息...")
 | 
				
			||||||
	scheduler.AddFun("@every 2m", func() {
 | 
						scheduler.AddFun("@every 2m", func() {
 | 
				
			||||||
		machineIds := new([]entity.Machine)
 | 
							machineIds, _ := m.ListByCond(model.NewModelCond(&entity.Machine{Status: entity.MachineStatusEnable, Protocol: entity.MachineProtocolSsh}).Columns("id"))
 | 
				
			||||||
		m.ListByCond(model.NewModelCond(&entity.Machine{Status: entity.MachineStatusEnable, Protocol: entity.MachineProtocolSsh}).Columns("id"), machineIds)
 | 
							for _, ma := range machineIds {
 | 
				
			||||||
		for _, ma := range *machineIds {
 | 
					 | 
				
			||||||
			go func(mid uint64) {
 | 
								go func(mid uint64) {
 | 
				
			||||||
				defer func() {
 | 
									defer func() {
 | 
				
			||||||
					if err := recover(); err != nil {
 | 
										if err := recover(); err != nil {
 | 
				
			||||||
@@ -320,7 +319,7 @@ func (m *machineAppImpl) ToMachineInfoById(machineId uint64) (*mcm.MachineInfo,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineAppImpl) getMachineAndAuthCert(machineId uint64) (*entity.Machine, *tagentity.ResourceAuthCert, error) {
 | 
					func (m *machineAppImpl) getMachineAndAuthCert(machineId uint64) (*entity.Machine, *tagentity.ResourceAuthCert, error) {
 | 
				
			||||||
	me, err := m.GetById(new(entity.Machine), machineId)
 | 
						me, err := m.GetById(machineId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, errorx.NewBiz("[%d]机器信息不存在", machineId)
 | 
							return nil, nil, errorx.NewBiz("[%d]机器信息不存在", machineId)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,7 +56,7 @@ func (m *machineCmdConfAppImpl) SaveCmdConf(ctx context.Context, cmdConfParam *S
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineCmdConfAppImpl) DeleteCmdConf(ctx context.Context, id uint64) error {
 | 
					func (m *machineCmdConfAppImpl) DeleteCmdConf(ctx context.Context, id uint64) error {
 | 
				
			||||||
	_, err := m.GetById(new(entity.MachineCmdConf), id)
 | 
						_, err := m.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该命令配置不存在")
 | 
							return errorx.NewBiz("该命令配置不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -82,9 +82,7 @@ func (m *machineCmdConfAppImpl) GetCmdConfsByMachineTags(tagPaths ...string) []*
 | 
				
			|||||||
		return cmds
 | 
							return cmds
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var cmdConfs []*entity.MachineCmdConf
 | 
						cmdConfs, _ := m.GetByIds(cmdConfIds)
 | 
				
			||||||
	m.GetByIds(&cmdConfs, cmdConfIds)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, cmdConf := range cmdConfs {
 | 
						for _, cmdConf := range cmdConfs {
 | 
				
			||||||
		for _, cmd := range cmdConf.Cmds {
 | 
							for _, cmd := range cmdConf.Cmds {
 | 
				
			||||||
			if p, err := regexp.Compile(cmd); err != nil {
 | 
								if p, err := regexp.Compile(cmd); err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,7 +78,7 @@ func (m *machineCronJobAppImpl) SaveMachineCronJob(ctx context.Context, mcj *ent
 | 
				
			|||||||
	// 更新操作
 | 
						// 更新操作
 | 
				
			||||||
	if mcj.Id != 0 {
 | 
						if mcj.Id != 0 {
 | 
				
			||||||
		m.UpdateById(ctx, mcj)
 | 
							m.UpdateById(ctx, mcj)
 | 
				
			||||||
		cj, err := m.GetById(new(entity.MachineCronJob), mcj.Id)
 | 
							cj, err := m.GetById(mcj.Id)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return 0, errorx.NewBiz("该任务不存在")
 | 
								return 0, errorx.NewBiz("该任务不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,7 +110,7 @@ func (m *machineFileAppImpl) GetMachineFile(condition *entity.MachineFile, cols
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 保存机器文件配置
 | 
					// 保存机器文件配置
 | 
				
			||||||
func (m *machineFileAppImpl) Save(ctx context.Context, mf *entity.MachineFile) error {
 | 
					func (m *machineFileAppImpl) Save(ctx context.Context, mf *entity.MachineFile) error {
 | 
				
			||||||
	_, err := m.machineApp.GetById(new(entity.Machine), mf.MachineId, "Name")
 | 
						_, err := m.machineApp.GetById(mf.MachineId, "Name")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该机器不存在")
 | 
							return errorx.NewBiz("该机器不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@ func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, page
 | 
				
			|||||||
func (m *machineScriptAppImpl) Save(ctx context.Context, ms *entity.MachineScript) error {
 | 
					func (m *machineScriptAppImpl) Save(ctx context.Context, ms *entity.MachineScript) error {
 | 
				
			||||||
	// 如果机器id不为公共脚本id,则校验机器是否存在
 | 
						// 如果机器id不为公共脚本id,则校验机器是否存在
 | 
				
			||||||
	if machineId := ms.MachineId; machineId != Common_Script_Machine_Id {
 | 
						if machineId := ms.MachineId; machineId != Common_Script_Machine_Id {
 | 
				
			||||||
		_, err := m.machineApp.GetById(new(entity.Machine), machineId, "Name")
 | 
							_, err := m.machineApp.GetById(machineId, "Name")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return errorx.NewBiz("该机器不存在")
 | 
								return errorx.NewBiz("该机器不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,8 +15,6 @@ type MachineCronJob interface {
 | 
				
			|||||||
type MachineCronJobRelate interface {
 | 
					type MachineCronJobRelate interface {
 | 
				
			||||||
	base.Repo[*entity.MachineCronJobRelate]
 | 
						base.Repo[*entity.MachineCronJobRelate]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GetList(condition *entity.MachineCronJobRelate) []entity.MachineCronJobRelate
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	GetMachineIds(cronJobId uint64) []uint64
 | 
						GetMachineIds(cronJobId uint64) []uint64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	GetCronJobIds(machineId uint64) []uint64
 | 
						GetCronJobIds(machineId uint64) []uint64
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,5 +35,5 @@ func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pagePar
 | 
				
			|||||||
		}))
 | 
							}))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,5 +18,5 @@ func newMachineCronJobRepo() repository.MachineCronJob {
 | 
				
			|||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineCronJobRepoImpl) GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *machineCronJobRepoImpl) GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewCond().Like("name", condition.Name).Eq("status", condition.Status).OrderBy(orderBy...)
 | 
						qd := model.NewCond().Like("name", condition.Name).Eq("status", condition.Status).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,5 +18,5 @@ func newMachineCronJobExecRepo() repository.MachineCronJobExec {
 | 
				
			|||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
						qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,20 +15,14 @@ func newMachineCronJobRelateRepo() repository.MachineCronJobRelate {
 | 
				
			|||||||
	return &machineCronJobRelateRepoImpl{base.RepoImpl[*entity.MachineCronJobRelate]{M: new(entity.MachineCronJobRelate)}}
 | 
						return &machineCronJobRelateRepoImpl{base.RepoImpl[*entity.MachineCronJobRelate]{M: new(entity.MachineCronJobRelate)}}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineCronJobRelateRepoImpl) GetList(condition *entity.MachineCronJobRelate) []entity.MachineCronJobRelate {
 | 
					 | 
				
			||||||
	list := new([]entity.MachineCronJobRelate)
 | 
					 | 
				
			||||||
	m.SelectByCond(condition, list)
 | 
					 | 
				
			||||||
	return *list
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (m *machineCronJobRelateRepoImpl) GetMachineIds(cronJobId uint64) []uint64 {
 | 
					func (m *machineCronJobRelateRepoImpl) GetMachineIds(cronJobId uint64) []uint64 {
 | 
				
			||||||
	var machineIds []uint64
 | 
						var machineIds []uint64
 | 
				
			||||||
	m.SelectByCond(model.NewModelCond(&entity.MachineCronJobRelate{CronJobId: cronJobId}).Columns("machine_id"), &machineIds)
 | 
						m.SelectByCondToAny(model.NewModelCond(&entity.MachineCronJobRelate{CronJobId: cronJobId}).Columns("machine_id"), &machineIds)
 | 
				
			||||||
	return machineIds
 | 
						return machineIds
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *machineCronJobRelateRepoImpl) GetCronJobIds(machineId uint64) []uint64 {
 | 
					func (m *machineCronJobRelateRepoImpl) GetCronJobIds(machineId uint64) []uint64 {
 | 
				
			||||||
	var cronJobIds []uint64
 | 
						var cronJobIds []uint64
 | 
				
			||||||
	m.SelectByCond(model.NewModelCond(&entity.MachineCronJobRelate{MachineId: machineId}).Columns("cron_job_id"), &cronJobIds)
 | 
						m.SelectByCondToAny(model.NewModelCond(&entity.MachineCronJobRelate{MachineId: machineId}).Columns("cron_job_id"), &cronJobIds)
 | 
				
			||||||
	return cronJobIds
 | 
						return cronJobIds
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,5 +18,5 @@ func newMachineFileRepo() repository.MachineFile {
 | 
				
			|||||||
// 分页获取机器文件信息列表
 | 
					// 分页获取机器文件信息列表
 | 
				
			||||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
						qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,5 +18,5 @@ func newMachineScriptRepo() repository.MachineScript {
 | 
				
			|||||||
// 分页获取机器信息列表
 | 
					// 分页获取机器信息列表
 | 
				
			||||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
						qd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,13 +17,11 @@ func newMachineTermOpRepoImpl() repository.MachineTermOp {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (m *machineTermOpRepoImpl) GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *machineTermOpRepoImpl) GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	pd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
						pd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(pd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(pd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据条件获取记录列表
 | 
					// 根据条件获取记录列表
 | 
				
			||||||
func (m *machineTermOpRepoImpl) SelectByQuery(cond *entity.MachineTermOpQuery) ([]*entity.MachineTermOp, error) {
 | 
					func (m *machineTermOpRepoImpl) SelectByQuery(cond *entity.MachineTermOpQuery) ([]*entity.MachineTermOp, error) {
 | 
				
			||||||
	qd := model.NewCond().Le("create_time", cond.StartCreateTime)
 | 
						qd := model.NewCond().Le("create_time", cond.StartCreateTime)
 | 
				
			||||||
	var res []*entity.MachineTermOp
 | 
						return m.SelectByCond(qd)
 | 
				
			||||||
	err := m.SelectByCond(qd, &res)
 | 
					 | 
				
			||||||
	return res, err
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *mode
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (d *mongoAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (d *mongoAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	mongoEntity, err := d.GetById(new(entity.Mongo), id)
 | 
						mongoEntity, err := d.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("mongo信息不存在")
 | 
							return errorx.NewBiz("mongo信息不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -106,7 +106,7 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagCodePa
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	// 如果调整了ssh等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
						// 如果调整了ssh等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
				
			||||||
	if oldMongo.Code == "" {
 | 
						if oldMongo.Code == "" {
 | 
				
			||||||
		oldMongo, _ = d.GetById(new(entity.Mongo), m.Id)
 | 
							oldMongo, _ = d.GetById(m.Id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 先关闭连接
 | 
						// 先关闭连接
 | 
				
			||||||
@@ -133,7 +133,7 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagCodePa
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *mongoAppImpl) GetMongoConn(id uint64) (*mgm.MongoConn, error) {
 | 
					func (d *mongoAppImpl) GetMongoConn(id uint64) (*mgm.MongoConn, error) {
 | 
				
			||||||
	return mgm.GetMongoConn(id, func() (*mgm.MongoInfo, error) {
 | 
						return mgm.GetMongoConn(id, func() (*mgm.MongoInfo, error) {
 | 
				
			||||||
		me, err := d.GetById(new(entity.Mongo), id)
 | 
							me, err := d.GetById(id)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, errorx.NewBiz("mongo信息不存在")
 | 
								return nil, errorx.NewBiz("mongo信息不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,5 +21,5 @@ func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.P
 | 
				
			|||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		Eq("code", condition.Code).
 | 
							Eq("code", condition.Code).
 | 
				
			||||||
		In("code", condition.Codes)
 | 
							In("code", condition.Codes)
 | 
				
			||||||
	return d.PageByCond(qd, pageParam, toEntity)
 | 
						return d.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,5 +17,5 @@ func newMsgRepo() repository.Msg {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *msgRepoImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	pd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
						pd := model.NewModelCond(condition).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(pd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(pd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -158,7 +158,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *SaveRedisParam) err
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	// 如果调整了ssh等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
						// 如果调整了ssh等会查不到旧数据,故需要根据id获取旧信息将code赋值给标签进行关联
 | 
				
			||||||
	if oldRedis.Code == "" {
 | 
						if oldRedis.Code == "" {
 | 
				
			||||||
		oldRedis, _ = r.GetById(new(entity.Redis), re.Id)
 | 
							oldRedis, _ = r.GetById(re.Id)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	re.Code = ""
 | 
						re.Code = ""
 | 
				
			||||||
@@ -189,7 +189,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *SaveRedisParam) err
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 删除Redis信息
 | 
					// 删除Redis信息
 | 
				
			||||||
func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	re, err := r.GetById(new(entity.Redis), id)
 | 
						re, err := r.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该redis信息不存在")
 | 
							return errorx.NewBiz("该redis信息不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -220,7 +220,7 @@ func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			|||||||
func (r *redisAppImpl) GetRedisConn(id uint64, db int) (*rdm.RedisConn, error) {
 | 
					func (r *redisAppImpl) GetRedisConn(id uint64, db int) (*rdm.RedisConn, error) {
 | 
				
			||||||
	return rdm.GetRedisConn(id, db, func() (*rdm.RedisInfo, error) {
 | 
						return rdm.GetRedisConn(id, db, func() (*rdm.RedisInfo, error) {
 | 
				
			||||||
		// 缓存不存在,则回调获取redis信息
 | 
							// 缓存不存在,则回调获取redis信息
 | 
				
			||||||
		re, err := r.GetById(new(entity.Redis), id)
 | 
							re, err := r.GetById(id)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, errorx.NewBiz("redis信息不存在")
 | 
								return nil, errorx.NewBiz("redis信息不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,5 +22,5 @@ func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *mo
 | 
				
			|||||||
		Like("host", condition.Host).
 | 
							Like("host", condition.Host).
 | 
				
			||||||
		Eq("code", condition.Code).
 | 
							Eq("code", condition.Code).
 | 
				
			||||||
		In("code", condition.Codes)
 | 
							In("code", condition.Codes)
 | 
				
			||||||
	return r.PageByCond(qd, pageParam, toEntity)
 | 
						return r.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,7 @@ func (a *Account) UpdateAccount(rc *req.Ctx) {
 | 
				
			|||||||
		updateAccount.Password = cryptox.PwdHash(updateAccount.Password)
 | 
							updateAccount.Password = cryptox.PwdHash(updateAccount.Password)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oldAcc, err := a.AccountApp.GetById(new(entity.Account), updateAccount.Id)
 | 
						oldAcc, err := a.AccountApp.GetById(updateAccount.Id)
 | 
				
			||||||
	biz.ErrIsNil(err, "账号信息不存在")
 | 
						biz.ErrIsNil(err, "账号信息不存在")
 | 
				
			||||||
	// 账号创建十分钟内允许修改用户名(兼容oauth2首次登录修改用户名),否则不允许修改
 | 
						// 账号创建十分钟内允许修改用户名(兼容oauth2首次登录修改用户名),否则不允许修改
 | 
				
			||||||
	if oldAcc.CreateTime.Add(10 * time.Minute).Before(time.Now()) {
 | 
						if oldAcc.CreateTime.Add(10 * time.Minute).Before(time.Now()) {
 | 
				
			||||||
@@ -148,7 +148,7 @@ func (a *Account) SimpleAccounts(rc *req.Ctx) {
 | 
				
			|||||||
// 获取账号详情
 | 
					// 获取账号详情
 | 
				
			||||||
func (a *Account) AccountDetail(rc *req.Ctx) {
 | 
					func (a *Account) AccountDetail(rc *req.Ctx) {
 | 
				
			||||||
	accountId := uint64(rc.PathParamInt("id"))
 | 
						accountId := uint64(rc.PathParamInt("id"))
 | 
				
			||||||
	account, err := a.AccountApp.GetById(new(entity.Account), accountId)
 | 
						account, err := a.AccountApp.GetById(accountId)
 | 
				
			||||||
	biz.ErrIsNil(err, "账号不存在")
 | 
						biz.ErrIsNil(err, "账号不存在")
 | 
				
			||||||
	accountvo := new(vo.SimpleAccountVO)
 | 
						accountvo := new(vo.SimpleAccountVO)
 | 
				
			||||||
	structx.Copy(accountvo, account)
 | 
						structx.Copy(accountvo, account)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,12 +18,12 @@ type Resource struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (r *Resource) GetAllResourceTree(rc *req.Ctx) {
 | 
					func (r *Resource) GetAllResourceTree(rc *req.Ctx) {
 | 
				
			||||||
	var resources vo.ResourceManageVOList
 | 
						var resources vo.ResourceManageVOList
 | 
				
			||||||
	r.ResourceApp.ListByCond(model.NewCond().OrderByAsc("weight"), &resources)
 | 
						r.ResourceApp.ListByCondToAny(model.NewCond().OrderByAsc("weight"), &resources)
 | 
				
			||||||
	rc.ResData = resources.ToTrees(0)
 | 
						rc.ResData = resources.ToTrees(0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *Resource) GetById(rc *req.Ctx) {
 | 
					func (r *Resource) GetById(rc *req.Ctx) {
 | 
				
			||||||
	res, err := r.ResourceApp.GetById(new(entity.Resource), uint64(rc.PathParamInt("id")))
 | 
						res, err := r.ResourceApp.GetById(uint64(rc.PathParamInt("id")))
 | 
				
			||||||
	biz.ErrIsNil(err, "该资源不存在")
 | 
						biz.ErrIsNil(err, "该资源不存在")
 | 
				
			||||||
	rc.ResData = res
 | 
						rc.ResData = res
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,7 @@ func (r *resourceAppImpl) Save(ctx context.Context, resource *entity.Resource) e
 | 
				
			|||||||
	// 更新操作
 | 
						// 更新操作
 | 
				
			||||||
	if resource.Id != 0 {
 | 
						if resource.Id != 0 {
 | 
				
			||||||
		if resource.Code != "" {
 | 
							if resource.Code != "" {
 | 
				
			||||||
			oldRes, err := r.GetById(new(entity.Resource), resource.Id, "Code")
 | 
								oldRes, err := r.GetById(resource.Id, "Code")
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return errorx.NewBiz("更新失败, 该资源不存在")
 | 
									return errorx.NewBiz("更新失败, 该资源不存在")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -60,7 +60,7 @@ func (r *resourceAppImpl) Save(ctx context.Context, resource *entity.Resource) e
 | 
				
			|||||||
	// 生成随机八位唯一标识符
 | 
						// 生成随机八位唯一标识符
 | 
				
			||||||
	ui := stringx.Rand(8)
 | 
						ui := stringx.Rand(8)
 | 
				
			||||||
	if pid := resource.Pid; pid != 0 {
 | 
						if pid := resource.Pid; pid != 0 {
 | 
				
			||||||
		pResource, err := r.GetById(new(entity.Resource), uint64(pid))
 | 
							pResource, err := r.GetById(uint64(pid))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return errorx.NewBiz("该父资源不存在")
 | 
								return errorx.NewBiz("该父资源不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -80,7 +80,7 @@ func (r *resourceAppImpl) Save(ctx context.Context, resource *entity.Resource) e
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAppImpl) ChangeStatus(ctx context.Context, resourceId uint64, status int8) error {
 | 
					func (r *resourceAppImpl) ChangeStatus(ctx context.Context, resourceId uint64, status int8) error {
 | 
				
			||||||
	resource, err := r.GetById(new(entity.Resource), resourceId)
 | 
						resource, err := r.GetById(resourceId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("资源不存在")
 | 
							return errorx.NewBiz("资源不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -89,7 +89,7 @@ func (r *resourceAppImpl) ChangeStatus(ctx context.Context, resourceId uint64, s
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAppImpl) Sort(ctx context.Context, sortResource *entity.Resource) error {
 | 
					func (r *resourceAppImpl) Sort(ctx context.Context, sortResource *entity.Resource) error {
 | 
				
			||||||
	resource, err := r.GetById(new(entity.Resource), sortResource.Id)
 | 
						resource, err := r.GetById(sortResource.Id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("资源不存在")
 | 
							return errorx.NewBiz("资源不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -115,7 +115,7 @@ func (r *resourceAppImpl) Sort(ctx context.Context, sortResource *entity.Resourc
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	newParentResourceUiPath := ""
 | 
						newParentResourceUiPath := ""
 | 
				
			||||||
	if sortResource.Pid != 0 {
 | 
						if sortResource.Pid != 0 {
 | 
				
			||||||
		newParentResource, err := r.GetById(new(entity.Resource), uint64(sortResource.Pid))
 | 
							newParentResource, err := r.GetById(uint64(sortResource.Pid))
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return errorx.NewBiz("父资源不存在")
 | 
								return errorx.NewBiz("父资源不存在")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -159,7 +159,7 @@ func (r *resourceAppImpl) checkCode(code string) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (r *resourceAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	resource, err := r.GetById(new(entity.Resource), id)
 | 
						resource, err := r.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("资源不存在")
 | 
							return errorx.NewBiz("资源不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -180,7 +180,7 @@ func (r *resourceAppImpl) GetAccountResources(accountId uint64, toEntity any) er
 | 
				
			|||||||
		cond := &entity.Resource{
 | 
							cond := &entity.Resource{
 | 
				
			||||||
			Status: entity.ResourceStatusEnable,
 | 
								Status: entity.ResourceStatusEnable,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return r.ListByCond(model.NewModelCond(cond).OrderByAsc("pid").OrderByAsc("weight"), toEntity)
 | 
							return r.ListByCondToAny(model.NewModelCond(cond).OrderByAsc("pid").OrderByAsc("weight"), toEntity)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r.GetRepo().GetAccountResources(accountId, toEntity)
 | 
						return r.GetRepo().GetAccountResources(accountId, toEntity)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -141,9 +141,7 @@ func (m *roleAppImpl) RelateAccountRole(ctx context.Context, accountId, roleId u
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *roleAppImpl) GetAccountRoles(accountId uint64) ([]*entity.AccountRole, error) {
 | 
					func (m *roleAppImpl) GetAccountRoles(accountId uint64) ([]*entity.AccountRole, error) {
 | 
				
			||||||
	var res []*entity.AccountRole
 | 
						return m.accountRoleRepo.SelectByCond(&entity.AccountRole{AccountId: accountId})
 | 
				
			||||||
	err := m.accountRoleRepo.SelectByCond(&entity.AccountRole{AccountId: accountId}, &res)
 | 
					 | 
				
			||||||
	return res, err
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *roleAppImpl) GetRoleAccountPage(condition *entity.RoleAccountQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *roleAppImpl) GetRoleAccountPage(condition *entity.RoleAccountQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -114,8 +114,8 @@ func (m *syslogAppImpl) GetLogDetail(logId uint64) *entity.SysLog {
 | 
				
			|||||||
	if syslog != nil {
 | 
						if syslog != nil {
 | 
				
			||||||
		return syslog
 | 
							return syslog
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	syslog = new(entity.SysLog)
 | 
						syslog, err := m.SyslogRepo.GetById(logId)
 | 
				
			||||||
	if err := m.SyslogRepo.GetById(syslog, logId); err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return syslog
 | 
						return syslog
 | 
				
			||||||
@@ -137,11 +137,12 @@ func (m *syslogAppImpl) CreateLog(ctx context.Context, log *CreateLogReq) (uint6
 | 
				
			|||||||
func (m *syslogAppImpl) AppendLog(logId uint64, appendLog *AppendLogReq) {
 | 
					func (m *syslogAppImpl) AppendLog(logId uint64, appendLog *AppendLogReq) {
 | 
				
			||||||
	syslog := m.GetCacheLog(logId)
 | 
						syslog := m.GetCacheLog(logId)
 | 
				
			||||||
	if syslog == nil {
 | 
						if syslog == nil {
 | 
				
			||||||
		syslog = new(entity.SysLog)
 | 
							sl, err := m.SyslogRepo.GetById(logId)
 | 
				
			||||||
		if err := m.SyslogRepo.GetById(syslog, logId); err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logx.Warnf("追加日志不存在: %d", logId)
 | 
								logx.Warnf("追加日志不存在: %d", logId)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							syslog = sl
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	appendLogMsg := fmt.Sprintf("%s %s", timex.DefaultFormat(time.Now()), appendLog.AppendResp)
 | 
						appendLogMsg := fmt.Sprintf("%s %s", timex.DefaultFormat(time.Now()), appendLog.AppendResp)
 | 
				
			||||||
@@ -158,11 +159,12 @@ func (m *syslogAppImpl) AppendLog(logId uint64, appendLog *AppendLogReq) {
 | 
				
			|||||||
func (m *syslogAppImpl) SetExtra(logId uint64, key string, val any) {
 | 
					func (m *syslogAppImpl) SetExtra(logId uint64, key string, val any) {
 | 
				
			||||||
	syslog := m.GetCacheLog(logId)
 | 
						syslog := m.GetCacheLog(logId)
 | 
				
			||||||
	if syslog == nil {
 | 
						if syslog == nil {
 | 
				
			||||||
		syslog = new(entity.SysLog)
 | 
							sl, err := m.SyslogRepo.GetById(logId)
 | 
				
			||||||
		if err := m.SyslogRepo.GetById(syslog, logId); err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logx.Warnf("追加日志不存在: %d", logId)
 | 
								logx.Warnf("追加日志不存在: %d", logId)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							syslog = sl
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	extraMap := jsonx.ToMap(syslog.Extra)
 | 
						extraMap := jsonx.ToMap(syslog.Extra)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,5 +20,5 @@ func (m *AccountRepoImpl) GetPageList(condition *entity.AccountQuery, pageParam
 | 
				
			|||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		Like("username", condition.Username).
 | 
							Like("username", condition.Username).
 | 
				
			||||||
		In("id", condition.Ids)
 | 
							In("id", condition.Ids)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,5 +20,5 @@ func (m *configRepoImpl) GetPageList(condition *entity.Config, pageParam *model.
 | 
				
			|||||||
		Like("`key`", condition.Key).
 | 
							Like("`key`", condition.Key).
 | 
				
			||||||
		And("permission = 'all' OR permission LIKE ?", "%"+condition.Permission+",%").
 | 
							And("permission = 'all' OR permission LIKE ?", "%"+condition.Permission+",%").
 | 
				
			||||||
		OrderBy(orderBy...)
 | 
							OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,17 +22,15 @@ func (m *roleRepoImpl) GetPageList(condition *entity.RoleQuery, pageParam *model
 | 
				
			|||||||
		In("id", condition.Ids).
 | 
							In("id", condition.Ids).
 | 
				
			||||||
		NotIn("id", condition.NotIds).
 | 
							NotIn("id", condition.NotIds).
 | 
				
			||||||
		OrderBy(orderBy...)
 | 
							OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *roleRepoImpl) ListByQuery(condition *entity.RoleQuery) ([]*entity.Role, error) {
 | 
					func (m *roleRepoImpl) ListByQuery(condition *entity.RoleQuery) ([]*entity.Role, error) {
 | 
				
			||||||
	var res []*entity.Role
 | 
					 | 
				
			||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		Like("code", condition.Code).
 | 
							Like("code", condition.Code).
 | 
				
			||||||
		In("id", condition.Ids).
 | 
							In("id", condition.Ids).
 | 
				
			||||||
		NotIn("id", condition.NotIds).
 | 
							NotIn("id", condition.NotIds).
 | 
				
			||||||
		OrderByDesc("id")
 | 
							OrderByDesc("id")
 | 
				
			||||||
	err := m.SelectByCond(qd, &res)
 | 
						return m.SelectByCond(qd)
 | 
				
			||||||
	return res, err
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ import (
 | 
				
			|||||||
	"mayfly-go/internal/sys/domain/entity"
 | 
						"mayfly-go/internal/sys/domain/entity"
 | 
				
			||||||
	"mayfly-go/internal/sys/domain/repository"
 | 
						"mayfly-go/internal/sys/domain/repository"
 | 
				
			||||||
	"mayfly-go/pkg/base"
 | 
						"mayfly-go/pkg/base"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type roleResourceRepoImpl struct {
 | 
					type roleResourceRepoImpl struct {
 | 
				
			||||||
@@ -17,10 +16,7 @@ func newRoleResourceRepo() repository.RoleResource {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 获取角色拥有的资源id数组
 | 
					// 获取角色拥有的资源id数组
 | 
				
			||||||
func (m *roleResourceRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
 | 
					func (m *roleResourceRepoImpl) GetRoleResourceIds(roleId uint64) []uint64 {
 | 
				
			||||||
	var rrs []entity.RoleResource
 | 
						rrs, _ := m.SelectByCond(&entity.RoleResource{RoleId: roleId}, "ResourceId")
 | 
				
			||||||
 | 
					 | 
				
			||||||
	condtion := &entity.RoleResource{RoleId: roleId}
 | 
					 | 
				
			||||||
	m.SelectByCond(model.NewModelCond(condtion).Columns("ResourceId"), &rrs)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var rids []uint64
 | 
						var rids []uint64
 | 
				
			||||||
	for _, v := range rrs {
 | 
						for _, v := range rrs {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,5 +18,5 @@ func newSyslogRepo() repository.Syslog {
 | 
				
			|||||||
func (m *syslogRepoImpl) GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
					func (m *syslogRepoImpl) GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
				
			||||||
	qd := model.NewCond().Like("description", condition.Description).
 | 
						qd := model.NewCond().Like("description", condition.Description).
 | 
				
			||||||
		Eq("creator_id", condition.CreatorId).Eq("type", condition.Type).OrderBy(orderBy...)
 | 
							Eq("creator_id", condition.CreatorId).Eq("type", condition.Type).OrderBy(orderBy...)
 | 
				
			||||||
	return m.PageByCond(qd, pageParam, toEntity)
 | 
						return m.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,10 +22,9 @@ func (r *ResourceAuthCert) ListByQuery(rc *req.Ctx) {
 | 
				
			|||||||
	cond.CiphertextType = entity.AuthCertCiphertextType(rc.QueryInt("ciphertextType"))
 | 
						cond.CiphertextType = entity.AuthCertCiphertextType(rc.QueryInt("ciphertextType"))
 | 
				
			||||||
	cond.Name = rc.Query("name")
 | 
						cond.Name = rc.Query("name")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var racs []*entity.ResourceAuthCert
 | 
						res, err := r.ResourceAuthCertApp.PageByCond(cond, rc.GetPageParam())
 | 
				
			||||||
	res, err := r.ResourceAuthCertApp.PageByCond(cond, rc.GetPageParam(), &racs)
 | 
					 | 
				
			||||||
	biz.ErrIsNil(err)
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
	for _, rac := range racs {
 | 
						for _, rac := range res.List {
 | 
				
			||||||
		rac.CiphertextClear()
 | 
							rac.CiphertextClear()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	rc.ResData = res
 | 
						rc.ResData = res
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,7 @@ func (r *ResourceOpLog) PageAccountOpLog(rc *req.Ctx) {
 | 
				
			|||||||
	cond.ResourceType = int8(rc.QueryInt("resourceType"))
 | 
						cond.ResourceType = int8(rc.QueryInt("resourceType"))
 | 
				
			||||||
	cond.CreatorId = rc.GetLoginAccount().Id
 | 
						cond.CreatorId = rc.GetLoginAccount().Id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var rols []*entity.ResourceOpLog
 | 
						rols, err := r.ResourceOpLogApp.PageByCond(cond, rc.GetPageParam())
 | 
				
			||||||
	res, err := r.ResourceOpLogApp.PageByCond(cond, rc.GetPageParam(), &rols)
 | 
					 | 
				
			||||||
	biz.ErrIsNil(err)
 | 
						biz.ErrIsNil(err)
 | 
				
			||||||
	rc.ResData = res
 | 
						rc.ResData = rols
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -107,8 +107,7 @@ func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *Re
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var oldAuthCert []*entity.ResourceAuthCert
 | 
						oldAuthCert, _ := r.ListByCond(&entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType})
 | 
				
			||||||
	r.ListByCond(&entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType}, &oldAuthCert)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 新增、删除以及不变的授权凭证名
 | 
						// 新增、删除以及不变的授权凭证名
 | 
				
			||||||
	var adds, dels, unmodifys []string
 | 
						var adds, dels, unmodifys []string
 | 
				
			||||||
@@ -185,7 +184,7 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, rac *entity.
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAuthCertAppImpl) DeleteAuthCert(ctx context.Context, id uint64) error {
 | 
					func (r *resourceAuthCertAppImpl) DeleteAuthCert(ctx context.Context, id uint64) error {
 | 
				
			||||||
	rac, err := r.GetById(new(entity.ResourceAuthCert), id)
 | 
						rac, err := r.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("授权凭证不存在")
 | 
							return errorx.NewBiz("授权凭证不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -224,11 +223,11 @@ func (r *resourceAuthCertAppImpl) GetAuthCert(authCertName string) (*entity.Reso
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAuthCertAppImpl) GetResourceAuthCert(resourceType entity.TagType, resourceCode string) (*entity.ResourceAuthCert, error) {
 | 
					func (r *resourceAuthCertAppImpl) GetResourceAuthCert(resourceType entity.TagType, resourceCode string) (*entity.ResourceAuthCert, error) {
 | 
				
			||||||
	var resourceAuthCerts []*entity.ResourceAuthCert
 | 
						resourceAuthCerts, err := r.ListByCond(&entity.ResourceAuthCert{
 | 
				
			||||||
	if err := r.ListByCond(&entity.ResourceAuthCert{
 | 
					 | 
				
			||||||
		ResourceType: int8(resourceType),
 | 
							ResourceType: int8(resourceType),
 | 
				
			||||||
		ResourceCode: resourceCode,
 | 
							ResourceCode: resourceCode,
 | 
				
			||||||
	}, &resourceAuthCerts); err != nil {
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -272,8 +271,7 @@ func (r *resourceAuthCertAppImpl) FillAuthCertByAcs(authCerts []*entity.Resource
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *resourceAuthCertAppImpl) FillAuthCertByAcNames(authCertNames []string, resources ...entity.IAuthCert) {
 | 
					func (r *resourceAuthCertAppImpl) FillAuthCertByAcNames(authCertNames []string, resources ...entity.IAuthCert) {
 | 
				
			||||||
	var acs []*entity.ResourceAuthCert
 | 
						acs, _ := r.ListByCond(model.NewCond().In("name", authCertNames))
 | 
				
			||||||
	r.ListByCond(model.NewCond().In("name", authCertNames), &acs)
 | 
					 | 
				
			||||||
	r.FillAuthCertByAcs(acs, resources...)
 | 
						r.FillAuthCertByAcs(acs, resources...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -285,8 +283,7 @@ func (r *resourceAuthCertAppImpl) FillAuthCert(resourceType int8, resources ...e
 | 
				
			|||||||
	resourceCodes := collx.ArrayMap(resources, func(ac entity.IAuthCert) string {
 | 
						resourceCodes := collx.ArrayMap(resources, func(ac entity.IAuthCert) string {
 | 
				
			||||||
		return ac.GetCode()
 | 
							return ac.GetCode()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	var acs []*entity.ResourceAuthCert
 | 
						acs, _ := r.ListByCond(model.NewCond().In("resource_code", resourceCodes).Eq("resource_type", resourceType))
 | 
				
			||||||
	r.ListByCond(model.NewCond().In("ResoourceCode", resourceCodes).Eq0("ResourceType", resourceType), &acs)
 | 
					 | 
				
			||||||
	r.FillAuthCertByAcs(acs, resources...)
 | 
						r.FillAuthCertByAcs(acs, resources...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -312,8 +309,7 @@ func (r *resourceAuthCertAppImpl) addAuthCert(ctx context.Context, rac *entity.R
 | 
				
			|||||||
	// 如果该资源存在对应的授权凭证标签类型,则说明需要关联至tagTree,否则直接从授权凭证库中验证资源编号是否正确即可(一个资源最少有一个授权凭证)
 | 
						// 如果该资源存在对应的授权凭证标签类型,则说明需要关联至tagTree,否则直接从授权凭证库中验证资源编号是否正确即可(一个资源最少有一个授权凭证)
 | 
				
			||||||
	if authCertTagType != 0 {
 | 
						if authCertTagType != 0 {
 | 
				
			||||||
		// 获取资源编号对应的资源标签信息
 | 
							// 获取资源编号对应的资源标签信息
 | 
				
			||||||
		var resourceTags []*entity.TagTree
 | 
							resourceTags, _ := r.tagTreeApp.ListByCond(&entity.TagTree{Type: entity.TagType(resourceType), Code: resourceCode})
 | 
				
			||||||
		r.tagTreeApp.ListByCond(&entity.TagTree{Type: entity.TagType(resourceType), Code: resourceCode}, &resourceTags)
 | 
					 | 
				
			||||||
		// 资源标签tagPath(相当于父tag)
 | 
							// 资源标签tagPath(相当于父tag)
 | 
				
			||||||
		resourceTagCodePaths = collx.ArrayMap(resourceTags, func(tag *entity.TagTree) string {
 | 
							resourceTagCodePaths = collx.ArrayMap(resourceTags, func(tag *entity.TagTree) string {
 | 
				
			||||||
			return tag.CodePath
 | 
								return tag.CodePath
 | 
				
			||||||
@@ -353,7 +349,7 @@ func (r *resourceAuthCertAppImpl) addAuthCert(ctx context.Context, rac *entity.R
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// updateAuthCert 更新授权凭证
 | 
					// updateAuthCert 更新授权凭证
 | 
				
			||||||
func (r *resourceAuthCertAppImpl) updateAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error {
 | 
					func (r *resourceAuthCertAppImpl) updateAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error {
 | 
				
			||||||
	oldRac, err := r.GetById(new(entity.ResourceAuthCert), rac.Id)
 | 
						oldRac, err := r.GetById(rac.Id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该授权凭证不存在")
 | 
							return errorx.NewBiz("该授权凭证不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,8 @@ func (rol *resourceOpLogAppImpl) AddResourceOpLog(ctx context.Context, codePath
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var logs []*entity.ResourceOpLog
 | 
						var logs []*entity.ResourceOpLog
 | 
				
			||||||
	qc := model.NewCond().Ge("create_time", time.Now().Add(-5*time.Minute)).Eq("creator_id", loginAccount.Id).Eq("code_path", codePath)
 | 
						qc := model.NewCond().Ge("create_time", time.Now().Add(-5*time.Minute)).Eq("creator_id", loginAccount.Id).Eq("code_path", codePath)
 | 
				
			||||||
	if err := rol.ListByCond(qc, &logs); err != nil {
 | 
						logs, err := rol.ListByCond(qc)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 指定时间内多次操作则不记录
 | 
						// 指定时间内多次操作则不记录
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,19 +53,6 @@ type TagTree interface {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	SaveTag(ctx context.Context, pid uint64, tt *entity.TagTree) error
 | 
						SaveTag(ctx context.Context, pid uint64, tt *entity.TagTree) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Delete(ctx context.Context, id uint64) error
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// GetAccountTags 获取指定账号有权限操作的标签列表
 | 
					 | 
				
			||||||
	// @param accountId 账号id
 | 
					 | 
				
			||||||
	// @param query 查询条件
 | 
					 | 
				
			||||||
	GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*entity.TagTree
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// GetAccountTagCodes 获取指定账号有权限操作的标签codes
 | 
					 | 
				
			||||||
	GetAccountTagCodes(accountId uint64, resourceType int8, tagPath string) []string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// GetAccountTagCodePaths 获取指定账号有权限操作的codePaths
 | 
					 | 
				
			||||||
	GetAccountTagCodePaths(accountId uint64, tagType entity.TagType, tagPath string) []string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// SaveResourceTag 保存资源类型标签
 | 
						// SaveResourceTag 保存资源类型标签
 | 
				
			||||||
	SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error
 | 
						SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -84,6 +71,19 @@ type TagTree interface {
 | 
				
			|||||||
	// DeleteTagByParam 删除标签,会删除该标签下所有子标签信息以及团队关联的标签信息
 | 
						// DeleteTagByParam 删除标签,会删除该标签下所有子标签信息以及团队关联的标签信息
 | 
				
			||||||
	DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error
 | 
						DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Delete(ctx context.Context, id uint64) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// GetAccountTags 获取指定账号有权限操作的标签列表
 | 
				
			||||||
 | 
						// @param accountId 账号id
 | 
				
			||||||
 | 
						// @param query 查询条件
 | 
				
			||||||
 | 
						GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*entity.TagTree
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// GetAccountTagCodes 获取指定账号有权限操作的标签codes
 | 
				
			||||||
 | 
						GetAccountTagCodes(accountId uint64, resourceType int8, tagPath string) []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// GetAccountTagCodePaths 获取指定账号有权限操作的codePaths
 | 
				
			||||||
 | 
						GetAccountTagCodePaths(accountId uint64, tagType entity.TagType, tagPath string) []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据标签类型和标签code获取对应的标签路径列表
 | 
						// 根据标签类型和标签code获取对应的标签路径列表
 | 
				
			||||||
	ListTagPathByTypeAndCode(resourceType int8, resourceCode string) []string
 | 
						ListTagPathByTypeAndCode(resourceType int8, resourceCode string) []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -116,7 +116,7 @@ func (p *tagTreeAppImpl) SaveTag(ctx context.Context, pid uint64, tag *entity.Ta
 | 
				
			|||||||
			return errorx.NewBiz("标识符不能包含'/'")
 | 
								return errorx.NewBiz("标识符不能包含'/'")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if pid != 0 {
 | 
							if pid != 0 {
 | 
				
			||||||
			parentTag, err := p.GetById(new(entity.TagTree), pid)
 | 
								parentTag, err := p.GetById(pid)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return errorx.NewBiz("父节点不存在")
 | 
									return errorx.NewBiz("父节点不存在")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -153,6 +153,208 @@ func (p *tagTreeAppImpl) SaveTag(ctx context.Context, pid uint64, tag *entity.Ta
 | 
				
			|||||||
	return p.UpdateById(ctx, tag)
 | 
						return p.UpdateById(ctx, tag)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error {
 | 
				
			||||||
 | 
						code := param.ResourceTag.Code
 | 
				
			||||||
 | 
						tagType := param.ResourceTag.Type
 | 
				
			||||||
 | 
						parentTagCodePaths := param.ParentTagCodePaths
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if code == "" {
 | 
				
			||||||
 | 
							return errorx.NewBiz("保存资源标签失败: 资源编号不能为空")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if tagType == 0 {
 | 
				
			||||||
 | 
							return errorx.NewBiz("保存资源标签失败:资源类型不能为空")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 如果tagIds为空数组,则为删除该资源标签
 | 
				
			||||||
 | 
						if len(parentTagCodePaths) == 0 {
 | 
				
			||||||
 | 
							return p.DeleteTagByParam(ctx, &DelResourceTagParam{
 | 
				
			||||||
 | 
								ResourceType: tagType,
 | 
				
			||||||
 | 
								ResourceCode: code,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取所有关联的父标签
 | 
				
			||||||
 | 
						parentTags, _ := p.ListByCond(model.NewCond().In("code_path", parentTagCodePaths))
 | 
				
			||||||
 | 
						if len(parentTags) == 0 || len(parentTags) != len(parentTagCodePaths) {
 | 
				
			||||||
 | 
							return errorx.NewBiz("保存资源标签失败: 存在错误的关联标签")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						newTags := p.toTags(parentTags, param.ResourceTag)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						oldParentTagTree, _ := p.ListByCond(&entity.TagTree{Type: tagType, Code: code})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 该资源对应的旧资源标签信息
 | 
				
			||||||
 | 
						var oldChildrenTags []*entity.TagTree
 | 
				
			||||||
 | 
						if len(oldParentTagTree) > 0 {
 | 
				
			||||||
 | 
							// 获取所有旧的子标签
 | 
				
			||||||
 | 
							p.ListByQuery(&entity.TagTreeQuery{
 | 
				
			||||||
 | 
								CodePathLikes: collx.ArrayMap[*entity.TagTree, string](oldParentTagTree, func(val *entity.TagTree) string {
 | 
				
			||||||
 | 
									return val.CodePath
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
							}, &oldChildrenTags)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 旧的codePath -> tag
 | 
				
			||||||
 | 
						oldCodePath2Tag := collx.ArrayToMap[*entity.TagTree, string](oldChildrenTags, func(val *entity.TagTree) string { return val.CodePath })
 | 
				
			||||||
 | 
						// 新的codePath -> tag
 | 
				
			||||||
 | 
						newCodePath2Tag := collx.ArrayToMap[*entity.TagTree, string](newTags, func(val *entity.TagTree) string { return val.CodePath })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var addCodePaths, delCodePaths []string
 | 
				
			||||||
 | 
						addCodePaths, delCodePaths, _ = collx.ArrayCompare(collx.MapKeys(newCodePath2Tag), collx.MapKeys(oldCodePath2Tag))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(addCodePaths) > 0 {
 | 
				
			||||||
 | 
							logx.DebugfContext(ctx, "SaveResourceTag-新增标签[%v]", addCodePaths)
 | 
				
			||||||
 | 
							addTags := make([]*entity.TagTree, 0)
 | 
				
			||||||
 | 
							for _, addCodePath := range addCodePaths {
 | 
				
			||||||
 | 
								addTags = append(addTags, newCodePath2Tag[addCodePath])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err := p.BatchInsert(ctx, addTags); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(delCodePaths) > 0 {
 | 
				
			||||||
 | 
							logx.DebugfContext(ctx, "SaveResourceTag-删除标签[%v]", delCodePaths)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var delTagIds []uint64
 | 
				
			||||||
 | 
							for _, delCodePath := range delCodePaths {
 | 
				
			||||||
 | 
								delTag := oldCodePath2Tag[delCodePath]
 | 
				
			||||||
 | 
								if delTag != nil && delTag.Id != 0 {
 | 
				
			||||||
 | 
									delTagIds = append(delTagIds, delTag.Id)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return p.deleteByIds(ctx, delTagIds)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *RelateTagsByCodeAndTypeParam) error {
 | 
				
			||||||
 | 
						parentTagCode := param.ParentTagCode
 | 
				
			||||||
 | 
						parentTagType := param.ParentTagType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取满足指定编号与类型的所有标签信息
 | 
				
			||||||
 | 
						parentTags, _ := p.ListByCond(&entity.TagTree{Type: parentTagType, Code: parentTagCode})
 | 
				
			||||||
 | 
						// 标签codePaths(相当于需要关联的标签数组的父tag)
 | 
				
			||||||
 | 
						parentTagCodePaths := collx.ArrayMap(parentTags, func(tag *entity.TagTree) string {
 | 
				
			||||||
 | 
							return tag.CodePath
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(parentTagCodePaths) == 0 {
 | 
				
			||||||
 | 
							return errorx.NewBiz("不存在满足[type=%d, code=%s]的标签", parentTagType, parentTagCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tag := range param.Tags {
 | 
				
			||||||
 | 
							if err := (p.SaveResourceTag(ctx, &SaveResourceTagParam{
 | 
				
			||||||
 | 
								ResourceTag:        tag,
 | 
				
			||||||
 | 
								ParentTagCodePaths: parentTagCodePaths,
 | 
				
			||||||
 | 
							})); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) UpdateTagName(ctx context.Context, tagType entity.TagType, tagCode string, tagName string) error {
 | 
				
			||||||
 | 
						return p.UpdateByCond(ctx, &entity.TagTree{Name: tagName}, &entity.TagTree{Type: tagType, Code: tagCode})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) ChangeParentTag(ctx context.Context, tagType entity.TagType, tagCode string, parentTagType entity.TagType, newParentCode string) error {
 | 
				
			||||||
 | 
						// 获取资源编号对应的资源标签信息
 | 
				
			||||||
 | 
						resourceTags, _ := p.ListByCond(&entity.TagTree{Type: tagType, Code: tagCode})
 | 
				
			||||||
 | 
						if len(resourceTags) == 0 {
 | 
				
			||||||
 | 
							logx.WarnfContext(ctx, "ChangeParentTag-[%d-%s]标签信息不存在", tagType, tagCode)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if p.CountByCond(&entity.TagTree{Type: parentTagType, Code: newParentCode}) == 0 {
 | 
				
			||||||
 | 
							return errorx.NewBiz("该父标签不存在")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取该资源编号对应的所有子资源标签信息
 | 
				
			||||||
 | 
						var resourceChildrenTags []*entity.TagTree
 | 
				
			||||||
 | 
						p.ListByQuery(&entity.TagTreeQuery{CodePathLikes: collx.ArrayMap(resourceTags, func(tag *entity.TagTree) string {
 | 
				
			||||||
 | 
							return tag.CodePath
 | 
				
			||||||
 | 
						})}, &resourceChildrenTags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 更新父标签的codepath
 | 
				
			||||||
 | 
						for _, tag := range resourceChildrenTags {
 | 
				
			||||||
 | 
							pathSection := entity.GetTagPathSections(tag.CodePath)
 | 
				
			||||||
 | 
							for i, ps := range pathSection {
 | 
				
			||||||
 | 
								if ps.Type == tagType && ps.Code == tagCode {
 | 
				
			||||||
 | 
									// 将父标签编号修改为对应的新编号与类型
 | 
				
			||||||
 | 
									pathSection[i-1].Code = newParentCode
 | 
				
			||||||
 | 
									pathSection[i-1].Type = parentTagType
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							tag.CodePath = pathSection.ToCodePath()
 | 
				
			||||||
 | 
							if err := p.UpdateById(ctx, tag); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) MovingTag(ctx context.Context, fromTagPath string, toTagPath string) error {
 | 
				
			||||||
 | 
						fromTag := &entity.TagTree{CodePath: fromTagPath}
 | 
				
			||||||
 | 
						if err := p.GetByCond(fromTag); err != nil {
 | 
				
			||||||
 | 
							return errorx.NewBiz("移动标签不存在")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						toTag := &entity.TagTree{CodePath: toTagPath}
 | 
				
			||||||
 | 
						if err := p.GetByCond(toTag); err != nil {
 | 
				
			||||||
 | 
							return errorx.NewBiz("目标标签不存在")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取要移动标签的所有子标签
 | 
				
			||||||
 | 
						var childrenTags []*entity.TagTree
 | 
				
			||||||
 | 
						p.ListByQuery(&entity.TagTreeQuery{CodePathLike: fromTagPath}, &childrenTags)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 获取父路径, 若fromTagPath=tag1/tag2/1|xxx则返回 tag1/tag2/
 | 
				
			||||||
 | 
						fromParentPath := entity.GetParentPath(fromTagPath, 0)
 | 
				
			||||||
 | 
						for _, childTag := range childrenTags {
 | 
				
			||||||
 | 
							// 替换path,若childPath = tag1/tag2/1|xxx/11|yyy, toTagPath=tag3/tag4则替换为tag3/tag4/1|xxx/11|yyy/
 | 
				
			||||||
 | 
							childTag.CodePath = strings.Replace(childTag.CodePath, fromParentPath, toTagPath, 1)
 | 
				
			||||||
 | 
							if err := p.UpdateById(ctx, childTag); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *tagTreeAppImpl) DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error {
 | 
				
			||||||
 | 
						// 获取资源编号对应的资源标签信息
 | 
				
			||||||
 | 
						cond := &entity.TagTree{Type: param.ResourceType, Code: param.ResourceCode}
 | 
				
			||||||
 | 
						cond.Id = param.Id
 | 
				
			||||||
 | 
						resourceTags, _ := p.ListByCond(cond)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(resourceTags) == 0 {
 | 
				
			||||||
 | 
							logx.DebugfContext(ctx, "TagTreeApp.DeleteTagByParam[%d-%s]不存在可删除的标签", param.ResourceType, param.ResourceCode)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						delTagType := param.ChildType
 | 
				
			||||||
 | 
						for _, resourceTag := range resourceTags {
 | 
				
			||||||
 | 
							// 获取所有关联的子标签
 | 
				
			||||||
 | 
							childrenTag, _ := p.ListByCond(model.NewCond().RLike("code_path", resourceTag.CodePath).Eq("type", delTagType))
 | 
				
			||||||
 | 
							if len(childrenTag) == 0 {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							childrenTagIds := collx.ArrayMap(childrenTag, func(item *entity.TagTree) uint64 {
 | 
				
			||||||
 | 
								return item.Id
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
							// 删除code_path下的所有子标签
 | 
				
			||||||
 | 
							return p.deleteByIds(ctx, childrenTagIds)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *tagTreeAppImpl) ListByQuery(condition *entity.TagTreeQuery, toEntity any) {
 | 
					func (p *tagTreeAppImpl) ListByQuery(condition *entity.TagTreeQuery, toEntity any) {
 | 
				
			||||||
	p.GetRepo().SelectByCondition(condition, toEntity)
 | 
						p.GetRepo().SelectByCondition(condition, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -231,218 +433,8 @@ func (p *tagTreeAppImpl) GetAccountTagCodePaths(accountId uint64, tagType entity
 | 
				
			|||||||
	return collx.MapKeys(code2Resource)
 | 
						return collx.MapKeys(code2Resource)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error {
 | 
					 | 
				
			||||||
	code := param.ResourceTag.Code
 | 
					 | 
				
			||||||
	tagType := param.ResourceTag.Type
 | 
					 | 
				
			||||||
	parentTagCodePaths := param.ParentTagCodePaths
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if code == "" {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("保存资源标签失败: 资源编号不能为空")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if tagType == 0 {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("保存资源标签失败:资源类型不能为空")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 如果tagIds为空数组,则为删除该资源标签
 | 
					 | 
				
			||||||
	if len(parentTagCodePaths) == 0 {
 | 
					 | 
				
			||||||
		return p.DeleteTagByParam(ctx, &DelResourceTagParam{
 | 
					 | 
				
			||||||
			ResourceType: tagType,
 | 
					 | 
				
			||||||
			ResourceCode: code,
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取所有关联的父标签
 | 
					 | 
				
			||||||
	var parentTags []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByCond(model.NewCond().In("code_path", parentTagCodePaths), &parentTags)
 | 
					 | 
				
			||||||
	if len(parentTags) == 0 || len(parentTags) != len(parentTagCodePaths) {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("保存资源标签失败: 存在错误的关联标签")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	newTags := p.toTags(parentTags, param.ResourceTag)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var oldParentTagTree []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByCond(&entity.TagTree{Type: tagType, Code: code}, &oldParentTagTree)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 该资源对应的旧资源标签信息
 | 
					 | 
				
			||||||
	var oldChildrenTags []*entity.TagTree
 | 
					 | 
				
			||||||
	if len(oldParentTagTree) > 0 {
 | 
					 | 
				
			||||||
		// 获取所有旧的子标签
 | 
					 | 
				
			||||||
		p.ListByQuery(&entity.TagTreeQuery{
 | 
					 | 
				
			||||||
			CodePathLikes: collx.ArrayMap[*entity.TagTree, string](oldParentTagTree, func(val *entity.TagTree) string {
 | 
					 | 
				
			||||||
				return val.CodePath
 | 
					 | 
				
			||||||
			}),
 | 
					 | 
				
			||||||
		}, &oldChildrenTags)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 旧的codePath -> tag
 | 
					 | 
				
			||||||
	oldCodePath2Tag := collx.ArrayToMap[*entity.TagTree, string](oldChildrenTags, func(val *entity.TagTree) string { return val.CodePath })
 | 
					 | 
				
			||||||
	// 新的codePath -> tag
 | 
					 | 
				
			||||||
	newCodePath2Tag := collx.ArrayToMap[*entity.TagTree, string](newTags, func(val *entity.TagTree) string { return val.CodePath })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var addCodePaths, delCodePaths []string
 | 
					 | 
				
			||||||
	addCodePaths, delCodePaths, _ = collx.ArrayCompare(collx.MapKeys(newCodePath2Tag), collx.MapKeys(oldCodePath2Tag))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(addCodePaths) > 0 {
 | 
					 | 
				
			||||||
		logx.DebugfContext(ctx, "SaveResourceTag-新增标签[%v]", addCodePaths)
 | 
					 | 
				
			||||||
		addTags := make([]*entity.TagTree, 0)
 | 
					 | 
				
			||||||
		for _, addCodePath := range addCodePaths {
 | 
					 | 
				
			||||||
			addTags = append(addTags, newCodePath2Tag[addCodePath])
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err := p.BatchInsert(ctx, addTags); err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(delCodePaths) > 0 {
 | 
					 | 
				
			||||||
		logx.DebugfContext(ctx, "SaveResourceTag-删除标签[%v]", delCodePaths)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var delTagIds []uint64
 | 
					 | 
				
			||||||
		for _, delCodePath := range delCodePaths {
 | 
					 | 
				
			||||||
			delTag := oldCodePath2Tag[delCodePath]
 | 
					 | 
				
			||||||
			if delTag != nil && delTag.Id != 0 {
 | 
					 | 
				
			||||||
				delTagIds = append(delTagIds, delTag.Id)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return p.deleteByIds(ctx, delTagIds)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *RelateTagsByCodeAndTypeParam) error {
 | 
					 | 
				
			||||||
	parentTagCode := param.ParentTagCode
 | 
					 | 
				
			||||||
	parentTagType := param.ParentTagType
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取满足指定编号与类型的所有标签信息
 | 
					 | 
				
			||||||
	var parentTags []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByCond(&entity.TagTree{Type: parentTagType, Code: parentTagCode}, &parentTags)
 | 
					 | 
				
			||||||
	// 标签codePaths(相当于需要关联的标签数组的父tag)
 | 
					 | 
				
			||||||
	parentTagCodePaths := collx.ArrayMap(parentTags, func(tag *entity.TagTree) string {
 | 
					 | 
				
			||||||
		return tag.CodePath
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(parentTagCodePaths) == 0 {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("不存在满足[type=%d, code=%s]的标签", parentTagType, parentTagCode)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, tag := range param.Tags {
 | 
					 | 
				
			||||||
		if err := (p.SaveResourceTag(ctx, &SaveResourceTagParam{
 | 
					 | 
				
			||||||
			ResourceTag:        tag,
 | 
					 | 
				
			||||||
			ParentTagCodePaths: parentTagCodePaths,
 | 
					 | 
				
			||||||
		})); err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) UpdateTagName(ctx context.Context, tagType entity.TagType, tagCode string, tagName string) error {
 | 
					 | 
				
			||||||
	return p.UpdateByCond(ctx, &entity.TagTree{Name: tagName}, &entity.TagTree{Type: tagType, Code: tagCode})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) ChangeParentTag(ctx context.Context, tagType entity.TagType, tagCode string, parentTagType entity.TagType, newParentCode string) error {
 | 
					 | 
				
			||||||
	// 获取资源编号对应的资源标签信息
 | 
					 | 
				
			||||||
	var resourceTags []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByCond(&entity.TagTree{Type: tagType, Code: tagCode}, &resourceTags)
 | 
					 | 
				
			||||||
	if len(resourceTags) == 0 {
 | 
					 | 
				
			||||||
		logx.WarnfContext(ctx, "ChangeParentTag-[%d-%s]标签信息不存在", tagType, tagCode)
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if p.CountByCond(&entity.TagTree{Type: parentTagType, Code: newParentCode}) == 0 {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("该父标签不存在")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取该资源编号对应的所有子资源标签信息
 | 
					 | 
				
			||||||
	var resourceChildrenTags []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByQuery(&entity.TagTreeQuery{CodePathLikes: collx.ArrayMap(resourceTags, func(tag *entity.TagTree) string {
 | 
					 | 
				
			||||||
		return tag.CodePath
 | 
					 | 
				
			||||||
	})}, &resourceChildrenTags)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 更新父标签的codepath
 | 
					 | 
				
			||||||
	for _, tag := range resourceChildrenTags {
 | 
					 | 
				
			||||||
		pathSection := entity.GetTagPathSections(tag.CodePath)
 | 
					 | 
				
			||||||
		for i, ps := range pathSection {
 | 
					 | 
				
			||||||
			if ps.Type == tagType && ps.Code == tagCode {
 | 
					 | 
				
			||||||
				// 将父标签编号修改为对应的新编号与类型
 | 
					 | 
				
			||||||
				pathSection[i-1].Code = newParentCode
 | 
					 | 
				
			||||||
				pathSection[i-1].Type = parentTagType
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tag.CodePath = pathSection.ToCodePath()
 | 
					 | 
				
			||||||
		if err := p.UpdateById(ctx, tag); err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) MovingTag(ctx context.Context, fromTagPath string, toTagPath string) error {
 | 
					 | 
				
			||||||
	fromTag := &entity.TagTree{CodePath: fromTagPath}
 | 
					 | 
				
			||||||
	if err := p.GetByCond(fromTag); err != nil {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("移动标签不存在")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	toTag := &entity.TagTree{CodePath: toTagPath}
 | 
					 | 
				
			||||||
	if err := p.GetByCond(toTag); err != nil {
 | 
					 | 
				
			||||||
		return errorx.NewBiz("目标标签不存在")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取要移动标签的所有子标签
 | 
					 | 
				
			||||||
	var childrenTags []*entity.TagTree
 | 
					 | 
				
			||||||
	p.ListByQuery(&entity.TagTreeQuery{CodePathLike: fromTagPath}, &childrenTags)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 获取父路径, 若fromTagPath=tag1/tag2/1|xxx则返回 tag1/tag2/
 | 
					 | 
				
			||||||
	fromParentPath := entity.GetParentPath(fromTagPath, 0)
 | 
					 | 
				
			||||||
	for _, childTag := range childrenTags {
 | 
					 | 
				
			||||||
		// 替换path,若childPath = tag1/tag2/1|xxx/11|yyy, toTagPath=tag3/tag4则替换为tag3/tag4/1|xxx/11|yyy/
 | 
					 | 
				
			||||||
		childTag.CodePath = strings.Replace(childTag.CodePath, fromParentPath, toTagPath, 1)
 | 
					 | 
				
			||||||
		if err := p.UpdateById(ctx, childTag); err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error {
 | 
					 | 
				
			||||||
	// 获取资源编号对应的资源标签信息
 | 
					 | 
				
			||||||
	var resourceTags []*entity.TagTree
 | 
					 | 
				
			||||||
	cond := &entity.TagTree{Type: param.ResourceType, Code: param.ResourceCode}
 | 
					 | 
				
			||||||
	cond.Id = param.Id
 | 
					 | 
				
			||||||
	p.ListByCond(cond, &resourceTags)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(resourceTags) == 0 {
 | 
					 | 
				
			||||||
		logx.DebugfContext(ctx, "TagTreeApp.DeleteTagByParam[%d-%s]不存在可删除的标签", param.ResourceType, param.ResourceCode)
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	delTagType := param.ChildType
 | 
					 | 
				
			||||||
	for _, resourceTag := range resourceTags {
 | 
					 | 
				
			||||||
		// 获取所有关联的子标签
 | 
					 | 
				
			||||||
		var childrenTag []*entity.TagTree
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		p.ListByCond(model.NewCond().RLike("code_path", resourceTag.CodePath).Eq0("type", delTagType), &childrenTag)
 | 
					 | 
				
			||||||
		if len(childrenTag) == 0 {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		childrenTagIds := collx.ArrayMap(childrenTag, func(item *entity.TagTree) uint64 {
 | 
					 | 
				
			||||||
			return item.Id
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
		// 删除code_path下的所有子标签
 | 
					 | 
				
			||||||
		return p.deleteByIds(ctx, childrenTagIds)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *tagTreeAppImpl) ListTagPathByTypeAndCode(resourceType int8, resourceCode string) []string {
 | 
					func (p *tagTreeAppImpl) ListTagPathByTypeAndCode(resourceType int8, resourceCode string) []string {
 | 
				
			||||||
	var trs []*entity.TagTree
 | 
						trs, _ := p.ListByCond(&entity.TagTree{Type: entity.TagType(resourceType), Code: resourceCode})
 | 
				
			||||||
	p.ListByCond(&entity.TagTree{Type: entity.TagType(resourceType), Code: resourceCode}, &trs)
 | 
					 | 
				
			||||||
	return collx.ArrayMap(trs, func(tr *entity.TagTree) string {
 | 
						return collx.ArrayMap(trs, func(tr *entity.TagTree) string {
 | 
				
			||||||
		return tr.CodePath
 | 
							return tr.CodePath
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -485,13 +477,16 @@ func (p *tagTreeAppImpl) FillTagInfo(resourceTagType entity.TagType, resources .
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for _, tr := range tagResources {
 | 
						for _, tr := range tagResources {
 | 
				
			||||||
		// 赋值标签信息
 | 
							// 赋值标签信息
 | 
				
			||||||
		resourceCode2Resouce[tr.Code].SetTagInfo(entity.ResourceTag{TagId: tr.Id, CodePath: tr.GetTagPath()})
 | 
							resource := resourceCode2Resouce[tr.Code]
 | 
				
			||||||
 | 
							if resource != nil {
 | 
				
			||||||
 | 
								resource.SetTagInfo(entity.ResourceTag{TagId: tr.Id, CodePath: tr.GetTagPath()})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *tagTreeAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
					func (p *tagTreeAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
				
			||||||
	accountId := contextx.GetLoginAccount(ctx).Id
 | 
						accountId := contextx.GetLoginAccount(ctx).Id
 | 
				
			||||||
	tag, err := p.GetById(new(entity.TagTree), id)
 | 
						tag, err := p.GetById(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return errorx.NewBiz("该标签不存在")
 | 
							return errorx.NewBiz("该标签不存在")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,8 +51,7 @@ func (tr *tagTreeRelateAppImpl) RelateTag(ctx context.Context, relateType entity
 | 
				
			|||||||
		return errorx.NewBiz("存在错误标签路径")
 | 
							return errorx.NewBiz("存在错误标签路径")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var oldRelates []*entity.TagTreeRelate
 | 
						oldRelates, _ := tr.ListByCond(&entity.TagTreeRelate{RelateType: relateType, RelateId: relateId})
 | 
				
			||||||
	tr.ListByCond(&entity.TagTreeRelate{RelateType: relateType, RelateId: relateId}, &oldRelates)
 | 
					 | 
				
			||||||
	oldTagIds := collx.ArrayMap[*entity.TagTreeRelate, uint64](oldRelates, func(val *entity.TagTreeRelate) uint64 {
 | 
						oldTagIds := collx.ArrayMap[*entity.TagTreeRelate, uint64](oldRelates, func(val *entity.TagTreeRelate) uint64 {
 | 
				
			||||||
		return val.TagId
 | 
							return val.TagId
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
@@ -111,21 +110,22 @@ func (tr *tagTreeRelateAppImpl) FillTagInfo(relateType entity.TagRelateType, rel
 | 
				
			|||||||
		return rt.GetRelateId()
 | 
							return rt.GetRelateId()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var relateTags []*entity.TagTreeRelate
 | 
						relateTags, _ := tr.ListByCond(model.NewCond().Eq("relate_type", relateType).In("relate_id", collx.MapKeys(relateIds2Relate)))
 | 
				
			||||||
	tr.ListByCond(model.NewCond().Eq("relate_type", relateType).In("relate_id", collx.MapKeys(relateIds2Relate)), &relateTags)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tagIds := collx.ArrayMap(relateTags, func(rt *entity.TagTreeRelate) uint64 {
 | 
						tagIds := collx.ArrayMap(relateTags, func(rt *entity.TagTreeRelate) uint64 {
 | 
				
			||||||
		return rt.TagId
 | 
							return rt.TagId
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	var tags []*entity.TagTree
 | 
						tags, _ := tr.tagTreeApp.GetByIds(tagIds)
 | 
				
			||||||
	tr.tagTreeApp.GetByIds(&tags, tagIds)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tagId2Tag := collx.ArrayToMap(tags, func(t *entity.TagTree) uint64 {
 | 
						tagId2Tag := collx.ArrayToMap(tags, func(t *entity.TagTree) uint64 {
 | 
				
			||||||
		return t.Id
 | 
							return t.Id
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	for _, rt := range relateTags {
 | 
						for _, rt := range relateTags {
 | 
				
			||||||
		// 赋值标签信息
 | 
							relate := relateIds2Relate[rt.RelateId]
 | 
				
			||||||
		tag := tagId2Tag[rt.TagId]
 | 
							tag := tagId2Tag[rt.TagId]
 | 
				
			||||||
		relateIds2Relate[rt.RelateId].SetTagInfo(entity.ResourceTag{CodePath: tag.CodePath, TagId: tag.Id})
 | 
							if relate != nil && tag != nil {
 | 
				
			||||||
 | 
								// 赋值标签信息
 | 
				
			||||||
 | 
								relate.SetTagInfo(entity.ResourceTag{CodePath: tag.CodePath, TagId: tag.Id})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ type TagTreeQuery struct {
 | 
				
			|||||||
	model.Model
 | 
						model.Model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Type          TagType `json:"type"`
 | 
						Type          TagType `json:"type"`
 | 
				
			||||||
 | 
						Types         []TagType
 | 
				
			||||||
	Codes         []string
 | 
						Codes         []string
 | 
				
			||||||
	CodePaths     []string // 标识路径
 | 
						CodePaths     []string // 标识路径
 | 
				
			||||||
	Name          string   `json:"name"` // 名称
 | 
						Name          string   `json:"name"` // 名称
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,10 @@ func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEn
 | 
				
			|||||||
		sql = sql + " AND p.type = ?"
 | 
							sql = sql + " AND p.type = ?"
 | 
				
			||||||
		params = append(params, condition.Type)
 | 
							params = append(params, condition.Type)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if len(condition.Types) > 0 {
 | 
				
			||||||
 | 
							sql = sql + " AND p.type = IN (?)"
 | 
				
			||||||
 | 
							params = append(params, condition.Types)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if len(condition.CodePathLikes) > 0 {
 | 
						if len(condition.CodePathLikes) > 0 {
 | 
				
			||||||
		sql = sql + " AND ("
 | 
							sql = sql + " AND ("
 | 
				
			||||||
		for i, v := range condition.CodePathLikes {
 | 
							for i, v := range condition.CodePathLikes {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,5 +19,5 @@ func (p *teamRepoImpl) GetPageList(condition *entity.TeamQuery, pageParam *model
 | 
				
			|||||||
	qd := model.NewCond().
 | 
						qd := model.NewCond().
 | 
				
			||||||
		Like("name", condition.Name).
 | 
							Like("name", condition.Name).
 | 
				
			||||||
		OrderBy(orderBy...)
 | 
							OrderBy(orderBy...)
 | 
				
			||||||
	return p.PageByCond(qd, pageParam, toEntity)
 | 
						return p.PageByCondToAny(qd, pageParam, toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ func newTeamMemberRepo() repository.TeamMember {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
 | 
					func (p *teamMemberRepoImpl) ListMemeber(condition *entity.TeamMember, toEntity any, orderBy ...string) {
 | 
				
			||||||
	p.SelectByCond(model.NewModelCond(condition).OrderBy(orderBy...), toEntity)
 | 
						p.SelectByCondToAny(model.NewModelCond(condition).OrderBy(orderBy...), toEntity)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) (*model.PageResult[any], error) {
 | 
					func (p *teamMemberRepoImpl) GetPageList(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) (*model.PageResult[any], error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,27 +31,40 @@ type App[T model.ModelI] interface {
 | 
				
			|||||||
	DeleteById(ctx context.Context, id ...uint64) error
 | 
						DeleteById(ctx context.Context, id ...uint64) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// DeleteByCond 根据条件进行删除
 | 
						// DeleteByCond 根据条件进行删除
 | 
				
			||||||
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
	DeleteByCond(ctx context.Context, cond any) error
 | 
						DeleteByCond(ctx context.Context, cond any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Save 保存实体,实体IsCreate返回true则新增,否则更新
 | 
						// Save 保存实体,实体IsCreate返回true则新增,否则更新
 | 
				
			||||||
	Save(ctx context.Context, e T) error
 | 
						Save(ctx context.Context, e T) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GetById 根据实体id查询
 | 
						// GetById 根据实体id查询
 | 
				
			||||||
	GetById(e T, id uint64, cols ...string) (T, error)
 | 
						GetById(id uint64, cols ...string) (T, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GetByIds 根据实体id数组查询
 | 
						// GetByIds 根据实体id数组查询
 | 
				
			||||||
	GetByIds(list any, ids []uint64, orderBy ...string) error
 | 
						GetByIds(ids []uint64, cols ...string) ([]T, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GetByCond 根据实体条件查询实体信息(获取单个实体)
 | 
						// GetByCond 根据实体条件查询实体信息(获取单个实体)
 | 
				
			||||||
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
	GetByCond(cond any) error
 | 
						GetByCond(cond any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ListByCond 根据条件查询数据映射至res
 | 
						// ListByCondToAny 根据条件查询数据映射至res
 | 
				
			||||||
	ListByCond(cond any, res any) error
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
 | 
						ListByCondToAny(cond any, res any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// PageByCond 分页查询
 | 
						// ListByCond 根据条件查询
 | 
				
			||||||
	PageByCond(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error)
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
 | 
						ListByCond(cond any, cols ...string) ([]T, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// PageByCondToAny 分页查询并绑定至指定toModels
 | 
				
			||||||
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
 | 
						PageByCondToAny(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// PageByCond 根据指定条件分页查询
 | 
				
			||||||
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
 | 
						PageByCond(cond any, pageParam *model.PageParam, cols ...string) (*model.PageResult[[]T], error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// CountByCond 根据指定条件统计model表的数量
 | 
						// CountByCond 根据指定条件统计model表的数量
 | 
				
			||||||
 | 
						// @param cond 可为*model.QueryCond也可以为普通查询model
 | 
				
			||||||
	CountByCond(cond any) int64
 | 
						CountByCond(cond any) int64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Tx 执行事务操作
 | 
						// Tx 执行事务操作
 | 
				
			||||||
@@ -112,15 +125,12 @@ func (ai *AppImpl[T, R]) DeleteByCond(ctx context.Context, cond any) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据实体id查询
 | 
					// 根据实体id查询
 | 
				
			||||||
func (ai *AppImpl[T, R]) GetById(e T, id uint64, cols ...string) (T, error) {
 | 
					func (ai *AppImpl[T, R]) GetById(id uint64, cols ...string) (T, error) {
 | 
				
			||||||
	if err := ai.GetRepo().GetById(e, id, cols...); err != nil {
 | 
						return ai.GetRepo().GetById(id, cols...)
 | 
				
			||||||
		return e, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return e, nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ai *AppImpl[T, R]) GetByIds(list any, ids []uint64, orderBy ...string) error {
 | 
					func (ai *AppImpl[T, R]) GetByIds(ids []uint64, cols ...string) ([]T, error) {
 | 
				
			||||||
	return ai.GetRepo().GetByIds(list, ids, orderBy...)
 | 
						return ai.GetRepo().GetByIds(ids, cols...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据实体条件查询实体信息
 | 
					// 根据实体条件查询实体信息
 | 
				
			||||||
@@ -128,13 +138,21 @@ func (ai *AppImpl[T, R]) GetByCond(cond any) error {
 | 
				
			|||||||
	return ai.GetRepo().GetByCond(cond)
 | 
						return ai.GetRepo().GetByCond(cond)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ai *AppImpl[T, R]) ListByCond(cond any, res any) error {
 | 
					func (ai *AppImpl[T, R]) ListByCondToAny(cond any, res any) error {
 | 
				
			||||||
	return ai.GetRepo().SelectByCond(cond, res)
 | 
						return ai.GetRepo().SelectByCondToAny(cond, res)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PageByCond 分页查询
 | 
					func (ai *AppImpl[T, R]) ListByCond(cond any, cols ...string) ([]T, error) {
 | 
				
			||||||
func (ai *AppImpl[T, R]) PageByCond(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error) {
 | 
						return ai.GetRepo().SelectByCond(cond, cols...)
 | 
				
			||||||
	return ai.GetRepo().PageByCond(cond, pageParam, toModels)
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PageByCondToAny 分页查询
 | 
				
			||||||
 | 
					func (ai *AppImpl[T, R]) PageByCondToAny(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error) {
 | 
				
			||||||
 | 
						return ai.GetRepo().PageByCondToAny(cond, pageParam, toModels)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ai *AppImpl[T, R]) PageByCond(cond any, pageParam *model.PageParam, cols ...string) (*model.PageResult[[]T], error) {
 | 
				
			||||||
 | 
						return ai.GetRepo().PageByCond(cond, pageParam, cols...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 根据指定条件统计model表的数量, cond为条件可以为map等
 | 
					// 根据指定条件统计model表的数量, cond为条件可以为map等
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"mayfly-go/pkg/gormx"
 | 
						"mayfly-go/pkg/gormx"
 | 
				
			||||||
	"mayfly-go/pkg/model"
 | 
						"mayfly-go/pkg/model"
 | 
				
			||||||
	"mayfly-go/pkg/utils/collx"
 | 
						"mayfly-go/pkg/utils/collx"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
@@ -14,9 +15,6 @@ import (
 | 
				
			|||||||
// 基础repo接口
 | 
					// 基础repo接口
 | 
				
			||||||
type Repo[T model.ModelI] interface {
 | 
					type Repo[T model.ModelI] interface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GetModel 获取表的模型实例
 | 
					 | 
				
			||||||
	GetModel() T
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 新增一个实体
 | 
						// 新增一个实体
 | 
				
			||||||
	Insert(ctx context.Context, e T) error
 | 
						Insert(ctx context.Context, e T) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,19 +65,25 @@ type Repo[T model.ModelI] interface {
 | 
				
			|||||||
	ExecBySql(sql string, params ...any) error
 | 
						ExecBySql(sql string, params ...any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据实体id查询
 | 
						// 根据实体id查询
 | 
				
			||||||
	GetById(e T, id uint64, cols ...string) error
 | 
						GetById(id uint64, cols ...string) (T, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 根据实体id数组查询对应实体列表,并将响应结果映射至list
 | 
						GetByIds(ids []uint64, cols ...string) ([]T, error)
 | 
				
			||||||
	GetByIds(list any, ids []uint64, orderBy ...string) error
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// GetByCond 根据实体条件查询实体信息(单个结果集)
 | 
						// GetByCond 根据实体条件查询实体信息(单个结果集)
 | 
				
			||||||
 | 
						// @param cond 支持普通结构体或*model.QueryCond。如果cond为model.QueryCond,则需要使用Dest方法绑定值的指针
 | 
				
			||||||
	GetByCond(cond any) error
 | 
						GetByCond(cond any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// SelectByCond 根据实体条件查询数据映射至res
 | 
						// SelectByCondToAny 根据条件查询数据映射至res
 | 
				
			||||||
	SelectByCond(cond any, res any) error
 | 
						SelectByCondToAny(cond any, res any) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// SelectByCond 根据条件查询模型实例数组
 | 
				
			||||||
 | 
						SelectByCond(cond any, cols ...string) ([]T, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// PageByCondToAny 根据查询条件分页查询,并绑定至指定res
 | 
				
			||||||
 | 
						PageByCondToAny(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// PageByCond 根据查询条件分页查询
 | 
						// PageByCond 根据查询条件分页查询
 | 
				
			||||||
	PageByCond(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error)
 | 
						PageByCond(cond any, pageParam *model.PageParam, cols ...string) (*model.PageResult[[]T], error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// SelectBySql 根据sql语句查询数据
 | 
						// SelectBySql 根据sql语句查询数据
 | 
				
			||||||
	SelectBySql(sql string, res any, params ...any) error
 | 
						SelectBySql(sql string, res any, params ...any) error
 | 
				
			||||||
@@ -91,6 +95,8 @@ type Repo[T model.ModelI] interface {
 | 
				
			|||||||
// 基础repo接口
 | 
					// 基础repo接口
 | 
				
			||||||
type RepoImpl[T model.ModelI] struct {
 | 
					type RepoImpl[T model.ModelI] struct {
 | 
				
			||||||
	M T // 模型实例
 | 
						M T // 模型实例
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						modelType reflect.Type // 模型类型
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) Insert(ctx context.Context, e T) error {
 | 
					func (br *RepoImpl[T]) Insert(ctx context.Context, e T) error {
 | 
				
			||||||
@@ -164,9 +170,9 @@ func (br *RepoImpl[T]) UpdateByCondWithDb(ctx context.Context, db *gorm.DB, valu
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if db == nil {
 | 
						if db == nil {
 | 
				
			||||||
		return gormx.UpdateByCond(br.GetModel(), values, toQueryCond(cond))
 | 
							return gormx.UpdateByCond(br.getModel(), values, toQueryCond(cond))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.UpdateByCondWithDb(db, br.GetModel(), values, toQueryCond(cond))
 | 
						return gormx.UpdateByCondWithDb(db, br.getModel(), values, toQueryCond(cond))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) Save(ctx context.Context, e T) error {
 | 
					func (br *RepoImpl[T]) Save(ctx context.Context, e T) error {
 | 
				
			||||||
@@ -187,49 +193,65 @@ func (br *RepoImpl[T]) DeleteById(ctx context.Context, id ...uint64) error {
 | 
				
			|||||||
	if db := contextx.GetDb(ctx); db != nil {
 | 
						if db := contextx.GetDb(ctx); db != nil {
 | 
				
			||||||
		return br.DeleteByIdWithDb(ctx, db, id...)
 | 
							return br.DeleteByIdWithDb(ctx, db, id...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.DeleteById(br.GetModel(), id...)
 | 
						return gormx.DeleteById(br.getModel(), id...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) DeleteByIdWithDb(ctx context.Context, db *gorm.DB, id ...uint64) error {
 | 
					func (br *RepoImpl[T]) DeleteByIdWithDb(ctx context.Context, db *gorm.DB, id ...uint64) error {
 | 
				
			||||||
	return gormx.DeleteByIdWithDb(db, br.GetModel(), id...)
 | 
						return gormx.DeleteByIdWithDb(db, br.getModel(), id...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) DeleteByCond(ctx context.Context, cond any) error {
 | 
					func (br *RepoImpl[T]) DeleteByCond(ctx context.Context, cond any) error {
 | 
				
			||||||
	if db := contextx.GetDb(ctx); db != nil {
 | 
						if db := contextx.GetDb(ctx); db != nil {
 | 
				
			||||||
		return br.DeleteByCondWithDb(ctx, db, cond)
 | 
							return br.DeleteByCondWithDb(ctx, db, cond)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return gormx.DeleteByCond(br.GetModel(), toQueryCond(cond))
 | 
						return gormx.DeleteByCond(br.getModel(), toQueryCond(cond))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) DeleteByCondWithDb(ctx context.Context, db *gorm.DB, cond any) error {
 | 
					func (br *RepoImpl[T]) DeleteByCondWithDb(ctx context.Context, db *gorm.DB, cond any) error {
 | 
				
			||||||
	return gormx.DeleteByCondWithDb(db, br.GetModel(), toQueryCond(cond))
 | 
						return gormx.DeleteByCondWithDb(db, br.getModel(), toQueryCond(cond))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) ExecBySql(sql string, params ...any) error {
 | 
					func (br *RepoImpl[T]) ExecBySql(sql string, params ...any) error {
 | 
				
			||||||
	return gormx.ExecSql(sql, params...)
 | 
						return gormx.ExecSql(sql, params...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) GetById(e T, id uint64, cols ...string) error {
 | 
					func (br *RepoImpl[T]) GetById(id uint64, cols ...string) (T, error) {
 | 
				
			||||||
	if err := gormx.GetById(e, id, cols...); err != nil {
 | 
						e := br.NewModel()
 | 
				
			||||||
		return err
 | 
						return e, gormx.GetById(e, id, cols...)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) GetByIds(list any, ids []uint64, orderBy ...string) error {
 | 
					func (br *RepoImpl[T]) GetByIds(ids []uint64, cols ...string) ([]T, error) {
 | 
				
			||||||
	return br.SelectByCond(model.NewCond().In(model.IdColumn, ids).OrderBy(orderBy...), list)
 | 
						var models []T
 | 
				
			||||||
 | 
						return models, br.SelectByCondToAny(model.NewCond().In(model.IdColumn, ids).Columns(cols...), &models)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) GetByCond(cond any) error {
 | 
					func (br *RepoImpl[T]) GetByCond(cond any) error {
 | 
				
			||||||
	return gormx.GetByCond(br.GetModel(), toQueryCond(cond))
 | 
						return gormx.GetByCond(br.getModel(), toQueryCond(cond))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) SelectByCond(cond any, res any) error {
 | 
					func (br *RepoImpl[T]) SelectByCondToAny(cond any, res any) error {
 | 
				
			||||||
	return gormx.SelectByCond(br.GetModel(), toQueryCond(cond).Dest(res))
 | 
						return gormx.SelectByCond(br.getModel(), toQueryCond(cond).Dest(res))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) PageByCond(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error) {
 | 
					func (br *RepoImpl[T]) SelectByCond(cond any, cols ...string) ([]T, error) {
 | 
				
			||||||
	return gormx.PageByCond(br.GetModel(), toQueryCond(cond), pageParam, toModels)
 | 
						var models []T
 | 
				
			||||||
 | 
						return models, br.SelectByCondToAny(toQueryCond(cond).Dest(models).Columns(cols...), &models)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (br *RepoImpl[T]) PageByCondToAny(cond any, pageParam *model.PageParam, toModels any) (*model.PageResult[any], error) {
 | 
				
			||||||
 | 
						return gormx.PageByCond(br.getModel(), toQueryCond(cond), pageParam, toModels)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (br *RepoImpl[T]) PageByCond(cond any, pageParam *model.PageParam, cols ...string) (*model.PageResult[[]T], error) {
 | 
				
			||||||
 | 
						var models []T
 | 
				
			||||||
 | 
						res, err := br.PageByCondToAny(toQueryCond(cond).Columns(cols...), pageParam, &models)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &model.PageResult[[]T]{
 | 
				
			||||||
 | 
							List:  models,
 | 
				
			||||||
 | 
							Total: res.Total,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) SelectBySql(sql string, res any, params ...any) error {
 | 
					func (br *RepoImpl[T]) SelectBySql(sql string, res any, params ...any) error {
 | 
				
			||||||
@@ -237,14 +259,47 @@ func (br *RepoImpl[T]) SelectBySql(sql string, res any, params ...any) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (br *RepoImpl[T]) CountByCond(cond any) int64 {
 | 
					func (br *RepoImpl[T]) CountByCond(cond any) int64 {
 | 
				
			||||||
	return gormx.CountByCond(br.GetModel(), toQueryCond(cond))
 | 
						return gormx.CountByCond(br.getModel(), toQueryCond(cond))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GetModel 获取表的模型实例
 | 
					// NewModel 新建模型实例
 | 
				
			||||||
func (br *RepoImpl[T]) GetModel() T {
 | 
					func (br *RepoImpl[T]) NewModel() T {
 | 
				
			||||||
 | 
						newModel := reflect.New(br.getModelType()).Interface()
 | 
				
			||||||
 | 
						return newModel.(T)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// func (br *RepoImpl[T]) NewModes() *[]T {
 | 
				
			||||||
 | 
					// 	// 创建一个空的切片
 | 
				
			||||||
 | 
					// 	slice := reflect.MakeSlice(reflect.SliceOf(reflect.PointerTo(br.getModelType())), 0, 0)
 | 
				
			||||||
 | 
					// 	// 创建指向切片的指针
 | 
				
			||||||
 | 
					// 	ptrToSlice := reflect.New(slice.Type())
 | 
				
			||||||
 | 
					// 	// 设置指向切片的指针为创建的空切片
 | 
				
			||||||
 | 
					// 	ptrToSlice.Elem().Set(slice)
 | 
				
			||||||
 | 
					// 	// 转换指向切片的指针
 | 
				
			||||||
 | 
					// 	return ptrToSlice.Interface().(*[]T)
 | 
				
			||||||
 | 
					// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getModel 获取表的模型实例
 | 
				
			||||||
 | 
					func (br *RepoImpl[T]) getModel() T {
 | 
				
			||||||
	return br.M
 | 
						return br.M
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getModelType 获取模型类型(非指针模型)
 | 
				
			||||||
 | 
					func (br *RepoImpl[T]) getModelType() reflect.Type {
 | 
				
			||||||
 | 
						if br.modelType != nil {
 | 
				
			||||||
 | 
							return br.modelType
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						modelType := reflect.TypeOf(br.M)
 | 
				
			||||||
 | 
						// 检查 model 是否为指针类型
 | 
				
			||||||
 | 
						if modelType.Kind() == reflect.Ptr {
 | 
				
			||||||
 | 
							// 获取指针指向的类型
 | 
				
			||||||
 | 
							modelType = modelType.Elem()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						br.modelType = modelType
 | 
				
			||||||
 | 
						return modelType
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 从上下文获取登录账号信息,并赋值至实体
 | 
					// 从上下文获取登录账号信息,并赋值至实体
 | 
				
			||||||
func (br *RepoImpl[T]) fillBaseInfo(ctx context.Context, e T) T {
 | 
					func (br *RepoImpl[T]) fillBaseInfo(ctx context.Context, e T) T {
 | 
				
			||||||
	// 默认使用数据库id策略, 若要改变则实体结构体自行覆盖FillBaseInfo方法。可参考 sys/entity.Resource
 | 
						// 默认使用数据库id策略, 若要改变则实体结构体自行覆盖FillBaseInfo方法。可参考 sys/entity.Resource
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user