From 6aa75c2a266a2522ae713b13dc702b5ad0a08f87 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 24 十月 2023 13:50:23 +0800 Subject: [PATCH] 编码规则需求功能开发 --- model/serviceOrder.go | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/model/serviceOrder.go b/model/serviceOrder.go index f593b5c..3440357 100644 --- a/model/serviceOrder.go +++ b/model/serviceOrder.go @@ -134,6 +134,9 @@ if len(slf.ServiceManIds) > 0 { db = db.Where("service_man_id in ?", slf.ServiceManIds) } + if slf.Number != "" { + db = db.Where("number = ?", slf.Number) + } return db } @@ -216,6 +219,11 @@ return slf } +func (slf *ServiceOrderSearch) SetNumber(number string) *ServiceOrderSearch { + slf.Number = number + return slf +} + func (slf *ServiceOrderSearch) First() (*ServiceOrder, error) { var db = slf.build() var record = new(ServiceOrder) @@ -260,3 +268,27 @@ var db = slf.build() return db.Updates(data).Error } + +func (slf *ServiceOrderSearch) Count() (int64, error) { + var db = slf.build() + var total int64 + err := db.Count(&total).Error + return total, err +} + +func (slf *ServiceOrderSearch) 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