mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: 机器列表新增运行状态 & refactor: 登录账号信息存储与context
This commit is contained in:
		@@ -31,7 +31,7 @@ func (r *Redis) RedisList(rc *req.Ctx) {
 | 
			
		||||
	queryCond, page := ginx.BindQueryAndPage[*entity.RedisQuery](rc.GinCtx, new(entity.RedisQuery))
 | 
			
		||||
 | 
			
		||||
	// 不存在可访问标签id,即没有可操作数据
 | 
			
		||||
	tagIds := r.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
 | 
			
		||||
	tagIds := r.TagApp.ListTagIdByAccountId(rc.GetLoginAccount().Id)
 | 
			
		||||
	if len(tagIds) == 0 {
 | 
			
		||||
		rc.ResData = model.EmptyPageResult[any]()
 | 
			
		||||
		return
 | 
			
		||||
@@ -44,7 +44,7 @@ func (r *Redis) RedisList(rc *req.Ctx) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) RedisTags(rc *req.Ctx) {
 | 
			
		||||
	rc.ResData = r.TagApp.ListTagByAccountIdAndResource(rc.LoginAccount.Id, new(entity.Redis))
 | 
			
		||||
	rc.ResData = r.TagApp.ListTagByAccountIdAndResource(rc.GetLoginAccount().Id, new(entity.Redis))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) Save(rc *req.Ctx) {
 | 
			
		||||
@@ -60,8 +60,7 @@ func (r *Redis) Save(rc *req.Ctx) {
 | 
			
		||||
	form.Password = "****"
 | 
			
		||||
	rc.ReqParam = form
 | 
			
		||||
 | 
			
		||||
	redis.SetBaseInfo(rc.LoginAccount)
 | 
			
		||||
	biz.ErrIsNil(r.RedisApp.Save(redis))
 | 
			
		||||
	biz.ErrIsNil(r.RedisApp.Save(rc.MetaCtx, redis))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取redis实例密码,由于数据库是加密存储,故提供该接口展示原文密码
 | 
			
		||||
@@ -81,7 +80,7 @@ func (r *Redis) DeleteRedis(rc *req.Ctx) {
 | 
			
		||||
	for _, v := range ids {
 | 
			
		||||
		value, err := strconv.Atoi(v)
 | 
			
		||||
		biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
 | 
			
		||||
		r.RedisApp.Delete(uint64(value))
 | 
			
		||||
		r.RedisApp.Delete(rc.MetaCtx, uint64(value))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -218,7 +217,7 @@ func (r *Redis) checkKeyAndGetRedisConn(rc *req.Ctx) (*rdm.RedisConn, string) {
 | 
			
		||||
func (r *Redis) getRedisConn(rc *req.Ctx) *rdm.RedisConn {
 | 
			
		||||
	ri, err := r.RedisApp.GetRedisConn(getIdAndDbNum(rc.GinCtx))
 | 
			
		||||
	biz.ErrIsNil(err)
 | 
			
		||||
	biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.Info.TagPath), "%s")
 | 
			
		||||
	biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.GetLoginAccount().Id, ri.Info.TagPath), "%s")
 | 
			
		||||
	return ri
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"mayfly-go/internal/redis/domain/entity"
 | 
			
		||||
	"mayfly-go/internal/redis/domain/repository"
 | 
			
		||||
	"mayfly-go/internal/redis/rdm"
 | 
			
		||||
@@ -19,10 +20,10 @@ type Redis interface {
 | 
			
		||||
 | 
			
		||||
	Count(condition *entity.RedisQuery) int64
 | 
			
		||||
 | 
			
		||||
	Save(re *entity.Redis) error
 | 
			
		||||
	Save(ctx context.Context, re *entity.Redis) error
 | 
			
		||||
 | 
			
		||||
	// 删除数据库信息
 | 
			
		||||
	Delete(id uint64) error
 | 
			
		||||
	Delete(ctx context.Context, id uint64) error
 | 
			
		||||
 | 
			
		||||
	// 获取数据库连接实例
 | 
			
		||||
	// id: 数据库实例id
 | 
			
		||||
@@ -52,7 +53,7 @@ func (r *redisAppImpl) Count(condition *entity.RedisQuery) int64 {
 | 
			
		||||
	return r.GetRepo().Count(condition)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *redisAppImpl) Save(re *entity.Redis) error {
 | 
			
		||||
func (r *redisAppImpl) Save(ctx context.Context, re *entity.Redis) error {
 | 
			
		||||
	// ’修改信息且密码不为空‘ or ‘新增’需要测试是否可连接
 | 
			
		||||
	if (re.Id != 0 && re.Password != "") || re.Id == 0 {
 | 
			
		||||
		if err := r.TestConn(re); err != nil {
 | 
			
		||||
@@ -72,7 +73,7 @@ func (r *redisAppImpl) Save(re *entity.Redis) error {
 | 
			
		||||
			return errorx.NewBiz("该实例已存在")
 | 
			
		||||
		}
 | 
			
		||||
		re.PwdEncrypt()
 | 
			
		||||
		return r.Insert(re)
 | 
			
		||||
		return r.Insert(ctx, re)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 如果存在该库,则校验修改的库是否为该库
 | 
			
		||||
@@ -87,11 +88,11 @@ func (r *redisAppImpl) Save(re *entity.Redis) error {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	re.PwdEncrypt()
 | 
			
		||||
	return r.UpdateById(re)
 | 
			
		||||
	return r.UpdateById(ctx, re)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 删除Redis信息
 | 
			
		||||
func (r *redisAppImpl) Delete(id uint64) error {
 | 
			
		||||
func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
	re, err := r.GetById(new(entity.Redis), id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errorx.NewBiz("该redis信息不存在")
 | 
			
		||||
@@ -101,7 +102,7 @@ func (r *redisAppImpl) Delete(id uint64) error {
 | 
			
		||||
		db, _ := strconv.Atoi(dbStr)
 | 
			
		||||
		rdm.CloseConn(re.Id, db)
 | 
			
		||||
	}
 | 
			
		||||
	return r.DeleteById(id)
 | 
			
		||||
	return r.DeleteById(ctx, id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取数据库连接实例
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user