diff --git a/core/orm/nent/types/gender.go b/core/orm/nent/types/gender.go index 141b2d3..4ac1aac 100644 --- a/core/orm/nent/types/gender.go +++ b/core/orm/nent/types/gender.go @@ -1,16 +1,37 @@ package types +import ( + "git.noahlan.cn/noahlan/ntool/narr" + "git.noahlan.cn/noahlan/ntool/nlog" +) + type Gender string const ( - GenderSecure Gender = "Secure" // 保密 - GenderMale Gender = "Male" // 男 - GenderFemale Gender = "Female" // 女 + GenderSecure Gender = "Secure" // 保密 + GenderMale Gender = "Male" // 男 + GenderFemale Gender = "Female" // 女 ) +var genderVals = []string{ + string(GenderSecure), + string(GenderMale), + string(GenderFemale), +} + func (Gender) Values() (kinds []string) { - for _, s := range []Gender{GenderSecure, GenderMale, GenderFemale} { - kinds = append(kinds, string(s)) - } - return + kinds = genderVals + return +} + +func (g Gender) String() string { + return string(g) +} + +func ParseGender(str string) Gender { + if narr.StringsHas(genderVals, str) { + return Gender(str) + } + nlog.Errorf("转换 %s 到 Gender类型 失败,使用Secure替代", str) + return GenderSecure } diff --git a/core/orm/nent/types/status.go b/core/orm/nent/types/status.go index b65be02..f0ac539 100644 --- a/core/orm/nent/types/status.go +++ b/core/orm/nent/types/status.go @@ -1,17 +1,39 @@ package types +import ( + "git.noahlan.cn/noahlan/ntool/narr" + "git.noahlan.cn/noahlan/ntool/nlog" +) + type Status string const ( - StatusNormal Status = "Normal" // 正常状态 - StatusPending Status = "Pending" // 等待状态 - StatusDisabled Status = "Disabled" // 禁用 - StatusLocked Status = "Locked" // 锁定 + StatusNormal Status = "Normal" // 正常状态 + StatusPending Status = "Pending" // 等待状态 + StatusDisabled Status = "Disabled" // 禁用 + StatusLocked Status = "Locked" // 锁定 ) +var statusVals = []string{ + string(StatusNormal), + string(StatusPending), + string(StatusDisabled), + string(StatusLocked), +} + func (Status) Values() (kinds []string) { - for _, s := range []Status{StatusNormal, StatusPending, StatusDisabled, StatusLocked} { - kinds = append(kinds, string(s)) - } - return + kinds = statusVals + return +} + +func (s Status) String() string { + return string(s) +} + +func ParseStatus(str string) Status { + if narr.StringsHas(statusVals, str) { + return Status(str) + } + nlog.Errorf("转换 %s 到 Status类型 失败,使用 Pending 替代", str) + return StatusPending }