From b9923a20b59938e59b3e57defee16a29a0c90a56 Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期五, 12 七月 2024 15:52:31 +0800 Subject: [PATCH] 产量登记表添加自动编号 --- constvar/const.go | 5 +++-- models/yield_register.go | 17 +++++++++++++++++ controllers/dict.go | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/constvar/const.go b/constvar/const.go index 97dccc0..81d8672 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -20,8 +20,9 @@ type CodeStandardType int const ( - CodeStandardType_Workshop CodeStandardType = iota + 1 - CodeStandardType_Fineness + CodeStandardType_Workshop CodeStandardType = iota + 1 // 杞﹂棿 + CodeStandardType_Fineness // 绾ゅ害鐧昏 + CodeStandardType_Yield // 浜ч噺鐧昏 ) type CarFlag int diff --git a/controllers/dict.go b/controllers/dict.go index 7155392..d2d4d8b 100644 --- a/controllers/dict.go +++ b/controllers/dict.go @@ -188,6 +188,9 @@ case constvar.CodeStandardType_Fineness: id, err = models.NewFinenessRegisterSearch().MaxAutoIncr() prefix = "XD" + case constvar.CodeStandardType_Yield: + id, err = models.NewYieldRegisterSearch().MaxAutoIncr() + prefix = "Cl" default: util.ResponseFormat(c, code.RequestParamError, "缂栫爜瑙勫垯涓嶅瓨鍦�") return diff --git a/models/yield_register.go b/models/yield_register.go index b22e269..489a38a 100644 --- a/models/yield_register.go +++ b/models/yield_register.go @@ -228,3 +228,20 @@ } return total, nil } + +func (slf *YieldRegisterSearch) MaxAutoIncr() (int, error) { + type Result struct { + Max int + } + + var ( + result Result + db = slf.build() + ) + + err := db.Select("MAX(id) as max").Scan(&result).Error + if err != nil { + return result.Max, fmt.Errorf("max err: %v", err) + } + return result.Max, nil +} -- Gitblit v1.8.0