...
|
...
|
@@ -13,14 +13,15 @@ type PgBatchAddOrgService struct { |
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error {
|
|
|
func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) ([]*domain.BatchAddOrgItem, error) {
|
|
|
orgRepository, err := repository.NewOrgRepository(ptr.transactionContext)
|
|
|
var failRows = make([]*domain.BatchAddOrgItem, 0)
|
|
|
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 {
|
...
|
...
|
@@ -42,20 +43,26 @@ func (ptr *PgBatchAddOrgService) BatchAddOrg(optUser *domain.OperateInfo, orgLis |
|
|
Ext: &domain.Ext{},
|
|
|
}
|
|
|
if v, ok := mapOrg[item.ParentOrgCode]; !ok {
|
|
|
return fmt.Errorf(fmt.Sprintf("找不到组织:%v", item.OrgCode))
|
|
|
item.FailReason = fmt.Sprintf("找不到组织:%v", item.OrgCode)
|
|
|
failRows = append(failRows, item)
|
|
|
continue
|
|
|
//return fmt.Errorf(fmt.Sprintf("找不到组织:%v", item.OrgCode))
|
|
|
} else {
|
|
|
orgItem.ParentId = v.OrgId
|
|
|
}
|
|
|
|
|
|
orgItem, err = createOrgService.CreateOrg(optUser, orgItem)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("%v %v", item.OrgName, err.Error())
|
|
|
item.FailReason = err.Error()
|
|
|
failRows = append(failRows, item)
|
|
|
continue
|
|
|
//return fmt.Errorf("%v %v", item.OrgName, err.Error())
|
|
|
}
|
|
|
if _, ok := mapOrg[orgItem.OrgCode]; !ok {
|
|
|
mapOrg[orgItem.OrgCode] = orgItem
|
|
|
}
|
|
|
}
|
|
|
return err
|
|
|
return failRows, nil
|
|
|
}
|
|
|
|
|
|
func NewPgBatchAddOrgService(transactionContext *pgTransaction.TransactionContext) (*PgBatchAddOrgService, error) {
|
...
|
...
|
|