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