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
package model
 
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
 
type (
    // EnterpriseScale 企业规模
    EnterpriseScale struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name;type:varchar(255);comment:企业规模名称"`
    }
 
    // EnterpriseScaleSearch 企业规模搜索条件
    EnterpriseScaleSearch struct {
        EnterpriseScale
        Orm *gorm.DB
    }
)
 
func (EnterpriseScale) TableName() string {
    return "enterprise_scale"
}
 
func NewEnterpriseScaleSearch() *EnterpriseScaleSearch {
    return &EnterpriseScaleSearch{
        Orm: mysqlx.GetDB(),
    }
}
 
func (slf *EnterpriseScaleSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&EnterpriseScale{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
 
    return db
}
 
func (slf *EnterpriseScaleSearch) Create(record *EnterpriseScale) error {
    var db = slf.build()
    return db.Create(record).Error
}
 
func (slf *EnterpriseScaleSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&EnterpriseScale{}).Error
}
 
func (slf *EnterpriseScaleSearch) Update(record *EnterpriseScale) error {
    var db = slf.build()
    return db.Updates(record).Error
}
 
func (slf *EnterpriseScaleSearch) Find() (*EnterpriseScale, error) {
    var db = slf.build()
 
    var record EnterpriseScale
    err := db.First(&record).Error
    return &record, err
}
 
func (slf *EnterpriseScaleSearch) FindAll() ([]*EnterpriseScale, error) {
    var db = slf.build()
 
    var record []*EnterpriseScale
    err := db.Find(&record).Error
    return record, err
}
 
func (slf *EnterpriseScaleSearch) Updates(data map[string]interface{}) error {
    var db = slf.build()
    return db.Model(&EnterpriseScale{}).Updates(data).Error
}
 
func (slf *EnterpriseScaleSearch) SetName(name string) *EnterpriseScaleSearch {
    slf.Name = name
    return slf
}
 
func (slf *EnterpriseScaleSearch) SetId(id int) *EnterpriseScaleSearch {
    slf.Id = id
    return slf
}