mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
[优化]
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"pandax/pkg/shadow"
|
||||
@@ -208,7 +209,39 @@ func (p *DeviceApi) UpdateDevice(rc *restfulx.ReqCtx) {
|
||||
func (p *DeviceApi) DeleteDevice(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParam(rc, "id")
|
||||
ids := strings.Split(id, ",")
|
||||
biz.ErrIsNil(p.DeviceApp.Delete(ids), "删除失败")
|
||||
|
||||
for _, id := range ids {
|
||||
device, err := p.DeviceApp.FindOne(id)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
err = p.DeviceApp.Delete([]string{id})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// 删除表
|
||||
err = deleteDeviceTable(device.Name)
|
||||
// 删除所有缓存
|
||||
if device.DeviceType == global.GATEWAYS {
|
||||
// 因为网关子设备没有Token,使用Name做的存储
|
||||
cache.DelDeviceEtoken(device.Name)
|
||||
} else {
|
||||
cache.DelDeviceEtoken(device.Token)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除Tdengine时序数据
|
||||
func deleteDeviceTable(device string) error {
|
||||
err := global.TdDb.DropTable(device + "_" + entity.ATTRIBUTES_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = global.TdDb.DropTable(device + "_" + entity.TELEMETRY_TSL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DeviceApi) ScreenTwinData(rc *restfulx.ReqCtx) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"strings"
|
||||
@@ -147,10 +148,27 @@ func (p *ProductApi) DeleteProduct(rc *restfulx.ReqCtx) {
|
||||
}
|
||||
// 删除产品
|
||||
err := p.ProductApp.Delete(ids)
|
||||
biz.ErrIsNil(err, "删除失败")
|
||||
biz.ErrIsNil(err, "产品删除失败")
|
||||
// 删除所有模型,固件
|
||||
for _, id := range ids {
|
||||
// 删除所有模型,固件
|
||||
// 删除超级表
|
||||
deleteDeviceStable(id)
|
||||
// 删除所有缓存
|
||||
cache.DelProductRule(id)
|
||||
// 删除绑定的属性及OTA记录
|
||||
p.TemplateApp.Delete([]string{id})
|
||||
p.OtaAPP.Delete([]string{id})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user