mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【feat】 添加postgresql数据库支持,【修复】pg数据库的代码生成功能
This commit is contained in:
@@ -237,6 +237,9 @@ func GetDeviceToken(data *entity.Device) *model.DeviceAuth {
|
||||
// 获取设备数量统计
|
||||
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`
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
sql = `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM devices WHERE DATE(create_time) = current_date) AS today FROM devices`
|
||||
}
|
||||
err := global.Db.Raw(sql).Scan(&result).Error
|
||||
biz.ErrIsNil(err, "获取设备统计总数失败")
|
||||
return result
|
||||
|
||||
@@ -101,12 +101,18 @@ func (m *alarmModelImpl) Delete(id []string) {
|
||||
// 获取告警数量统计
|
||||
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`
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
sql = `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM device_alarms WHERE DATE(time) = current_date) AS today FROM device_alarms`
|
||||
}
|
||||
err := global.Db.Raw(sql).Scan(&count).Error
|
||||
biz.ErrIsNil(err, "获取告警统计总数失败")
|
||||
return
|
||||
}
|
||||
func (m *alarmModelImpl) FindAlarmPanel() (count []entity.DeviceAlarmCount) {
|
||||
sql := `SELECT CAST(time AS DATE) AS date, COUNT(*) AS count FROM device_alarms WHERE time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY CAST(time AS DATE)`
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
sql = `SELECT CAST(time AS DATE) AS date, COUNT(*) AS count FROM device_alarms WHERE time >= CURRENT_DATE - INTERVAL '30 day' GROUP BY CAST(time AS DATE);`
|
||||
}
|
||||
err := global.Db.Raw(sql).Scan(&count).Error
|
||||
biz.ErrIsNil(err, "获取告警统计列表失败")
|
||||
return
|
||||
|
||||
@@ -151,6 +151,9 @@ func deleteDeviceStable(productId string) error {
|
||||
// 获取产品数量统计
|
||||
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`
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
sql = `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM products WHERE DATE(create_time) = current_date) AS today FROM products`
|
||||
}
|
||||
err := global.Db.Raw(sql).Scan(&count).Error
|
||||
biz.ErrIsNil(err, "获取产品统计总数失败")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user