...
|
...
|
@@ -8,6 +8,8 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/org/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 组织管理
|
...
|
...
|
@@ -35,23 +37,25 @@ func (orgService *OrgService) CreateOrg(createOrgCommand *command.CreateOrgComma |
|
|
OrgName: createOrgCommand.OrgName,
|
|
|
IsOrg: createOrgCommand.IsOrg,
|
|
|
ParentId: createOrgCommand.ParentId,
|
|
|
OrgStatus: domain.OrgStatusEnable,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
Ext: &domain.Ext{},
|
|
|
}
|
|
|
var orgRepository domain.OrgRepository
|
|
|
if value, err := factory.CreateOrgRepository(map[string]interface{}{
|
|
|
var org *domain.Org
|
|
|
if createOrgService, err := factory.CreatePgCreateOrgService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
orgRepository = value
|
|
|
if org, err = createOrgService.CreateOrg(nil, newOrg); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
if org, err := orgRepository.Save(newOrg); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return org, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 设置组织启用状态
|
...
|
...
|
@@ -156,7 +160,7 @@ func (orgService *OrgService) ListOrg(listOrgQuery *query.ListOrgQuery) (interfa |
|
|
} else {
|
|
|
orgRepository = value
|
|
|
}
|
|
|
if count, orgs, err := orgRepository.Find(tool_funs.SimpleStructToMap(listOrgQuery)); err != nil {
|
|
|
if count, orgs, err := orgRepository.Find(utils.ObjectToMap(listOrgQuery)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -224,32 +228,37 @@ func (orgService *OrgService) UpdateOrg(updateOrgCommand *command.UpdateOrgComma |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var orgRepository domain.OrgRepository
|
|
|
if value, err := factory.CreateOrgRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
orgRepository = value
|
|
|
}
|
|
|
org, err := orgRepository.FindOne(map[string]interface{}{"orgId": updateOrgCommand.OrgId})
|
|
|
orgRepository, org, err := factory.FastPgOrg(transactionContext, updateOrgCommand.OrgId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
if org == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateOrgCommand.OrgId)))
|
|
|
|
|
|
//判断当前组织内是否唯一 组织编码、组织名称
|
|
|
if findOne, err := orgRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId, "parentId": updateOrgCommand.ParentId, "orgName": updateOrgCommand.OrgName, "notEqualOrgId": org.OrgId}); err == nil || findOne != nil {
|
|
|
return nil, fmt.Errorf("部门名称重复")
|
|
|
}
|
|
|
if findOne, err := orgRepository.FindOne(map[string]interface{}{"companyId": org.CompanyId, "parentId": updateOrgCommand.ParentId, "orgCode": updateOrgCommand.OrgCode, "notEqualOrgId": org.OrgId}); err == nil || findOne != nil {
|
|
|
return nil, fmt.Errorf("部门编码重复")
|
|
|
}
|
|
|
|
|
|
if err := org.Update(tool_funs.SimpleStructToMap(updateOrgCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if org, err := orgRepository.Save(org); err != nil {
|
|
|
//上继组织
|
|
|
if updateOrgCommand.ParentId != 0 {
|
|
|
_, parentOrg, err := factory.FastPgOrg(transactionContext, updateOrgCommand.ParentId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
org.Ext.ParentDepName = parentOrg.OrgName
|
|
|
}
|
|
|
if org, err = orgRepository.Save(org); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return org, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func NewOrgService(options map[string]interface{}) *OrgService {
|
...
|
...
|
|