From 3369456ac6de01e8703a9b38537406ec7c550bc5 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 25 八月 2023 11:05:45 +0800
Subject: [PATCH] fix
---
model/contract.go | 79 +++++++++++++++++++++++++++------------
1 files changed, 54 insertions(+), 25 deletions(-)
diff --git a/model/contract.go b/model/contract.go
index 024cf8b..2597428 100644
--- a/model/contract.go
+++ b/model/contract.go
@@ -7,26 +7,29 @@
type (
Contract struct {
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
- MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
- Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
- QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
- Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"`
- StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"`
- File string `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
- gorm.Model `json:"-"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+ Client Client `json:"client" gorm:"foreignKey:ClientId"`
+ MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+ Member User `json:"member" gorm:"foreignKey:MemberId"`
+ Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
+ QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+ Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"`
+ StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"`
+ ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:StatusId;references:Id"`
+ File string `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
+ CreatedAt *CustomTime `json:"created_at" gorm:"column:created_at;type:datetime;comment:鍒涘缓鏃堕棿"`
+ gormModel
}
ContractSearch struct {
Contract
- Orm *gorm.DB
- Keyword string
- OrderBy string
- PageNum int
- PageSize int
-
+ Orm *gorm.DB
+ SearchMap map[string]interface{}
+ OrderBy string
+ PageNum int
+ PageSize int
}
)
@@ -42,11 +45,33 @@
func (slf *ContractSearch) build() *gorm.DB {
var db = slf.Orm.Model(&Contract{})
- if slf.Keyword != "" {
- db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
- }
+
if slf.Id != 0 {
db = db.Where("id = ?", slf.Id)
+ }
+
+ if len(slf.SearchMap) > 0 {
+ for key, value := range slf.SearchMap {
+ switch v := value.(type) {
+ case string:
+ if key == "client_name" {
+ db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "member_name" {
+ db = db.Joins("User").Where("User.username LIKE ?", "%"+v+"%")
+ }
+
+ if key == "number" {
+ db = db.Where("number LIKE ?", "%"+v+"%")
+ }
+
+ if key == "created_at" {
+ db = db.Where(key+"= ?", v)
+ }
+ case int:
+ }
+ }
}
return db
@@ -89,17 +114,12 @@
db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
}
- err := db.Preload("Quotation").Find(&records).Error
+ err := db.Preload("ServiceContractStatus").Preload("Client").Preload("Member").Preload("Quotation").Order("id desc").Find(&records).Error
return records, total, err
}
func (slf *ContractSearch) SetId(id int) *ContractSearch {
slf.Id = id
- return slf
-}
-
-func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch {
- slf.Keyword = keyword
return slf
}
@@ -111,4 +131,13 @@
func (slf *ContractSearch) SetOrder(order string) *ContractSearch {
slf.OrderBy = order
return slf
-}
\ No newline at end of file
+}
+
+func (slf *ContractSearch) SetSearchMap(data map[string]interface{}) *ContractSearch {
+ slf.SearchMap = data
+ return slf
+}
+func (slf *ContractSearch) SetIds(ids []int) *ContractSearch {
+ slf.Orm = slf.Orm.Where("id in (?)", ids)
+ return slf
+}
--
Gitblit v1.8.0