|
|
package subscriber
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/domain"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
|
|
|
)
|
|
|
|
|
|
type AbilityServiceSubscriber struct {
|
|
|
}
|
|
|
|
|
|
func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
|
|
|
abilityServiceGateway, err := factory.CreateAbilityServiceGateway(nil)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
switch domainEvent.EventType() {
|
|
|
case event.TASK_RELEASED_EVENT:
|
|
|
taskReleasedEvent := domainEvent.(*event.TaskReleased)
|
|
|
var serials []int64
|
|
|
for _, referenceResourceItem := range taskReleasedEvent.ReferenceResource.ReferenceResourceItems {
|
|
|
serials = append(serials, referenceResourceItem.SerialNumber)
|
|
|
}
|
|
|
data, err := abilityServiceGateway.CommitQuestionQuotes(taskReleasedEvent.Sponsor.Uid, taskReleasedEvent.TaskId, serials)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return err
|
|
|
}
|
|
|
fmt.Println(data)
|
|
|
break
|
|
|
case event.TASK_ACCEPTANCED_EVENT:
|
|
|
taskAcceptancedEvent := domainEvent.(*event.TaskAcceptanced)
|
|
|
if taskAcceptancedEvent.ReferenceResource != nil {
|
|
|
var solveUid int64
|
|
|
var scoreSolve float64
|
|
|
var partners []map[string]interface{}
|
|
|
for _, referenceResourceItem := range taskAcceptancedEvent.ReferenceResource.ReferenceResourceItems {
|
|
|
for _, solveScore := range referenceResourceItem.SolveScore {
|
|
|
if solveScore.IsReceiver {
|
|
|
solveUid = solveScore.Contributor.Uid
|
|
|
scoreSolve = solveScore.Score
|
|
|
} else {
|
|
|
partners = append(partners, map[string]interface{}{
|
|
|
"uid": solveScore.Contributor.Uid,
|
|
|
"scoreSolution": solveScore.Score,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return err
|
|
|
}
|
|
|
fmt.Println(data)
|
|
|
}
|
|
|
}
|
|
|
break
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (subscriber *AbilityServiceSubscriber) SubscribedToEventTypes() []string {
|
|
|
return [] string{
|
|
|
event.TASK_RELEASED_EVENT,
|
|
|
event.TASK_ACCEPTANCED_EVENT,
|
|
|
}
|
|
|
} |
...
|
...
|
|