作者 linmadan

添加领域事件订阅处理,同步问题系统

@@ -49,7 +49,6 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai @@ -49,7 +49,6 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
49 } 49 }
50 data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners) 50 data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners)
51 if err != nil { 51 if err != nil {
52 - fmt.Println(err.Error())  
53 return err 52 return err
54 } 53 }
55 fmt.Println(data) 54 fmt.Println(data)
@@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query"
@@ -171,6 +172,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT @@ -171,6 +172,7 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
171 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 172 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
172 } else { 173 } else {
173 releaseTaskService = value 174 releaseTaskService = value
  175 + releaseTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
174 } 176 }
175 if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil { 177 if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil {
176 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 178 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -237,6 +239,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac @@ -237,6 +239,7 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac
237 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 239 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
238 } else { 240 } else {
239 acceptanceTaskService = value 241 acceptanceTaskService = value
  242 + acceptanceTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
240 } 243 }
241 if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil { 244 if task, err := acceptanceTaskService.Acceptance(acceptanceTaskCommand.TaskId, acceptanceTaskCommand.Operator, acceptanceTaskCommand.Participators, acceptanceTaskCommand.TaskPercentage, acceptanceTaskCommand.ReferenceResourceScore, acceptanceTaskCommand.SolveReport, acceptanceTaskCommand.SolvePictureUrls); err != nil {
242 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 245 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type AcceptanceTaskService interface { 8 type AcceptanceTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error) 10 Acceptance(taskId int64, operatorUid int64, participators []int64, taskPercentage []*domain.TaskPercentageItem, referenceResourceScore []*domain.ReferenceResourceItem, solveReport string, solvePictureUrls []string) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type ApplyCompleteTaskService interface { 8 type ApplyCompleteTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 ApplyComplete(taskId int64, receiverUid int64) (*domain.Task, error) 10 ApplyComplete(taskId int64, receiverUid int64) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type BidTaskService interface { 8 type BidTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 Bid(taskId int64, bidderUid int64) (*domain.Task, error) 10 Bid(taskId int64, bidderUid int64) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type ChooseSuccessfulBidderService interface { 8 type ChooseSuccessfulBidderService interface {
  9 + coreDomain.DomainEventPublisher
6 Choose(taskId int64, successfulBidderUid int64, operatorUid int64) (*domain.Task, error) 10 Choose(taskId int64, successfulBidderUid int64, operatorUid int64) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type ExchangeSuMoneyService interface { 8 type ExchangeSuMoneyService interface {
  9 + coreDomain.DomainEventPublisher
6 Exchange(uid int64, operatorUid int64, suMoney float64, recordDescription string) (*domain.SuMoneyTransactionRecord, error) 10 Exchange(uid int64, operatorUid int64, suMoney float64, recordDescription string) (*domain.SuMoneyTransactionRecord, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type OffTaskService interface { 8 type OffTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 Off(taskId int64, operatorUid int64, offReason string) (*domain.Task, error) 10 Off(taskId int64, operatorUid int64, offReason string) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type ReleaseTaskService interface { 8 type ReleaseTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 Release(taskId int64, operatorUid int64) (*domain.Task, error) 10 Release(taskId int64, operatorUid int64) (*domain.Task, error)
7 } 11 }
1 package service 1 package service
2 2
3 -import "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 3 +import (
  4 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 +)
4 7
5 type RobTaskService interface { 8 type RobTaskService interface {
  9 + coreDomain.DomainEventPublisher
6 Rob(taskId int64, receiverUid int64) (*domain.Task, error) 10 Rob(taskId int64, receiverUid int64) (*domain.Task, error)
7 } 11 }
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
10 "time" 11 "time"
@@ -93,6 +94,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 @@ -93,6 +94,23 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
93 if task, err := taskRepository.Save(task); err != nil { 94 if task, err := taskRepository.Save(task); err != nil {
94 return nil, err 95 return nil, err
95 } else { 96 } else {
  97 + taskAcceptancedEvent := new(event.TaskAcceptanced)
  98 + taskAcceptancedEvent.OccurredOn = time.Now()
  99 + taskAcceptancedEvent.TaskId = task.TaskId
  100 + taskAcceptancedEvent.CompanyId = task.CompanyId
  101 + taskAcceptancedEvent.TaskName = task.TaskName
  102 + taskAcceptancedEvent.TaskType = task.TaskType
  103 + taskAcceptancedEvent.Sponsor = task.Sponsor
  104 + taskAcceptancedEvent.TaskStatus = task.TaskStatus
  105 + taskAcceptancedEvent.ReferenceResource = task.ReferenceResource
  106 + taskAcceptancedEvent.AcceptanceStandard = task.AcceptanceStandard
  107 + taskAcceptancedEvent.Participators = task.Participators
  108 + taskAcceptancedEvent.TaskPercentage = task.TaskPercentage
  109 + taskAcceptancedEvent.SolveReport = task.SolveReport
  110 + taskAcceptancedEvent.SolvePictureUrls = task.SolvePictureUrls
  111 + if err := service.Publish(taskAcceptancedEvent); err != nil {
  112 + println(err.Error())
  113 + }
96 return task, nil 114 return task, nil
97 } 115 }
98 } 116 }
@@ -5,7 +5,9 @@ import ( @@ -5,7 +5,9 @@ import (
5 coreDomain "github.com/linmadan/egglib-go/core/domain" 5 coreDomain "github.com/linmadan/egglib-go/core/domain"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
  10 + "time"
9 ) 11 )
10 12
11 type ReleaseTaskService struct { 13 type ReleaseTaskService struct {
@@ -53,6 +55,24 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do @@ -53,6 +55,24 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
53 if task, err := taskRepository.Save(task); err != nil { 55 if task, err := taskRepository.Save(task); err != nil {
54 return nil, err 56 return nil, err
55 } else { 57 } else {
  58 + taskReleasedEvent := new(event.TaskReleased)
  59 + taskReleasedEvent.OccurredOn = time.Now()
  60 + taskReleasedEvent.TaskId = task.TaskId
  61 + taskReleasedEvent.CompanyId = task.CompanyId
  62 + taskReleasedEvent.TaskName = task.TaskName
  63 + taskReleasedEvent.TaskType = task.TaskType
  64 + taskReleasedEvent.Sponsor = task.Sponsor
  65 + taskReleasedEvent.TaskStatus = task.TaskStatus
  66 + taskReleasedEvent.ReferenceResource = task.ReferenceResource
  67 + taskReleasedEvent.CustomerValue = task.CustomerValue
  68 + taskReleasedEvent.TaskNature = task.TaskNature
  69 + taskReleasedEvent.SuMoney = task.SuMoney
  70 + taskReleasedEvent.AcceptanceStandard = task.AcceptanceStandard
  71 + taskReleasedEvent.TaskDescription = task.TaskDescription
  72 + taskReleasedEvent.BidInfo = task.BidInfo
  73 + if err := service.Publish(taskReleasedEvent); err != nil {
  74 + println(err.Error())
  75 + }
56 return task, nil 76 return task, nil
57 } 77 }
58 } 78 }