zhangqian
2023-08-26 5193dcb9336e853502baf8a539d3f45efebe2f86
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 IndustryService struct {
}
 
// CreateIndustry 创建Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) CreateIndustry(i *test.Industry) (err error) {
    err = global.GVA_DB.Create(i).Error
    return err
}
 
// DeleteIndustry 删除Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) DeleteIndustry(i test.Industry) (err error) {
    err = global.GVA_DB.Delete(&i).Error
    return err
}
 
// DeleteIndustryByIds 批量删除Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) DeleteIndustryByIds(ids request.IdsReq) (err error) {
    err = global.GVA_DB.Delete(&[]test.Industry{}, "id in ?", ids.Ids).Error
    return err
}
 
// UpdateIndustry 更新Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) UpdateIndustry(i test.Industry) (err error) {
    err = global.GVA_DB.Save(&i).Error
    return err
}
 
// GetIndustry 根据id获取Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) GetIndustry(id uint) (i test.Industry, err error) {
    err = global.GVA_DB.Where("id = ?", id).First(&i).Error
    return
}
 
// GetIndustryInfoList 分页获取Industry记录
// Author [piexlmax](https://github.com/piexlmax)
func (iService *IndustryService) GetIndustryInfoList(info testReq.IndustrySearch) (list []test.Industry, total int64, err error) {
    limit := info.PageSize
    offset := info.PageSize * (info.Page - 1)
    // 创建db
    db := global.GVA_DB.Model(&test.Industry{})
    var is []test.Industry
    // 如果有条件搜索 下方会自动创建搜索语句
    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(&is).Error
    return is, total, err
}
 
func (iService *IndustryService) DeleteAll() (err error) {
    err = global.GVA_DB.Where("1=1").Delete(&[]test.Industry{}).Error
    return err
}