mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-03 21:26:35 +08:00
feat: dbms新增支持工单流程审批
This commit is contained in:
@@ -635,3 +635,26 @@ func Case2Camel(name string) string {
|
||||
name = strings.Title(name)
|
||||
return strings.Replace(name, " ", "", -1)
|
||||
}
|
||||
|
||||
// 结构体转为map
|
||||
func ToMap(input any) map[string]any {
|
||||
result := make(map[string]any)
|
||||
v := Indirect(reflect.ValueOf(input))
|
||||
if v.Kind() != reflect.Struct {
|
||||
return result
|
||||
}
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
field := v.Field(i)
|
||||
zeroValue := reflect.Zero(field.Type()).Interface()
|
||||
fieldValue := field.Interface()
|
||||
|
||||
if !reflect.DeepEqual(fieldValue, zeroValue) {
|
||||
result[v.Type().Field(i).Name] = fieldValue
|
||||
} else {
|
||||
result[v.Type().Field(i).Name] = zeroValue
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
)
|
||||
|
||||
type Src struct {
|
||||
Id *int64 `json:"id"`
|
||||
Id int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
CreateTime time.Time `json:"time"`
|
||||
UpdateTime time.Time
|
||||
UpdateTime *time.Time
|
||||
Inner *SrcInner
|
||||
}
|
||||
|
||||
@@ -194,3 +194,12 @@ func TestTemplateResolve(t *testing.T) {
|
||||
fmt.Println(resolve)
|
||||
|
||||
}
|
||||
|
||||
func TestToMap(t *testing.T) {
|
||||
mapRes := ToMap(&Src{
|
||||
Id: 0,
|
||||
Username: "哈哈哈",
|
||||
CreateTime: time.Now(),
|
||||
})
|
||||
fmt.Println(mapRes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user