From d8c708a30d938ceb87348257add9dc10926044df Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 24 十月 2023 20:08:02 +0800 Subject: [PATCH] 编码规则需求功能开发2 --- model/quotation.go | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/model/quotation.go b/model/quotation.go index 4aff38e..969d34f 100644 --- a/model/quotation.go +++ b/model/quotation.go @@ -2,6 +2,7 @@ import ( "aps_crm/pkg/mysqlx" + "fmt" "gorm.io/gorm" ) @@ -58,6 +59,9 @@ var db = slf.Orm.Model(&Quotation{}) if slf.Id != 0 { db = db.Where("id = ?", slf.Id) + } + if slf.Number != "" { + db = db.Where("number = ?", slf.Number) } if len(slf.SearchMap) > 0 { @@ -128,6 +132,30 @@ return records, total, err } +func (slf *QuotationSearch) Count() (int64, error) { + var db = slf.build() + var total int64 + err := db.Count(&total).Error + return total, err +} + +func (slf *QuotationSearch) 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 +} + func (slf *QuotationSearch) SetId(id int) *QuotationSearch { slf.Id = id return slf @@ -152,6 +180,11 @@ slf.SearchMap = searchMap return slf } + +func (slf *QuotationSearch) SetNumber(number string) *QuotationSearch { + slf.Number = number + return slf +} func (slf *QuotationSearch) SetIds(ids []int) *QuotationSearch { slf.Orm = slf.Orm.Where("id in (?)", ids) return slf -- Gitblit v1.8.0