正在显示
5 个修改的文件
包含
41 行增加
和
20 行删除
@@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm | @@ -65,10 +65,15 @@ func (userService *UserService) BatchAdd2(batchAddCommand *command.BatchAdd2Comm | ||
65 | batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ | 65 | batchAddUserService, _ := factory.CreateBatchAddUserService(map[string]interface{}{ |
66 | "transactionContext": transactionContext, | 66 | "transactionContext": transactionContext, |
67 | }) | 67 | }) |
68 | - if err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil { | ||
69 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 68 | + var failRows []*domain.BatchAddUserItem |
69 | + if failRows, err = batchAddUserService.BatchAddUser2(batchAddCommand.OperateInfo, batchAddCommand.Users, batchAddCommand.Password); err != nil { | ||
70 | + return batchAddCommand.Users, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
71 | + } | ||
72 | + if len(failRows) != 0 { | ||
73 | + return map[string]interface{}{ | ||
74 | + "failRows": failRows, | ||
75 | + }, nil //有错误行,回滚 | ||
70 | } | 76 | } |
71 | - | ||
72 | if err := transactionContext.CommitTransaction(); err != nil { | 77 | if err := transactionContext.CommitTransaction(); err != nil { |
73 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 78 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
74 | } | 79 | } |
@@ -414,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer | @@ -414,7 +419,7 @@ func (userService *UserService) GetUserAccessMenus(getUserAccessMenusQuery *quer | ||
414 | "transactionContext": transactionContext, | 419 | "transactionContext": transactionContext, |
415 | }) | 420 | }) |
416 | 421 | ||
417 | - menus, err := roleAccessMenusService.AccessMenus(nil, user.UserRoleIds(), domain.AccessMenusOptions{ | 422 | + menus, err := roleAccessMenusService.AccessMenus(getUserAccessMenusQuery.OperateInfo, user.UserRoleIds(), domain.AccessMenusOptions{ |
418 | CompanyId: user.CompanyId, | 423 | CompanyId: user.CompanyId, |
419 | MenuCategory: getUserAccessMenusQuery.MenuCategory, | 424 | MenuCategory: getUserAccessMenusQuery.MenuCategory, |
420 | OrgId: getUserAccessMenusQuery.OrgId, | 425 | OrgId: getUserAccessMenusQuery.OrgId, |
@@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -5,5 +5,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
5 | // PgBatchAddUserService 批量添加用户服务 | 5 | // PgBatchAddUserService 批量添加用户服务 |
6 | type PgBatchAddUserService interface { | 6 | type PgBatchAddUserService interface { |
7 | BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error | 7 | BatchAddUser(optUser *domain.OperateInfo, users []*domain.User, password string) error |
8 | - BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error | 8 | + BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) |
9 | } | 9 | } |
@@ -294,21 +294,24 @@ type BatchAddUserItem struct { | @@ -294,21 +294,24 @@ type BatchAddUserItem struct { | ||
294 | // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) | 294 | // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) |
295 | UserType int `json:"userType,omitempty"` | 295 | UserType int `json:"userType,omitempty"` |
296 | // 用户姓名 | 296 | // 用户姓名 |
297 | - UserName string `json:"userName,omitempty"` | 297 | + UserName string `json:"userName"` |
298 | // 手机号码 | 298 | // 手机号码 |
299 | - Phone string `json:"phone,omitempty"` | 299 | + Phone string `json:"phone"` |
300 | // 邮箱 | 300 | // 邮箱 |
301 | - Email string `json:"email,omitempty"` | 301 | + Email string `json:"email"` |
302 | // 用户编号 企业内标识 | 302 | // 用户编号 企业内标识 |
303 | - UserCode string `json:"userCode,omitempty"` | 303 | + UserCode string `json:"userCode"` |
304 | // 组织编码 | 304 | // 组织编码 |
305 | - Org string `json:"org,omitempty"` | 305 | + Org string `json:"org"` |
306 | // 部门编码 | 306 | // 部门编码 |
307 | - Department string `json:"department,omitempty"` | 307 | + Department string `json:"department"` |
308 | // 状态(1:启用 2:禁用 3:注销) | 308 | // 状态(1:启用 2:禁用 3:注销) |
309 | EnableStatus int `json:"enableStatus,omitempty"` | 309 | EnableStatus int `json:"enableStatus,omitempty"` |
310 | // 共创公司 cooperationCompany | 310 | // 共创公司 cooperationCompany |
311 | CooperationCompany string `json:"cooperationCompany"` | 311 | CooperationCompany string `json:"cooperationCompany"` |
312 | // 共创到期时间 (yyyy-MM-dd) cooperationDeadline | 312 | // 共创到期时间 (yyyy-MM-dd) cooperationDeadline |
313 | CooperationDeadline time.Time `json:"cooperationDeadline"` | 313 | CooperationDeadline time.Time `json:"cooperationDeadline"` |
314 | + | ||
315 | + // 失败理由 | ||
316 | + FailReason string `json:"failReason"` | ||
314 | } | 317 | } |
@@ -34,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis | @@ -34,7 +34,7 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis | ||
34 | CompanyId: optUser.CompanyId, | 34 | CompanyId: optUser.CompanyId, |
35 | OrgCode: item.OrgCode, | 35 | OrgCode: item.OrgCode, |
36 | OrgName: item.OrgName, | 36 | OrgName: item.OrgName, |
37 | - IsOrg: domain.IsOrgFlag, | 37 | + IsOrg: domain.IsNotOrgFlag, |
38 | ParentId: 0, | 38 | ParentId: 0, |
39 | OrgStatus: domain.OrgStatusEnable, | 39 | OrgStatus: domain.OrgStatusEnable, |
40 | CreatedAt: time.Now(), | 40 | CreatedAt: time.Now(), |
@@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user | @@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user | ||
82 | return nil | 82 | return nil |
83 | } | 83 | } |
84 | 84 | ||
85 | -func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error { | 85 | +func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) { |
86 | var ( | 86 | var ( |
87 | err error | 87 | err error |
88 | ) | 88 | ) |
89 | + var failRows = make([]*domain.BatchAddUserItem, 0) | ||
89 | orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) | 90 | orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) |
90 | if err != nil { | 91 | if err != nil { |
91 | - return err | 92 | + return failRows, err |
92 | } | 93 | } |
93 | _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000}) | 94 | _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000}) |
94 | if err != nil { | 95 | if err != nil { |
95 | - return err | 96 | + return failRows, err |
96 | } | 97 | } |
97 | var mapOrg = make(map[string]*domain.Org) | 98 | var mapOrg = make(map[string]*domain.Org) |
98 | for i := range orgs { | 99 | for i := range orgs { |
@@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
103 | for i := range users { | 104 | for i := range users { |
104 | user := users[i] | 105 | user := users[i] |
105 | if err = ptr.preCheck2(user); err != nil { | 106 | if err = ptr.preCheck2(user); err != nil { |
106 | - return err | 107 | + user.FailReason = err.Error() |
108 | + failRows = append(failRows, user) | ||
109 | + continue | ||
110 | + //return err | ||
107 | } | 111 | } |
108 | var org, dep *domain.Org | 112 | var org, dep *domain.Org |
109 | var ok bool | 113 | var ok bool |
110 | if org, ok = mapOrg[user.Org]; !ok { | 114 | if org, ok = mapOrg[user.Org]; !ok { |
111 | - return fmt.Errorf("导入的组织机构不存在:" + user.Org) | 115 | + user.FailReason = "导入的组织机构不存在:" + user.Org |
116 | + failRows = append(failRows, user) | ||
117 | + continue | ||
118 | + //return fmt.Errorf("导入的组织机构不存在:" + user.Org) | ||
112 | } | 119 | } |
113 | if dep, ok = mapOrg[user.Department]; !ok { | 120 | if dep, ok = mapOrg[user.Department]; !ok { |
114 | - return fmt.Errorf("导入的所属部门不存在:" + user.Department) | 121 | + user.FailReason = "导入的所属部门不存在:" + user.Department |
122 | + failRows = append(failRows, user) | ||
123 | + continue | ||
124 | + //return fmt.Errorf("导入的所属部门不存在:" + user.Department) | ||
115 | } | 125 | } |
116 | newUser := &domain.User{ | 126 | newUser := &domain.User{ |
117 | CompanyId: user.CompanyId, | 127 | CompanyId: user.CompanyId, |
@@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
143 | UpdatedAt: time.Now(), | 153 | UpdatedAt: time.Now(), |
144 | } | 154 | } |
145 | if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { | 155 | if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil { |
146 | - return fmt.Errorf("%v %v", user.UserName, err.Error()) | 156 | + user.FailReason = err.Error() |
157 | + failRows = append(failRows, user) | ||
158 | + continue | ||
159 | + //return fmt.Errorf("%v %v", user.UserName, err.Error()) | ||
147 | } | 160 | } |
148 | } | 161 | } |
149 | - return nil | 162 | + return failRows, nil |
150 | } | 163 | } |
151 | 164 | ||
152 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { | 165 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { |
-
请 注册 或 登录 后发表评论