mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]优化目录
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"pandax/apps/device/util"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"pandax/pkg/shadow"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -199,7 +199,7 @@ func (p *DeviceApi) InsertDevice(rc *restfulx.ReqCtx) {
|
||||
data.OrgId = rc.LoginAccount.OrganizationId
|
||||
list := p.DeviceApp.FindList(entity.Device{Name: data.Name})
|
||||
biz.IsTrue(!(list != nil && len(*list) > 0), fmt.Sprintf("名称%s已存在,设置其他命名", data.Name))
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model2.GenerateID()
|
||||
data.LinkStatus = global.INACTIVE
|
||||
data.LastAt = time.Now()
|
||||
data.Protocol = product.ProtocolName
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/apps/device/util"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -48,7 +48,7 @@ func (p *DeviceCmdLogApi) InsertDeviceCmdLog(rc *restfulx.ReqCtx) {
|
||||
ms := make(map[string]interface{})
|
||||
err := json.Unmarshal([]byte(data.CmdContent), &ms)
|
||||
biz.ErrIsNil(err, "指令格式不正确")
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model2.GenerateID()
|
||||
data.State = "2"
|
||||
data.RequestTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
go func() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/apps/device/services"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ func (p *DeviceGroupApi) GetDeviceGroup(rc *restfulx.ReqCtx) {
|
||||
func (p *DeviceGroupApi) InsertDeviceGroup(rc *restfulx.ReqCtx) {
|
||||
var data entity.DeviceGroup
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model.GenerateID()
|
||||
data.Owner = rc.LoginAccount.UserName
|
||||
data.OrgId = rc.LoginAccount.OrganizationId
|
||||
p.DeviceGroupApp.Insert(data)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/model"
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"strings"
|
||||
|
||||
"pandax/apps/device/entity"
|
||||
@@ -102,7 +102,7 @@ func (p *ProductApi) GetProduct(rc *restfulx.ReqCtx) {
|
||||
func (p *ProductApi) InsertProduct(rc *restfulx.ReqCtx) {
|
||||
var data entity.Product
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model2.GenerateID()
|
||||
data.Owner = rc.LoginAccount.UserName
|
||||
data.OrgId = rc.LoginAccount.OrganizationId
|
||||
// 如果未设置规则链,默认为主链
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/apps/device/services"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ func (p *ProductCategoryApi) GetProductCategory(rc *restfulx.ReqCtx) {
|
||||
func (p *ProductCategoryApi) InsertProductCategory(rc *restfulx.ReqCtx) {
|
||||
var data entity.ProductCategory
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model.GenerateID()
|
||||
data.Owner = rc.LoginAccount.UserName
|
||||
data.OrgId = rc.LoginAccount.OrganizationId
|
||||
p.ProductCategoryApp.Insert(data)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"github.com/PandaXGO/PandaKit/model"
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/pkg/global_model"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"pandax/pkg/tool"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -51,7 +51,7 @@ func (p *ProductOtaApi) InsertProductOta(rc *restfulx.ReqCtx) {
|
||||
// 生成文件MD5值
|
||||
md5, err := tool.GetFileMd5(path.Join(filePath, data.Url))
|
||||
biz.ErrIsNil(err, "读取文件md5校验值错误")
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model2.GenerateID()
|
||||
data.Check = md5
|
||||
p.ProductOtaApp.Insert(data)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/model"
|
||||
"github.com/PandaXGO/PandaKit/restfulx"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
model2 "pandax/pkg/global/model"
|
||||
"strings"
|
||||
|
||||
"pandax/apps/device/entity"
|
||||
@@ -55,7 +55,7 @@ func (p *ProductTemplateApi) GetProductTemplate(rc *restfulx.ReqCtx) {
|
||||
func (p *ProductTemplateApi) InsertProductTemplate(rc *restfulx.ReqCtx) {
|
||||
var data entity.ProductTemplate
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
data.Id = global_model.GenerateID()
|
||||
data.Id = model2.GenerateID()
|
||||
if data.Classify == entity.ATTRIBUTES_TSL || data.Classify == entity.TELEMETRY_TSL {
|
||||
// 向超级表及子表中添加字段
|
||||
len := 0
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DeviceGroup 设备分组
|
||||
type DeviceGroup struct {
|
||||
global_model.BaseAuthModel
|
||||
model.BaseAuthModel
|
||||
Name string `json:"name" gorm:"type:varchar(128);comment:设备分组名称" validate:"required"`
|
||||
Pid string `json:"pid" gorm:"type:varchar(64);comment:设备分组类型"`
|
||||
Path string `json:"path" gorm:"type:varchar(255);comment:设备分组路径"`
|
||||
@@ -31,7 +31,7 @@ type DeviceGroupLabel struct {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
global_model.BaseAuthModel
|
||||
model.BaseAuthModel
|
||||
Name string `json:"name" gorm:"type:varchar(128);comment:设备名称" validate:"required,alphanum"` // mqtt 用户名英文
|
||||
ParentId string `json:"parentId" gorm:"type:varchar(64);comment:父设备"`
|
||||
DeviceType string `json:"deviceType" gorm:"type:varchar(64);comment:设备类型"`
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,7 +22,7 @@ const (
|
||||
)
|
||||
|
||||
type ProductCategory struct {
|
||||
global_model.BaseAuthModel
|
||||
model.BaseAuthModel
|
||||
Name string `json:"name" gorm:"type:varchar(128);comment:产品类型名称" validate:"required"`
|
||||
Pid string `json:"pid" gorm:"type:varchar(64);comment:父产品类型"`
|
||||
Path string `json:"path" gorm:"type:varchar(255);comment:产品类型路径"`
|
||||
@@ -39,7 +39,7 @@ type ProductCategoryLabel struct {
|
||||
}
|
||||
|
||||
type Product struct {
|
||||
global_model.BaseAuthModel
|
||||
model.BaseAuthModel
|
||||
Name string `json:"name" gorm:"type:varchar(128);comment:产品名称" validate:"required"`
|
||||
PhotoUrl string `json:"photoUrl" gorm:"type:varchar(255);comment:图片地址"`
|
||||
Description string `json:"description" gorm:"type:varchar(255);comment:产品说明"`
|
||||
@@ -57,7 +57,7 @@ type ProductRes struct {
|
||||
}
|
||||
|
||||
type ProductTemplate struct {
|
||||
global_model.BaseModel
|
||||
model.BaseModel
|
||||
Pid string `json:"pid" gorm:"type:varchar(64);comment:产品Id" validate:"required"`
|
||||
Classify string `json:"classify" gorm:"type:varchar(64);comment:模型归类" validate:"required"` // 属性 遥测 命令 事件
|
||||
Name string `json:"name" gorm:"type:varchar(64);comment:名称" validate:"required"`
|
||||
@@ -68,7 +68,7 @@ type ProductTemplate struct {
|
||||
}
|
||||
|
||||
type ProductOta struct {
|
||||
global_model.BaseModel
|
||||
model.BaseModel
|
||||
Pid string `json:"pid" gorm:"comment:产品Id" validate:"required"`
|
||||
Name string `json:"name" gorm:"type:varchar(64);comment:固件名称" validate:"required"`
|
||||
Version string `json:"version" gorm:"type:varchar(64);comment:固件版本" validate:"required"`
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/pkg/cache"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (m *deviceModelImpl) FindListPage(page, pageSize int, data entity.Device) (
|
||||
db = db.Where("parent_id = ?", data.ParentId)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("create_time").Preload("Product").Preload("DeviceGroup").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
@@ -150,7 +150,7 @@ func (m *deviceModelImpl) FindList(data entity.Device) *[]entity.DeviceRes {
|
||||
if data.ParentId != "" {
|
||||
db = db.Where("parent_id = ?", data.ParentId)
|
||||
}
|
||||
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
db.Preload("Product").Preload("DeviceGroup")
|
||||
biz.ErrIsNil(db.Order("create_time").Find(&list).Error, "查询设备列表失败")
|
||||
return &list
|
||||
@@ -217,9 +217,9 @@ func deleteDeviceTable(device string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetDeviceToken(data *entity.Device) *global_model.DeviceAuth {
|
||||
func GetDeviceToken(data *entity.Device) *model.DeviceAuth {
|
||||
now := time.Now()
|
||||
etoken := &global_model.DeviceAuth{
|
||||
etoken := &model.DeviceAuth{
|
||||
DeviceId: data.Id,
|
||||
OrgId: data.OrgId,
|
||||
Owner: data.Owner,
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -78,7 +78,7 @@ func (m *alarmModelImpl) FindListPage(page, pageSize int, data entity.DeviceAlar
|
||||
db = db.Where("time < ?", data.EndTime)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("time").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/biz"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global_model"
|
||||
"pandax/pkg/global/model"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -69,7 +69,7 @@ func (m *deviceGroupModelImpl) FindListPage(page, pageSize int, data entity.Devi
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
|
||||
err := db.Count(&total).Error
|
||||
err = db.Order("sort").Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
@@ -91,7 +91,7 @@ func (m *deviceGroupModelImpl) FindList(data entity.DeviceGroup) *[]entity.Devic
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
model.OrgAuthSet(db, data.RoleId, data.Owner)
|
||||
biz.ErrIsNil(db.Order("sort").Find(&list).Error, "查询设备分组列表失败")
|
||||
return &list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user