From a5d7b504ccebac78c0141853c7d3cee79010b282 Mon Sep 17 00:00:00 2001 From: PandaX <18610165312@163.com> Date: Wed, 18 Oct 2023 09:12:49 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/device/api/product_template.go | 1 - iothub/netbase/hook_base.go | 35 +++++---------------------- pkg/global_model/device_auth_model.go | 1 - pkg/global_model/global_model.go | 1 - 4 files changed, 6 insertions(+), 32 deletions(-) diff --git a/apps/device/api/product_template.go b/apps/device/api/product_template.go index f635f1a..67c5f8c 100644 --- a/apps/device/api/product_template.go +++ b/apps/device/api/product_template.go @@ -56,7 +56,6 @@ func (p *ProductTemplateApi) InsertProductTemplate(rc *restfulx.ReqCtx) { var data entity.ProductTemplate restfulx.BindJsonAndValid(rc, &data) data.Id = global_model.GenerateID() - data.OrgId = rc.LoginAccount.OrganizationId if data.Classify == entity.ATTRIBUTES_TSL || data.Classify == entity.TELEMETRY_TSL { // 向超级表及子表中添加字段 len := 0 diff --git a/iothub/netbase/hook_base.go b/iothub/netbase/hook_base.go index 5a2e33e..89db010 100644 --- a/iothub/netbase/hook_base.go +++ b/iothub/netbase/hook_base.go @@ -87,21 +87,6 @@ func SubAuth(name string) (*global_model.DeviceAuth, bool) { return etoken, true } -// CreateSubTable 创建子设备表 -func CreateSubTable(productId, deviceName string) error { - err := global.TdDb.CreateTable(productId+"_"+entity.ATTRIBUTES_TSL, deviceName+"_"+entity.ATTRIBUTES_TSL) - if err != nil { - global.Log.Error(err) - return err - } - err = global.TdDb.CreateTable(productId+"_"+entity.TELEMETRY_TSL, deviceName+"_"+entity.TELEMETRY_TSL) - if err != nil { - global.Log.Error(err) - return err - } - return nil -} - // CreateSubTableField 添加子设备字段 func CreateSubTableField(productId, ty string, fields map[string]interface{}) { var group sync.WaitGroup @@ -124,11 +109,9 @@ func CreateSubTableField(productId, ty string, fields map[string]interface{}) { if err != nil { return } - one := services.ProductModelDao.FindOne(productId) tsl := entity.ProductTemplate{} tsl.Pid = productId tsl.Id = global_model.GenerateID() - tsl.OrgId = one.OrgId tsl.Name = key tsl.Type = interfaceType tsl.Key = key @@ -139,7 +122,7 @@ func CreateSubTableField(productId, ty string, fields map[string]interface{}) { group.Wait() } -// 解析遥测数据类型 返回标准带时间戳格式 +// UpdateDeviceTelemetryData 解析遥测数据类型 返回标准带时间戳格式 func UpdateDeviceTelemetryData(data string) map[string]interface{} { tel := make(map[string]interface{}) err := json.Unmarshal([]byte(data), &tel) @@ -169,6 +152,7 @@ func UpdateDeviceTelemetryData(data string) map[string]interface{} { return tel } +// UpdateDeviceAttributesData 解析属性数据类型 返回标准带时间戳格式 func UpdateDeviceAttributesData(data string) map[string]interface{} { tel := make(map[string]interface{}) err := json.Unmarshal([]byte(data), &tel) @@ -179,6 +163,8 @@ func UpdateDeviceAttributesData(data string) map[string]interface{} { tel["ts"] = time.Now().Format("2006-01-02 15:04:05.000") return tel } + +// GetUserName 根据emqx连接信息获取用户名 func GetUserName(Clientinfo *exhook.ClientInfo) string { // coap 协议 用户名最大支持5个字符 protocol := Clientinfo.GetProtocol() @@ -202,15 +188,6 @@ func SplitLwm2mClientID(lwm2mClientID string, index int) string { return idArray[index] } -// encode data -func EncodeData(jsonData interface{}) ([]byte, error) { - byteData, err := json.Marshal(jsonData) - if nil != err { - return nil, err - } - return byteData, nil -} - func GetRequestIdFromTopic(reg, topic string) (requestId string) { re := regexp.MustCompile(reg) res := re.FindStringSubmatch(topic) @@ -230,8 +207,8 @@ func CreateConnectionInfo(msgType, protocol, clientID, peerHost string, deviceAu Type: msgType, Ts: ts, } - v, err := EncodeData(*ci) - if err != nil { + v, err := json.Marshal(*ci) + if nil != err { return nil } // 添加设备上线记录 diff --git a/pkg/global_model/device_auth_model.go b/pkg/global_model/device_auth_model.go index dbe8dfe..0e22ccb 100644 --- a/pkg/global_model/device_auth_model.go +++ b/pkg/global_model/device_auth_model.go @@ -67,7 +67,6 @@ func OrgAuthSet(tx *gorm.DB, roleId int64, owner string) { if roleId == 0 { return } - //TODO 使用缓存 role, err := services.SysRoleModelDao.FindOrganizationsByRoleId(roleId) biz.ErrIsNil(err, "查询角色数据权限失败") if role.DataScope != entity.SELFDATASCOPE { diff --git a/pkg/global_model/global_model.go b/pkg/global_model/global_model.go index fa71f9c..2dc9f09 100644 --- a/pkg/global_model/global_model.go +++ b/pkg/global_model/global_model.go @@ -8,7 +8,6 @@ type BaseModel struct { Id string `json:"id" gorm:"primary_key;"` CreatedAt time.Time `gorm:"column:create_time" json:"createTime" form:"create_time"` UpdatedAt time.Time `gorm:"column:update_time" json:"updateTime" form:"update_time"` - OrgId int64 `json:"orgId" gorm:"type:int;comment:机构ID"` } type BaseAuthModel struct {