zhangqian
2024-04-19 cdb38521ea1f662b53bafb87412c38dfd0d5e11d
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
package test
 
import (
    "srm/global"
    "srm/model/common/request"
    "srm/model/test"
    testReq "srm/model/test/request"
)
 
type SupplierTypeService struct {
}
 
// CreateSupplierType 创建SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) CreateSupplierType(st *test.SupplierType) (err error) {
    err = global.GVA_DB.Create(st).Error
    return err
}
 
// DeleteSupplierType 删除SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) DeleteSupplierType(st test.SupplierType) (err error) {
    err = global.GVA_DB.Delete(&st).Error
    return err
}
 
// DeleteSupplierTypeByIds 批量删除SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) DeleteSupplierTypeByIds(ids request.IdsReq) (err error) {
    err = global.GVA_DB.Delete(&[]test.SupplierType{}, "id in ?", ids.Ids).Error
    return err
}
 
// UpdateSupplierType 更新SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) UpdateSupplierType(st test.SupplierType) (err error) {
    err = global.GVA_DB.Updates(&st).Error
    return err
}
 
// GetSupplierType 根据id获取SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) GetSupplierType(id uint) (st test.SupplierType, err error) {
    err = global.GVA_DB.Where("id = ?", id).First(&st).Error
    return
}
 
// GetSupplierTypeInfoList 分页获取SupplierType记录
// Author [piexlmax](https://github.com/piexlmax)
func (stService *SupplierTypeService) GetSupplierTypeInfoList(info testReq.SupplierTypeSearch) (list []test.SupplierType, total int64, err error) {
    limit := info.PageSize
    offset := info.PageSize * (info.Page - 1)
    // 创建db
    db := global.GVA_DB.Model(&test.SupplierType{})
    var sts []test.SupplierType
    // 如果有条件搜索 下方会自动创建搜索语句
    if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
        db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
    }
    err = db.Count(&total).Error
    if err != nil {
        return
    }
 
    err = db.Limit(limit).Offset(offset).Find(&sts).Error
    return sts, total, err
}
 
func (stService *SupplierTypeService) DeleteAll() (err error) {
    err = global.GVA_DB.Where("1=1").Delete(&[]test.SupplierType{}).Error
    return err
}