[优化]优化目录

This commit is contained in:
PandaX
2023-11-07 16:45:23 +08:00
parent 3a4cea5b26
commit 6bdc4b1dd6
37 changed files with 97 additions and 98 deletions

View File

@@ -6,7 +6,7 @@ import (
"github.com/PandaXGO/PandaKit/utils"
"pandax/apps/develop/entity"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
/**
@@ -135,7 +135,7 @@ func (m *devGenTableModelImpl) FindTree(data entity.DevGenTable) *[]entity.DevGe
db = db.Where("table_comment = ?", data.TableComment)
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
err := db.Find(&resData).Error
biz.ErrIsNil(err, "获取TableTree失败")
for i := 0; i < len(resData); i++ {
@@ -162,7 +162,7 @@ func (m *devGenTableModelImpl) FindListPage(page, pageSize int, data entity.DevG
db = db.Where("table_comment = ?", data.TableComment)
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
db.Where("delete_time IS NULL")
err := db.Count(&total).Error
err = db.Limit(pageSize).Offset(offset).Find(&list).Error

View File

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

View File

@@ -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() {

View File

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

View File

@@ -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
// 如果未设置规则链,默认为主链

View File

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

View File

@@ -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)
}

View File

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

View File

@@ -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:设备类型"`

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ import (
"pandax/apps/job/entity"
"pandax/apps/job/jobs"
"pandax/apps/job/services"
"pandax/pkg/global_model"
model2 "pandax/pkg/global/model"
"strings"
)
@@ -19,7 +19,7 @@ type JobApi struct {
func (j *JobApi) CreateJob(rc *restfulx.ReqCtx) {
var job entity.SysJob
restfulx.BindQuery(rc, &job)
job.Id = global_model.GenerateID()
job.Id = model2.GenerateID()
job.Owner = rc.LoginAccount.UserName
job.OrgId = rc.LoginAccount.OrganizationId
j.JobApp.Insert(job)

View File

@@ -1,11 +1,11 @@
package entity
import (
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type SysJob struct {
global_model.BaseAuthModel
model.BaseAuthModel
JobName string `json:"jobName" gorm:"type:varchar(255);"` // 名称
TargetInvoke string `json:"targetInvoke" gorm:"type:varchar(64);comment:目标类型"` //调用目标 设备还是产品
TargetArgs string `json:"targetArgs" gorm:"type:varchar(64);comment:目标Id"` //目标传参 设备或者产品id

View File

@@ -1,11 +1,11 @@
package entity
import (
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type JobLog struct {
global_model.BaseAuthModel
model.BaseAuthModel
Name string `json:"name" gorm:"type:varchar(128);comment:任务名称"`
EntryId int `json:"entryId" gorm:"type:int;comment:任务id"`
TargetInvoke string `json:"targetInvoke" gorm:"type:varchar(128);comment:调用方法"`

View File

@@ -7,8 +7,7 @@ import (
"pandax/apps/job/services"
logServices "pandax/apps/job/services"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"sync"
"time"
@@ -53,7 +52,7 @@ type ExecJob struct {
func (e *ExecJob) Run() {
startTime := time.Now()
jobLog := logEntity.JobLog{Name: e.Name, EntryId: e.EntryId, TargetInvoke: e.InvokeTarget, Status: "0"}
jobLog.Id = global_model.GenerateID()
jobLog.Id = model.GenerateID()
jobLog.OrgId = e.OrgId
jobLog.Owner = e.Owner
var obj = jobList[e.InvokeTarget]

View File

@@ -4,7 +4,7 @@ import (
"github.com/PandaXGO/PandaKit/biz"
"pandax/apps/job/entity"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type (
@@ -55,7 +55,7 @@ func (m *jobModelImpl) FindListPage(page, pageSize int, data entity.SysJob) (*[]
}
// 组织数据访问权限
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 desc").Limit(pageSize).Offset(offset).Find(&list).Error
@@ -75,7 +75,7 @@ func (m *jobModelImpl) FindList(data entity.SysJob) *[]entity.SysJob {
db = db.Where("status = ?", data.Status)
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
err := db.Order("create_time desc").Find(&list).Error
if err != nil {
global.Log.Error("查询任务分页信息失败:" + err.Error())

View File

@@ -4,7 +4,7 @@ import (
"github.com/PandaXGO/PandaKit/biz"
"pandax/apps/job/entity"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type (
@@ -43,7 +43,7 @@ func (m *JobLogModelImpl) FindListPage(page, pageSize int, data entity.JobLog) (
}
// 组织数据访问权限
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 desc").Limit(pageSize).Offset(offset).Find(&list).Error

View File

@@ -6,7 +6,7 @@ import (
"github.com/PandaXGO/PandaKit/restfulx"
"pandax/apps/rule/entity"
"pandax/apps/rule/services"
"pandax/pkg/global_model"
model2 "pandax/pkg/global/model"
"pandax/pkg/rule_engine"
"strings"
)
@@ -77,7 +77,7 @@ func (p *RuleChainApi) GetRuleChain(rc *restfulx.ReqCtx) {
func (p *RuleChainApi) InsertRuleChain(rc *restfulx.ReqCtx) {
var data entity.RuleChain
restfulx.BindJsonAndValid(rc, &data)
data.Id = global_model.GenerateID()
data.Id = model2.GenerateID()
data.Owner = rc.LoginAccount.UserName
data.OrgId = rc.LoginAccount.OrganizationId
p.RuleChainApp.Insert(data)
@@ -104,7 +104,7 @@ func (p *RuleChainApi) CloneRuleChain(rc *restfulx.ReqCtx) {
id := restfulx.PathParam(rc, "id")
one := p.RuleChainApp.FindOne(id)
one.RuleName = one.RuleName + "-克隆"
one.Id = global_model.GenerateID()
one.Id = model2.GenerateID()
one.Root = "0"
p.RuleChainApp.Insert(*one)
}

View File

@@ -1,7 +1,7 @@
package entity
import (
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"time"
)
@@ -12,7 +12,7 @@ type RuleChainBaseLabel struct {
}
type RuleChainBase struct {
global_model.BaseAuthModel
model.BaseAuthModel
Root string `json:"root" gorm:"comment:是否根节点,1 根链 0 普通链"`
RuleName string `gorm:"ruleName;type:varchar(50);comment:名称" json:"ruleName"`
RuleBase64 string `gorm:"ruleBase64;type:longtext;comment:Base64缩略图" json:"ruleBase64"` //缩略图 base64

View File

@@ -11,7 +11,7 @@ import (
"pandax/apps/rule/entity"
"pandax/pkg/events"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type (
@@ -77,7 +77,7 @@ func (m *ruleChainModelImpl) FindListPage(page, pageSize int, data entity.RuleCh
db = db.Where("rule_remark like ?", "%"+data.RuleRemark+"%")
}
// 组织数据访问权限
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").Limit(pageSize).Offset(offset).Find(&list).Error
biz.ErrIsNil(err, "查询规则链分页列表失败")
@@ -95,7 +95,7 @@ func (m *ruleChainModelImpl) FindList(data entity.RuleChain) *[]entity.RuleChain
db = db.Where("rule_remark like ?", "%"+data.RuleRemark+"%")
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
biz.ErrIsNil(db.Order("create_time").Find(&list).Error, "查询规则链列表失败")
return &list
}
@@ -108,7 +108,7 @@ func (m *ruleChainModelImpl) FindListBaseLabel(data entity.RuleChain) *[]entity.
db = db.Where("rule_name like ?", "%"+data.RuleName+"%")
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
biz.ErrIsNil(db.Find(&list).Error, "查询规则链列表失败")
return &list
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/PandaXGO/PandaKit/biz"
"pandax/apps/rule/entity"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type (
@@ -51,7 +51,7 @@ func (m *ruleChainLogModelImpl) FindListPage(page, pageSize int, data entity.Rul
db = db.Where("msg_type = ?", data.MsgType)
}
// 组织数据访问权限
global_model.OrgAuthSet(db, data.RoleId, data.Owner)
model.OrgAuthSet(db, data.RoleId, data.Owner)
err := db.Count(&total).Error
err = db.Order("create_at").Limit(pageSize).Offset(offset).Find(&list).Error
biz.ErrIsNil(err, "查询规则链分页列表失败")

View File

@@ -11,7 +11,7 @@ import (
"pandax/iothub/netbase"
"pandax/pkg/cache"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine"
"pandax/pkg/rule_engine/message"
"pandax/pkg/shadow"
@@ -98,7 +98,7 @@ func (s *HookService) handleOne(msg *netbase.DeviceEventInfo) {
}
// 获取规则实体
func getRuleChainInstance(etoken *global_model.DeviceAuth) *rule_engine.RuleChainInstance {
func getRuleChainInstance(etoken *model.DeviceAuth) *rule_engine.RuleChainInstance {
defer func() {
if err := recover(); err != nil {
global.Log.Error(err)
@@ -131,7 +131,7 @@ func getRuleChainInstance(etoken *global_model.DeviceAuth) *rule_engine.RuleChai
}
// 构建规则链执行的消息
func buildRuleMessage(etoken *global_model.DeviceAuth, msgVals map[string]interface{}, msgType string) *message.Message {
func buildRuleMessage(etoken *model.DeviceAuth, msgVals map[string]interface{}, msgType string) *message.Message {
metadataVals := map[string]interface{}{
"deviceId": etoken.DeviceId,
"deviceName": etoken.Name,
@@ -161,7 +161,7 @@ func SendZtWebsocket(deviceId, message string) {
}
// SetDeviceShadow 设置设备点
func SetDeviceShadow(etoken *global_model.DeviceAuth, msgVals map[string]interface{}, msgType string) {
func SetDeviceShadow(etoken *model.DeviceAuth, msgVals map[string]interface{}, msgType string) {
defer func() {
if err := recover(); err != nil {
global.Log.Error(err)

View File

@@ -8,7 +8,7 @@ import (
"pandax/iothub/server/emqxserver/protobuf"
"pandax/pkg/cache"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/tdengine"
"pandax/pkg/tool"
"regexp"
@@ -22,7 +22,7 @@ func Auth(authToken string) bool {
if authToken == global.Conf.Mqtt.Username {
return true
}
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
// redis 中有就查询,没有就添加
exists := cache.ExistsDeviceEtoken(authToken)
if exists {
@@ -55,14 +55,14 @@ func Auth(authToken string) bool {
}
// SubAuth 获取子设备的认证信息
func SubAuth(name string) (*global_model.DeviceAuth, bool) {
func SubAuth(name string) (*model.DeviceAuth, bool) {
defer func() {
if Rerr := recover(); Rerr != nil {
global.Log.Error(Rerr)
return
}
}()
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
// redis 中有就查询,没有就添加
exists := cache.ExistsDeviceEtoken(name)
if exists {
@@ -113,7 +113,7 @@ func CreateSubTableField(productId, ty string, fields map[string]interface{}) {
}
tsl := entity.ProductTemplate{}
tsl.Pid = productId
tsl.Id = global_model.GenerateID()
tsl.Id = model.GenerateID()
tsl.Name = key
tsl.Type = interfaceType
tsl.Key = key
@@ -199,7 +199,7 @@ func GetRequestIdFromTopic(reg, topic string) (requestId string) {
return ""
}
func CreateConnectionInfo(msgType, protocol, clientID, peerHost string, deviceAuth *global_model.DeviceAuth) *DeviceEventInfo {
func CreateConnectionInfo(msgType, protocol, clientID, peerHost string, deviceAuth *model.DeviceAuth) *DeviceEventInfo {
ts := time.Now().Format("2006-01-02 15:04:05.000")
ci := &tdengine.ConnectInfo{
ClientID: clientID,

View File

@@ -1,13 +1,13 @@
package netbase
import (
"pandax/pkg/global_model"
"pandax/pkg/global/model"
)
type DeviceEventInfo struct {
DeviceId string `json:"deviceId"`
DeviceAuth *global_model.DeviceAuth `json:"deviceAuth"`
Datas string `json:"datas"`
Type string `json:"type"`
RequestId string `json:"requestId"`
DeviceId string `json:"deviceId"`
DeviceAuth *model.DeviceAuth `json:"deviceAuth"`
Datas string `json:"datas"`
Type string `json:"type"`
RequestId string `json:"requestId"`
}

View File

@@ -9,7 +9,7 @@ import (
"pandax/iothub/netbase"
exhook2 "pandax/iothub/server/emqxserver/protobuf"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
"time"
)
@@ -81,7 +81,7 @@ func (s *HookGrpcService) OnClientConnack(ctx context.Context, in *exhook2.Clien
func (s *HookGrpcService) OnClientConnected(ctx context.Context, in *exhook2.ClientConnectedRequest) (*exhook2.EmptySuccess, error) {
global.Log.Info(fmt.Sprintf("Client %s Connected ", in.Clientinfo.GetNode()))
token := netbase.GetUserName(in.Clientinfo)
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
err := etoken.GetDeviceToken(token)
if err != nil {
return nil, err
@@ -96,7 +96,7 @@ func (s *HookGrpcService) OnClientConnected(ctx context.Context, in *exhook2.Cli
func (s *HookGrpcService) OnClientDisconnected(ctx context.Context, in *exhook2.ClientDisconnectedRequest) (*exhook2.EmptySuccess, error) {
global.Log.Info(fmt.Sprintf("%s断开连接", in.Clientinfo.Username))
token := netbase.GetUserName(in.Clientinfo)
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
err := etoken.GetDeviceToken(token)
if err != nil {
return nil, err
@@ -180,7 +180,7 @@ func (s *HookGrpcService) OnMessagePublish(ctx context.Context, in *exhook2.Mess
res.Value = &exhook2.ValuedResponse_BoolResult{BoolResult: true}
return res, nil
}
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
etoken.GetDeviceToken(in.Message.Headers["username"])
// 获取topic类型
ts := time.Now().Format("2006-01-02 15:04:05.000")

View File

@@ -11,7 +11,7 @@ import (
"pandax/iothub/hook_message_work"
"pandax/iothub/netbase"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
"sync"
"time"
@@ -42,7 +42,7 @@ func InitHttpHook(addr string, hs *hook_message_work.HookService) {
case http.StateHijacked, http.StateClosed:
etoken, _ := activeConnections.Load(conn.RemoteAddr().String())
if etoken != nil {
data := netbase.CreateConnectionInfo(message.DisConnectMes, "http", conn.RemoteAddr().String(), conn.RemoteAddr().String(), etoken.(*global_model.DeviceAuth))
data := netbase.CreateConnectionInfo(message.DisConnectMes, "http", conn.RemoteAddr().String(), conn.RemoteAddr().String(), etoken.(*model.DeviceAuth))
activeConnections.Delete(conn.RemoteAddr().String())
service.HookService.MessageCh <- data
}
@@ -80,7 +80,7 @@ func (hhs *HookHttpService) hook(req *restful.Request, resp *restful.Response) {
resp.Write([]byte("解析上报参数失败"))
return
}
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
etoken.GetDeviceToken(token)
_, ok := activeConnections.Load(req.Request.RemoteAddr)
// 是否需要添加设备上线通知

View File

@@ -9,7 +9,7 @@ import (
"pandax/iothub/hook_message_work"
"pandax/iothub/netbase"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
"time"
)
@@ -48,7 +48,7 @@ func InitTcpHook(addr string, hs *hook_message_work.HookService) {
func (hhs *HookTcpService) hook() {
isAuth := false
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
for {
buf := make([]byte, 128)
n := 0

View File

@@ -9,7 +9,7 @@ import (
"pandax/iothub/hook_message_work"
"pandax/iothub/netbase"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
"time"
)
@@ -30,7 +30,7 @@ func InitUdpHook(addr string, hs *hook_message_work.HookService) {
}
buffer := make([]byte, 1024)
authMap := make(map[string]bool)
etoken := &global_model.DeviceAuth{}
etoken := &model.DeviceAuth{}
hhs := &HookUdpService{
HookService: hs,
conn: server.listener,

View File

@@ -1,4 +1,4 @@
package global_model
package model
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package global_model
package model
import (
"time"

View File

@@ -1,4 +1,4 @@
package global_model
package model
import (
"errors"

View File

@@ -5,7 +5,7 @@ import (
"pandax/apps/device/entity"
"pandax/apps/device/services"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
"time"
)
@@ -48,7 +48,7 @@ func (n *createAlarmNode) Handle(msg *message.Message) error {
}
} else {
alarm = &entity.DeviceAlarm{}
alarm.Id = global_model.GenerateID()
alarm.Id = model.GenerateID()
alarm.DeviceId = msg.Metadata.GetValue("deviceId").(string)
alarm.ProductId = msg.Metadata.GetValue("productId").(string)
alarm.Name = msg.Metadata.GetValue("deviceName").(string)

View File

@@ -5,7 +5,7 @@ import (
"pandax/iothub/client/mqttclient"
"pandax/iothub/client/tcpclient"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
)
@@ -34,7 +34,7 @@ func (n *rpcRequestFromDeviceNode) Handle(msg *message.Message) error {
if msg.Msg.GetValue("method") == nil || msg.Msg.GetValue("params") == nil {
return errors.New("指令请求格式错误")
}
var rpcp = global_model.RpcPayload{
var rpcp = model.RpcPayload{
Method: msg.Msg.GetValue("method").(string),
Params: msg.Msg.GetValue("params"),
}

View File

@@ -6,7 +6,7 @@ import (
"pandax/iothub/client/mqttclient"
"pandax/iothub/client/tcpclient"
"pandax/pkg/global"
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"pandax/pkg/rule_engine/message"
)
@@ -34,7 +34,7 @@ func (n *rpcRequestToDeviceNode) Handle(msg *message.Message) error {
if msg.Msg.GetValue("method") == nil || msg.Msg.GetValue("params") == nil {
return errors.New("指令下发格式错误")
}
var datas = global_model.RpcPayload{
var datas = model.RpcPayload{
Method: msg.Msg.GetValue("method").(string),
Params: msg.Msg.GetValue("params"),
}

View File

@@ -1,7 +1,7 @@
package tool
import (
"pandax/pkg/global_model"
"pandax/pkg/global/model"
"testing"
)
@@ -11,7 +11,7 @@ func TestToCamelCase(t *testing.T) {
}
func TestGenerateID(t *testing.T) {
id := global_model.GenerateID()
id := model.GenerateID()
t.Log(id)
}