users.go
23.2 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
package service
import (
"crypto/sha1"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
"strconv"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 用户信息
type UsersService struct {
}
func NewUsersService(options map[string]interface{}) *UsersService {
newUsersService := &UsersService{}
return newUsersService
}
// 获取公司用户信息
func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.CompanyUserGetQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserGetQuery.Operator)
userid, _ := strconv.Atoi(companyUserGetQuery.UsersId)
resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
UserId: userid,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
resultMenu, err := creationUserGateway.UserAccessMenus(allied_creation_user.ReqUserAccessMenus{
UserId: userid,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var (
usersOrg []dto.UserOrg = make([]dto.UserOrg, 0)
userRole []dto.UserRole = make([]dto.UserRole, 0)
userMenu []dto.UserMenu = make([]dto.UserMenu, 0)
)
for _, v := range resultMenu.Menus {
userMenu = append(userMenu, dto.UserMenu{
Category: v.Category,
Code: v.Code,
Icon: v.Icon,
MenuName: v.MenuName,
MenuID: strconv.Itoa(v.MenuID),
MenuType: v.MenuType,
ParentID: strconv.Itoa(v.ParentID),
Remark: v.Remark,
Sort: v.Sort,
})
}
for _, v := range resultUser.UserOrg {
usersOrg = append(usersOrg, dto.UserOrg{
OrgID: strconv.Itoa(v.OrgID),
OrgName: v.OrgName,
})
}
for _, v := range resultUser.UserRole {
userRole = append(userRole, dto.UserRole{
RoleID: strconv.Itoa(v.RoleID),
OrgId: v.OrgId,
RoleName: v.RoleName,
OrgName: v.Ext.OrgName,
RoleType: v.RoleType,
})
}
user := dto.CompanyUserInfo{
Email: resultUser.UserInfo.Email,
Phone: resultUser.UserInfo.Phone,
Avatar: resultUser.UserInfo.Avatar,
EnableStatus: resultUser.EnableStatus,
UsersCode: resultUser.UserCode,
UsersID: strconv.Itoa(resultUser.UserId),
UsersName: resultUser.UserInfo.UserName,
OrgID: strconv.Itoa(resultUser.Org.OrgId),
OrgName: resultUser.Org.OrgName,
DepartmentID: strconv.Itoa(resultUser.Department.DepartmentId),
DepartmentName: resultUser.Department.DepartmentName,
UsersOrg: usersOrg,
UsersRole: userRole,
}
datas := map[string]interface{}{
"user": user,
"userMenu": userMenu,
}
return datas, err
}
// 创建公司用户信息
func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.CompanyUserAddCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserAddCommand.Operator)
orgId, _ := strconv.Atoi(companyUserAddCommand.OrgId)
departmentId, _ := strconv.Atoi(companyUserAddCommand.DepartmentId)
userOrg := []int64{}
userRole := []int64{}
initPassword, _, err := usersService.GetInitPassword(companyUserAddCommand.Operator)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
for _, v := range companyUserAddCommand.UserOrg {
id, err := strconv.Atoi(v.OrgId)
if err == nil {
userOrg = append(userOrg, int64(id))
}
}
for _, v := range companyUserAddCommand.UserRole {
id, err := strconv.Atoi(v.RoleId)
if err == nil {
userRole = append(userRole, int64(id))
}
}
result, err := creationUserGateway.UserCreate(allied_creation_user.ReqCreateUser{
CompanyId: companyUserAddCommand.Operator.CompanyId,
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UserType: domain.UserTypeEmployee,
UserCode: companyUserAddCommand.UsersCode,
OrganizationId: int64(orgId),
DepartmentId: int64(departmentId),
UserOrg: userOrg,
UserRole: userRole,
// 启用状态(启用:1 禁用:2)
EnableStatus: companyUserAddCommand.EnableStatus,
UserName: companyUserAddCommand.UsersName,
Phone: companyUserAddCommand.Phone,
Avatar: companyUserAddCommand.Avatar,
Email: companyUserAddCommand.Email,
Password: initPassword,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
data := struct {
UserId string `json:"userId"`
command.CompanyUserAddCommand
}{
UserId: strconv.Itoa(result.UserId),
CompanyUserAddCommand: *companyUserAddCommand,
}
return data, err
}
// 启用禁用公司用户信息
func (usersService *UsersService) CompanyUserEnable(companyUserEnableCommand *command.CompanyUserEnableCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserEnableCommand.Operator)
var userIds []int64
for i := range companyUserEnableCommand.UsersIds {
id, _ := strconv.Atoi(companyUserEnableCommand.UsersIds[i])
userIds = append(userIds, int64(id))
}
_, err := creationUserGateway.UserBatchEnable(allied_creation_user.ReqBatchEnableUser{
UserIds: userIds,
EnableStatus: companyUserEnableCommand.EnableStatus,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return companyUserEnableCommand, err
}
// 返回公司用户信息列表
func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.CompanyUserListQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
Offset: (companyUserListQuery.PageNumber - 1) * companyUserListQuery.PageSize,
Limit: companyUserListQuery.PageSize,
CompanyId: companyUserListQuery.Operator.CompanyId,
OrganizationId: 0,
DepartmentId: 0,
UserName: companyUserListQuery.UserName,
DepName: companyUserListQuery.DepartmentName,
Phone: "",
UserType: domain.UserTypeEmployee,
InOrgIds: companyUserListQuery.Operator.OrgIds,
PullRealTime: true,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
//数据转换
cnt := int64(result.Count)
var (
listData = make([]dto.CompanyUserItem, 0)
item dto.CompanyUserItem
)
for _, v := range result.Users {
item = dto.CompanyUserItem{
DepName: v.Department.DepartmentName,
OrgName: v.Org.OrgName,
Phone: v.UserInfo.Phone,
EnableStatus: v.EnableStatus,
UserCode: v.UserCode,
UserId: strconv.Itoa(v.UserId),
UserName: v.UserInfo.UserName,
UserType: v.UserType,
}
if v.Org.OrgId == int(companyUserListQuery.Operator.OrgId) {
item.AuthFlag = true
}
listData = append(listData, item)
}
return cnt, listData, nil
}
// 批量重置密码
func (usersService *UsersService) CompanyUserResetPassword(companyUserResetPasswordCommand *command.CompanyUserResetPasswordCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserResetPasswordCommand.Operator)
var userIds []int64
for i := range companyUserResetPasswordCommand.UserIds {
id, _ := strconv.Atoi(companyUserResetPasswordCommand.UserIds[i])
userIds = append(userIds, int64(id))
}
initPassword, primitivePassword, err := usersService.GetInitPassword(companyUserResetPasswordCommand.Operator)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
_, err = creationUserGateway.UserBatchResetPassword(allied_creation_user.ReqBatchResetPasswordUser{
Password: initPassword,
UserIds: userIds,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return primitivePassword, err
}
// 更新公司用户信息
func (usersService *UsersService) CompanyUserUpdate(companyUserUpdateCommand *command.CompanyUserUpdateCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
companyUserUpdateCommand.Operator)
departmentId, _ := strconv.Atoi(companyUserUpdateCommand.DepartmentId)
orgId, _ := strconv.Atoi(companyUserUpdateCommand.OrganizationId)
userOrg := []int64{}
userRole := []int64{}
for _, v := range companyUserUpdateCommand.UserOrg {
id, err := strconv.Atoi(v.OrgId)
if err == nil {
userOrg = append(userOrg, int64(id))
}
}
for _, v := range companyUserUpdateCommand.UserRole {
id, err := strconv.Atoi(v.RoleId)
if err == nil {
userRole = append(userRole, int64(id))
}
}
userId, _ := strconv.Atoi(companyUserUpdateCommand.UsersId)
_, err := creationUserGateway.UserUpdate(allied_creation_user.ReqUpdateUser{
UserId: int64(userId),
CompanyId: companyUserUpdateCommand.Operator.CompanyId,
UserCode: companyUserUpdateCommand.UsersCode,
OrganizationId: int64(orgId),
DepartmentId: int64(departmentId),
UserOrg: userOrg,
UserRole: userRole,
EnableStatus: companyUserUpdateCommand.EnableStatus,
UserName: companyUserUpdateCommand.UsersName,
Phone: companyUserUpdateCommand.Phone,
Avatar: companyUserUpdateCommand.Avatar,
Email: companyUserUpdateCommand.Email,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return companyUserUpdateCommand, err
}
// 创建共创用户信息
func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *command.CooperationUserAddCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
cooperationUserAddCommand.Operator)
initPassword, _, err := usersService.GetInitPassword(cooperationUserAddCommand.Operator)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cooperationDeadline := time.Time{}
if cooperationUserAddCommand.CooperationDeadline > 0 {
cooperationDeadline = time.Unix(cooperationUserAddCommand.CooperationDeadline/1e3, 0)
}
result, err := creationUserGateway.CooperatorUserCreate(allied_creation_user.ReqCreateCooperatorUser{
CompanyId: cooperationUserAddCommand.Operator.CompanyId,
CooperationCompany: cooperationUserAddCommand.CooperationCompany,
CooperationDeadline: cooperationDeadline,
Email: cooperationUserAddCommand.Email,
EnableStatus: cooperationUserAddCommand.EnableStatus,
UserCode: cooperationUserAddCommand.UsersCode,
UserName: cooperationUserAddCommand.UsersName,
Avatar: cooperationUserAddCommand.Avatar,
OrgId: cooperationUserAddCommand.Operator.OrgId,
Phone: cooperationUserAddCommand.Phone,
Password: initPassword,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
data := struct {
UserId string `json:"userId"`
command.CooperationUserAddCommand
}{
UserId: strconv.Itoa(result.UserId),
CooperationUserAddCommand: *cooperationUserAddCommand,
}
return data, err
}
// 启用禁用共创用户信息
func (usersService *UsersService) CooperationUserEnable(cooperationUserEnableCommand *command.CooperationUserEnableCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
cooperationUserEnableCommand.Operator)
var userIds []int64
for i := range cooperationUserEnableCommand.UsersIds {
id, _ := strconv.Atoi(cooperationUserEnableCommand.UsersIds[i])
userIds = append(userIds, int64(id))
}
_, err := creationUserGateway.UserBatchEnable(allied_creation_user.ReqBatchEnableUser{
UserIds: userIds,
EnableStatus: cooperationUserEnableCommand.EnableStatus,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return cooperationUserEnableCommand, err
}
// 获取共创用户信息
func (usersService *UsersService) CooperationUserGet(cooperationUserGetQuery *query.CooperationUserGetQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
cooperationUserGetQuery.Operator)
userId, _ := strconv.Atoi(cooperationUserGetQuery.UserId)
result, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
UserId: userId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var deadline int64
if !result.CooperationInfo.CooperationDeadline.IsZero() {
deadline = result.CooperationInfo.CooperationDeadline.UnixNano() / 1e6
}
userInfo := dto.CooperationUserInfo{
UserId: strconv.Itoa(result.UserId),
UserCode: result.UserCode,
EnableStatus: int32(result.EnableStatus),
CooperationCompany: result.CooperationInfo.CooperationCompany,
CooperationDeadline: deadline,
UserName: result.UserInfo.UserName,
Email: result.UserInfo.Email,
Phone: result.UserInfo.Phone,
Avatar: result.UserInfo.Avatar,
}
return userInfo, nil
}
// 返回共创用户信息列表
func (usersService *UsersService) CooperationUserList(cooperationUserListQuery *query.CooperationUserListQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
Offset: (cooperationUserListQuery.PageNumber - 1) * cooperationUserListQuery.PageSize,
Limit: cooperationUserListQuery.PageSize,
CompanyId: cooperationUserListQuery.Operator.CompanyId,
DepartmentId: 0,
UserName: cooperationUserListQuery.UserName,
CooperationCompany: cooperationUserListQuery.CooperationCompany,
DepName: "",
Phone: "",
UserType: domain.UserTypeCooperation,
InOrgIds: cooperationUserListQuery.Operator.OrgIds,
})
var (
listData = make([]dto.CooperationUserItem, 0)
item dto.CooperationUserItem
)
cnt := result.Count
for _, v := range result.Users {
item = dto.CooperationUserItem{
CooperationCompany: v.CooperationInfo.CooperationCompany,
UserId: strconv.Itoa(v.UserId),
CooperationDeadline: "",
Phone: v.UserInfo.Phone,
EnableStatus: v.EnableStatus,
UserCode: v.UserCode,
UserName: v.UserInfo.UserName,
OrgName: v.Org.OrgName,
OrgId: strconv.Itoa(v.Org.OrgId),
}
if v.Org.OrgId == int(cooperationUserListQuery.Operator.OrgId) {
item.AuthFlag = true
}
if !v.CooperationInfo.CooperationDeadline.IsZero() && v.CooperationInfo.CooperationDeadline.After(time.Unix(1136044800, 0)) {
item.CooperationDeadline = v.CooperationInfo.CooperationDeadline.Format("2006-01-02")
}
listData = append(listData, item)
}
return cnt, listData, err
}
// 批量重置密码
func (usersService *UsersService) CooperationUserResetPassword(cooperationUserResetPasswordCommand *command.CooperationUserResetPasswordCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
cooperationUserResetPasswordCommand.Operator)
initPassword, primitivePassword, err := usersService.GetInitPassword(cooperationUserResetPasswordCommand.Operator)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var userIds []int64
for i := range cooperationUserResetPasswordCommand.UserIds {
id, _ := strconv.Atoi(cooperationUserResetPasswordCommand.UserIds[i])
userIds = append(userIds, int64(id))
}
_, err = creationUserGateway.UserBatchResetPassword(allied_creation_user.ReqBatchResetPasswordUser{
Password: initPassword, //TODO 填充密码
UserIds: userIds,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return primitivePassword, err
}
// 编辑共创用户信息
func (usersService *UsersService) CooperationUserUpdate(cooperationUserUpdateCommand *command.CooperationUserUpdateCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
cooperationUserUpdateCommand.Operator)
_, err := creationUserGateway.CooperatorUserUpdate(allied_creation_user.ReqUpdateCooperatorUser{
UserId: cooperationUserUpdateCommand.UserId,
CooperationCompany: cooperationUserUpdateCommand.CooperationCompany,
CooperationDeadline: time.Unix(cooperationUserUpdateCommand.CooperationDeadline/1000, 0),
Email: cooperationUserUpdateCommand.Email,
EnableStatus: cooperationUserUpdateCommand.EnableStatus,
UserCode: cooperationUserUpdateCommand.UserCode,
UserName: cooperationUserUpdateCommand.UserName,
Avatar: cooperationUserUpdateCommand.Avatar,
OrgId: cooperationUserUpdateCommand.Operator.OrgId,
Phone: cooperationUserUpdateCommand.Phone,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return cooperationUserUpdateCommand, err
}
//CompanyOrgSelector 获取公司组织的下拉列表
func (usersService *UsersService) SelectorCompanyOrg(selectorQuery *query.CompanyOrgSelectorQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
selectorQuery.Operator)
result, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
CompanyId: int(selectorQuery.Operator.CompanyId),
DepName: selectorQuery.OrgName,
IsOrg: 1,
Limit: selectorQuery.PageSize,
Offset: (selectorQuery.PageNumber - 1) * selectorQuery.PageSize,
OrgCode: "",
ParentId: 0,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var (
dataList []dto.UserOrg
item dto.UserOrg
)
for _, v := range result.Orgs {
item = dto.UserOrg{
OrgID: strconv.Itoa(v.OrgID),
OrgName: v.OrgName,
ParentId: strconv.Itoa(v.ParentID),
IsOrg: v.IsOrg,
}
dataList = append(dataList, item)
}
return int64(result.Count), dataList, nil
}
//SelectorCompanyRole 获取公司角色的下拉列表
func (usersService *UsersService) SelectorCompanyRole(selectorQuery *query.CompanyRoleSelectorQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
selectorQuery.Operator)
result, err := creationUserGateway.RoleSearch(allied_creation_user.ReqRoleSearch{
Limit: selectorQuery.PageSize,
Offset: (selectorQuery.PageNumber - 1) * selectorQuery.PageSize,
RoleName: selectorQuery.RoleName,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var (
dataList []dto.UserRole
item dto.UserRole
)
for _, v := range result.Roles {
item = dto.UserRole{
RoleID: strconv.Itoa(int(v.RoleID)),
RoleName: v.RoleName,
OrgName: v.Ext.OrgName,
Description: v.Desc,
}
dataList = append(dataList, item)
}
return int64(result.Count), dataList, nil
}
//CompanyOrgSelector 获取公司全组织部门的下拉列表
func (usersService *UsersService) SelectorCompanyOrgAll(selectorQuery *query.CompanyOrgSelectorQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
selectorQuery.Operator)
result, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
CompanyId: int(selectorQuery.Operator.CompanyId),
DepName: "",
IsOrg: 0,
Limit: 0,
Offset: 0,
OrgCode: "",
ParentId: 0,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
dataList []dto.UserOrg
item dto.UserOrg
)
for _, v := range result.Orgs {
item = dto.UserOrg{
OrgID: strconv.Itoa(v.OrgID),
OrgName: v.OrgName,
ParentId: strconv.Itoa(v.ParentID),
IsOrg: v.IsOrg,
}
dataList = append(dataList, item)
}
return int64(result.Count), dataList, nil
}
//GetInitPassword 获取公司初始化密码
func (usersService *UsersService) GetInitPassword(operator domain.Operator) (string, string, error) {
var password string
alliedCreationBasic := allied_creation_basic.NewHttplibAlliedCreationBasic(operator)
reqResult, err := alliedCreationBasic.SystemSettingGet(allied_creation_basic.ReqSystemSettingGet{
domain.InitPasswordSettingKey,
})
if err != nil {
log.Logger.Error(err.Error())
return "", "", err
}
if len(reqResult.Value) == 0 {
return "", "", fmt.Errorf("初始化密码不能为空 ")
}
password = fmt.Sprintf("%x", sha1.Sum([]byte(reqResult.Value)))
return password, reqResult.Value, err
}
// SelectorCooperationProjectUsers 共创项目用户下拉列表
func (usersService *UsersService) SelectorCooperationProjectUsers(q *query.CooperationProjectUsersQuery) (interface{}, error) {
applications := make([]interface{}, 0)
// 项目申请人
if q.CooperationProjectId != 0 {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(q.Operator)
resultProject, err := creationCooperationGateway.CooperationProjectGet(allied_creation_cooperation.ReqCooperationProjectGet{
CooperationProjectId: q.CooperationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
PageNumber: 0,
PageSize: 1000,
CompanyId: resultProject.Company.CompanyId,
OrgId: int64(resultProject.Org.OrgId),
CooperationApplicationStatus: 2, //审核通过的
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for i := range resultApplication.Grid.List {
item := resultApplication.Grid.List[i]
user := map[string]interface{}{
"userId": item.CooperationApplicationApplicant.UserID,
"userCode": item.CooperationApplicationApplicant.UserInfo.UserCode,
"userInfo": map[string]interface{}{
"userName": item.CooperationApplicationApplicant.UserInfo.UserName,
"phone": item.CooperationApplicationApplicant.UserInfo.UserPhone,
},
"department": item.CooperationApplicationApplicant.Department,
}
applications = append(applications, user)
}
}
return map[string]interface{}{
"applicants": applications,
}, nil
}