作者 linmadan

添加服务网关功能

  1 +package subscriber
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/domain"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
  8 +)
  9 +
  10 +type AbilityServiceSubscriber struct {
  11 +}
  12 +
  13 +func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
  14 + abilityServiceGateway, err := factory.CreateAbilityServiceGateway(nil)
  15 + if err != nil {
  16 + return err
  17 + }
  18 + switch domainEvent.EventType() {
  19 + case event.TASK_RELEASED_EVENT:
  20 + taskReleasedEvent := domainEvent.(*event.TaskReleased)
  21 + var serials []int64
  22 + for _, referenceResourceItem := range taskReleasedEvent.ReferenceResource.ReferenceResourceItems {
  23 + serials = append(serials, referenceResourceItem.SerialNumber)
  24 + }
  25 + data, err := abilityServiceGateway.CommitQuestionQuotes(taskReleasedEvent.Sponsor.Uid, taskReleasedEvent.TaskId, serials)
  26 + if err != nil {
  27 + fmt.Println(err.Error())
  28 + return err
  29 + }
  30 + fmt.Println(data)
  31 + break
  32 + case event.TASK_ACCEPTANCED_EVENT:
  33 + taskAcceptancedEvent := domainEvent.(*event.TaskAcceptanced)
  34 + if taskAcceptancedEvent.ReferenceResource != nil {
  35 + var solveUid int64
  36 + var scoreSolve float64
  37 + var partners []map[string]interface{}
  38 + for _, referenceResourceItem := range taskAcceptancedEvent.ReferenceResource.ReferenceResourceItems {
  39 + for _, solveScore := range referenceResourceItem.SolveScore {
  40 + if solveScore.IsReceiver {
  41 + solveUid = solveScore.Contributor.Uid
  42 + scoreSolve = solveScore.Score
  43 + } else {
  44 + partners = append(partners, map[string]interface{}{
  45 + "uid": solveScore.Contributor.Uid,
  46 + "scoreSolution": solveScore.Score,
  47 + })
  48 + }
  49 + }
  50 + data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners)
  51 + if err != nil {
  52 + fmt.Println(err.Error())
  53 + return err
  54 + }
  55 + fmt.Println(data)
  56 + }
  57 + }
  58 + break
  59 + }
  60 + return nil
  61 +}
  62 +
  63 +func (subscriber *AbilityServiceSubscriber) SubscribedToEventTypes() []string {
  64 + return [] string{
  65 + event.TASK_RELEASED_EVENT,
  66 + event.TASK_ACCEPTANCED_EVENT,
  67 + }
  68 +}
  1 +package factory
  2 +
  3 +import serviceGateway "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/service_gateway"
  4 +
  5 +func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway.AbilityServiceGateway, error) {
  6 + return serviceGateway.NewHttplibAbilityServiceGateway(), nil
  7 +}
  1 +package event
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
  7 +
  8 +const TASK_ACCEPTANCED_EVENT = "task-acceptanced-event"
  9 +
  10 +type TaskAcceptanced struct {
  11 + coreDomain.BaseEvent
  12 + // 任务ID
  13 + TaskId int64 `json:"taskId"`
  14 + // 公司ID
  15 + CompanyId int64 `json:"companyId"`
  16 + // 任务名称
  17 + TaskName string `json:"taskName"`
  18 + // 任务类型Type
  19 + TaskType int `json:"taskType"`
  20 + // 任务发起者
  21 + Sponsor *domain.EmployeeInfo `json:"sponsor"`
  22 + // 任务状态
  23 + TaskStatus int `json:"taskStatus"`
  24 + // 引用资源
  25 + ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
  26 + // 验收标准
  27 + AcceptanceStandard string `json:"acceptanceStandard"`
  28 + // 任务参与者列表
  29 + Participators []*domain.EmployeeInfo `json:"participators"`
  30 + // 任务贡献占比
  31 + TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
  32 + // 解决报告
  33 + SolveReport string `json:"solveReport"`
  34 + // 解决图片URL列表
  35 + SolvePictureUrls []string `json:"solvePictureUrls"`
  36 +}
  37 +
  38 +func (event *TaskAcceptanced) EventType() string {
  39 + return TASK_ACCEPTANCED_EVENT
  40 +}
  1 +package event
  2 +
  3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
  7 +
  8 +const TASK_RELEASED_EVENT = "task-released-event"
  9 +
  10 +type TaskReleased struct {
  11 + coreDomain.BaseEvent
  12 + // 任务ID
  13 + TaskId int64 `json:"taskId"`
  14 + // 公司ID
  15 + CompanyId int64 `json:"companyId"`
  16 + // 任务名称
  17 + TaskName string `json:"taskName"`
  18 + // 任务类型Type
  19 + TaskType int `json:"taskType"`
  20 + // 任务发起者
  21 + Sponsor *domain.EmployeeInfo `json:"sponsor"`
  22 + // 任务状态
  23 + TaskStatus int `json:"taskStatus"`
  24 + // 引用资源
  25 + ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
  26 + // 客户价值列表
  27 + CustomerValue []string `json:"customerValue"`
  28 + // 任务性质
  29 + TaskNature string `json:"taskNature"`
  30 + // 奖励素币
  31 + SuMoney float64 `json:"suMoney"`
  32 + // 验收标准
  33 + AcceptanceStandard string `json:"acceptanceStandard"`
  34 + // 任务描述
  35 + TaskDescription string `json:"taskDescription"`
  36 + // 竞标任务信息
  37 + BidInfo *domain.BidInfo `json:"bidInfo"`
  38 +}
  39 +
  40 +func (event *TaskReleased) EventType() string {
  41 + return TASK_RELEASED_EVENT
  42 +}
@@ -86,7 +86,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -86,7 +86,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
86 if _, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil { 86 if _, err := suMoneyTransactionRecordRepository.Save(suMoneyTransactionRecord); err != nil {
87 return nil, err 87 return nil, err
88 } 88 }
89 - if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, task.SuMoney); err != nil { 89 + if err := employeeDao.TransferSuMoney(taskPercentageItem.Contributor.Uid, taskPercentageItem.SuMoney); err != nil {
90 return nil, err 90 return nil, err
91 } 91 }
92 } 92 }