-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.go
359 lines (340 loc) · 12.1 KB
/
task.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/woocoos/workflow/ent/procinst"
"github.com/woocoos/workflow/ent/task"
)
// Task is the model entity for the Task schema.
type Task struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// TenantID holds the value of the "tenant_id" field.
TenantID int `json:"tenant_id,omitempty"`
// 流程实例ID
ProcInstID int `json:"proc_inst_id,omitempty"`
// 流程定义ID
ProcDefID int `json:"proc_def_id,omitempty"`
// workflow id
ExecutionID string `json:"execution_id,omitempty"`
// run id
RunID string `json:"run_id,omitempty"`
// 流程节点名称
TaskDefKey string `json:"task_def_key,omitempty"`
// 父任务ID
ParentID int `json:"parent_id,omitempty"`
// 任务描述
Comments string `json:"comments,omitempty"`
// 设定的受理人
Assignee string `json:"assignee,omitempty"`
// 任务成员人数
MemberCount int32 `json:"member_count,omitempty"`
// 未任务成员完成人数
UnfinishedCount int32 `json:"unfinished_count,omitempty"`
// 通过数量
AgreeCount int32 `json:"agree_count,omitempty"`
// 会签类型
Kind task.Kind `json:"kind,omitempty"`
// 默认并行false,顺序执行true
Sequential bool `json:"sequential,omitempty"`
// 创建时间
CreatedAt time.Time `json:"created_at,omitempty"`
// 创建时间
UpdatedAt time.Time `json:"updated_at,omitempty"`
// 任务状态
Status task.Status `json:"status,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TaskQuery when eager-loading is set.
Edges TaskEdges `json:"edges"`
selectValues sql.SelectValues
}
// TaskEdges holds the relations/edges for other nodes in the graph.
type TaskEdges struct {
// 流程实例
ProcInst *ProcInst `json:"proc_inst,omitempty"`
// 任务主体
TaskIdentities []*IdentityLink `json:"task_identities,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
// totalCount holds the count of the edges above.
totalCount [2]map[string]int
namedTaskIdentities map[string][]*IdentityLink
}
// ProcInstOrErr returns the ProcInst value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TaskEdges) ProcInstOrErr() (*ProcInst, error) {
if e.loadedTypes[0] {
if e.ProcInst == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: procinst.Label}
}
return e.ProcInst, nil
}
return nil, &NotLoadedError{edge: "proc_inst"}
}
// TaskIdentitiesOrErr returns the TaskIdentities value or an error if the edge
// was not loaded in eager-loading.
func (e TaskEdges) TaskIdentitiesOrErr() ([]*IdentityLink, error) {
if e.loadedTypes[1] {
return e.TaskIdentities, nil
}
return nil, &NotLoadedError{edge: "task_identities"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Task) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case task.FieldSequential:
values[i] = new(sql.NullBool)
case task.FieldID, task.FieldTenantID, task.FieldProcInstID, task.FieldProcDefID, task.FieldParentID, task.FieldMemberCount, task.FieldUnfinishedCount, task.FieldAgreeCount:
values[i] = new(sql.NullInt64)
case task.FieldExecutionID, task.FieldRunID, task.FieldTaskDefKey, task.FieldComments, task.FieldAssignee, task.FieldKind, task.FieldStatus:
values[i] = new(sql.NullString)
case task.FieldCreatedAt, task.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Task fields.
func (t *Task) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case task.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
t.ID = int(value.Int64)
case task.FieldTenantID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field tenant_id", values[i])
} else if value.Valid {
t.TenantID = int(value.Int64)
}
case task.FieldProcInstID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field proc_inst_id", values[i])
} else if value.Valid {
t.ProcInstID = int(value.Int64)
}
case task.FieldProcDefID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field proc_def_id", values[i])
} else if value.Valid {
t.ProcDefID = int(value.Int64)
}
case task.FieldExecutionID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field execution_id", values[i])
} else if value.Valid {
t.ExecutionID = value.String
}
case task.FieldRunID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field run_id", values[i])
} else if value.Valid {
t.RunID = value.String
}
case task.FieldTaskDefKey:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field task_def_key", values[i])
} else if value.Valid {
t.TaskDefKey = value.String
}
case task.FieldParentID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field parent_id", values[i])
} else if value.Valid {
t.ParentID = int(value.Int64)
}
case task.FieldComments:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field comments", values[i])
} else if value.Valid {
t.Comments = value.String
}
case task.FieldAssignee:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field assignee", values[i])
} else if value.Valid {
t.Assignee = value.String
}
case task.FieldMemberCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field member_count", values[i])
} else if value.Valid {
t.MemberCount = int32(value.Int64)
}
case task.FieldUnfinishedCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field unfinished_count", values[i])
} else if value.Valid {
t.UnfinishedCount = int32(value.Int64)
}
case task.FieldAgreeCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field agree_count", values[i])
} else if value.Valid {
t.AgreeCount = int32(value.Int64)
}
case task.FieldKind:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field kind", values[i])
} else if value.Valid {
t.Kind = task.Kind(value.String)
}
case task.FieldSequential:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field sequential", values[i])
} else if value.Valid {
t.Sequential = value.Bool
}
case task.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
t.CreatedAt = value.Time
}
case task.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
t.UpdatedAt = value.Time
}
case task.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
t.Status = task.Status(value.String)
}
default:
t.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Task.
// This includes values selected through modifiers, order, etc.
func (t *Task) Value(name string) (ent.Value, error) {
return t.selectValues.Get(name)
}
// QueryProcInst queries the "proc_inst" edge of the Task entity.
func (t *Task) QueryProcInst() *ProcInstQuery {
return NewTaskClient(t.config).QueryProcInst(t)
}
// QueryTaskIdentities queries the "task_identities" edge of the Task entity.
func (t *Task) QueryTaskIdentities() *IdentityLinkQuery {
return NewTaskClient(t.config).QueryTaskIdentities(t)
}
// Update returns a builder for updating this Task.
// Note that you need to call Task.Unwrap() before calling this method if this Task
// was returned from a transaction, and the transaction was committed or rolled back.
func (t *Task) Update() *TaskUpdateOne {
return NewTaskClient(t.config).UpdateOne(t)
}
// Unwrap unwraps the Task entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (t *Task) Unwrap() *Task {
_tx, ok := t.config.driver.(*txDriver)
if !ok {
panic("ent: Task is not a transactional entity")
}
t.config.driver = _tx.drv
return t
}
// String implements the fmt.Stringer.
func (t *Task) String() string {
var builder strings.Builder
builder.WriteString("Task(")
builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
builder.WriteString("tenant_id=")
builder.WriteString(fmt.Sprintf("%v", t.TenantID))
builder.WriteString(", ")
builder.WriteString("proc_inst_id=")
builder.WriteString(fmt.Sprintf("%v", t.ProcInstID))
builder.WriteString(", ")
builder.WriteString("proc_def_id=")
builder.WriteString(fmt.Sprintf("%v", t.ProcDefID))
builder.WriteString(", ")
builder.WriteString("execution_id=")
builder.WriteString(t.ExecutionID)
builder.WriteString(", ")
builder.WriteString("run_id=")
builder.WriteString(t.RunID)
builder.WriteString(", ")
builder.WriteString("task_def_key=")
builder.WriteString(t.TaskDefKey)
builder.WriteString(", ")
builder.WriteString("parent_id=")
builder.WriteString(fmt.Sprintf("%v", t.ParentID))
builder.WriteString(", ")
builder.WriteString("comments=")
builder.WriteString(t.Comments)
builder.WriteString(", ")
builder.WriteString("assignee=")
builder.WriteString(t.Assignee)
builder.WriteString(", ")
builder.WriteString("member_count=")
builder.WriteString(fmt.Sprintf("%v", t.MemberCount))
builder.WriteString(", ")
builder.WriteString("unfinished_count=")
builder.WriteString(fmt.Sprintf("%v", t.UnfinishedCount))
builder.WriteString(", ")
builder.WriteString("agree_count=")
builder.WriteString(fmt.Sprintf("%v", t.AgreeCount))
builder.WriteString(", ")
builder.WriteString("kind=")
builder.WriteString(fmt.Sprintf("%v", t.Kind))
builder.WriteString(", ")
builder.WriteString("sequential=")
builder.WriteString(fmt.Sprintf("%v", t.Sequential))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(t.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(t.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", t.Status))
builder.WriteByte(')')
return builder.String()
}
// NamedTaskIdentities returns the TaskIdentities named value or an error if the edge was not
// loaded in eager-loading with this name.
func (t *Task) NamedTaskIdentities(name string) ([]*IdentityLink, error) {
if t.Edges.namedTaskIdentities == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := t.Edges.namedTaskIdentities[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (t *Task) appendNamedTaskIdentities(name string, edges ...*IdentityLink) {
if t.Edges.namedTaskIdentities == nil {
t.Edges.namedTaskIdentities = make(map[string][]*IdentityLink)
}
if len(edges) == 0 {
t.Edges.namedTaskIdentities[name] = []*IdentityLink{}
} else {
t.Edges.namedTaskIdentities[name] = append(t.Edges.namedTaskIdentities[name], edges...)
}
}
// Tasks is a parsable slice of Task.
type Tasks []*Task