[feat]网关子设备,直接上传,自动创建设备模型,无需手动创建

This commit is contained in:
PandaX
2023-10-17 11:14:18 +08:00
parent f26c5a2647
commit 55e399e5cb
23 changed files with 1457 additions and 74 deletions

View File

@@ -2,7 +2,9 @@ package tool
import (
"encoding/json"
"pandax/pkg/global"
"strings"
"time"
)
// SnakeString snake string, XxYy to xx_yy , XxYY to xx_y_y
@@ -100,3 +102,26 @@ func StringToStruct(m string, s interface{}) error {
}
return nil
}
func TimeToFormat(val interface{}) string {
switch v := val.(type) {
case int64:
// 如果是时间戳类型,将其转换为时间对象
t := time.Unix(v, 0)
// 格式化时间字符串
formattedTime := t.Format("2006-01-02 15:04:05")
return formattedTime
case string:
// 如果是字符串类型,将其解析为时间对象
t, err := time.Parse("2006-01-02 15:04:05", v)
if err != nil {
global.Log.Error("时间格式非标准格式")
return ""
}
// 格式化时间字符串
formattedTime := t.Format("2006-01-02 15:04:05")
return formattedTime
default:
return ""
}
}