forked from cookieY/Yearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.go
197 lines (175 loc) · 6.92 KB
/
modal.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
// Copyright 2019 HenryYee.
//
// Licensed under the AGPL, Version 3.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.gnu.org/licenses/agpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package model
import (
"bytes"
"database/sql/driver"
"errors"
)
type JSON []byte
func (j JSON) Value() (driver.Value, error) {
if j.IsNull() {
return nil, nil
}
return string(j), nil
}
func (j *JSON) Scan(value interface{}) error {
if value == nil {
*j = nil
return nil
}
s, ok := value.([]byte)
if !ok {
return errors.New("Invalid Scan Source")
}
*j = append((*j)[0:0], s...)
return nil
}
func (m JSON) MarshalJSON() ([]byte, error) {
if m == nil {
return []byte("null"), nil
}
return m, nil
}
func (m *JSON) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("null point exception")
}
*m = append((*m)[0:0], data...)
return nil
}
func (j JSON) IsNull() bool {
return len(j) == 0 || string(j) == "null"
}
func (j JSON) Equals(j1 JSON) bool {
return bytes.Equal([]byte(j), []byte(j1))
}
type CoreAccount struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT";json:"id"`
Username string `gorm:"type:varchar(50);not null;index:user_idx";json:"username"`
Password string `gorm:"type:varchar(150);not null";json:"password"`
Rule string `gorm:"type:varchar(10);not null";json:"rule"`
Department string `gorm:"type:varchar(50);";json:"department"`
RealName string `gorm:"type:varchar(50);";json:"realname"`
Email string `gorm:"type:varchar(50);";json:"email"`
}
type CoreGlobalConfiguration struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT";json:"id"`
Authorization string `gorm:"type:varchar(50);not null";json:"authorization"`
Ldap JSON `gorm:"type:json;";json:"ldap"`
Message JSON `gorm:"type:json;";json:"message"`
Other JSON `gorm:"type:json;";json:"other"`
Stmt uint `gorm:"type:tinyint(2) not null default 0"`
AuditRole JSON `gorm:"type:json;";json:"audit_role"`
}
type CoreSqlRecord struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT";json:"id"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
SQL string `gorm:"type:longtext;not null"`
State string `gorm:"type:varchar(50);not null;"`
Affectrow uint `gorm:"type:int(50);not null;"`
Time string `gorm:"type:varchar(50);not null;"`
Error string `gorm:"type:longtext"`
}
type CoreSqlOrder struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
Username string `gorm:"type:varchar(50);not null;index:query_idx"`
Status uint `gorm:"type:tinyint(2);not null;"`
Type uint `gorm:"type:tinyint(2);not null"`
Backup uint `gorm:"type:tinyint(2);not null"`
IDC string `gorm:"type:varchar(50);not null"`
Source string `gorm:"type:varchar(50);not null"`
DataBase string `gorm:"type:varchar(50);not null"`
Table string `gorm:"type:varchar(50);not null"`
Date string `gorm:"type:varchar(50);not null"`
SQL string `gorm:"type:longtext;not null"`
Text string `gorm:"type:longtext;not null"`
Assigned string `gorm:"type:varchar(50);not null"`
Delay string `gorm:"type:varchar(50);not null;default:'none'"`
Rejected string `gorm:"type:longtext;"`
RealName string `gorm:"type:varchar(50);not null"`
Executor string `gorm:"type:varchar(50);"`
ExecuteTime string `gorm:"type:varchar(50);"`
Time string `gorm:"type:varchar(50);not null;"`
Percent int `gorm:"type:int(50);"`
Current int `gorm:"type:int(50);"`
IsKill uint `gorm:"type:tinyint(2);not null;default:'0'"`
}
type CoreRollback struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
SQL string `gorm:"type:longtext;not null"`
}
type CoreGroupOrder struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
Permissions JSON `gorm:"type:json"`
Status int `gorm:"type:tinyint(5);not null;default 2"`
Date string `gorm:"type:varchar(50);not null;"`
Username string `gorm:"type:varchar(50);not null"`
}
type CoreDataSource struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
IDC string `gorm:"type:varchar(50);not null"`
Source string `gorm:"type:varchar(50);not null"`
IP string `gorm:"type:varchar(200);not null"`
Port int `gorm:"type:int(10);not null"`
Username string `gorm:"type:varchar(50);not null"`
Password string `gorm:"type:varchar(150);not null"`
IsQuery int `gorm:"type:tinyint(2);not null"` // 0写 1读 2读写
}
type CoreGrained struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
Username string `gorm:"type:varchar(50);not null"`
Rule string `gorm:"type:varchar(10);not null";json:"rule"`
Permissions JSON `gorm:"type:json"`
Group JSON `gorm:"type:json"`
}
type CoreRoleGroup struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
Name string `gorm:"type:varchar(50);not null"`
Permissions JSON `gorm:"type:json"`
}
type CoreQueryOrder struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
Username string `gorm:"type:varchar(50);not null"`
Date string `gorm:"type:varchar(50);not null;index:query_idx"`
Text string `gorm:"type:longtext;not null"`
IDC string `gorm:"type:varchar(50);not null"`
Assigned string `gorm:"type:varchar(50);not null"`
Realname string `gorm:"type:varchar(50);not null"`
Export uint `gorm:"type:tinyint(2);not null"`
QueryPer int `gorm:"type:tinyint(2);not null"`
ExDate string `gorm:"type:varchar(50);"`
}
type CoreQueryRecord struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
WorkId string `gorm:"type:varchar(50);not null;index:workId_idx"`
SQL string `gorm:"type:longtext;not null"`
ExTime int `gorm:"type:int(10);not null"`
Time string `gorm:"type:varchar(50);not null"`
Source string `gorm:"type:varchar(50);not null"`
BaseName string `gorm:"type:varchar(50);not null"`
}
type CoreAutoTask struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
Name string `gorm:"type:varchar(50);not null"`
Source string `gorm:"type:varchar(50);not null"`
Base string `gorm:"type:varchar(50);not null"`
Table string `gorm:"type:varchar(50);not null"`
Tp int `gorm:"type:tinyint(2);not null"` // 0 insert 1 update 2delete
Affectrow uint `gorm:"type:int(50);not null default 0;"`
Status int `gorm:"type:tinyint(2);not null default 0"` // 0 close 1 on
}