company.go
6.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
package service
import (
"github.com/emirpasic/gods/sets/hashset"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/company/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
)
// 企业
type CompanyService struct {
}
// 创建企业
// func (companyService *CompanyService) CreateCompany(createCompanyCommand *command.CreateCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 返回企业
func (companyService *CompanyService) GetCompany(getCompanyQuery *query.GetCompanyQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.CompanyGet(allied_creation_user.ReqCompanyGet{
CompanyId: getCompanyQuery.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
InCompanyIds: []interface{}{result.CompanyId},
UserType: domain.UserTypeCompanyAdmin,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var user allied_creation_user.UserDetail
if len(userResult.Users) > 0 {
user = userResult.Users[0]
}
companyDto := &dto.CompanyGetItemDto{}
companyDto.LoadDto(allied_creation_user.CompanyItem(*result), user)
return companyDto, nil
}
func (companyService *CompanyService) AuditCompany(cmd *command.AuditCompanyCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err := creationUserGateway.AuditCompany(allied_creation_user.ReqCompanyAudit{
CompanyId: int(cmd.CompanyId),
Status: cmd.Status,
Remark: cmd.Remark,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
smsServe := sms_serve.NewHttplibHttplibSmsServe()
if cmd.Status == domain.CompanyAuthenticated {
var tmpPhone []rune = []rune(cmd.Phone)
for i := 0; i < 4; i++ {
tmpPhone[i+3] = rune('*')
}
err = smsServe.SendNoticeSms(cmd.Phone, 5007040, map[string]interface{}{"phone": string(tmpPhone)})
} else if cmd.Status == domain.CompanyUnauthenticated {
err = smsServe.SendNoticeSms(cmd.Phone, 5006964, map[string]interface{}{"reason": cmd.Remark})
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return struct{}{}, nil
}
func (companyService *CompanyService) EnableCompany(cmd *command.EnableCompanyCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err := creationUserGateway.EnableCompany(allied_creation_user.ReqCompanyEnable{
CompanyId: int(cmd.CompanyId),
Status: cmd.Status,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return struct{}{}, nil
}
// 返回企业列表
func (companyService *CompanyService) ListCompany(listCompanyQuery *query.ListCompanyQuery) (int64, interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
result, err := creationUserGateway.CompanySearch(allied_creation_user.ReqCompanySearch{
Offset: (listCompanyQuery.PageNumber - 1) * listCompanyQuery.PageSize,
Limit: listCompanyQuery.PageSize,
Status: listCompanyQuery.Status,
CompanyName: listCompanyQuery.CompanyName,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
companySet := hashset.New()
for i := range result.Companys {
companySet.Add(result.Companys[i].CompanyId)
}
var users = make([]allied_creation_user.UserDetail, 0)
if companySet.Size() > 0 {
userResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
InCompanyIds: companySet.Values(),
UserType: domain.UserTypeCompanyAdmin,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
users = userResult.Users
}
companyListItemsDto := dto.CompanyListItemsDto{}
companyListItemsDto.LoadDto(result.Companys, users)
return int64(result.Count), companyListItemsDto, nil
}
// 返回自定义菜单列表(匹配有设置的菜单)
// func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCustomizeMenusCommand *command.ListCompanyCustomizeMenusCommand) (interface{}, error) {
// return nil, nil
// }
// 移除企业
// func (companyService *CompanyService) RemoveCompany(removeCompanyCommand *command.RemoveCompanyCommand) (interface{}, error) {
// return nil, nil
// }
// 更新企业
func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *command.UpdateCompanyCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(updateCompanyCommand.Operator)
_, err := creationUserGateway.CompanyUpdate(allied_creation_user.ReqCompanyUpdate{
CompanyId: updateCompanyCommand.Operator.CompanyId,
CompanyName: updateCompanyCommand.CompanyName,
Address: updateCompanyCommand.Address,
SystemName: updateCompanyCommand.SystemName,
Logo: updateCompanyCommand.Logo,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return updateCompanyCommand, nil
}
func NewCompanyService(options map[string]interface{}) *CompanyService {
newCompanyService := &CompanyService{}
return newCompanyService
}