ability_service_subscriber.go
4.0 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
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 {
fmt.Println(err.Error())
return nil
}
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 nil
}
fmt.Println(data)
break
case event.TASK_CLOSED_EVENT:
taskClosedEvent := domainEvent.(*event.TaskClosed)
var referenceResourceIds []int64
for _, referenceResourceItem := range taskClosedEvent.ReferenceResource.ReferenceResourceItems {
referenceResourceIds = append(referenceResourceIds, referenceResourceItem.ReferenceResourceId)
}
data, err := abilityServiceGateway.CloseTaskCallback(taskClosedEvent.TaskId, referenceResourceIds)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
case event.TASK_ROBED_EVENT:
taskRobedEvent := domainEvent.(*event.TaskRobed)
var referenceResourceIds []int64
for _, referenceResourceItem := range taskRobedEvent.ReferenceResource.ReferenceResourceItems {
referenceResourceIds = append(referenceResourceIds, referenceResourceItem.ReferenceResourceId)
}
data, err := abilityServiceGateway.ReceiverTaskCallback(taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.TaskId, referenceResourceIds, taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.RobInfo.ReceiveTime)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
case event.TASK_BIDDED_EVENT:
taskBiddedEvent := domainEvent.(*event.TaskBidded)
var referenceResourceIds []int64
for _, referenceResourceItem := range taskBiddedEvent.ReferenceResource.ReferenceResourceItems {
referenceResourceIds = append(referenceResourceIds, referenceResourceItem.ReferenceResourceId)
}
data, err := abilityServiceGateway.ReceiverTaskCallback(taskBiddedEvent.BidInfo.SuccessfulBidder.Uid, taskBiddedEvent.TaskId, referenceResourceIds, taskBiddedEvent.Operator.Uid, taskBiddedEvent.BidInfo.WinBidTime)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
case event.TASK_ACCEPTANCED_EVENT:
taskAcceptancedEvent := domainEvent.(*event.TaskAcceptanced)
if taskAcceptancedEvent.ReferenceResource != nil {
var solveUid int64
var scoreSolve float64
for _, referenceResourceItem := range taskAcceptancedEvent.ReferenceResource.ReferenceResourceItems {
var partners []map[string]interface{}
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 nil
}
fmt.Println(data)
}
}
break
}
return nil
}
func (subscriber *AbilityServiceSubscriber) SubscribedToEventTypes() []string {
return [] string{
event.TASK_RELEASED_EVENT,
event.TASK_ACCEPTANCED_EVENT,
event.TASK_CLOSED_EVENT,
event.TASK_ROBED_EVENT,
event.TASK_BIDDED_EVENT,
}
}