...
|
...
|
@@ -82,17 +82,18 @@ func (ptr *PgBatchAddUserService) BatchAddUser(optUser *domain.OperateInfo, user |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) error {
|
|
|
func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, users []*domain.BatchAddUserItem, password string) ([]*domain.BatchAddUserItem, error) {
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
var failRows = make([]*domain.BatchAddUserItem, 0)
|
|
|
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
return failRows, err
|
|
|
}
|
|
|
_, orgs, err := orgRepository.Find(map[string]interface{}{"companyId": optUser.CompanyId, "limit": 10000})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
return failRows, err
|
|
|
}
|
|
|
var mapOrg = make(map[string]*domain.Org)
|
|
|
for i := range orgs {
|
...
|
...
|
@@ -103,15 +104,24 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
|
for i := range users {
|
|
|
user := users[i]
|
|
|
if err = ptr.preCheck2(user); err != nil {
|
|
|
return err
|
|
|
user.FailReason = err.Error()
|
|
|
failRows = append(failRows, user)
|
|
|
continue
|
|
|
//return err
|
|
|
}
|
|
|
var org, dep *domain.Org
|
|
|
var ok bool
|
|
|
if org, ok = mapOrg[user.Org]; !ok {
|
|
|
return fmt.Errorf("导入的组织机构不存在:" + user.Org)
|
|
|
user.FailReason = "导入的组织机构不存在:" + user.Org
|
|
|
failRows = append(failRows, user)
|
|
|
continue
|
|
|
//return fmt.Errorf("导入的组织机构不存在:" + user.Org)
|
|
|
}
|
|
|
if dep, ok = mapOrg[user.Department]; !ok {
|
|
|
return fmt.Errorf("导入的所属部门不存在:" + user.Department)
|
|
|
user.FailReason = "导入的所属部门不存在:" + user.Department
|
|
|
failRows = append(failRows, user)
|
|
|
continue
|
|
|
//return fmt.Errorf("导入的所属部门不存在:" + user.Department)
|
|
|
}
|
|
|
newUser := &domain.User{
|
|
|
CompanyId: user.CompanyId,
|
...
|
...
|
@@ -143,10 +153,13 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use |
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
if newUser, err = createUserService.CreateUser(nil, newUser, password); err != nil {
|
|
|
return fmt.Errorf("%v %v", user.UserName, err.Error())
|
|
|
user.FailReason = err.Error()
|
|
|
failRows = append(failRows, user)
|
|
|
continue
|
|
|
//return fmt.Errorf("%v %v", user.UserName, err.Error())
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
return failRows, nil
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
|
...
|
...
|
|