mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-15 20:26:36 +08:00
refactor: 代码重构、分页数据组件支持多选
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/redis/domain/entity"
|
||||
"mayfly-go/internal/redis/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type redisRepoImpl struct{}
|
||||
@@ -17,22 +15,13 @@ func newRedisRepo() repository.Redis {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
|
||||
values := make([]any, 0)
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE ?"
|
||||
values = append(values, "%"+condition.Host+"%")
|
||||
}
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = sql + " AND d.tag_id IN " + fmt.Sprintf("(%s)", strings.Join(utils.NumberArr2StrArr(condition.TagIds), ","))
|
||||
}
|
||||
if condition.TagPathLike != "" {
|
||||
sql = sql + " AND d.tag_path LIKE ?"
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY d.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
qd := gormx.NewQuery(new(entity.Redis)).
|
||||
Like("host", condition.Host).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
||||
@@ -44,30 +33,30 @@ func (r *redisRepoImpl) Count(condition *entity.RedisQuery) int64 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
|
||||
return model.CountByMap(new(entity.Redis), where)
|
||||
return gormx.CountByCond(new(entity.Redis), where)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
||||
rd := new(entity.Redis)
|
||||
if err := model.GetById(rd, id, cols...); err != nil {
|
||||
if err := gormx.GetById(rd, id, cols...); err != nil {
|
||||
return nil
|
||||
}
|
||||
return rd
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Insert(redis *entity.Redis) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(redis), "新增失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(redis), "新增失败: %s")
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Update(redis *entity.Redis) {
|
||||
biz.ErrIsNilAppendErr(model.UpdateById(redis), "更新失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.UpdateById(redis), "更新失败: %s")
|
||||
}
|
||||
|
||||
func (r *redisRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNilAppendErr(model.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user