正在显示
16 个修改的文件
包含
462 行增加
和
13 行删除
@@ -2,10 +2,38 @@ package main | @@ -2,10 +2,38 @@ package main | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/astaxie/beego" | 4 | "github.com/astaxie/beego" |
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/service" | ||
5 | _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | 6 | _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" |
6 | _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego" | 7 | _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego" |
8 | + "time" | ||
7 | ) | 9 | ) |
8 | 10 | ||
9 | func main() { | 11 | func main() { |
12 | + go func() { | ||
13 | + notificationService := service.NewNotificationService(nil) | ||
14 | + for { | ||
15 | + now := time.Now() | ||
16 | + next := now.Add(time.Hour * 24) | ||
17 | + nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()) | ||
18 | + dispatchTicker := time.NewTimer(nextZero.Sub(now)) | ||
19 | + <-dispatchTicker.C | ||
20 | + if _, err := notificationService.SystemNotificationNearThePlannedCompletionTimeTaskReceiver(); err != nil { | ||
21 | + println(err.Error()) | ||
22 | + } | ||
23 | + } | ||
24 | + }() | ||
25 | + go func() { | ||
26 | + notificationService := service.NewNotificationService(nil) | ||
27 | + for { | ||
28 | + now := time.Now() | ||
29 | + next := now.Add(time.Hour * 24) | ||
30 | + nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()) | ||
31 | + dispatchTicker := time.NewTimer(nextZero.Sub(now)) | ||
32 | + <-dispatchTicker.C | ||
33 | + if _, err := notificationService.SystemNotificationNearBidEndTimeTaskSponsor(); err != nil { | ||
34 | + println(err.Error()) | ||
35 | + } | ||
36 | + } | ||
37 | + }() | ||
10 | beego.Run() | 38 | beego.Run() |
11 | } | 39 | } |
@@ -13,7 +13,8 @@ type AbilityServiceSubscriber struct { | @@ -13,7 +13,8 @@ type AbilityServiceSubscriber struct { | ||
13 | func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error { | 13 | func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error { |
14 | abilityServiceGateway, err := factory.CreateAbilityServiceGateway(nil) | 14 | abilityServiceGateway, err := factory.CreateAbilityServiceGateway(nil) |
15 | if err != nil { | 15 | if err != nil { |
16 | - return err | 16 | + fmt.Println(err.Error()) |
17 | + return nil | ||
17 | } | 18 | } |
18 | switch domainEvent.EventType() { | 19 | switch domainEvent.EventType() { |
19 | case event.TASK_RELEASED_EVENT: | 20 | case event.TASK_RELEASED_EVENT: |
@@ -25,7 +26,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | @@ -25,7 +26,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | ||
25 | data, err := abilityServiceGateway.CommitQuestionQuotes(taskReleasedEvent.Sponsor.Uid, taskReleasedEvent.TaskId, serials) | 26 | data, err := abilityServiceGateway.CommitQuestionQuotes(taskReleasedEvent.Sponsor.Uid, taskReleasedEvent.TaskId, serials) |
26 | if err != nil { | 27 | if err != nil { |
27 | fmt.Println(err.Error()) | 28 | fmt.Println(err.Error()) |
28 | - return err | 29 | + return nil |
29 | } | 30 | } |
30 | fmt.Println(data) | 31 | fmt.Println(data) |
31 | break | 32 | break |
@@ -38,7 +39,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | @@ -38,7 +39,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | ||
38 | data, err := abilityServiceGateway.CloseTaskCallback(taskClosedEvent.TaskId, referenceResourceIds) | 39 | data, err := abilityServiceGateway.CloseTaskCallback(taskClosedEvent.TaskId, referenceResourceIds) |
39 | if err != nil { | 40 | if err != nil { |
40 | fmt.Println(err.Error()) | 41 | fmt.Println(err.Error()) |
41 | - return err | 42 | + return nil |
42 | } | 43 | } |
43 | fmt.Println(data) | 44 | fmt.Println(data) |
44 | break | 45 | break |
@@ -51,7 +52,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | @@ -51,7 +52,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | ||
51 | data, err := abilityServiceGateway.ReceiverTaskCallback(taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.TaskId, referenceResourceIds, taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.RobInfo.ReceiveTime) | 52 | data, err := abilityServiceGateway.ReceiverTaskCallback(taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.TaskId, referenceResourceIds, taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.RobInfo.ReceiveTime) |
52 | if err != nil { | 53 | if err != nil { |
53 | fmt.Println(err.Error()) | 54 | fmt.Println(err.Error()) |
54 | - return err | 55 | + return nil |
55 | } | 56 | } |
56 | fmt.Println(data) | 57 | fmt.Println(data) |
57 | break | 58 | break |
@@ -64,7 +65,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | @@ -64,7 +65,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | ||
64 | data, err := abilityServiceGateway.ReceiverTaskCallback(taskBiddedEvent.BidInfo.SuccessfulBidder.Uid, taskBiddedEvent.TaskId, referenceResourceIds, taskBiddedEvent.Operator.Uid, taskBiddedEvent.BidInfo.WinBidTime) | 65 | data, err := abilityServiceGateway.ReceiverTaskCallback(taskBiddedEvent.BidInfo.SuccessfulBidder.Uid, taskBiddedEvent.TaskId, referenceResourceIds, taskBiddedEvent.Operator.Uid, taskBiddedEvent.BidInfo.WinBidTime) |
65 | if err != nil { | 66 | if err != nil { |
66 | fmt.Println(err.Error()) | 67 | fmt.Println(err.Error()) |
67 | - return err | 68 | + return nil |
68 | } | 69 | } |
69 | fmt.Println(data) | 70 | fmt.Println(data) |
70 | break | 71 | break |
@@ -88,7 +89,8 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | @@ -88,7 +89,8 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai | ||
88 | } | 89 | } |
89 | data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners) | 90 | data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners) |
90 | if err != nil { | 91 | if err != nil { |
91 | - return err | 92 | + fmt.Println(err.Error()) |
93 | + return nil | ||
92 | } | 94 | } |
93 | fmt.Println(data) | 95 | fmt.Println(data) |
94 | } | 96 | } |
1 | +package subscriber | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + coreDomain "github.com/linmadan/egglib-go/core/domain" | ||
6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +type NotificationHandleSubscriber struct { | ||
14 | + TransactionContext *pgTransaction.TransactionContext | ||
15 | +} | ||
16 | + | ||
17 | +func (subscriber *NotificationHandleSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error { | ||
18 | + var notificationRepository domain.NotificationRepository | ||
19 | + if value, err := factory.CreateNotificationRepository(map[string]interface{}{ | ||
20 | + "transactionContext": subscriber.TransactionContext, | ||
21 | + }); err != nil { | ||
22 | + return err | ||
23 | + } else { | ||
24 | + notificationRepository = value | ||
25 | + } | ||
26 | + var sentNotificationRepository domain.SentNotificationRepository | ||
27 | + if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{ | ||
28 | + "transactionContext": subscriber.TransactionContext, | ||
29 | + }); err != nil { | ||
30 | + return err | ||
31 | + } else { | ||
32 | + sentNotificationRepository = value | ||
33 | + } | ||
34 | + switch domainEvent.EventType() { | ||
35 | + case event.TASK_ROBED_EVENT: | ||
36 | + taskRobedEvent := domainEvent.(*event.TaskRobed) | ||
37 | + notification := &domain.Notification{ | ||
38 | + NotificationType: domain.NOTIFICATION_TYPE_INTERACTION, | ||
39 | + NotificationTitle: fmt.Sprintf("%s领取了任务", taskRobedEvent.RobInfo.Receiver.EmployeeName), | ||
40 | + NotificationContent: taskRobedEvent.TaskName, | ||
41 | + NotificationTime: time.Now(), | ||
42 | + ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK, | ||
43 | + ExternalResource: taskRobedEvent.TaskId, | ||
44 | + } | ||
45 | + if notification, err := notificationRepository.Save(notification); err != nil { | ||
46 | + return err | ||
47 | + } else { | ||
48 | + sentNotification := &domain.SentNotification{ | ||
49 | + Notification: notification, | ||
50 | + Receiver: taskRobedEvent.Sponsor, | ||
51 | + IsRead: false, | ||
52 | + ReadTime: time.Time{}, | ||
53 | + } | ||
54 | + if _, err := sentNotificationRepository.Save(sentNotification); err != nil { | ||
55 | + return err | ||
56 | + } | ||
57 | + } | ||
58 | + break | ||
59 | + case event.TASK_CONFIRMED_EVENT: | ||
60 | + taskConfirmedEvent := domainEvent.(*event.TaskConfirmed) | ||
61 | + notification := &domain.Notification{ | ||
62 | + NotificationType: domain.NOTIFICATION_TYPE_INTERACTION, | ||
63 | + NotificationTitle: "你已成功领取了任务", | ||
64 | + NotificationContent: taskConfirmedEvent.TaskName, | ||
65 | + NotificationTime: time.Now(), | ||
66 | + ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK, | ||
67 | + ExternalResource: taskConfirmedEvent.TaskId, | ||
68 | + } | ||
69 | + if notification, err := notificationRepository.Save(notification); err != nil { | ||
70 | + return err | ||
71 | + } else { | ||
72 | + sentNotification := &domain.SentNotification{ | ||
73 | + Notification: notification, | ||
74 | + Receiver: taskConfirmedEvent.RobInfo.Receiver, | ||
75 | + IsRead: false, | ||
76 | + ReadTime: time.Time{}, | ||
77 | + } | ||
78 | + if _, err := sentNotificationRepository.Save(sentNotification); err != nil { | ||
79 | + return err | ||
80 | + } | ||
81 | + } | ||
82 | + break | ||
83 | + case event.TASK_REJECTED_EVENT: | ||
84 | + taskRejectedEvent := domainEvent.(*event.TaskRejected) | ||
85 | + notification := &domain.Notification{ | ||
86 | + NotificationType: domain.NOTIFICATION_TYPE_INTERACTION, | ||
87 | + NotificationTitle: "您领取的任务被驳回了,查看理由", | ||
88 | + NotificationContent: taskRejectedEvent.TaskName, | ||
89 | + NotificationTime: time.Now(), | ||
90 | + ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_REJECT_TASK_RECORD, | ||
91 | + ExternalResource: taskRejectedEvent.RejectTaskRecord.RejectTaskRecordId, | ||
92 | + } | ||
93 | + if notification, err := notificationRepository.Save(notification); err != nil { | ||
94 | + return err | ||
95 | + } else { | ||
96 | + var receiver *domain.EmployeeInfo | ||
97 | + if taskRejectedEvent.TaskType == domain.TASK_TYPE_ROB { | ||
98 | + receiver = taskRejectedEvent.RobInfo.Receiver | ||
99 | + } | ||
100 | + if taskRejectedEvent.TaskType == domain.TASK_TYPE_BID { | ||
101 | + receiver = taskRejectedEvent.BidInfo.SuccessfulBidder | ||
102 | + } | ||
103 | + sentNotification := &domain.SentNotification{ | ||
104 | + Notification: notification, | ||
105 | + Receiver: receiver, | ||
106 | + IsRead: false, | ||
107 | + ReadTime: time.Time{}, | ||
108 | + } | ||
109 | + if _, err := sentNotificationRepository.Save(sentNotification); err != nil { | ||
110 | + return err | ||
111 | + } | ||
112 | + } | ||
113 | + break | ||
114 | + } | ||
115 | + return nil | ||
116 | +} | ||
117 | + | ||
118 | +func (subscriber *NotificationHandleSubscriber) SubscribedToEventTypes() []string { | ||
119 | + return [] string{ | ||
120 | + event.TASK_ROBED_EVENT, | ||
121 | + event.TASK_CONFIRMED_EVENT, | ||
122 | + event.TASK_REJECTED_EVENT, | ||
123 | + } | ||
124 | +} |
@@ -8,12 +8,164 @@ import ( | @@ -8,12 +8,164 @@ import ( | ||
8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/query" | 8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/query" |
9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" |
10 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" | 10 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" |
11 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" | ||
12 | + "time" | ||
11 | ) | 13 | ) |
12 | 14 | ||
13 | // 通知服务 | 15 | // 通知服务 |
14 | type NotificationService struct { | 16 | type NotificationService struct { |
15 | } | 17 | } |
16 | 18 | ||
19 | +//系统通知快到计划完成时间的任务的对应领取人 | ||
20 | +func (notificationService *NotificationService) SystemNotificationNearThePlannedCompletionTimeTaskReceiver() (interface{}, error) { | ||
21 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
22 | + if err != nil { | ||
23 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | + } | ||
25 | + if err := transactionContext.StartTransaction(); err != nil { | ||
26 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
27 | + } | ||
28 | + defer func() { | ||
29 | + transactionContext.RollbackTransaction() | ||
30 | + }() | ||
31 | + var notificationRepository domain.NotificationRepository | ||
32 | + if value, err := factory.CreateNotificationRepository(map[string]interface{}{ | ||
33 | + "transactionContext": transactionContext, | ||
34 | + }); err != nil { | ||
35 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
36 | + } else { | ||
37 | + notificationRepository = value | ||
38 | + } | ||
39 | + var sentNotificationRepository domain.SentNotificationRepository | ||
40 | + if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{ | ||
41 | + "transactionContext": transactionContext, | ||
42 | + }); err != nil { | ||
43 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
44 | + } else { | ||
45 | + sentNotificationRepository = value | ||
46 | + } | ||
47 | + var taskDao *dao.TaskDao | ||
48 | + if value, err := factory.CreateTaskDao(map[string]interface{}{ | ||
49 | + "transactionContext": transactionContext, | ||
50 | + }); err != nil { | ||
51 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
52 | + } else { | ||
53 | + taskDao = value | ||
54 | + } | ||
55 | + if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil { | ||
56 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
57 | + } else { | ||
58 | + for _, task := range tasks { | ||
59 | + notification := &domain.Notification{ | ||
60 | + NotificationType: domain.NOTIFICATION_TYPE_SYSTEM, | ||
61 | + NotificationTitle: "任务快到计划完成时间,尽快完成哦", | ||
62 | + NotificationContent: task.TaskName, | ||
63 | + NotificationTime: time.Now(), | ||
64 | + ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK, | ||
65 | + ExternalResource: task.Id, | ||
66 | + } | ||
67 | + if notification, err := notificationRepository.Save(notification); err != nil { | ||
68 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
69 | + } else { | ||
70 | + var receiver *domain.EmployeeInfo | ||
71 | + if task.TaskType == domain.TASK_TYPE_ROB { | ||
72 | + receiver = task.RobInfo.Receiver | ||
73 | + } | ||
74 | + if task.TaskType == domain.TASK_TYPE_BID { | ||
75 | + receiver = task.BidInfo.SuccessfulBidder | ||
76 | + } | ||
77 | + if task.TaskType == domain.TASK_TYPE_DESIGNATE { | ||
78 | + receiver = task.AssignedPerson | ||
79 | + } | ||
80 | + sentNotification := &domain.SentNotification{ | ||
81 | + Notification: notification, | ||
82 | + Receiver: receiver, | ||
83 | + IsRead: false, | ||
84 | + ReadTime: time.Time{}, | ||
85 | + } | ||
86 | + if _, err := sentNotificationRepository.Save(sentNotification); err != nil { | ||
87 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
88 | + } | ||
89 | + } | ||
90 | + } | ||
91 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
92 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
93 | + } else { | ||
94 | + return true, nil | ||
95 | + } | ||
96 | + } | ||
97 | +} | ||
98 | + | ||
99 | +//系统通知快到竞标截止时间的任务的对应发布人 | ||
100 | +func (notificationService *NotificationService) SystemNotificationNearBidEndTimeTaskSponsor() (interface{}, error) { | ||
101 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
102 | + if err != nil { | ||
103 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
104 | + } | ||
105 | + if err := transactionContext.StartTransaction(); err != nil { | ||
106 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
107 | + } | ||
108 | + defer func() { | ||
109 | + transactionContext.RollbackTransaction() | ||
110 | + }() | ||
111 | + var notificationRepository domain.NotificationRepository | ||
112 | + if value, err := factory.CreateNotificationRepository(map[string]interface{}{ | ||
113 | + "transactionContext": transactionContext, | ||
114 | + }); err != nil { | ||
115 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
116 | + } else { | ||
117 | + notificationRepository = value | ||
118 | + } | ||
119 | + var sentNotificationRepository domain.SentNotificationRepository | ||
120 | + if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{ | ||
121 | + "transactionContext": transactionContext, | ||
122 | + }); err != nil { | ||
123 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
124 | + } else { | ||
125 | + sentNotificationRepository = value | ||
126 | + } | ||
127 | + var taskDao *dao.TaskDao | ||
128 | + if value, err := factory.CreateTaskDao(map[string]interface{}{ | ||
129 | + "transactionContext": transactionContext, | ||
130 | + }); err != nil { | ||
131 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
132 | + } else { | ||
133 | + taskDao = value | ||
134 | + } | ||
135 | + if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil { | ||
136 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
137 | + } else { | ||
138 | + for _, task := range tasks { | ||
139 | + notification := &domain.Notification{ | ||
140 | + NotificationType: domain.NOTIFICATION_TYPE_SYSTEM, | ||
141 | + NotificationTitle: "竞标任务截止时间就差一天就结束了", | ||
142 | + NotificationContent: task.TaskName, | ||
143 | + NotificationTime: time.Now(), | ||
144 | + ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK, | ||
145 | + ExternalResource: task.Id, | ||
146 | + } | ||
147 | + if notification, err := notificationRepository.Save(notification); err != nil { | ||
148 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
149 | + } else { | ||
150 | + sentNotification := &domain.SentNotification{ | ||
151 | + Notification: notification, | ||
152 | + Receiver: task.Sponsor, | ||
153 | + IsRead: false, | ||
154 | + ReadTime: time.Time{}, | ||
155 | + } | ||
156 | + if _, err := sentNotificationRepository.Save(sentNotification); err != nil { | ||
157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
158 | + } | ||
159 | + } | ||
160 | + } | ||
161 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
162 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
163 | + } else { | ||
164 | + return true, nil | ||
165 | + } | ||
166 | + } | ||
167 | +} | ||
168 | + | ||
17 | // 读取发送出的通知 | 169 | // 读取发送出的通知 |
18 | func (notificationService *NotificationService) ReadSentNotification(readSentNotificationCommand *command.ReadSentNotificationCommand) (interface{}, error) { | 170 | func (notificationService *NotificationService) ReadSentNotification(readSentNotificationCommand *command.ReadSentNotificationCommand) (interface{}, error) { |
19 | if err := readSentNotificationCommand.ValidateCommand(); err != nil { | 171 | if err := readSentNotificationCommand.ValidateCommand(); err != nil { |
@@ -3,6 +3,7 @@ package service | @@ -3,6 +3,7 @@ package service | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | "github.com/linmadan/egglib-go/utils/tool_funs" | 7 | "github.com/linmadan/egglib-go/utils/tool_funs" |
7 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber" | 8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber" |
8 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" | 9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" |
@@ -41,7 +42,9 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co | @@ -41,7 +42,9 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co | ||
41 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 42 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
42 | } else { | 43 | } else { |
43 | confirmRobTaskService = value | 44 | confirmRobTaskService = value |
44 | - //confirmRobTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) | 45 | + confirmRobTaskService.Subscribe(&subscriber.NotificationHandleSubscriber{ |
46 | + TransactionContext: transactionContext.(*pgTransaction.TransactionContext), | ||
47 | + }) | ||
45 | } | 48 | } |
46 | if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil { | 49 | if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil { |
47 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 50 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -75,7 +78,9 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co | @@ -75,7 +78,9 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co | ||
75 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 78 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
76 | } else { | 79 | } else { |
77 | rejectTaskReceiverService = value | 80 | rejectTaskReceiverService = value |
78 | - //rejectTaskReceiverService.Subscribe(&subscriber.AbilityServiceSubscriber{}) | 81 | + rejectTaskReceiverService.Subscribe(&subscriber.NotificationHandleSubscriber{ |
82 | + TransactionContext: transactionContext.(*pgTransaction.TransactionContext), | ||
83 | + }) | ||
79 | } | 84 | } |
80 | if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil { | 85 | if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil { |
81 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 86 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -110,6 +115,9 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) | @@ -110,6 +115,9 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) | ||
110 | } else { | 115 | } else { |
111 | robTaskService = value | 116 | robTaskService = value |
112 | robTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) | 117 | robTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{}) |
118 | + robTaskService.Subscribe(&subscriber.NotificationHandleSubscriber{ | ||
119 | + TransactionContext: transactionContext.(*pgTransaction.TransactionContext), | ||
120 | + }) | ||
113 | } | 121 | } |
114 | if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil { | 122 | if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil { |
115 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 123 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
pkg/domain/event/taskConfirmed.go
0 → 100644
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_CONFIRMED_EVENT = "task-confirmed-event" | ||
9 | + | ||
10 | +type TaskConfirmed 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 | + RobInfo *domain.RobInfo `json:"robInfo"` | ||
26 | +} | ||
27 | + | ||
28 | +func (event *TaskConfirmed) EventType() string { | ||
29 | + return TASK_CONFIRMED_EVENT | ||
30 | +} |
pkg/domain/event/taskRejected.go
0 → 100644
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_REJECTED_EVENT = "task-rejected-event" | ||
9 | + | ||
10 | +type TaskRejected 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 | + RobInfo *domain.RobInfo `json:"robInfo"` | ||
26 | + // 竞标任务信息 | ||
27 | + BidInfo *domain.BidInfo `json:"bidInfo"` | ||
28 | + //驳回任务记录 | ||
29 | + RejectTaskRecord *domain.RejectTaskRecord | ||
30 | +} | ||
31 | + | ||
32 | +func (event *TaskRejected) EventType() string { | ||
33 | + return TASK_REJECTED_EVENT | ||
34 | +} |
@@ -14,6 +14,41 @@ type TaskDao struct { | @@ -14,6 +14,41 @@ type TaskDao struct { | ||
14 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
15 | } | 15 | } |
16 | 16 | ||
17 | +func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, error) { | ||
18 | + tx := dao.transactionContext.PgTx | ||
19 | + var taskModels []*models.Task | ||
20 | + currentTime := time.Now() | ||
21 | + currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location()) | ||
22 | + after24Hour, _ := time.ParseDuration("24h") | ||
23 | + after48Hour, _ := time.ParseDuration("48h") | ||
24 | + query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo"). | ||
25 | + Where("task.planned_completion_time >= ?", currentDay.Add(after24Hour)). | ||
26 | + Where("task.planned_completion_time < ?", currentDay.Add(after48Hour)) | ||
27 | + if err := query.Select(); err != nil { | ||
28 | + return make([]*models.Task, 0), err | ||
29 | + } else { | ||
30 | + return taskModels, nil | ||
31 | + } | ||
32 | +} | ||
33 | + | ||
34 | +func (dao *TaskDao) ListNearBidEndTimeTask() ([]*models.Task, error) { | ||
35 | + tx := dao.transactionContext.PgTx | ||
36 | + var taskModels []*models.Task | ||
37 | + currentTime := time.Now() | ||
38 | + currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location()) | ||
39 | + after24Hour, _ := time.ParseDuration("24h") | ||
40 | + after48Hour, _ := time.ParseDuration("48h") | ||
41 | + query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo"). | ||
42 | + Where("task.task_type = ?", domain.TASK_TYPE_BID). | ||
43 | + Where("bid_info.bid_end_time >= ?", currentDay.Add(after24Hour)). | ||
44 | + Where("bid_info.bid_end_time < ?", currentDay.Add(after48Hour)) | ||
45 | + if err := query.Select(); err != nil { | ||
46 | + return make([]*models.Task, 0), err | ||
47 | + } else { | ||
48 | + return taskModels, nil | ||
49 | + } | ||
50 | +} | ||
51 | + | ||
17 | func (dao *TaskDao) AddRobInfo(taskId int64, receiver *domain.EmployeeInfo) error { | 52 | func (dao *TaskDao) AddRobInfo(taskId int64, receiver *domain.EmployeeInfo) error { |
18 | tx := dao.transactionContext.PgTx | 53 | tx := dao.transactionContext.PgTx |
19 | _, err := tx.QueryOne( | 54 | _, err := tx.QueryOne( |
@@ -139,7 +139,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 | @@ -139,7 +139,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64 | ||
139 | taskAcceptancedEvent.SolveReport = task.SolveReport | 139 | taskAcceptancedEvent.SolveReport = task.SolveReport |
140 | taskAcceptancedEvent.SolvePictureUrls = task.SolvePictureUrls | 140 | taskAcceptancedEvent.SolvePictureUrls = task.SolvePictureUrls |
141 | if err := service.Publish(taskAcceptancedEvent); err != nil { | 141 | if err := service.Publish(taskAcceptancedEvent); err != nil { |
142 | - println(err.Error()) | 142 | + return nil, err |
143 | } | 143 | } |
144 | return task, nil | 144 | return task, nil |
145 | } | 145 | } |
@@ -86,7 +86,7 @@ func (service *ChooseSuccessfulBidderService) Choose(taskId int64, successfulBid | @@ -86,7 +86,7 @@ func (service *ChooseSuccessfulBidderService) Choose(taskId int64, successfulBid | ||
86 | taskBiddedEvent.BidInfo = task.BidInfo | 86 | taskBiddedEvent.BidInfo = task.BidInfo |
87 | taskBiddedEvent.Operator = operator.EmployeeInfo | 87 | taskBiddedEvent.Operator = operator.EmployeeInfo |
88 | if err := service.Publish(taskBiddedEvent); err != nil { | 88 | if err := service.Publish(taskBiddedEvent); err != nil { |
89 | - println(err.Error()) | 89 | + return nil, err |
90 | } | 90 | } |
91 | return task, nil | 91 | return task, nil |
92 | } | 92 | } |
@@ -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/repository" | 9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" |
9 | "time" | 10 | "time" |
10 | ) | 11 | ) |
@@ -54,6 +55,18 @@ func (service *ConfirmRobTaskService) Confirm(taskId int64, operatorUid int64, p | @@ -54,6 +55,18 @@ func (service *ConfirmRobTaskService) Confirm(taskId int64, operatorUid int64, p | ||
54 | if task, err := taskRepository.Save(task); err != nil { | 55 | if task, err := taskRepository.Save(task); err != nil { |
55 | return nil, err | 56 | return nil, err |
56 | } else { | 57 | } else { |
58 | + taskConfirmed := new(event.TaskConfirmed) | ||
59 | + taskConfirmed.OccurredOn = time.Now() | ||
60 | + taskConfirmed.TaskId = task.TaskId | ||
61 | + taskConfirmed.CompanyId = task.CompanyId | ||
62 | + taskConfirmed.TaskName = task.TaskName | ||
63 | + taskConfirmed.TaskType = task.TaskType | ||
64 | + taskConfirmed.Sponsor = task.Sponsor | ||
65 | + taskConfirmed.TaskStatus = task.TaskStatus | ||
66 | + taskConfirmed.RobInfo = task.RobInfo | ||
67 | + if err := service.Publish(taskConfirmed); err != nil { | ||
68 | + return nil, err | ||
69 | + } | ||
57 | return task, nil | 70 | return task, nil |
58 | } | 71 | } |
59 | } | 72 | } |
@@ -80,7 +80,7 @@ func (service *OffTaskService) Off(taskId int64, operatorUid int64, offReason st | @@ -80,7 +80,7 @@ func (service *OffTaskService) Off(taskId int64, operatorUid int64, offReason st | ||
80 | taskClosedEvent.TaskStatus = task.TaskStatus | 80 | taskClosedEvent.TaskStatus = task.TaskStatus |
81 | taskClosedEvent.ReferenceResource = task.ReferenceResource | 81 | taskClosedEvent.ReferenceResource = task.ReferenceResource |
82 | if err := service.Publish(taskClosedEvent); err != nil { | 82 | if err := service.Publish(taskClosedEvent); err != nil { |
83 | - println(err.Error()) | 83 | + return nil, err |
84 | } | 84 | } |
85 | return task, nil | 85 | return task, nil |
86 | } | 86 | } |
@@ -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/repository" | 9 | "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" |
9 | "time" | 10 | "time" |
10 | ) | 11 | ) |
@@ -69,6 +70,20 @@ func (service *RejectTaskReceiverService) Reject(taskId int64, operatorUid int64 | @@ -69,6 +70,20 @@ func (service *RejectTaskReceiverService) Reject(taskId int64, operatorUid int64 | ||
69 | if task, err := taskRepository.Save(task); err != nil { | 70 | if task, err := taskRepository.Save(task); err != nil { |
70 | return nil, err | 71 | return nil, err |
71 | } else { | 72 | } else { |
73 | + taskRejectedEvent := new(event.TaskRejected) | ||
74 | + taskRejectedEvent.OccurredOn = time.Now() | ||
75 | + taskRejectedEvent.TaskId = task.TaskId | ||
76 | + taskRejectedEvent.CompanyId = task.CompanyId | ||
77 | + taskRejectedEvent.TaskName = task.TaskName | ||
78 | + taskRejectedEvent.TaskType = task.TaskType | ||
79 | + taskRejectedEvent.Sponsor = task.Sponsor | ||
80 | + taskRejectedEvent.TaskStatus = task.TaskStatus | ||
81 | + taskRejectedEvent.RobInfo = task.RobInfo | ||
82 | + taskRejectedEvent.BidInfo = task.BidInfo | ||
83 | + taskRejectedEvent.RejectTaskRecord = rejectTaskRecord | ||
84 | + if err := service.Publish(taskRejectedEvent); err != nil { | ||
85 | + return nil, err | ||
86 | + } | ||
72 | return task, nil | 87 | return task, nil |
73 | } | 88 | } |
74 | } | 89 | } |
@@ -94,7 +94,7 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do | @@ -94,7 +94,7 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do | ||
94 | taskReleasedEvent.TaskDescription = task.TaskDescription | 94 | taskReleasedEvent.TaskDescription = task.TaskDescription |
95 | taskReleasedEvent.BidInfo = task.BidInfo | 95 | taskReleasedEvent.BidInfo = task.BidInfo |
96 | if err := service.Publish(taskReleasedEvent); err != nil { | 96 | if err := service.Publish(taskReleasedEvent); err != nil { |
97 | - println(err.Error()) | 97 | + return nil, err |
98 | } | 98 | } |
99 | return task, nil | 99 | return task, nil |
100 | } | 100 | } |
@@ -79,7 +79,7 @@ func (service *RobTaskService) Rob(taskId int64, receiverUid int64) (*domain.Tas | @@ -79,7 +79,7 @@ func (service *RobTaskService) Rob(taskId int64, receiverUid int64) (*domain.Tas | ||
79 | taskRobedEvent.ReferenceResource = task.ReferenceResource | 79 | taskRobedEvent.ReferenceResource = task.ReferenceResource |
80 | taskRobedEvent.RobInfo = task.RobInfo | 80 | taskRobedEvent.RobInfo = task.RobInfo |
81 | if err := service.Publish(taskRobedEvent); err != nil { | 81 | if err := service.Publish(taskRobedEvent); err != nil { |
82 | - println(err.Error()) | 82 | + return nil, err |
83 | } | 83 | } |
84 | return task, nil | 84 | return task, nil |
85 | } | 85 | } |
@@ -39,6 +39,14 @@ var _ = Describe("对抢单任务进行确认", func() { | @@ -39,6 +39,14 @@ var _ = Describe("对抢单任务进行确认", func() { | ||
39 | "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", | 39 | "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)", |
40 | 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0) | 40 | 2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0) |
41 | Expect(err2).NotTo(HaveOccurred()) | 41 | Expect(err2).NotTo(HaveOccurred()) |
42 | + _, err3 := pG.DB.QueryOne( | ||
43 | + pg.Scan(), | ||
44 | + "INSERT INTO rob_infos (id, task_id ,receiver) VALUES (?, ?, ?)", | ||
45 | + 1, 1, &domain.EmployeeInfo{ | ||
46 | + Uid: 2499036607974745099, | ||
47 | + EmployeeName: "员工", | ||
48 | + }) | ||
49 | + Expect(err3).NotTo(HaveOccurred()) | ||
42 | }) | 50 | }) |
43 | Describe("对抢单任务进行确认", func() { | 51 | Describe("对抢单任务进行确认", func() { |
44 | Context("任务发布人对抢单任务进行确认", func() { | 52 | Context("任务发布人对抢单任务进行确认", func() { |
-
请 注册 或 登录 后发表评论