From 12e09639dcbfa63b5a23cde8642b72829d4f3a3b Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 10 八月 2023 11:42:31 +0800 Subject: [PATCH] Merge branch 'zq' --- model/serviceContract.go | 84 +++++++++++++++++++++++------------------ 1 files changed, 47 insertions(+), 37 deletions(-) diff --git a/model/serviceContract.go b/model/serviceContract.go index 5c5a497..651ad73 100644 --- a/model/serviceContract.go +++ b/model/serviceContract.go @@ -11,26 +11,32 @@ type ( ServiceContract struct { - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` - Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` - MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` - ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` - SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"` - ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:鍚堝悓id"` - QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"` - ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"` - SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"` - StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"` - EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"` - ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:鍚堝悓鐘舵�乮d"` - ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"` - Terms string `json:"terms" gorm:"column:terms;type:text;comment:鏉℃"` - Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` - AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦 - AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 宸叉敹閲戦 - AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 宸插紑绁ㄩ噾棰� - Products []Product `json:"products" gorm:"many2many:serviceContract_product;"` + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"` + Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"` + MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` + ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"` + SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"` + SaleChance SaleChance `json:"SaleChance" gorm:"foreignKey:SaleChanceId"` + SalesDetailsId int `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:鍚堝悓璁㈠崟id"` + SalesDetails SalesDetails `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"` + QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"` + Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId"` + ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"` + ServiceContractType ServiceContractType `json:"serviceContractType" gorm:"foreignKey:ServiceContractTypeId"` + SignTime string `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"` + StartTime string `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"` + EndTime string `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"` + ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:鍚堝悓鐘舵�乮d"` + ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:ServiceContractStatusId"` + ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"` + Terms string `json:"terms" gorm:"column:terms;type:text;comment:鏉℃"` + Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"` + AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦 + AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 宸叉敹閲戦 + AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 宸插紑绁ㄩ噾棰� + AmountUnInvoiced decimal.Decimal `gorm:"-" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰� + Products []*Product `json:"products" gorm:"many2many:service_contract_product;"` gorm.Model `json:"-"` } @@ -44,6 +50,7 @@ OrderBy string PageNum int PageSize int + Preload bool } ) @@ -64,13 +71,13 @@ } switch slf.QueryClass { case constvar.ServiceContractQueryClassExpireAfter30Day: - db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 30)) + db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 30).Format("2006-01-02")) case constvar.ServiceContractQueryClassExpireAfter60Day: - db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 60)) + db = db.Where("end_time > ?", time.Now().AddDate(0, 0, 60).Format("2006-01-02")) case constvar.ServiceContractQueryClassExpiredBefore15Day: - db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15)) + db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15).Format("2006-01-02")) case constvar.ServiceContractQueryClassExpiredBefore60Day: - db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60)) + db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60).Format("2006-01-02")) } switch slf.KeywordType { @@ -97,6 +104,15 @@ //todo } + if slf.Preload { + db = db. + Preload("SaleChance"). + Preload("SalesDetails"). + Preload("Quotation"). + Preload("ServiceContractType"). + Preload("ServiceContractStatus"). + Preload("Products") + } return db } @@ -116,14 +132,7 @@ return db.Delete(&ServiceContract{}).Error } -func (slf *ServiceContractSearch) Find() (*ServiceContract, error) { - var db = slf.build() - var record = &ServiceContract{} - err := db.First(record).Error - return record, err -} - -func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) { +func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) { var db = slf.build() var records = make([]*ServiceContract, 0) var total int64 @@ -134,11 +143,7 @@ db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } - if slf.PageNum > 0 && slf.PageSize > 0 { - db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) - } - - err := db.Preload("Products").Find(&records).Error + err := db.Find(&records).Error return records, total, err } @@ -176,6 +181,11 @@ return slf } +func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch { + slf.Preload = preload + return slf +} + func (slf *ServiceContractSearch) UpdateByMap(upMap map[string]interface{}) error { var ( db = slf.build() -- Gitblit v1.8.0