正在显示
5 个修改的文件
包含
27 行增加
和
8 行删除
@@ -35,9 +35,15 @@ func (orgService *OrgService) BatchAdd(batchAddCommand *command.BatchAddCommand) | @@ -35,9 +35,15 @@ func (orgService *OrgService) BatchAdd(batchAddCommand *command.BatchAddCommand) | ||
35 | batchAddOrgService, _ := factory.CreatePgBatchAddOrgService(map[string]interface{}{ | 35 | batchAddOrgService, _ := factory.CreatePgBatchAddOrgService(map[string]interface{}{ |
36 | "transactionContext": transactionContext, | 36 | "transactionContext": transactionContext, |
37 | }) | 37 | }) |
38 | - if err = batchAddOrgService.BatchAddOrg(batchAddCommand.OperateInfo, batchAddCommand.OrgList); err != nil { | 38 | + var failRows []*domain.BatchAddOrgItem |
39 | + if failRows, err = batchAddOrgService.BatchAddOrg(batchAddCommand.OperateInfo, batchAddCommand.OrgList); err != nil { | ||
39 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 40 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
40 | } | 41 | } |
42 | + if len(failRows) > 0 { | ||
43 | + return map[string]interface{}{ | ||
44 | + "failRows": failRows, | ||
45 | + }, nil | ||
46 | + } | ||
41 | 47 | ||
42 | if err := transactionContext.CommitTransaction(); err != nil { | 48 | if err := transactionContext.CommitTransaction(); err != nil { |
43 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 49 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -217,4 +217,7 @@ type BatchAddOrgItem struct { | @@ -217,4 +217,7 @@ type BatchAddOrgItem struct { | ||
217 | OrgName string `json:"orgName,omitempty"` | 217 | OrgName string `json:"orgName,omitempty"` |
218 | // 企业id | 218 | // 企业id |
219 | CompanyId int64 `json:"companyId,omitempty"` | 219 | CompanyId int64 `json:"companyId,omitempty"` |
220 | + | ||
221 | + // 失败理由 | ||
222 | + FailReason string `json:"failReason"` | ||
220 | } | 223 | } |
@@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | ||
4 | 4 | ||
5 | // PgBatchAddUserService 批量添加用户服务 | 5 | // PgBatchAddUserService 批量添加用户服务 |
6 | type PgBatchAddOrgService interface { | 6 | type PgBatchAddOrgService interface { |
7 | - BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error | 7 | + BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) ([]*domain.BatchAddOrgItem, error) |
8 | } | 8 | } |
@@ -13,14 +13,15 @@ type PgBatchAddOrgService struct { | @@ -13,14 +13,15 @@ type PgBatchAddOrgService struct { | ||
13 | transactionContext *pgTransaction.TransactionContext | 13 | transactionContext *pgTransaction.TransactionContext |
14 | } | 14 | } |
15 | 15 | ||
16 | -func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error { | 16 | +func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) ([]*domain.BatchAddOrgItem, error) { |
17 | orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) | 17 | orgRepository, err := repository.NewOrgRepository(ptr.transactionContext) |
18 | + var failRows = make([]*domain.BatchAddOrgItem, 0) | ||
18 | if err != nil { | 19 | if err != nil { |
19 | - return err | 20 | + return failRows, err |
20 | } | 21 | } |
21 | _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000}) | 22 | _, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000}) |
22 | if err != nil { | 23 | if err != nil { |
23 | - return err | 24 | + return failRows, err |
24 | } | 25 | } |
25 | var mapOrg = make(map[string]*domain.Org) | 26 | var mapOrg = make(map[string]*domain.Org) |
26 | for i := range orgs { | 27 | for i := range orgs { |
@@ -42,20 +43,26 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis | @@ -42,20 +43,26 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis | ||
42 | Ext: &domain.Ext{}, | 43 | Ext: &domain.Ext{}, |
43 | } | 44 | } |
44 | if v, ok := mapOrg[item.ParentOrgCode]; !ok { | 45 | if v, ok := mapOrg[item.ParentOrgCode]; !ok { |
45 | - return fmt.Errorf(fmt.Sprintf("找不到组织:%v", item.OrgCode)) | 46 | + item.FailReason = fmt.Sprintf("找不到组织:%v", item.OrgCode) |
47 | + failRows = append(failRows, item) | ||
48 | + continue | ||
49 | + //return fmt.Errorf(fmt.Sprintf("找不到组织:%v", item.OrgCode)) | ||
46 | } else { | 50 | } else { |
47 | orgItem.ParentId = v.OrgId | 51 | orgItem.ParentId = v.OrgId |
48 | } | 52 | } |
49 | 53 | ||
50 | orgItem, err = createOrgService.CreateOrg(optUser, orgItem) | 54 | orgItem, err = createOrgService.CreateOrg(optUser, orgItem) |
51 | if err != nil { | 55 | if err != nil { |
52 | - return fmt.Errorf("%v %v", item.OrgName, err.Error()) | 56 | + item.FailReason = err.Error() |
57 | + failRows = append(failRows, item) | ||
58 | + continue | ||
59 | + //return fmt.Errorf("%v %v", item.OrgName, err.Error()) | ||
53 | } | 60 | } |
54 | if _, ok := mapOrg[orgItem.OrgCode]; !ok { | 61 | if _, ok := mapOrg[orgItem.OrgCode]; !ok { |
55 | mapOrg[orgItem.OrgCode] = orgItem | 62 | mapOrg[orgItem.OrgCode] = orgItem |
56 | } | 63 | } |
57 | } | 64 | } |
58 | - return err | 65 | + return failRows, nil |
59 | } | 66 | } |
60 | 67 | ||
61 | func NewPgBatchAddOrgService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddOrgService, error) { | 68 | func NewPgBatchAddOrgService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddOrgService, error) { |
@@ -163,6 +163,9 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | @@ -163,6 +163,9 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use | ||
163 | } | 163 | } |
164 | 164 | ||
165 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { | 165 | func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error { |
166 | + if len(user.UserCode) == 0 { | ||
167 | + return fmt.Errorf("导入的用户编码为空值") | ||
168 | + } | ||
166 | if len(user.UserInfo.UserName) == 0 { | 169 | if len(user.UserInfo.UserName) == 0 { |
167 | return fmt.Errorf("导入的用户姓名为空值") | 170 | return fmt.Errorf("导入的用户姓名为空值") |
168 | } | 171 | } |
-
请 注册 或 登录 后发表评论