From 33b23ccb75daf065ad5e1a2051d713305100cb13 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Mon, 3 Jul 2023 15:43:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0Gender=E5=92=8CStatus?= =?UTF-8?q?=E7=9A=84=E5=BF=AB=E9=80=9Fparse=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/orm/nent/types/gender.go | 35 +++++++++++++++++++++++++------- core/orm/nent/types/status.go | 38 +++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 15 deletions(-) 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 }