2021-07-28 18:03:19 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
2022-09-09 18:26:08 +08:00
|
|
|
"mayfly-go/internal/redis/domain/entity"
|
|
|
|
|
"mayfly-go/internal/redis/domain/repository"
|
2023-10-26 17:15:49 +08:00
|
|
|
"mayfly-go/pkg/base"
|
2023-07-01 14:34:42 +08:00
|
|
|
"mayfly-go/pkg/gormx"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/model"
|
2021-07-28 18:03:19 +08:00
|
|
|
)
|
|
|
|
|
|
2023-10-26 17:15:49 +08:00
|
|
|
type redisRepoImpl struct {
|
|
|
|
|
base.RepoImpl[*entity.Redis]
|
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func newRedisRepo() repository.Redis {
|
2023-10-26 17:15:49 +08:00
|
|
|
return &redisRepoImpl{base.RepoImpl[*entity.Redis]{M: new(entity.Redis)}}
|
2022-09-09 18:26:08 +08:00
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
// 分页获取机器信息列表
|
2023-10-26 17:15:49 +08:00
|
|
|
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
2023-07-01 14:34:42 +08:00
|
|
|
qd := gormx.NewQuery(new(entity.Redis)).
|
|
|
|
|
Like("host", condition.Host).
|
|
|
|
|
In("tag_id", condition.TagIds).
|
2023-07-08 20:05:55 +08:00
|
|
|
RLike("tag_path", condition.TagPath).
|
2023-07-01 14:34:42 +08:00
|
|
|
OrderByAsc("tag_path")
|
|
|
|
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 20:49:29 +08:00
|
|
|
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
2023-06-01 12:31:32 +08:00
|
|
|
where := make(map[string]any)
|
2022-10-26 20:49:29 +08:00
|
|
|
if len(condition.TagIds) > 0 {
|
|
|
|
|
where["tag_id"] = condition.TagIds
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.CountByCond(new(entity.Redis), where)
|
2021-09-11 14:04:09 +08:00
|
|
|
}
|