message_service_subscriber.go
6.1 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package subscriber
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/event"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type MessageServiceSubscriber struct {
//TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *MessageServiceSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
// 消息推送服务
messageServiceGateway, err := factory.CreateMessageServiceGateway(nil)
if err != nil {
log.Logger.Error("消息推送服务初始化", map[string]interface{}{
"err": err.Error(),
})
return nil
}
switch domainEvent.EventType() {
case event.COOPERATION_APPLICATION_AGREED: // 共创申请审核通过
cooperationApplicationAgreedEvent := domainEvent.(*event.CooperationApplicationAgreed)
data, err1 := messageServiceGateway.AgreeCooperationApplication(
cooperationApplicationAgreedEvent.CreationProjectId,
cooperationApplicationAgreedEvent.CreationProjectName,
cooperationApplicationAgreedEvent.CreationProjectNumber,
cooperationApplicationAgreedEvent.UserId,
cooperationApplicationAgreedEvent.UserBaseId,
cooperationApplicationAgreedEvent.OrgId,
cooperationApplicationAgreedEvent.CompanyId,
)
if err1 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err1.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
case event.CREATION_CONTRACT_INFORM_JOINT: // 共创确认
creationContractInformJointEvent := domainEvent.(*event.CreationContractInformJoint)
data, err2 := messageServiceGateway.InformJoinCreationContract(
creationContractInformJointEvent.CreationContractId,
creationContractInformJointEvent.CreationContractName,
creationContractInformJointEvent.CreationContractNumber,
creationContractInformJointEvent.CreationProjectId,
creationContractInformJointEvent.CreationProjectName,
creationContractInformJointEvent.UserId,
creationContractInformJointEvent.UserBaseId,
creationContractInformJointEvent.OrgId,
creationContractInformJointEvent.CompanyId,
)
if err2 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err2.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
case event.COOPERATION_APPLICATION_REJECTED: // 共创申请审核拒绝
cooperationApplicationRejectedEvent := domainEvent.(*event.CooperationApplicationRejected)
data, err3 := messageServiceGateway.RejectCooperationApplication(
cooperationApplicationRejectedEvent.CreationProjectId,
cooperationApplicationRejectedEvent.CreationProjectName,
cooperationApplicationRejectedEvent.CreationProjectNumber,
cooperationApplicationRejectedEvent.UserId,
cooperationApplicationRejectedEvent.UserBaseId,
cooperationApplicationRejectedEvent.OrgId,
cooperationApplicationRejectedEvent.CompanyId,
)
if err3 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err3.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
case event.CREDIT_ACCOUNT_PAID: // 账期结算支付
creditAccountPaidEvent := domainEvent.(*event.CreditAccountPaid)
data, err4 := messageServiceGateway.PayCreditAccount(
creditAccountPaidEvent.CreditAccountOrderNum,
creditAccountPaidEvent.SettlementAmount,
creditAccountPaidEvent.CreditAccountId,
creditAccountPaidEvent.DividendsEstimateId,
creditAccountPaidEvent.DividendsEstimateOrderNumber,
creditAccountPaidEvent.UserId,
creditAccountPaidEvent.UserBaseId,
creditAccountPaidEvent.OrgId,
creditAccountPaidEvent.CompanyId,
)
if err4 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err4.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
case event.DIVIDENDS_ESTIMATED: // 账期结算
dividendsEstimatedEvent := domainEvent.(*event.DividendsEstimated)
data, err5 := messageServiceGateway.DividendsEstimate(
dividendsEstimatedEvent.CreditAccountOrderNum,
dividendsEstimatedEvent.SettlementAmount,
dividendsEstimatedEvent.CreditAccountId,
dividendsEstimatedEvent.DividendsEstimateId,
dividendsEstimatedEvent.DividendsEstimateOrderNumber,
dividendsEstimatedEvent.UserId,
dividendsEstimatedEvent.UserBaseId,
dividendsEstimatedEvent.OrgId,
dividendsEstimatedEvent.CompanyId,
)
if err5 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err5.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
case event.DIVIDENDS_INFORM_EXPECTED: // 分红预算
dividendsInformExpectedEvent := domainEvent.(*event.DividendsInformExpected)
data, err6 := messageServiceGateway.InformExpectedDividends(
dividendsInformExpectedEvent.CreationContractId,
dividendsInformExpectedEvent.CreationContractName,
dividendsInformExpectedEvent.CreationContractNumber,
dividendsInformExpectedEvent.CreationProjectId,
dividendsInformExpectedEvent.CreationProjectName,
dividendsInformExpectedEvent.ProductName,
dividendsInformExpectedEvent.UserId,
dividendsInformExpectedEvent.UserBaseId,
dividendsInformExpectedEvent.OrgId,
dividendsInformExpectedEvent.CompanyId,
dividendsInformExpectedEvent.DividendsEstimateId,
dividendsInformExpectedEvent.DividendsAmount,
)
if err6 != nil {
log.Logger.Error("推送消息错误", map[string]interface{}{
"err": err6.Error(),
})
return nil
} else {
log.Logger.Info("推送数据返回", data)
}
break
}
return nil
}
func (subscriber *MessageServiceSubscriber) SubscribedToEventTypes() []string {
return []string{
event.COOPERATION_APPLICATION_AGREED, // 同意共创申请
event.CREATION_CONTRACT_INFORM_JOINT, // 确认共创
event.COOPERATION_APPLICATION_REJECTED, // 拒绝共创申请
event.CREDIT_ACCOUNT_PAID, // 账期支付
event.DIVIDENDS_ESTIMATED, // 账期结算
event.DIVIDENDS_INFORM_EXPECTED, // 分红预算
}
}