-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind_audit.go
241 lines (230 loc) · 8.04 KB
/
bind_audit.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
package OrgCoreCore
import (
"errors"
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLConfig "github.com/fotomxq/weeekj_core/v5/core/sql/config"
CoreSQLPages "github.com/fotomxq/weeekj_core/v5/core/sql/pages"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
UserCore "github.com/fotomxq/weeekj_core/v5/user/core"
"github.com/lib/pq"
)
// ArgsGetBindAuditList 获取审核列表参数
type ArgsGetBindAuditList struct {
//分页
Pages CoreSQLPages.ArgsDataList `json:"pages"`
//组织ID
// 必填
OrgID int64 `json:"orgID" check:"id"`
//用户ID
UserID int64 `json:"userID" check:"id" empty:"true"`
//分组ID
GroupID int64 `json:"groupID" check:"id" empty:"true"`
//符合权限的
Manager string `json:"manager" check:"mark" empty:"true"`
//是否审核
NeedIsAudit bool `db:"need_is_audit" json:"needIsAudit" check:"bool" empty:"true"`
IsAudit bool `db:"is_audit" json:"isAudit" check:"bool" empty:"true"`
//是否拒绝
IsBan bool `db:"is_ban" json:"isBan" check:"bool" empty:"true"`
//审核人员
AuditBindID int64 `db:"audit_bind_id" json:"auditBindID" check:"id" empty:"true"`
//是否删除
IsRemove bool `json:"isRemove" check:"bool" empty:"true"`
//搜索
Search string `json:"search" check:"search" empty:"true"`
}
// GetBindAuditList 获取审核列表
func GetBindAuditList(args *ArgsGetBindAuditList) (dataList []FieldsBindAudit, dataCount int64, err error) {
where := "org_id = :org_id"
maps := map[string]interface{}{
"org_id": args.OrgID,
}
if args.IsRemove {
where = where + " AND delete_at > to_timestamp(1000000)"
} else {
where = where + " AND delete_at < to_timestamp(1000000)"
}
if args.UserID > 0 {
where = where + " AND user_id = :user_id"
maps["user_id"] = args.UserID
}
if args.GroupID > 0 {
where = where + " AND :group_id = ANY(group_ids)"
maps["group_id"] = args.GroupID
}
if args.Manager != "" {
where = where + " AND :manager = ANY(manager)"
maps["manager"] = args.Manager
}
if args.NeedIsAudit {
if args.IsAudit {
where = where + " AND audit_at > to_timestamp(1000000) AND ban_at <= to_timestamp(1000000)"
} else {
if args.IsBan {
where = where + " AND ban_at > to_timestamp(1000000)"
} else {
where = where + " AND audit_at <= to_timestamp(1000000) AND ban_at <= to_timestamp(1000000)"
}
}
}
if args.AuditBindID > 0 {
where = where + " AND audit_bind_id = :audit_bind_id"
maps["audit_bind_id"] = args.AuditBindID
}
if args.Search != "" {
where = where + " AND (name ILIKE '%' || :search || '%' OR ban_des ILIKE '%' || :search || '%')"
maps["search"] = args.Search
}
tableName := "org_core_bind_audit"
dataCount, err = CoreSQL.GetListPageAndCount(
Router2SystemConfig.MainDB.DB,
&dataList,
tableName,
"id",
"SELECT id, create_at, delete_at, audit_at, ban_at, ban_des, audit_bind_id, user_id, name, org_id, group_ids, manager, params FROM "+tableName+" WHERE "+where,
where,
maps,
&args.Pages,
[]string{"id", "create_at", "update_at", "delete_at", "audit_at", "ban_at"},
)
return
}
// ArgsCreateBindAudit 创建新审核请求
type ArgsCreateBindAudit struct {
//用户ID
UserID int64 `db:"user_id" json:"userID" check:"id"`
//名称
Name string `db:"name" json:"name" check:"name"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//组织分组ID列
GroupIDs pq.Int64Array `db:"group_ids" json:"groupIDs" check:"ids" empty:"true"`
//权利主张
Manager pq.StringArray `db:"manager" json:"manager" check:"marks" empty:"true"`
//附加参数
Params CoreSQLConfig.FieldsConfigsType `db:"params" json:"params"`
}
// CreateBindAudit 创建新审核请求
func CreateBindAudit(args *ArgsCreateBindAudit) (auditData FieldsBindAudit, errCode string, err error) {
//用户禁止重复申请
err = Router2SystemConfig.MainDB.Get(&auditData, "SELECT id FROM org_core_bind_audit WHERE delete_at < to_timestamp(1000000) AND audit_at < to_timestamp(1000000) AND ban_at < to_timestamp(1000000) AND user_id = $1 LIMIT 1", args.UserID)
if err == nil && auditData.ID > 0 {
errCode = "replace_audit"
err = errors.New("user replace audit")
return
}
//检查用户是否存在绑定关系
_, err = GetBindByUserAndOrg(&ArgsGetBindByUserAndOrg{
UserID: args.UserID,
OrgID: args.OrgID,
})
if err == nil {
errCode = "have_bind"
err = errors.New("user have bind")
return
}
//获取用户信息
if args.UserID < 1 {
errCode = "user_not_exist"
err = errors.New("user id is empty")
return
}
_, err = UserCore.GetUserByID(&UserCore.ArgsGetUserByID{
ID: args.UserID,
OrgID: -1,
})
if err != nil {
errCode = "user_not_exist"
err = errors.New("get user by id, " + err.Error())
return
}
//检查组织
var orgData FieldsOrg
orgData, err = GetOrg(&ArgsGetOrg{
ID: args.OrgID,
})
if err != nil || orgData.ID < 1 {
errCode = "org_not_exist"
err = errors.New("org not exist")
return
}
//生成数据
if err = CoreSQL.CreateOneAndData(Router2SystemConfig.MainDB.DB, "org_core_bind_audit", "INSERT INTO org_core_bind_audit (audit_at, ban_at, ban_des, audit_bind_id, user_id, name, org_id, group_ids, manager, params) VALUES (to_timestamp(0), to_timestamp(0), '', 0, :user_id, :name, :org_id, :group_ids, :manager, :params)", args, &auditData); err != nil {
errCode = "insert"
return
}
return
}
// ArgsUpdateBindAuditPass 通过审核参数
type ArgsUpdateBindAuditPass struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//操作人
AuditBindID int64 `db:"audit_bind_id" json:"auditBindID" check:"id" empty:"true"`
}
// UpdateBindAuditPass 通过审核
func UpdateBindAuditPass(args *ArgsUpdateBindAuditPass) (err error) {
var auditData FieldsBindAudit
err = Router2SystemConfig.MainDB.Get(&auditData, "SELECT id FROM org_core_bind_audit WHERE id = $1 AND delete_at < to_timestamp(1000000)", args.ID)
if err != nil {
return
}
userData, _ := UserCore.GetUserByID(&UserCore.ArgsGetUserByID{
ID: auditData.UserID,
OrgID: auditData.OrgID,
})
_, err = CoreSQL.UpdateOneSoft(Router2SystemConfig.MainDB.DB, "UPDATE org_core_bind_audit SET audit_at = NOW(), ban_at = to_timestamp(0), audit_bind_id = :audit_bind_id WHERE id = :id AND (:org_id < 1 OR org_id = :org_id)", args)
if err == nil {
err = Router2SystemConfig.MainDB.Get(&auditData, "SELECT id, create_at, delete_at, audit_at, ban_at, ban_des, audit_bind_id, user_id, name, org_id, group_ids, manager, params FROM org_core_bind_audit WHERE id = $1 LIMIT 1", args.ID)
if err != nil {
return
}
_, err = SetBind(&ArgsSetBind{
UserID: auditData.UserID,
Avatar: 0,
Name: auditData.Name,
OrgID: auditData.OrgID,
GroupIDs: auditData.GroupIDs,
Manager: auditData.Manager,
NationCode: userData.NationCode,
Phone: userData.Phone,
Email: userData.Email,
SyncSystem: "",
SyncID: 0,
SyncHash: "",
Params: auditData.Params,
})
return
}
return
}
// ArgsUpdateBindAuditBan 拒绝审核参数
type ArgsUpdateBindAuditBan struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//操作人
AuditBindID int64 `db:"audit_bind_id" json:"auditBindID" check:"id" empty:"true"`
//拒绝审核原因
BanDes string `db:"ban_des" json:"banDes" check:"des" min:"1" max:"600" empty:"true"`
}
// UpdateBindAuditBan 拒绝审核
func UpdateBindAuditBan(args *ArgsUpdateBindAuditBan) (err error) {
_, err = CoreSQL.UpdateOneSoft(Router2SystemConfig.MainDB.DB, "UPDATE org_core_bind_audit SET audit_at = to_timestamp(0), ban_at = NOW(), audit_bind_id = :audit_bind_id, ban_des = :ban_des WHERE id = :id AND (:org_id < 1 OR org_id = :org_id)", args)
return
}
// ArgsDeleteBindAudit 删除审核参数
type ArgsDeleteBindAudit struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
}
// DeleteBindAudit 删除审核
func DeleteBindAudit(args *ArgsDeleteBindAudit) (err error) {
_, err = CoreSQL.DeleteAllSoft(Router2SystemConfig.MainDB.DB, "org_core_bind_audit", "id = :id AND (:org_id < 1 OR org_id = :org_id)", args)
return
}