orgs.go
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/orgs/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/orgs/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/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)
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)
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)
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.OrgID),
OrgName: result.OrgName,
ParentId: strconv.Itoa(result.ParentID),
IsOrg: result.IsOrg,
OrgCode: result.OrgCode,
ParentDepName: result.Ext.ParentDepName,
OrgStatus: result.OrgStatus,
}
return data, nil
}
// 返回组织管理列表
func (orgsService *OrgsService) OrgList(orgListQuery *query.OrgListQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgListQuery.Operator)
parentOrgId, _ := strconv.Atoi(orgListQuery.ParentId)
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: parentOrgId,
})
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,
OrgStatus: v.OrgStatus,
}
dataList = append(dataList, item)
}
return dataList, nil
}
// 更新组织管理
func (orgsService *OrgsService) OrgUpdate(orgUpdateCommand *command.OrgUpdateCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgUpdateCommand.Operator)
parentId, _ := strconv.Atoi(orgUpdateCommand.ParentId)
orgId, _ := strconv.Atoi(orgUpdateCommand.OrgId)
_, err := creationUserGateway.OrgUpdate(allied_creation_user.ReqOrgUpdate{
OrgId: int64(orgId),
IsOrg: orgUpdateCommand.IsOrg,
OrgCode: orgUpdateCommand.OrgCode,
OrgName: orgUpdateCommand.OrgName,
ParentId: int64(parentId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return orgUpdateCommand, nil
}
// 返回组织管理
func (orgsService *OrgsService) OrgGetSubDepartment(orgGetQuery *query.OrgGetSubDepartmentQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
orgGetQuery.Operator)
orgId, _ := strconv.Atoi(orgGetQuery.OrgId)
result, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: int64(orgId),
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"list": result.Orgs,
}, nil
}
func NewOrgsService(options map[string]interface{}) *OrgsService {
newOrgsService := &OrgsService{}
return newOrgsService
}