【feat】首页面板数据

This commit is contained in:
XM-GO
2023-09-23 16:55:24 +08:00
parent 79314f6f7e
commit d3a7deb66f
10 changed files with 393 additions and 2 deletions

View File

@@ -19,6 +19,9 @@ type (
Update(data entity.Device) *entity.Device
UpdateStatus(id, linkStatus string)
Delete(ids []string)
FindDeviceCount() entity.DeviceCount
FindDeviceCountGroupByLinkStatus() []entity.DeviceCountLinkStatus
FindDeviceCountGroupByType() []entity.DeviceCountType
}
deviceModelImpl struct {
@@ -209,3 +212,26 @@ func GetDeviceToken(data *entity.Device) (*tool.DeviceAuth, error) {
err := etoken.CreateDeviceToken(data.Id)
return etoken, err
}
// 获取设备数量统计
func (m *deviceModelImpl) FindDeviceCount() (result entity.DeviceCount) {
sql := `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM devices WHERE DATE(create_time) = CURDATE()) AS today FROM devices`
err := global.Db.Raw(sql).Scan(&result).Error
biz.ErrIsNil(err, "获取设备统计总数失败")
return result
}
// 获取设备类型数量统计
func (m *deviceModelImpl) FindDeviceCountGroupByLinkStatus() (count []entity.DeviceCountLinkStatus) {
sql := `SELECT link_status, COUNT(*) AS total FROM devices GROUP BY link_status`
err := global.Db.Raw(sql, m.table).Scan(&count).Error
biz.ErrIsNil(err, "获取通过设备在线状态的设备统计总数失败")
return
}
func (m *deviceModelImpl) FindDeviceCountGroupByType() (count []entity.DeviceCountType) {
sql := `SELECT device_type, COUNT(*) AS total FROM devices GROUP BY device_type`
err := global.Db.Raw(sql, m.table).Scan(&count).Error
biz.ErrIsNil(err, "获取通过设备类型的设备统计总数失败")
return
}

View File

@@ -15,6 +15,7 @@ type (
FindListPage(page, pageSize int, data entity.DeviceAlarmForm) (*[]entity.DeviceAlarm, int64)
Update(data entity.DeviceAlarm) error
Delete(ids []string)
FindAlarmCount() entity.DeviceCount
}
alarmModelImpl struct {
@@ -93,3 +94,11 @@ func (m *alarmModelImpl) Update(data entity.DeviceAlarm) error {
func (m *alarmModelImpl) Delete(id []string) {
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.DeviceAlarm{}, "id in (?)", id).Error, "删除设备告警失败")
}
// 获取告警数量统计
func (m *alarmModelImpl) FindAlarmCount() (count entity.DeviceCount) {
sql := `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM device_alarms WHERE DATE(time) = CURDATE()) AS today FROM device_alarms`
err := global.Db.Raw(sql).Scan(&count).Error
biz.ErrIsNil(err, "获取告警统计总数失败")
return
}

View File

@@ -16,6 +16,7 @@ type (
FindList(data entity.Product) *[]entity.ProductRes
Update(data entity.Product) *entity.Product
Delete(ids []string)
FindProductCount() entity.DeviceCount
}
productModelImpl struct {
@@ -148,3 +149,11 @@ func deleteDeviceStable(productId string) error {
}
return nil
}
// 获取产品数量统计
func (m *productModelImpl) FindProductCount() (count entity.DeviceCount) {
sql := `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM products WHERE DATE(create_time) = CURDATE()) AS today FROM products`
err := global.Db.Raw(sql).Scan(&count).Error
biz.ErrIsNil(err, "获取产品统计总数失败")
return
}