/
ci_data.go
323 lines (281 loc) · 9.28 KB
/
ci_data.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
package models
import (
"fmt"
"sort"
"strings"
)
type CiDataMapObj map[string]string
type CiDataColumnObj struct {
ColumnName string
ColumnValue interface{}
ValueString string
}
type AutofillObj struct {
Type string `json:"type"`
Value string `json:"value"`
}
type AutofillValueObj struct {
CiTypeId string `json:"ciTypeId"`
ParentRs *AutofillValueAttrObj `json:"parentRs"`
Filters []*AutofillFilterObj `json:"filters"`
}
type AutofillValueAttrObj struct {
AttrId string `json:"attrId"`
IsReferedFromParent int `json:"isReferedFromParent"`
}
type AutofillFilterObj struct {
Name string `json:"name"`
Code string `json:"code"`
Operator string `json:"operator"`
Type string `json:"type"`
Value interface{} `json:"value"`
CiType string `json:"-"`
}
type SysStateMachineTable struct {
Id string `json:"id" xorm:"id"`
Description string `json:"description" xorm:"description"`
StartState string `json:"startState" xorm:"start_state"`
FinalState string `json:"finalState" xorm:"final_state"`
}
type GetStateMachineList struct {
Id string `json:"id" xorm:"id"`
Description string `json:"description" xorm:"description"`
StartState string `json:"startState" xorm:"start_state"`
FinalState string `json:"finalState" xorm:"final_state"`
States []*SysStateTable `json:"states"`
Transitions []*SysStateTransitionTable `json:"transitions"`
}
type ImportStateMachineResult struct {
DiffFlag bool `json:"diff_flag"`
StateMachine *SysStateMachineTable `json:"state_machine"`
OldStates []*SysStateTable `json:"old_states"`
NewStates []*SysStateTable `json:"new_states"`
OldTransitions []*SysStateTransitionTable `json:"old_transitions"`
NewTransitions []*SysStateTransitionTable `json:"new_transitions"`
}
type SysStateTable struct {
Id string `json:"id" xorm:"id"`
Name string `json:"name" xorm:"name"`
Description string `json:"description" xorm:"description"`
StateMachine string `json:"stateMachine" xorm:"state_machine"`
UniquePathTrigger string `json:"uniquePathTrigger" xorm:"unique_path_trigger"`
IsConfirm string `json:"isConfirm" xorm:"is_confirm"`
}
type SysStateTransitionTable struct {
Guid string `json:"guid" xorm:"guid"`
StateMachine string `json:"stateMachine" xorm:"state_machine"`
CurrentState string `json:"currentState" xorm:"current_state"`
TargetState string `json:"targetState" xorm:"target_state"`
Operation string `json:"operation" xorm:"operation"`
OperationEn string `json:"operation_en" xorm:"operation_en"`
Permission string `json:"permission" xorm:"permission"`
Action string `json:"action" xorm:"action"`
OperationFormType string `json:"operationFormType" xorm:"operation_form_type"`
OperationMultiple string `json:"operationMultiple" xorm:"operation_multiple"`
}
type SysStateTransitionQuery struct {
CiType string `json:"ci_type" xorm:"ci_type"`
Guid string `json:"guid" xorm:"guid"`
StateMachine string `json:"stateMachine" xorm:"state_machine"`
CurrentState string `json:"currentState" xorm:"current_state"`
CurrentStateName string `json:"currentStateName" xorm:"current_state_name"`
TargetState string `json:"targetState" xorm:"target_state"`
TargetStateName string `json:"targetStateName" xorm:"target_state_name"`
TargetIsConfirm string `json:"targetIsConfirm" xorm:"target_is_confirm"`
TargetUniquePath string `json:"targetUniquePath" xorm:"target_unique_path"`
Operation string `json:"operation" xorm:"operation"`
OperationEn string `json:"operation_en" xorm:"operation_en"`
Action string `json:"action" xorm:"action"`
StartState string `json:"start_state" xorm:"start_state"`
FinalState string `json:"final_state" xorm:"final_state"`
}
type BuildAttrValueParam struct {
IsSystem bool
NowTime string
AttributeConfig *SysCiTypeAttrTable
InputData CiDataMapObj
Action string
FromCore bool
NowData CiDataMapObj
}
type ActionFuncParam struct {
CiType string
Attributes []*SysCiTypeAttrTable
ReferenceAttributes []*SysCiTypeAttrTable
Transition *SysStateTransitionQuery
InputData CiDataMapObj
NowData CiDataMapObj
Operator string
Operation string
NowTime string
RefCiTypeMap map[string]*SysCiTypeTable
UpdateColumn []string
BareAction string
DeleteList []string
FromCore bool
MultiColumnDelMap map[string][]string
}
type MultiCiDataObj struct {
CiTypeId string
Transition []*SysStateTransitionQuery
Attributes []*SysCiTypeAttrTable
ReferenceAttributes []*SysCiTypeAttrTable
NowData []map[string]string
InputData []CiDataMapObj
RefCiTypeMap map[string]*SysCiTypeTable
}
type AttrRefFilterLegalObj struct {
AttrName string
GuidMap map[string]bool
}
type CiQueryColumnObj struct {
Name string
Index int
}
type CiDataRefDataObj struct {
Guid string `json:"guid"`
KeyName string `json:"key_name"`
HistoryTime string `json:"-"`
}
type CiDataRefFilterRight struct {
Type string `json:"type"`
Value interface{} `json:"value"`
}
type CiDataRefFilterObj struct {
Left string `json:"left"`
Operator string `json:"operator"`
Right CiDataRefFilterRight `json:"right"`
}
type HistoryGuidObj struct {
Guid string
HistoryTime string
}
type CiDataQueryRefAttrObj struct {
Attribute *SysCiTypeAttrTable
GuidList []string
HistoryGuidList []*HistoryGuidObj
RefObj map[string]*CiDataRefDataObj
MultiGuidList []string
MultiRefObj map[string][]*CiDataRefDataObj
}
type CiQueryColumnList []*CiQueryColumnObj
func (c CiQueryColumnList) Len() int {
return len(c)
}
func (c CiQueryColumnList) Swap(i, j int) {
c[i], c[j] = c[j], c[i]
}
func (c CiQueryColumnList) Less(i, j int) bool {
if c[i].Index == c[j].Index {
return c[i].Name < c[j].Name
}
return c[i].Index < c[j].Index
}
func (c CiQueryColumnList) GetNameList() []string {
sort.Sort(c)
nameList := []string{}
for _, v := range c {
nameList = append(nameList, v.Name)
}
return nameList
}
// Try to build sql to impl autofill
type AutofillRuleList []*AutofillValueObj
func (af AutofillRuleList) BuildBaseSql(prefix string) (sql, column string) {
afLen := len(af)
if afLen < 2 {
return
} else if afLen == 2 {
column = af[1].ParentRs.AttrId
column = column[strings.Index(column, "#")+1:]
return
}
var whereSql string
column = af[1].ParentRs.AttrId
column = column[strings.Index(column, "#")+1:]
if af[1].ParentRs.IsReferedFromParent == 1 {
whereSql = fmt.Sprintf(" where %st1.guid=?", prefix)
} else {
whereSql = fmt.Sprintf(" where %st1.%s=?", prefix, column)
column = "guid"
}
sql = fmt.Sprintf("select %st%d.%s from ", prefix, afLen-1, af[afLen-1].ParentRs.AttrId[strings.Index(af[afLen-1].ParentRs.AttrId, "#")+1:])
for i, rule := range af {
if i == 0 {
continue
}
if rule.ParentRs.IsReferedFromParent == 0 && len(af[i].Filters) > 0 {
continue
}
if i == 1 {
sql += fmt.Sprintf(" %s %st%d ", af[i].CiTypeId, prefix, i)
continue
}
if rule.ParentRs.IsReferedFromParent == 1 {
sql += fmt.Sprintf(" left join %s %st%d on %st%d.%s=%s.guid ", af[i].CiTypeId, prefix, i, prefix, i-1,
af[i].ParentRs.AttrId[strings.Index(af[i].ParentRs.AttrId, "#")+1:], af[i].CiTypeId)
} else {
sql += fmt.Sprintf(" right join %s %st%d on %st%d.%s=%s.guid ", af[i].CiTypeId, prefix, i, prefix, i-1,
af[i].ParentRs.AttrId[strings.Index(af[i].ParentRs.AttrId, "#")+1:], af[i].CiTypeId)
}
}
sql += whereSql
return
}
type AttrAutofillSortObj struct {
AttrName string `json:"attr_name"`
Attr *SysCiTypeAttrTable `json:"attr"`
Dep []string `json:"type"`
PValue int `json:"value"`
Link []string `json:"link"`
}
type AttrAutofillSortList []*AttrAutofillSortObj
func (a AttrAutofillSortList) Len() int {
return len(a)
}
func (a AttrAutofillSortList) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a AttrAutofillSortList) Less(i, j int) bool {
return a[i].PValue > a[j].PValue
}
type AutofillChainObj struct {
Guid string
UpdateColumn []string
MultiColumnDelMap map[string][]string
}
type AutofillChainCiColumn struct {
AttrId string
CiTypeId string
CiAttrName string
AutofillRule string
UsedColumn []string
UpdatedSubMap map[string][]string
DeleteList []string
}
type AutoActiveHandleParam struct {
Data []map[string]string
CiType string
Operation string
User string
}
type CiDataObjectErrOutput struct {
Error string `json:"error"`
Content string `json:"content"`
}
type HandleCiDataParam struct {
InputData []CiDataMapObj
CiTypeId string
Operation string
Operator string
BareAction string
Roles []string
Permission bool
FromCore bool
UserToken string
}
type SysCiImportGuidMap struct {
Id int `json:"id" xorm:"id"`
Source string `json:"source" xorm:"source"`
Target string `json:"target" xorm:"target"`
}