【feat】添加设备影子

This commit is contained in:
XM-GO
2023-09-21 18:00:33 +08:00
parent 3ac9354573
commit 11d7459271
12 changed files with 253 additions and 446 deletions

View File

@@ -46,7 +46,6 @@ type Product struct {
ProductCategoryId string `json:"productCategoryId" gorm:"type:varchar(64);comment:产品类型Id" validate:"required"`
ProtocolName string `json:"protocolName" gorm:"type:varchar(64);comment:协议名称"` //MQTT COAP WebSocket LwM2M
DeviceType string `json:"deviceType" gorm:"type:varchar(64);comment:设备类型"` // 直连设备 网关设备 网关子设备 监控设备
SelfLearn bool `json:"selfLearn" gorm:"default:0;comment:自学习开关"`
RuleChainId string `json:"ruleChainId" gorm:"type:varchar(64);comment:规则链Id"` //可空,如果空就走根规则链
Status string `gorm:"status;type:varchar(1);comment:状态" json:"status"`

View File

@@ -66,7 +66,7 @@ func (m *deviceModelImpl) FindOne(id string) *entity.DeviceRes {
func (m *deviceModelImpl) FindOneByToken(token string) (*entity.Device, error) {
resData := new(entity.Device)
db := global.Db.Table(m.table).Where("token = ?", token)
err := db.First(resData).Error
err := db.Preload("Product").First(resData).Error
return resData, err
}

View File

@@ -30,8 +30,6 @@ func (t ValueType) ConvertValue(v interface{}) interface{} {
transfer = TDate(t.DefineBase)
case TypeEnum:
transfer = TEnum(t.DefineBase)
case TypeStruct:
transfer = TStruct(t.DefineBase)
default:
return nil
}
@@ -140,29 +138,9 @@ func (tEnum TEnum) Convert(v interface{}) interface{} {
return ""
}
for _, node := range tEnum.Enums {
if node.Value == tE {
return node.Key
if node.Key == tE {
return node.Value
}
}
return ""
}
type TStruct DefineBase
func (tStruct TStruct) Convert(v interface{}) interface{} {
m, ok := v.(map[string]interface{})
if !ok {
return nil
}
result := make(map[string]interface{})
if tStruct.Struct != nil {
for k, value := range m {
for _, t := range tStruct.Struct {
if t.Name == k {
result[t.Name] = t.ValueType.ConvertValue(value)
}
}
}
}
return result
}

View File

@@ -26,9 +26,9 @@ type DefineBase struct {
MaxLength *int `json:"maxLength"` // 最大长度,字符类型:string
DefineBool []DefineBool `json:"boolDefine"`
Enums []DefineEnum `json:"enumDefine"` // 枚举类型:enum
Struct []DefineStruct `json:"structDefine" ` // 对象类型:Struct
DefineBool []DefineBool `json:"boolDefine"`
Enums []DefineEnum `json:"enumDefine"` // 枚举类型:enum
Struct any `json:"structDefine" ` // 对象类型:Struct
}
type DefineBool struct {
@@ -50,17 +50,17 @@ type DefineStruct struct {
}
type ValueType struct {
Type string `json:"type" dc:"数据类型" v:"required#请选择数据类型"` // 类型
Type string `json:"type"` // 类型
DefineBase // 参数
}
// DefineCommands 命令
type DefineCommands struct {
Key string `json:"key" dc:"功能标识" v:"required|regex:^[A-Za-z_]+[\\w]*$#请输入功能标识|标识由字母、数字和下划线组成,且不能以数字开头"`
Name string `json:"name" dc:"功能名称" v:"required#请输入功能名称"` // 功能名称
Inputs []DefineCommandsInput `json:"inputs" dc:"输入参数"` // 输入参数
Output ValueType `json:"output" dc:"输出参数"` // 输出参数
Desc string `json:"desc" dc:"描述"` // 描述
Key string `json:"key" `
Name string `json:"name"` // 功能名称
Inputs []DefineCommandsInput `json:"inputs"` // 输入参数
Output ValueType `json:"output"` // 输出参数
Desc string `json:"desc"` // 描述
}
// DefineCommandsInput 命令:输入参数