zhangqian
2023-08-17 a934b5ea45f84c71d9d309a1c69bfa21d1898b4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package model
 
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
 
type (
    // ClientType 客户类型
    ClientType struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:客户类型名称"`
    }
 
    // ClientTypeSearch 客户类型搜索条件
    ClientTypeSearch struct {
        ClientType
        Orm *gorm.DB
    }
)
 
func (ClientType) TableName() string {
    return "client_type"
}
 
func NewClientTypeSearch() *ClientTypeSearch {
    return &ClientTypeSearch{
        Orm: mysqlx.GetDB(),
    }
}
 
func (slf *ClientTypeSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&ClientType{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
 
    return db
}
 
func (slf *ClientTypeSearch) Create(record *ClientType) error {
    var db = slf.build()
    return db.Create(record).Error
}
 
func (slf *ClientTypeSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&ClientType{}).Error
}
 
func (slf *ClientTypeSearch) Update(record *ClientType) error {
    var db = slf.build()
    return db.Updates(record).Error
}
 
func (slf *ClientTypeSearch) Find() (*ClientType, error) {
    var db = slf.build()
    var record = new(ClientType)
    err := db.First(record).Error
    return record, err
}
 
func (slf *ClientTypeSearch) FindAll() ([]*ClientType, error) {
    var db = slf.build()
    var records = make([]*ClientType, 0)
    err := db.Find(&records).Error
    return records, err
}
 
func (slf *ClientTypeSearch) SetId(id int) *ClientTypeSearch {
    slf.Id = id
    return slf
}
 
func (slf *ClientTypeSearch) SetName(name string) *ClientTypeSearch {
    slf.Name = name
    return slf
}
 
func (slf *ClientTypeSearch) First() (*ClientType, error) {
    var db = slf.build()
    var record = new(ClientType)
    err := db.First(record).Error
    return record, err
}
 
func (slf *ClientTypeSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}