mmm_open_api_service_subscriber.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
package subscriber
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
)
type MmmOpenApiServiceServiceSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *MmmOpenApiServiceServiceSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
mmmOpenApiServiceGateway, err := factory.CreateMmmOpenApiServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil
}
switch domainEvent.EventType() {
case event.TASK_RELEASED_EVENT:
taskReleasedEvent := domainEvent.(*event.TaskReleased)
var employeeRepository domain.EmployeeRepository
if repository, err := repository.NewEmployeeRepository(subscriber.TransactionContext); err != nil {
fmt.Println(err.Error())
return nil
} else {
employeeRepository = repository
}
uids := make([]int64, 0)
if _, employees, err := employeeRepository.FindAll(map[string]interface{}{"companyId": taskReleasedEvent.CompanyId, "status": 1}); err != nil {
fmt.Println(err.Error())
return nil
} else {
for _, employee := range employees {
uids = append(uids, employee.EmployeeInfo.Uid)
}
}
title := fmt.Sprintf("%s发布了一个任务", taskReleasedEvent.Sponsor.EmployeeName)
content := fmt.Sprintf("%s发布了一个任务", taskReleasedEvent.Sponsor.EmployeeName)
transData := make(map[string]interface{})
transData["mmmType"] = "101"
transData["mmmTitle"] = title
transData["mmmContent"] = content
transData["resourceId"] = taskReleasedEvent.TaskId
ext := make(map[string]interface{})
ext["transData"] = transData
data, err := mmmOpenApiServiceGateway.PushInfo(0, uids, title, content, ext)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
}
return nil
}
func (subscriber *MmmOpenApiServiceServiceSubscriber) SubscribedToEventTypes() []string {
return [] string{
event.TASK_RELEASED_EVENT,
}
}