2021-07-28 18:03:19 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
2021-12-11 11:19:47 +08:00
|
|
|
"fmt"
|
2022-09-09 18:26:08 +08:00
|
|
|
"mayfly-go/internal/redis/domain/entity"
|
|
|
|
|
"mayfly-go/internal/redis/domain/repository"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/biz"
|
|
|
|
|
"mayfly-go/pkg/model"
|
2022-10-26 20:49:29 +08:00
|
|
|
"mayfly-go/pkg/utils"
|
|
|
|
|
"strings"
|
2021-07-28 18:03:19 +08:00
|
|
|
)
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
type redisRepoImpl struct{}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func newRedisRepo() repository.Redis {
|
|
|
|
|
return new(redisRepoImpl)
|
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
// 分页获取机器信息列表
|
2022-10-26 20:49:29 +08:00
|
|
|
func (r *redisRepoImpl) GetRedisList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
|
|
|
|
sql := "SELECT d.* FROM t_redis d WHERE 1=1 "
|
|
|
|
|
|
2021-12-11 11:19:47 +08:00
|
|
|
if condition.Host != "" {
|
|
|
|
|
sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
|
|
|
|
|
}
|
2022-10-26 20:49:29 +08:00
|
|
|
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 '" + condition.TagPathLike + "%'"
|
|
|
|
|
}
|
2021-12-11 11:19:47 +08:00
|
|
|
sql = sql + " ORDER BY d.create_time DESC"
|
|
|
|
|
return model.GetPageBySql(sql, 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 {
|
|
|
|
|
where := make(map[string]interface{})
|
|
|
|
|
if len(condition.TagIds) > 0 {
|
|
|
|
|
where["tag_id"] = condition.TagIds
|
|
|
|
|
}
|
|
|
|
|
if condition.TagId != 0 {
|
|
|
|
|
where["tag_id"] = condition.TagId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model.CountByMap(new(entity.Redis), where)
|
2021-09-11 14:04:09 +08:00
|
|
|
}
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
// 根据id获取
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *redisRepoImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
2021-07-28 18:03:19 +08:00
|
|
|
rd := new(entity.Redis)
|
|
|
|
|
if err := model.GetById(rd, id, cols...); err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return rd
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *redisRepoImpl) GetRedis(condition *entity.Redis, cols ...string) error {
|
2021-07-28 18:03:19 +08:00
|
|
|
return model.GetBy(condition, cols...)
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *redisRepoImpl) Insert(redis *entity.Redis) {
|
2021-07-28 18:03:19 +08:00
|
|
|
biz.ErrIsNilAppendErr(model.Insert(redis), "新增失败: %s")
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *redisRepoImpl) Update(redis *entity.Redis) {
|
2021-07-28 18:03:19 +08:00
|
|
|
biz.ErrIsNilAppendErr(model.UpdateById(redis), "更新失败: %s")
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func (r *redisRepoImpl) Delete(id uint64) {
|
2021-07-28 18:03:19 +08:00
|
|
|
biz.ErrIsNilAppendErr(model.DeleteById(new(entity.Redis), id), "删除失败: %s")
|
|
|
|
|
}
|