feat(设备管理): 添加设备在线记录查询功能并优化设备列表排序
Build docker and publish / build (20.15.1) (push) Successful in 7m28s
Build docker and publish / build (20.15.1) (push) Successful in 7m28s
添加FindLatestDeviceOnlineRecord接口用于查询设备最新在线记录 实现GetOnlineDeviceLoginTime方法获取设备登录时间 优化设备列表查询按最后活动时间排序 移除未使用的依赖项
This commit is contained in:
@@ -40,7 +40,7 @@ func (m *customUserModel) QueryDevicePageList(ctx context.Context, userId, subsc
|
||||
var list []*Device
|
||||
var total int64
|
||||
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Device{}).Where("`user_id` = ? and `subscribe_id` = ?", userId, subscribeId).Count(&total).Limit(size).Offset((page - 1) * size).Find(&list).Error
|
||||
return conn.Model(&Device{}).Where("`user_id` = ? and `subscribe_id` = ?", userId, subscribeId).Count(&total).Order("created_at DESC").Limit(size).Offset((page - 1) * size).Find(&list).Error
|
||||
})
|
||||
return list, total, err
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (m *customUserModel) QueryDeviceList(ctx context.Context, userId int64) ([]
|
||||
var list []*Device
|
||||
var total int64
|
||||
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Device{}).Where("`user_id` = ?", userId).Count(&total).Find(&list).Error
|
||||
return conn.Model(&Device{}).Where("`user_id` = ?", userId).Count(&total).Order("created_at DESC").Find(&list).Error
|
||||
})
|
||||
return list, total, err
|
||||
}
|
||||
@@ -100,3 +100,14 @@ func (m *customUserModel) InsertDevice(ctx context.Context, data *Device, tx ...
|
||||
return conn.Create(data).Error
|
||||
})
|
||||
}
|
||||
|
||||
func (m *customUserModel) FindLatestDeviceOnlineRecord(ctx context.Context, userId int64, identifier string) (*DeviceOnlineRecord, error) {
|
||||
var rec DeviceOnlineRecord
|
||||
err := m.QueryNoCacheCtx(ctx, &rec, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&DeviceOnlineRecord{}).Where("user_id = ? AND identifier = ?", userId, identifier).Order("online_time DESC").First(&rec).Error
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &rec, nil
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ type customUserLogicModel interface {
|
||||
DeleteDevice(ctx context.Context, id int64, tx ...*gorm.DB) error
|
||||
InsertDevice(ctx context.Context, data *Device, tx ...*gorm.DB) error
|
||||
|
||||
FindLatestDeviceOnlineRecord(ctx context.Context, userId int64, identifier string) (*DeviceOnlineRecord, error)
|
||||
|
||||
ClearSubscribeCache(ctx context.Context, data ...*Subscribe) error
|
||||
ClearUserCache(ctx context.Context, data ...*User) error
|
||||
BatchClearRelatedCache(ctx context.Context, user *User) error
|
||||
|
||||
Reference in New Issue
Block a user