users_service_subscirber.go
2.2 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
package subscriber
import (
"github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/factory"
domainx "gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain/event"
"time"
)
type UsersServiceSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *UsersServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
userCreateService, _ := factory.CreateUserCreateService(map[string]interface{}{
"transactionContext": subscriber.TransactionContext,
})
switch domainEvent.EventType() {
case event.CompanyCreatedEvent:
companyCreatedEvent := domainEvent.(*event.CompanyCreated)
admin := companyCreatedEvent.Company.CompanyInfo.Admin
if _, err := userCreateService.CreateUser(companyCreatedEvent.OperatorId, &domainx.User{
UserType: domainx.Manager,
CompanyId: companyCreatedEvent.Company.CompanyId,
UserInfo: &domainx.UserInfo{
IsPrincipal: true,
UserAccount: admin.UserAccount,
UserName: admin.UserName,
},
AdminType: domainx.EnterpriseAdministrator,
PartnerInfo: &domainx.PartnerInfo{},
Status: domainx.StatusEnable,
CreateAt: time.Now(),
}); err != nil {
return err
}
case event.CompanyAdminAssignedEvent:
companyAdminAssigned := domainEvent.(*event.CompanyAdminAssigned)
admin := companyAdminAssigned.Admin
if _, err := userCreateService.CreateUser(companyAdminAssigned.OperatorId, &domainx.User{
UserType: domainx.Manager,
CompanyId: companyAdminAssigned.CompanyId,
UserInfo: &domainx.UserInfo{
IsPrincipal: true,
UserAccount: admin.UserAccount,
UserName: admin.UserName,
},
AdminType: domainx.EnterpriseAdministrator,
PartnerInfo: &domainx.PartnerInfo{},
Status: domainx.StatusEnable,
CreateAt: time.Now(),
}); err != nil {
return err
}
case event.UsersCreatedEvent:
}
return nil
}
func (subscriber *UsersServiceSubscriber) SubscribedToEventTypes() []string {
return []string{
event.CompanyAdminAssignedEvent,
event.CompanyCreatedEvent,
}
}