mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]
This commit is contained in:
@@ -56,7 +56,6 @@ func (p *ProductTemplateApi) InsertProductTemplate(rc *restfulx.ReqCtx) {
|
|||||||
var data entity.ProductTemplate
|
var data entity.ProductTemplate
|
||||||
restfulx.BindJsonAndValid(rc, &data)
|
restfulx.BindJsonAndValid(rc, &data)
|
||||||
data.Id = global_model.GenerateID()
|
data.Id = global_model.GenerateID()
|
||||||
data.OrgId = rc.LoginAccount.OrganizationId
|
|
||||||
if data.Classify == entity.ATTRIBUTES_TSL || data.Classify == entity.TELEMETRY_TSL {
|
if data.Classify == entity.ATTRIBUTES_TSL || data.Classify == entity.TELEMETRY_TSL {
|
||||||
// 向超级表及子表中添加字段
|
// 向超级表及子表中添加字段
|
||||||
len := 0
|
len := 0
|
||||||
|
|||||||
@@ -87,21 +87,6 @@ func SubAuth(name string) (*global_model.DeviceAuth, bool) {
|
|||||||
return etoken, true
|
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 添加子设备字段
|
// CreateSubTableField 添加子设备字段
|
||||||
func CreateSubTableField(productId, ty string, fields map[string]interface{}) {
|
func CreateSubTableField(productId, ty string, fields map[string]interface{}) {
|
||||||
var group sync.WaitGroup
|
var group sync.WaitGroup
|
||||||
@@ -124,11 +109,9 @@ func CreateSubTableField(productId, ty string, fields map[string]interface{}) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
one := services.ProductModelDao.FindOne(productId)
|
|
||||||
tsl := entity.ProductTemplate{}
|
tsl := entity.ProductTemplate{}
|
||||||
tsl.Pid = productId
|
tsl.Pid = productId
|
||||||
tsl.Id = global_model.GenerateID()
|
tsl.Id = global_model.GenerateID()
|
||||||
tsl.OrgId = one.OrgId
|
|
||||||
tsl.Name = key
|
tsl.Name = key
|
||||||
tsl.Type = interfaceType
|
tsl.Type = interfaceType
|
||||||
tsl.Key = key
|
tsl.Key = key
|
||||||
@@ -139,7 +122,7 @@ func CreateSubTableField(productId, ty string, fields map[string]interface{}) {
|
|||||||
group.Wait()
|
group.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析遥测数据类型 返回标准带时间戳格式
|
// UpdateDeviceTelemetryData 解析遥测数据类型 返回标准带时间戳格式
|
||||||
func UpdateDeviceTelemetryData(data string) map[string]interface{} {
|
func UpdateDeviceTelemetryData(data string) map[string]interface{} {
|
||||||
tel := make(map[string]interface{})
|
tel := make(map[string]interface{})
|
||||||
err := json.Unmarshal([]byte(data), &tel)
|
err := json.Unmarshal([]byte(data), &tel)
|
||||||
@@ -169,6 +152,7 @@ func UpdateDeviceTelemetryData(data string) map[string]interface{} {
|
|||||||
return tel
|
return tel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateDeviceAttributesData 解析属性数据类型 返回标准带时间戳格式
|
||||||
func UpdateDeviceAttributesData(data string) map[string]interface{} {
|
func UpdateDeviceAttributesData(data string) map[string]interface{} {
|
||||||
tel := make(map[string]interface{})
|
tel := make(map[string]interface{})
|
||||||
err := json.Unmarshal([]byte(data), &tel)
|
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")
|
tel["ts"] = time.Now().Format("2006-01-02 15:04:05.000")
|
||||||
return tel
|
return tel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserName 根据emqx连接信息获取用户名
|
||||||
func GetUserName(Clientinfo *exhook.ClientInfo) string {
|
func GetUserName(Clientinfo *exhook.ClientInfo) string {
|
||||||
// coap 协议 用户名最大支持5个字符
|
// coap 协议 用户名最大支持5个字符
|
||||||
protocol := Clientinfo.GetProtocol()
|
protocol := Clientinfo.GetProtocol()
|
||||||
@@ -202,15 +188,6 @@ func SplitLwm2mClientID(lwm2mClientID string, index int) string {
|
|||||||
return idArray[index]
|
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) {
|
func GetRequestIdFromTopic(reg, topic string) (requestId string) {
|
||||||
re := regexp.MustCompile(reg)
|
re := regexp.MustCompile(reg)
|
||||||
res := re.FindStringSubmatch(topic)
|
res := re.FindStringSubmatch(topic)
|
||||||
@@ -230,8 +207,8 @@ func CreateConnectionInfo(msgType, protocol, clientID, peerHost string, deviceAu
|
|||||||
Type: msgType,
|
Type: msgType,
|
||||||
Ts: ts,
|
Ts: ts,
|
||||||
}
|
}
|
||||||
v, err := EncodeData(*ci)
|
v, err := json.Marshal(*ci)
|
||||||
if err != nil {
|
if nil != err {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// 添加设备上线记录
|
// 添加设备上线记录
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ func OrgAuthSet(tx *gorm.DB, roleId int64, owner string) {
|
|||||||
if roleId == 0 {
|
if roleId == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//TODO 使用缓存
|
|
||||||
role, err := services.SysRoleModelDao.FindOrganizationsByRoleId(roleId)
|
role, err := services.SysRoleModelDao.FindOrganizationsByRoleId(roleId)
|
||||||
biz.ErrIsNil(err, "查询角色数据权限失败")
|
biz.ErrIsNil(err, "查询角色数据权限失败")
|
||||||
if role.DataScope != entity.SELFDATASCOPE {
|
if role.DataScope != entity.SELFDATASCOPE {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ type BaseModel struct {
|
|||||||
Id string `json:"id" gorm:"primary_key;"`
|
Id string `json:"id" gorm:"primary_key;"`
|
||||||
CreatedAt time.Time `gorm:"column:create_time" json:"createTime" form:"create_time"`
|
CreatedAt time.Time `gorm:"column:create_time" json:"createTime" form:"create_time"`
|
||||||
UpdatedAt time.Time `gorm:"column:update_time" json:"updateTime" form:"update_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 {
|
type BaseAuthModel struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user