mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
优化
This commit is contained in:
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
@@ -117,14 +118,26 @@ func (m *productModelImpl) Delete(ids []string) error {
|
||||
if err := global.Db.Table(m.table).Delete(&entity.Product{}, "id in (?)", ids).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除所有模型,固件
|
||||
for _, id := range ids {
|
||||
// 删除超级表
|
||||
deleteDeviceStable(id)
|
||||
// 删除所有缓存
|
||||
cache.DelProductRule(id)
|
||||
// 删除绑定的属性及OTA记录
|
||||
ProductTemplateModelDao.Delete([]string{id})
|
||||
ProductOtaModelDao.Delete([]string{id})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createDeviceStable(productId string) error {
|
||||
// 属性表
|
||||
err := global.TdDb.CreateStable(productId + "_" + entity.ATTRIBUTES_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 遥测表
|
||||
err = global.TdDb.CreateStable(productId + "_" + entity.TELEMETRY_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -132,6 +145,18 @@ func createDeviceStable(productId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteDeviceStable(productId string) error {
|
||||
err := global.TdDb.DropStable(productId + "_" + entity.ATTRIBUTES_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = global.TdDb.DropStable(productId + "_" + entity.TELEMETRY_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取产品数量统计
|
||||
func (m *productModelImpl) FindProductCount() (count entity.DeviceCount, err error) {
|
||||
sql := `SELECT COUNT(*) AS total, (SELECT COUNT(*) FROM products WHERE DATE(create_time) = CURDATE()) AS today FROM products`
|
||||
|
||||
Reference in New Issue
Block a user