/
sail.gen.publish_strategy.go
255 lines (217 loc) · 5.96 KB
/
sail.gen.publish_strategy.go
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package repo
import (
"context"
"fmt"
"github.com/HYY-yu/sail/internal/service/sail/model"
"gorm.io/gorm"
)
// Code generated by gormt. DO NOT EDIT.
// 非线程安全
type _PublishStrategyMgr struct {
*_BaseMgr
}
// PublishStrategyMgr open func
func PublishStrategyMgr(ctx context.Context, db *gorm.DB) *_PublishStrategyMgr {
if db == nil {
panic(fmt.Errorf("PublishStrategyMgr need init by db"))
}
ctx, cancel := context.WithCancel(ctx)
return &_PublishStrategyMgr{_BaseMgr: &_BaseMgr{DB: db.Table("publish_strategy").WithContext(ctx), isRelated: globalIsRelated, ctx: ctx, cancel: cancel}}
}
func (obj *_PublishStrategyMgr) WithSelects(idName string, selects ...string) *_PublishStrategyMgr {
if len(idName) > 0 {
selects = append(selects, idName)
}
if len(selects) > 0 {
// 对Select进行去重
selectMap := make(map[string]int, len(selects))
for _, e := range selects {
if _, ok := selectMap[e]; !ok {
selectMap[e] = 1
}
}
newSelects := make([]string, 0, len(selects))
for k := range selectMap {
if len(k) > 0 {
newSelects = append(newSelects, k)
}
}
obj.DB = obj.DB.Select(newSelects)
}
return obj
}
func (obj *_PublishStrategyMgr) WithOptions(opts ...Option) *_PublishStrategyMgr {
obj.Reset()
options := options{
query: make(map[string]queryData, len(opts)),
}
for _, o := range opts {
o.apply(&options)
}
for k, v := range options.query {
if v.data == nil {
obj.DB = obj.DB.Where(k + " " + v.cond)
} else {
obj.DB = obj.DB.Where(k+" "+v.cond, v.data)
}
}
return obj
}
// GetTableName get sql table name.获取表名字
func (obj *_PublishStrategyMgr) GetTableName() string {
return "publish_strategy"
}
// Tx 开启事务会话
func (obj *_PublishStrategyMgr) Tx(tx *gorm.DB) *_PublishStrategyMgr {
obj.DB = tx.Table(obj.GetTableName()).WithContext(obj.ctx)
return obj
}
// WithPrepareStmt 开启语句 PrepareStmt 功能
// 接下来执行的SQL将会是PrepareStmt的
func (obj *_PublishStrategyMgr) WithPrepareStmt() {
obj.DB = obj.DB.Session(&gorm.Session{Context: obj.ctx, PrepareStmt: true})
}
// Reset 重置gorm会话
func (obj *_PublishStrategyMgr) Reset() *_PublishStrategyMgr {
obj.DB = obj.DB.Session(&gorm.Session{NewDB: true, Context: obj.ctx}).Table(obj.GetTableName())
return obj
}
// Get 获取
func (obj *_PublishStrategyMgr) Get() (result model.PublishStrategy, err error) {
err = obj.DB.Find(&result).Error
return
}
// Gets 获取批量结果
func (obj *_PublishStrategyMgr) Gets() (results []model.PublishStrategy, err error) {
err = obj.DB.Find(&results).Error
return
}
// Catch 必须获取结果(单条)
func (obj *_PublishStrategyMgr) Catch() (results model.PublishStrategy, err error) {
err = obj.DB.Take(&results).Error
return
}
func (obj *_PublishStrategyMgr) Count() (count int64, err error) {
err = obj.DB.Count(&count).Error
return
}
func (obj *_PublishStrategyMgr) HasRecord() (bool, error) {
count, err := obj.Count()
if err != nil {
return false, err
}
return count != 0, nil
}
// WithID id获取
func (obj *_PublishStrategyMgr) WithID(id interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["id"] = queryData{
cond: cond[0],
data: id,
}
})
}
// WithPublishID publish_id获取
func (obj *_PublishStrategyMgr) WithPublishID(publishID interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["publish_id"] = queryData{
cond: cond[0],
data: publishID,
}
})
}
// WithType type获取 发布类型
func (obj *_PublishStrategyMgr) WithType(_type interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["type"] = queryData{
cond: cond[0],
data: _type,
}
})
}
// WithData data获取
func (obj *_PublishStrategyMgr) WithData(data interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["data"] = queryData{
cond: cond[0],
data: data,
}
})
}
// WithStatus status获取
func (obj *_PublishStrategyMgr) WithStatus(status interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["status"] = queryData{
cond: cond[0],
data: status,
}
})
}
// WithResult result获取
func (obj *_PublishStrategyMgr) WithResult(result interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["result"] = queryData{
cond: cond[0],
data: result,
}
})
}
// WithCreateTime create_time获取
func (obj *_PublishStrategyMgr) WithCreateTime(createTime interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["create_time"] = queryData{
cond: cond[0],
data: createTime,
}
})
}
// WithUpdateTime update_time获取
func (obj *_PublishStrategyMgr) WithUpdateTime(updateTime interface{}, cond ...string) Option {
return optionFunc(func(o *options) {
if len(cond) == 0 {
cond = []string{" = ? "}
}
o.query["update_time"] = queryData{
cond: cond[0],
data: updateTime,
}
})
}
func (obj *_PublishStrategyMgr) CreatePublishStrategy(bean *model.PublishStrategy) (err error) {
err = obj.DB.Create(bean).Error
return
}
func (obj *_PublishStrategyMgr) UpdatePublishStrategy(bean *model.PublishStrategy) (err error) {
err = obj.DB.Updates(bean).Error
return
}
func (obj *_PublishStrategyMgr) DeletePublishStrategy(bean *model.PublishStrategy) (err error) {
err = obj.DB.Delete(bean).Error
return
}
// FetchIndexByPublishID 获取多个内容
func (obj *_PublishStrategyMgr) FetchIndexByPublishID(publishID int) (results []*model.PublishStrategy, err error) {
err = obj.DB.WithContext(obj.ctx).Model(model.PublishStrategy{}).Where("`publish_id` = ?", publishID).Find(&results).Error
return
}