作者 yangfu

组织导入修改

... ... @@ -35,9 +35,15 @@ func (orgService *OrgService) BatchAdd(batchAddCommand *command.BatchAddCommand)
batchAddOrgService, _ := factory.CreatePgBatchAddOrgService(map[string]interface{}{
"transactionContext": transactionContext,
})
if err = batchAddOrgService.BatchAddOrg(batchAddCommand.OperateInfo, batchAddCommand.OrgList); err != nil {
var failRows []*domain.BatchAddOrgItem
if failRows, err = batchAddOrgService.BatchAddOrg(batchAddCommand.OperateInfo, batchAddCommand.OrgList); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(failRows) > 0 {
return map[string]interface{}{
"failRows": failRows,
}, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -217,4 +217,7 @@ type BatchAddOrgItem struct {
OrgName string `json:"orgName,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 失败理由
FailReason string `json:"failReason"`
}
... ...
... ... @@ -4,5 +4,5 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
// PgBatchAddUserService 批量添加用户服务
type PgBatchAddOrgService interface {
BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) error
BatchAddOrg(optUser *domain.OperateInfo, orgList []*domain.BatchAddOrgItem) ([]*domain.BatchAddOrgItem, error)
}
... ...
... ... @@ -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) {
... ...
... ... @@ -163,6 +163,9 @@ func (ptr *PgBatchAddUserService) BatchAddUser2(optUser *domain.OperateInfo, use
}
func (ptr *PgBatchAddUserService) preCheck(user *domain.User) error {
if len(user.UserCode) == 0 {
return fmt.Errorf("导入的用户编码为空值")
}
if len(user.UserInfo.UserName) == 0 {
return fmt.Errorf("导入的用户姓名为空值")
}
... ...