|
|
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.Find(map[string]interface{}{"companyId": taskReleasedEvent.CompanyId}); 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,
|
|
|
}
|
|
|
} |
...
|
...
|
|