【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

@@ -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 命令:输入参数