From 34ef7217a034599217a7fdd1e28e1ae6910e1b4b Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期三, 11 十月 2023 20:15:21 +0800 Subject: [PATCH] 菜单获取编码规则 --- model/util.go | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) diff --git a/model/util.go b/model/util.go index 9e738d9..8ac7156 100644 --- a/model/util.go +++ b/model/util.go @@ -2,8 +2,11 @@ import ( "aps_crm/pkg/mysqlx" + "aps_crm/proto/code" "fmt" "gorm.io/gorm" + "strconv" + "time" ) // WithTransaction 锛� var funcs []func(db *gorm.DB) error锛屾妸鐩稿叧鍑芥暟娣诲姞杩涘幓 @@ -26,3 +29,28 @@ err = tx.Commit().Error return } + +func GetAutoCode(id int, codeStandard *code.CodeStandard) string { + autoCode := "" + var prefixValue string + if codeStandard.AutoRule.PrefixMethod == 2 { // 鏉ユ簮鍗曟嵁 + prefixValue = "" + } else { // 鍥哄畾鍊� + prefixValue = codeStandard.AutoRule.PrefixValue + } + strMaxAutoIncr := strconv.Itoa(id) + count := int(codeStandard.AutoRule.AutoLength) - len(strMaxAutoIncr) + for i := 0; i < count; i++ { + strMaxAutoIncr = "0" + strMaxAutoIncr + } + + var suffixValue string + if codeStandard.AutoRule.SuffixMethod == 2 { // 骞存湀鏃�+鑷闀� + suffixValue = fmt.Sprintf("%v%v", time.Now().Format("20060102"), strMaxAutoIncr) + } else { // 鑷闀� + suffixValue = strMaxAutoIncr + } + + autoCode = prefixValue + suffixValue + return autoCode +} -- Gitblit v1.8.0