mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-28 16:39:37 +08:00
[优化]
This commit is contained in:
@@ -88,8 +88,7 @@ sudo ./startup.sh
|
|||||||
- <span class="tag done-tag">✔</span> **`设备管理`** - _设备的管理,支持多协议接入,MQTT,TCP,UDP,COAP,Modbus,Opcua,S7,HL7等_
|
- <span class="tag done-tag">✔</span> **`设备管理`** - _设备的管理,支持多协议接入,MQTT,TCP,UDP,COAP,Modbus,Opcua,S7,HL7等_
|
||||||
|
|
||||||
## 🛠 以后可能会有什么NB功能?
|
## 🛠 以后可能会有什么NB功能?
|
||||||
- <span class="tag wip-tag">开发中</span> **`3D组态(2024-Q1-Q2)`** - _3D组态场景编辑器_
|
- <span class="tag wip-tag">开发中</span> **`3D组态(2024-Q1-Q3)`** - _3D组态场景编辑器_
|
||||||
- <span class="tag wip-tag">开发中</span> **`多时序数据库支持(2024-Q3)`** - _多时序数据库支持,规划除Tdengine外,适配Greptime,Timescaledb_
|
|
||||||
- <span class="tag wip-tag">开发中</span> **`报表设计器(2024-Q4)`** - _excel的低代码报表设计_
|
- <span class="tag wip-tag">开发中</span> **`报表设计器(2024-Q4)`** - _excel的低代码报表设计_
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"pandax/kit/biz"
|
"pandax/kit/biz"
|
||||||
"pandax/kit/model"
|
"pandax/kit/model"
|
||||||
"pandax/kit/restfulx"
|
"pandax/kit/restfulx"
|
||||||
|
"pandax/pkg/cache"
|
||||||
"pandax/pkg/global"
|
"pandax/pkg/global"
|
||||||
model2 "pandax/pkg/global/model"
|
model2 "pandax/pkg/global/model"
|
||||||
"pandax/pkg/shadow"
|
"pandax/pkg/shadow"
|
||||||
@@ -208,7 +209,39 @@ func (p *DeviceApi) UpdateDevice(rc *restfulx.ReqCtx) {
|
|||||||
func (p *DeviceApi) DeleteDevice(rc *restfulx.ReqCtx) {
|
func (p *DeviceApi) DeleteDevice(rc *restfulx.ReqCtx) {
|
||||||
id := restfulx.PathParam(rc, "id")
|
id := restfulx.PathParam(rc, "id")
|
||||||
ids := strings.Split(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) {
|
func (p *DeviceApi) ScreenTwinData(rc *restfulx.ReqCtx) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"pandax/kit/biz"
|
"pandax/kit/biz"
|
||||||
"pandax/kit/model"
|
"pandax/kit/model"
|
||||||
"pandax/kit/restfulx"
|
"pandax/kit/restfulx"
|
||||||
|
"pandax/pkg/cache"
|
||||||
"pandax/pkg/global"
|
"pandax/pkg/global"
|
||||||
model2 "pandax/pkg/global/model"
|
model2 "pandax/pkg/global/model"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -147,10 +148,27 @@ func (p *ProductApi) DeleteProduct(rc *restfulx.ReqCtx) {
|
|||||||
}
|
}
|
||||||
// 删除产品
|
// 删除产品
|
||||||
err := p.ProductApp.Delete(ids)
|
err := p.ProductApp.Delete(ids)
|
||||||
biz.ErrIsNil(err, "删除失败")
|
biz.ErrIsNil(err, "产品删除失败")
|
||||||
|
// 删除所有模型,固件
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
// 删除所有模型,固件
|
// 删除超级表
|
||||||
|
deleteDeviceStable(id)
|
||||||
|
// 删除所有缓存
|
||||||
|
cache.DelProductRule(id)
|
||||||
|
// 删除绑定的属性及OTA记录
|
||||||
p.TemplateApp.Delete([]string{id})
|
p.TemplateApp.Delete([]string{id})
|
||||||
p.OtaAPP.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
|
||||||
|
}
|
||||||
|
|||||||
@@ -193,20 +193,6 @@ func (m *deviceModelImpl) Delete(ids []string) error {
|
|||||||
if err := global.Db.Table(m.table).Delete(&entity.Device{}, "id in (?)", ids).Error; err != nil {
|
if err := global.Db.Table(m.table).Delete(&entity.Device{}, "id in (?)", ids).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, id := range ids {
|
|
||||||
device, err := m.FindOne(id)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// 删除表
|
|
||||||
err = deleteDeviceTable(device.Name)
|
|
||||||
// 删除所有缓存
|
|
||||||
if device.DeviceType == global.GATEWAYS {
|
|
||||||
cache.DelDeviceEtoken(device.Name)
|
|
||||||
} else {
|
|
||||||
cache.DelDeviceEtoken(device.Token)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,19 +209,6 @@ func createDeviceTable(productId, device string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除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 GetDeviceToken(data *entity.Device) *model.DeviceAuth {
|
func GetDeviceToken(data *entity.Device) *model.DeviceAuth {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
etoken := &model.DeviceAuth{
|
etoken := &model.DeviceAuth{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"pandax/apps/device/entity"
|
"pandax/apps/device/entity"
|
||||||
"pandax/pkg/cache"
|
|
||||||
"pandax/pkg/global"
|
"pandax/pkg/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -118,12 +117,6 @@ func (m *productModelImpl) Delete(ids []string) error {
|
|||||||
if err := global.Db.Table(m.table).Delete(&entity.Product{}, "id in (?)", ids).Error; err != nil {
|
if err := global.Db.Table(m.table).Delete(&entity.Product{}, "id in (?)", ids).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, id := range ids {
|
|
||||||
// 删除超级表
|
|
||||||
deleteDeviceStable(id)
|
|
||||||
// 删除所有缓存
|
|
||||||
cache.DelProductRule(id)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,18 +132,6 @@ func createDeviceStable(productId string) error {
|
|||||||
return nil
|
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) {
|
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`
|
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