|
@@ -18,71 +18,71 @@ type PgBatchAddUserService struct { |
|
@@ -18,71 +18,71 @@ type PgBatchAddUserService struct { |
18
|
// optUser 操作用户
|
18
|
// optUser 操作用户
|
19
|
// users 待添加用户列表数据
|
19
|
// users 待添加用户列表数据
|
20
|
// password 密码
|
20
|
// password 密码
|
21
|
-func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
|
|
|
22
|
- var (
|
|
|
23
|
- err error
|
|
|
24
|
- )
|
|
|
25
|
- orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
|
|
|
26
|
- if err != nil {
|
|
|
27
|
- return err
|
|
|
28
|
- }
|
|
|
29
|
- _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
|
|
|
30
|
- if err != nil {
|
|
|
31
|
- return err
|
|
|
32
|
- }
|
|
|
33
|
- var mapOrg = make(map[int64]*domain.Org)
|
|
|
34
|
- for i := range orgs {
|
|
|
35
|
- mapOrg[orgs[i].OrgId] = orgs[i]
|
|
|
36
|
- }
|
|
|
37
|
-
|
|
|
38
|
- createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
|
|
|
39
|
- for i := range users {
|
|
|
40
|
- user := users[i]
|
|
|
41
|
- if err = ptr.preCheck(user); err != nil {
|
|
|
42
|
- return err
|
|
|
43
|
- }
|
|
|
44
|
- newUser := &domain.User{
|
|
|
45
|
- CompanyId: user.CompanyId,
|
|
|
46
|
- UserType: user.UserType,
|
|
|
47
|
- UserCode: user.UserCode,
|
|
|
48
|
- OrganizationId: user.OrganizationId,
|
|
|
49
|
- DepartmentId: user.DepartmentId,
|
|
|
50
|
- UserOrg: []*domain.Org{},
|
|
|
51
|
- UserRole: []*domain.Role{},
|
|
|
52
|
- FavoriteMenus: []string{},
|
|
|
53
|
- CooperationInfo: user.CooperationInfo,
|
|
|
54
|
- UserInfo: user.UserInfo,
|
|
|
55
|
- EnableStatus: int(domain.UserStatusEnable),
|
|
|
56
|
- Ext: &domain.Ext{
|
|
|
57
|
- Phone: user.UserInfo.Phone,
|
|
|
58
|
- UserName: user.UserInfo.UserName,
|
|
|
59
|
- },
|
|
|
60
|
- CreatedAt: time.Now(),
|
|
|
61
|
- UpdatedAt: time.Now(),
|
|
|
62
|
- }
|
|
|
63
|
- if user.OrganizationId > 0 {
|
|
|
64
|
- if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
|
|
|
65
|
- newUser.Ext.OrgName = v.OrgName
|
|
|
66
|
- } else {
|
|
|
67
|
- return fmt.Errorf("导入的组织机构不存在")
|
|
|
68
|
- }
|
|
|
69
|
- }
|
|
|
70
|
- if user.DepartmentId > 0 {
|
|
|
71
|
- if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
|
|
|
72
|
- newUser.Ext.DepName = v.OrgName
|
|
|
73
|
- } else {
|
|
|
74
|
- return fmt.Errorf("导入的所属部门不存在")
|
|
|
75
|
- }
|
|
|
76
|
- }
|
|
|
77
|
-
|
|
|
78
|
- if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
|
|
|
79
|
- return err
|
|
|
80
|
- }
|
|
|
81
|
- }
|
|
|
82
|
- return nil
|
|
|
83
|
-}
|
21
|
+//func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error {
|
|
|
22
|
+// var (
|
|
|
23
|
+// err error
|
|
|
24
|
+// )
|
|
|
25
|
+// orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
|
|
|
26
|
+// if err != nil {
|
|
|
27
|
+// return err
|
|
|
28
|
+// }
|
|
|
29
|
+// _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId})
|
|
|
30
|
+// if err != nil {
|
|
|
31
|
+// return err
|
|
|
32
|
+// }
|
|
|
33
|
+// var mapOrg = make(map[int64]*domain.Org)
|
|
|
34
|
+// for i := range orgs {
|
|
|
35
|
+// mapOrg[orgs[i].OrgId] = orgs[i]
|
|
|
36
|
+// }
|
|
|
37
|
+//
|
|
|
38
|
+// createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
|
|
|
39
|
+// for i := range users {
|
|
|
40
|
+// user := users[i]
|
|
|
41
|
+// if err = ptr.preCheck(user); err != nil {
|
|
|
42
|
+// return err
|
|
|
43
|
+// }
|
|
|
44
|
+// newUser := &domain.User{
|
|
|
45
|
+// CompanyId: user.CompanyId,
|
|
|
46
|
+// UserType: user.UserType,
|
|
|
47
|
+// UserCode: user.UserCode,
|
|
|
48
|
+// OrganizationId: user.OrganizationId,
|
|
|
49
|
+// DepartmentId: user.DepartmentId,
|
|
|
50
|
+// UserOrg: []*domain.Org{},
|
|
|
51
|
+// UserRole: []*domain.Role{},
|
|
|
52
|
+// FavoriteMenus: []string{},
|
|
|
53
|
+// CooperationInfo: user.CooperationInfo,
|
|
|
54
|
+// UserInfo: user.UserInfo,
|
|
|
55
|
+// EnableStatus: int(domain.UserStatusEnable),
|
|
|
56
|
+// Ext: &domain.Ext{
|
|
|
57
|
+// Phone: user.UserInfo.Phone,
|
|
|
58
|
+// UserName: user.UserInfo.UserName,
|
|
|
59
|
+// },
|
|
|
60
|
+// CreatedAt: time.Now(),
|
|
|
61
|
+// UpdatedAt: time.Now(),
|
|
|
62
|
+// }
|
|
|
63
|
+// if user.OrganizationId > 0 {
|
|
|
64
|
+// if v, ok := mapOrg[user.OrganizationId]; ok && v.CompanyId == user.CompanyId {
|
|
|
65
|
+// newUser.Ext.OrgName = v.OrgName
|
|
|
66
|
+// } else {
|
|
|
67
|
+// return fmt.Errorf("导入的组织机构不存在")
|
|
|
68
|
+// }
|
|
|
69
|
+// }
|
|
|
70
|
+// if user.DepartmentId > 0 {
|
|
|
71
|
+// if v, ok := mapOrg[user.DepartmentId]; ok && v.CompanyId == user.CompanyId {
|
|
|
72
|
+// newUser.Ext.DepName = v.OrgName
|
|
|
73
|
+// } else {
|
|
|
74
|
+// return fmt.Errorf("导入的所属部门不存在")
|
|
|
75
|
+// }
|
|
|
76
|
+// }
|
|
|
77
|
+//
|
|
|
78
|
+// if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
|
|
|
79
|
+// return err
|
|
|
80
|
+// }
|
|
|
81
|
+// }
|
|
|
82
|
+// return nil
|
|
|
83
|
+//}
|
84
|
|
84
|
|
85
|
-func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
|
85
|
+func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
|
86
|
var (
|
86
|
var (
|
87
|
err error
|
87
|
err error
|
88
|
)
|
88
|
)
|
|
@@ -99,6 +99,10 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
@@ -99,6 +99,10 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
99
|
for i := range orgs {
|
99
|
for i := range orgs {
|
100
|
mapOrg[orgs[i].OrgCode] = orgs[i]
|
100
|
mapOrg[orgs[i].OrgCode] = orgs[i]
|
101
|
}
|
101
|
}
|
|
|
102
|
+ optUserOrg, err := orgRepository.FindOne(map[string]interface{}{"orgId": optUser.OrgId})
|
|
|
103
|
+ if err != nil {
|
|
|
104
|
+ return failRows, err
|
|
|
105
|
+ }
|
102
|
|
106
|
|
103
|
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
|
107
|
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
|
104
|
for i := range users {
|
108
|
for i := range users {
|
|
@@ -110,13 +114,19 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
@@ -110,13 +114,19 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
110
|
}
|
114
|
}
|
111
|
var org, dep *domain.Org
|
115
|
var org, dep *domain.Org
|
112
|
var ok bool
|
116
|
var ok bool
|
113
|
- if org, ok = mapOrg[user.Org]; !ok {
|
|
|
114
|
- user.FailReason = "导入的组织机构不存在:" + user.Org
|
117
|
+ // 使用导入用户的组织作为默认组织
|
|
|
118
|
+ //if org, ok = mapOrg[user.Org]; !ok {
|
|
|
119
|
+ // user.FailReason = "导入的组织机构不存在:" + user.Org
|
|
|
120
|
+ // failRows = append(failRows, user)
|
|
|
121
|
+ // continue
|
|
|
122
|
+ //}
|
|
|
123
|
+ if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation {
|
|
|
124
|
+ user.FailReason = "导入的所属部门不存在:" + user.Department
|
115
|
failRows = append(failRows, user)
|
125
|
failRows = append(failRows, user)
|
116
|
continue
|
126
|
continue
|
117
|
}
|
127
|
}
|
118
|
- if dep, ok = mapOrg[user.Department]; !ok && user.UserType != domain.UserTypeCooperation {
|
|
|
119
|
- user.FailReason = "导入的所属部门不存在:" + user.Department
|
128
|
+ if dep != nil && !dep.IsChild(optUser.OrgId) {
|
|
|
129
|
+ user.FailReason = fmt.Sprintf("导入的所属部门不是当前登录组织(%v)的子部门:%v", optUserOrg.OrgName, user.Department)
|
120
|
failRows = append(failRows, user)
|
130
|
failRows = append(failRows, user)
|
121
|
continue
|
131
|
continue
|
122
|
}
|
132
|
}
|
|
@@ -124,7 +134,7 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
@@ -124,7 +134,7 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
124
|
CompanyId: user.CompanyId,
|
134
|
CompanyId: user.CompanyId,
|
125
|
UserType: user.UserType,
|
135
|
UserType: user.UserType,
|
126
|
UserCode: user.UserCode,
|
136
|
UserCode: user.UserCode,
|
127
|
- OrganizationId: org.OrgId,
|
137
|
+ OrganizationId: optUser.OrgId,
|
128
|
UserOrg: []*domain.Org{},
|
138
|
UserOrg: []*domain.Org{},
|
129
|
UserRole: []*domain.Role{},
|
139
|
UserRole: []*domain.Role{},
|
130
|
FavoriteMenus: []string{},
|
140
|
FavoriteMenus: []string{},
|
|
@@ -172,24 +182,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
@@ -172,24 +182,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
172
|
return failRows, nil
|
182
|
return failRows, nil
|
173
|
}
|
183
|
}
|
174
|
|
184
|
|
175
|
-func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
|
|
|
176
|
- if len(user.UserCode) == 0 {
|
|
|
177
|
- return fmt.Errorf("导入的用户编码为空值")
|
|
|
178
|
- }
|
|
|
179
|
- if len(user.UserInfo.UserName) == 0 {
|
|
|
180
|
- return fmt.Errorf("导入的用户姓名为空值")
|
|
|
181
|
- }
|
|
|
182
|
- if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
|
|
|
183
|
- return fmt.Errorf("导入的手机号不是有效手机号")
|
|
|
184
|
- }
|
|
|
185
|
- if user.OrganizationId == 0 {
|
|
|
186
|
- return fmt.Errorf("导入的组织机构不存在")
|
|
|
187
|
- }
|
|
|
188
|
- if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
|
|
|
189
|
- return fmt.Errorf("导入的所属部门不存在")
|
|
|
190
|
- }
|
|
|
191
|
- return nil
|
|
|
192
|
-}
|
185
|
+//func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
|
|
|
186
|
+// if len(user.UserCode) == 0 {
|
|
|
187
|
+// return fmt.Errorf("导入的用户编码为空值")
|
|
|
188
|
+// }
|
|
|
189
|
+// if len(user.UserInfo.UserName) == 0 {
|
|
|
190
|
+// return fmt.Errorf("导入的用户姓名为空值")
|
|
|
191
|
+// }
|
|
|
192
|
+// if len(user.UserInfo.Phone) == 0 || len(user.UserInfo.Phone) != 11 {
|
|
|
193
|
+// return fmt.Errorf("导入的手机号不是有效手机号")
|
|
|
194
|
+// }
|
|
|
195
|
+// if user.OrganizationId == 0 {
|
|
|
196
|
+// return fmt.Errorf("导入的组织机构不存在")
|
|
|
197
|
+// }
|
|
|
198
|
+// if user.DepartmentId == 0 && user.UserType == domain.UserTypeEmployee {
|
|
|
199
|
+// return fmt.Errorf("导入的所属部门不存在")
|
|
|
200
|
+// }
|
|
|
201
|
+// return nil
|
|
|
202
|
+//}
|
193
|
|
203
|
|
194
|
func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error {
|
204
|
func (ptr *PgBatchAddUserService) preCheck2(user *domain.BatchAddUserItem) error {
|
195
|
if len(user.UserCode) == 0 {
|
205
|
if len(user.UserCode) == 0 {
|