作者 linmadan

添加服务网关功能

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,
}
}
... ...
package factory
import serviceGateway "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/service_gateway"
func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway.AbilityServiceGateway, error) {
return serviceGateway.NewHttplibAbilityServiceGateway(), nil
}
... ...
package event
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
const TASK_ACCEPTANCED_EVENT = "task-acceptanced-event"
type TaskAcceptanced struct {
coreDomain.BaseEvent
// 任务ID
TaskId int64 `json:"taskId"`
// 公司ID
CompanyId int64 `json:"companyId"`
// 任务名称
TaskName string `json:"taskName"`
// 任务类型Type
TaskType int `json:"taskType"`
// 任务发起者
Sponsor *domain.EmployeeInfo `json:"sponsor"`
// 任务状态
TaskStatus int `json:"taskStatus"`
// 引用资源
ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard"`
// 任务参与者列表
Participators []*domain.EmployeeInfo `json:"participators"`
// 任务贡献占比
TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
// 解决报告
SolveReport string `json:"solveReport"`
// 解决图片URL列表
SolvePictureUrls []string `json:"solvePictureUrls"`
}
func (event *TaskAcceptanced) EventType() string {
return TASK_ACCEPTANCED_EVENT
}
... ...
package event
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
const TASK_RELEASED_EVENT = "task-released-event"
type TaskReleased struct {
coreDomain.BaseEvent
// 任务ID
TaskId int64 `json:"taskId"`
// 公司ID
CompanyId int64 `json:"companyId"`
// 任务名称
TaskName string `json:"taskName"`
// 任务类型Type
TaskType int `json:"taskType"`
// 任务发起者
Sponsor *domain.EmployeeInfo `json:"sponsor"`
// 任务状态
TaskStatus int `json:"taskStatus"`
// 引用资源
ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
// 客户价值列表
CustomerValue []string `json:"customerValue"`
// 任务性质
TaskNature string `json:"taskNature"`
// 奖励素币
SuMoney float64 `json:"suMoney"`
// 验收标准
AcceptanceStandard string `json:"acceptanceStandard"`
// 任务描述
TaskDescription string `json:"taskDescription"`
// 竞标任务信息
BidInfo *domain.BidInfo `json:"bidInfo"`
}
func (event *TaskReleased) EventType() string {
return TASK_RELEASED_EVENT
}
... ...
... ... @@ -86,7 +86,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
if _, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil {
return nil, err
}
if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, task.SuMoney); err != nil {
if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, taskPercentageItem.SuMoney); err != nil {
return nil, err
}
}
... ...