diff --git a/apps/develop/services/gen_table.go b/apps/develop/services/gen_table.go index 73e0074..7d8e2a5 100644 --- a/apps/develop/services/gen_table.go +++ b/apps/develop/services/gen_table.go @@ -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 diff --git a/apps/device/api/device.go b/apps/device/api/device.go index c5f103f..b5b5977 100644 --- a/apps/device/api/device.go +++ b/apps/device/api/device.go @@ -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 diff --git a/apps/device/api/device_cmd.go b/apps/device/api/device_cmd.go index 37439ae..321d21b 100644 --- a/apps/device/api/device_cmd.go +++ b/apps/device/api/device_cmd.go @@ -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() { diff --git a/apps/device/api/device_group.go b/apps/device/api/device_group.go index 2eacd8d..ee85aab 100644 --- a/apps/device/api/device_group.go +++ b/apps/device/api/device_group.go @@ -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) diff --git a/apps/device/api/product.go b/apps/device/api/product.go index ad23097..a2ebbc4 100644 --- a/apps/device/api/product.go +++ b/apps/device/api/product.go @@ -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 // 如果未设置规则链,默认为主链 diff --git a/apps/device/api/product_category.go b/apps/device/api/product_category.go index eb074b4..343a432 100644 --- a/apps/device/api/product_category.go +++ b/apps/device/api/product_category.go @@ -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) diff --git a/apps/device/api/product_ota.go b/apps/device/api/product_ota.go index f0b77b2..0df1f74 100644 --- a/apps/device/api/product_ota.go +++ b/apps/device/api/product_ota.go @@ -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) } diff --git a/apps/device/api/product_template.go b/apps/device/api/product_template.go index 67c5f8c..681bb34 100644 --- a/apps/device/api/product_template.go +++ b/apps/device/api/product_template.go @@ -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 diff --git a/apps/device/entity/device.go b/apps/device/entity/device.go index 9962058..03ff523 100644 --- a/apps/device/entity/device.go +++ b/apps/device/entity/device.go @@ -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:设备类型"` diff --git a/apps/device/entity/product.go b/apps/device/entity/product.go index 2b7080f..1683483 100644 --- a/apps/device/entity/product.go +++ b/apps/device/entity/product.go @@ -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"` diff --git a/apps/device/services/device.go b/apps/device/services/device.go index 63d475f..cd2978a 100644 --- a/apps/device/services/device.go +++ b/apps/device/services/device.go @@ -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, diff --git a/apps/device/services/device_alarm.go b/apps/device/services/device_alarm.go index 079d2d1..21771fb 100644 --- a/apps/device/services/device_alarm.go +++ b/apps/device/services/device_alarm.go @@ -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 diff --git a/apps/device/services/device_group.go b/apps/device/services/device_group.go index 80895b7..663ada5 100644 --- a/apps/device/services/device_group.go +++ b/apps/device/services/device_group.go @@ -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 } diff --git a/apps/job/api/job.go b/apps/job/api/job.go index 0ae9bb0..67f78fe 100644 --- a/apps/job/api/job.go +++ b/apps/job/api/job.go @@ -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) diff --git a/apps/job/entity/job.go b/apps/job/entity/job.go index 6eae1a6..ed5e8ea 100644 --- a/apps/job/entity/job.go +++ b/apps/job/entity/job.go @@ -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 diff --git a/apps/job/entity/log_job.go b/apps/job/entity/log_job.go index 85b9842..d10c588 100644 --- a/apps/job/entity/log_job.go +++ b/apps/job/entity/log_job.go @@ -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:调用方法"` diff --git a/apps/job/jobs/jobbase.go b/apps/job/jobs/jobbase.go index 97208a7..54147e7 100644 --- a/apps/job/jobs/jobbase.go +++ b/apps/job/jobs/jobbase.go @@ -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] diff --git a/apps/job/services/job.go b/apps/job/services/job.go index 2867846..7978648 100644 --- a/apps/job/services/job.go +++ b/apps/job/services/job.go @@ -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()) diff --git a/apps/job/services/log_job.go b/apps/job/services/log_job.go index 3936181..07d885e 100644 --- a/apps/job/services/log_job.go +++ b/apps/job/services/log_job.go @@ -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 diff --git a/apps/rule/api/rulechain.go b/apps/rule/api/rulechain.go index b226d7d..51e95a2 100644 --- a/apps/rule/api/rulechain.go +++ b/apps/rule/api/rulechain.go @@ -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) } diff --git a/apps/rule/entity/rulechain.go b/apps/rule/entity/rulechain.go index 46de91a..cb9cd63 100644 --- a/apps/rule/entity/rulechain.go +++ b/apps/rule/entity/rulechain.go @@ -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 diff --git a/apps/rule/services/rulechain.go b/apps/rule/services/rulechain.go index 236c4d1..2a6404b 100644 --- a/apps/rule/services/rulechain.go +++ b/apps/rule/services/rulechain.go @@ -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 } diff --git a/apps/rule/services/rulechain_log.go b/apps/rule/services/rulechain_log.go index 844f36c..3c4172a 100644 --- a/apps/rule/services/rulechain_log.go +++ b/apps/rule/services/rulechain_log.go @@ -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, "查询规则链分页列表失败") diff --git a/iothub/hook_message_work/hook_message_work.go b/iothub/hook_message_work/hook_message_work.go index 0fb0790..c32d9a2 100644 --- a/iothub/hook_message_work/hook_message_work.go +++ b/iothub/hook_message_work/hook_message_work.go @@ -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) diff --git a/iothub/netbase/hook_base.go b/iothub/netbase/hook_base.go index d3a206c..a7f53d2 100644 --- a/iothub/netbase/hook_base.go +++ b/iothub/netbase/hook_base.go @@ -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, diff --git a/iothub/netbase/iothub_session.go b/iothub/netbase/iothub_session.go index bb9288b..d9ba545 100644 --- a/iothub/netbase/iothub_session.go +++ b/iothub/netbase/iothub_session.go @@ -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"` } diff --git a/iothub/server/emqxserver/hook.go b/iothub/server/emqxserver/hook.go index d9057f1..8d96133 100644 --- a/iothub/server/emqxserver/hook.go +++ b/iothub/server/emqxserver/hook.go @@ -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") diff --git a/iothub/server/httpserver/hook.go b/iothub/server/httpserver/hook.go index 0b8e083..de27b22 100644 --- a/iothub/server/httpserver/hook.go +++ b/iothub/server/httpserver/hook.go @@ -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) // 是否需要添加设备上线通知 diff --git a/iothub/server/tcpserver/hook.go b/iothub/server/tcpserver/hook.go index a886b50..9bfff63 100644 --- a/iothub/server/tcpserver/hook.go +++ b/iothub/server/tcpserver/hook.go @@ -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 diff --git a/iothub/server/udpserver/hook.go b/iothub/server/udpserver/hook.go index 85af874..013f78e 100644 --- a/iothub/server/udpserver/hook.go +++ b/iothub/server/udpserver/hook.go @@ -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, diff --git a/pkg/global_model/device_auth_model.go b/pkg/global/model/device_auth_model.go similarity index 99% rename from pkg/global_model/device_auth_model.go rename to pkg/global/model/device_auth_model.go index 0e22ccb..c9299b2 100644 --- a/pkg/global_model/device_auth_model.go +++ b/pkg/global/model/device_auth_model.go @@ -1,4 +1,4 @@ -package global_model +package model import ( "bytes" diff --git a/pkg/global_model/global_model.go b/pkg/global/model/global_model.go similarity index 97% rename from pkg/global_model/global_model.go rename to pkg/global/model/global_model.go index 2dc9f09..5db71bc 100644 --- a/pkg/global_model/global_model.go +++ b/pkg/global/model/global_model.go @@ -1,4 +1,4 @@ -package global_model +package model import ( "time" diff --git a/pkg/global_model/rpc_model.go b/pkg/global/model/rpc_model.go similarity index 96% rename from pkg/global_model/rpc_model.go rename to pkg/global/model/rpc_model.go index 5c71d18..042d29c 100644 --- a/pkg/global_model/rpc_model.go +++ b/pkg/global/model/rpc_model.go @@ -1,4 +1,4 @@ -package global_model +package model import ( "errors" diff --git a/pkg/rule_engine/nodes/action_create_alarm_node.go b/pkg/rule_engine/nodes/action_create_alarm_node.go index 6f11bb0..3af23f1 100644 --- a/pkg/rule_engine/nodes/action_create_alarm_node.go +++ b/pkg/rule_engine/nodes/action_create_alarm_node.go @@ -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) diff --git a/pkg/rule_engine/nodes/action_rpc_request_from_device_node.go b/pkg/rule_engine/nodes/action_rpc_request_from_device_node.go index 3aa21d4..c03a2bc 100644 --- a/pkg/rule_engine/nodes/action_rpc_request_from_device_node.go +++ b/pkg/rule_engine/nodes/action_rpc_request_from_device_node.go @@ -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"), } diff --git a/pkg/rule_engine/nodes/action_rpc_request_to_device_node.go b/pkg/rule_engine/nodes/action_rpc_request_to_device_node.go index 88d4601..72e5882 100644 --- a/pkg/rule_engine/nodes/action_rpc_request_to_device_node.go +++ b/pkg/rule_engine/nodes/action_rpc_request_to_device_node.go @@ -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"), } diff --git a/pkg/tool/base_test.go b/pkg/tool/base_test.go index 78cc4ce..7240b84 100644 --- a/pkg/tool/base_test.go +++ b/pkg/tool/base_test.go @@ -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) }