|
|
package service
|
|
|
|
|
|
import (
|
|
|
"strconv"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/orgs/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
|
|
|
)
|
|
|
|
|
|
// 组织管理
|
|
|
type OrgsService struct {
|
|
|
}
|
|
|
|
|
|
// 创建组织管理
|
|
|
func (orgsService *OrgsService) OrgAdd(orgAddCommand *command.OrgAddCommand) (interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
orgAddCommand.Operator.CompanyId,
|
|
|
orgAddCommand.Operator.OrgId,
|
|
|
orgAddCommand.Operator.UserId)
|
|
|
parentId, _ := strconv.Atoi(orgAddCommand.ParentId)
|
|
|
result, err := creationUserGateway.OrgCreate(allied_creation_user.ReqOrgCreate{
|
|
|
CompanyId: int(orgAddCommand.Operator.CompanyId),
|
|
|
IsOrg: orgAddCommand.IsOrg,
|
|
|
OrgCode: orgAddCommand.OrgCode,
|
|
|
OrgName: orgAddCommand.OrgName,
|
|
|
ParentId: parentId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
data := struct {
|
|
|
OrgId int `json:"orgId"`
|
|
|
command.OrgAddCommand
|
|
|
}{
|
|
|
OrgId: result.OrgId,
|
|
|
OrgAddCommand: *orgAddCommand,
|
|
|
}
|
|
|
return data, nil
|
|
|
}
|
|
|
|
|
|
// 禁用、启用组织管理
|
|
|
func (orgsService *OrgsService) OrgEnable(orgEnableCommand *command.OrgEnableCommand) (interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
orgEnableCommand.Operator.CompanyId,
|
|
|
orgEnableCommand.Operator.OrgId,
|
|
|
orgEnableCommand.Operator.UserId)
|
|
|
orgId, _ := strconv.Atoi(orgEnableCommand.OrgId)
|
|
|
_, err := creationUserGateway.OrgEnable(allied_creation_user.ReqOrgEnable{
|
|
|
OrgId: orgId,
|
|
|
OrgStatus: orgEnableCommand.Status,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return orgEnableCommand, nil
|
|
|
}
|
|
|
|
|
|
// 返回组织管理
|
|
|
func (orgsService *OrgsService) OrgGet(orgGetQuery *query.OrgGetQuery) (interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
orgGetQuery.Operator.CompanyId,
|
|
|
orgGetQuery.Operator.OrgId,
|
|
|
orgGetQuery.Operator.UserId)
|
|
|
orgId, _ := strconv.Atoi(orgGetQuery.OrgId)
|
|
|
result, err := creationUserGateway.OrgGet(allied_creation_user.ReqOrgGet{
|
|
|
OrgId: orgId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
data := dto.OrgItem{
|
|
|
OrgId: strconv.Itoa(result.Org.OrgID),
|
|
|
OrgName: result.Org.OrgName,
|
|
|
ParentId: strconv.Itoa(result.Org.ParentID),
|
|
|
IsOrg: result.Org.IsOrg,
|
|
|
OrgCode: result.Org.OrgCode,
|
|
|
ParentDepName: result.Org.Ext.ParentDepName,
|
|
|
}
|
|
|
return data, nil
|
|
|
}
|
|
|
|
|
|
// 返回组织管理列表
|
|
|
func (orgsService *OrgsService) OrgList(orgListQuery *query.OrgListQuery) (interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
orgListQuery.Operator.CompanyId,
|
|
|
orgListQuery.Operator.OrgId,
|
|
|
orgListQuery.Operator.UserId)
|
|
|
result, err := creationUserGateway.OrgSearch(allied_creation_user.ReqOrgSearch{
|
|
|
CompanyId: int(orgListQuery.Operator.CompanyId),
|
|
|
DepName: orgListQuery.DepName,
|
|
|
IsOrg: 0,
|
|
|
Limit: 0,
|
|
|
Offset: 0,
|
|
|
OrgCode: orgListQuery.OrgCode,
|
|
|
ParentId: orgListQuery.ParentId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
dataList []dto.OrgItem
|
|
|
item dto.OrgItem
|
|
|
)
|
|
|
for _, v := range result.Orgs {
|
|
|
item = dto.OrgItem{
|
|
|
OrgId: strconv.Itoa(v.OrgID),
|
|
|
OrgName: v.OrgName,
|
|
|
ParentId: strconv.Itoa(v.ParentID),
|
|
|
IsOrg: v.IsOrg,
|
|
|
OrgCode: v.OrgCode,
|
|
|
ParentDepName: v.Ext.ParentDepName,
|
|
|
}
|
|
|
dataList = append(dataList, item)
|
|
|
}
|
|
|
return dataList, nil
|
|
|
}
|
|
|
|
|
|
// 更新组织管理
|
|
|
func (orgsService *OrgsService) OrgUpdate(orgUpdateCommand *command.OrgUpdateCommand) (interface{}, error) {
|
|
|
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
|
|
|
orgUpdateCommand.Operator.CompanyId,
|
|
|
orgUpdateCommand.Operator.OrgId,
|
|
|
orgUpdateCommand.Operator.UserId)
|
|
|
parentId, _ := strconv.Atoi(orgUpdateCommand.ParentId)
|
|
|
_, err := creationUserGateway.OrgCreate(allied_creation_user.ReqOrgCreate{
|
|
|
IsOrg: orgUpdateCommand.IsOrg,
|
|
|
OrgCode: orgUpdateCommand.OrgCode,
|
|
|
OrgName: orgUpdateCommand.OrgName,
|
|
|
ParentId: parentId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return orgUpdateCommand, nil
|
|
|
}
|
|
|
|
|
|
func NewOrgsService(options map[string]interface{}) *OrgsService {
|
|
|
newOrgsService := &OrgsService{}
|
|
|
return newOrgsService
|
|
|
} |
...
|
...
|
|