This commit is contained in:
tfl
2024-08-20 17:46:15 +08:00
parent 1467b349a2
commit 8b167d8c02
16 changed files with 182 additions and 160 deletions

View File

@@ -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`