作者 linmadan

完成相关通知逻辑

... ... @@ -2,10 +2,38 @@ package main
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/service"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
"time"
)
func main() {
go func() {
notificationService := service.NewNotificationService(nil)
for {
now := time.Now()
next := now.Add(time.Hour * 24)
nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
dispatchTicker := time.NewTimer(nextZero.Sub(now))
<-dispatchTicker.C
if _, err := notificationService.SystemNotificationNearThePlannedCompletionTimeTaskReceiver(); err != nil {
println(err.Error())
}
}
}()
go func() {
notificationService := service.NewNotificationService(nil)
for {
now := time.Now()
next := now.Add(time.Hour * 24)
nextZero := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
dispatchTicker := time.NewTimer(nextZero.Sub(now))
<-dispatchTicker.C
if _, err := notificationService.SystemNotificationNearBidEndTimeTaskSponsor(); err != nil {
println(err.Error())
}
}
}()
beego.Run()
}
... ...
... ... @@ -13,7 +13,8 @@ type AbilityServiceSubscriber struct {
func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
abilityServiceGateway, err := factory.CreateAbilityServiceGateway(nil)
if err != nil {
return err
fmt.Println(err.Error())
return nil
}
switch domainEvent.EventType() {
case event.TASK_RELEASED_EVENT:
... ... @@ -25,7 +26,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
data, err := abilityServiceGateway.CommitQuestionQuotes(taskReleasedEvent.Sponsor.Uid, taskReleasedEvent.TaskId, serials)
if err != nil {
fmt.Println(err.Error())
return err
return nil
}
fmt.Println(data)
break
... ... @@ -38,7 +39,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
data, err := abilityServiceGateway.CloseTaskCallback(taskClosedEvent.TaskId, referenceResourceIds)
if err != nil {
fmt.Println(err.Error())
return err
return nil
}
fmt.Println(data)
break
... ... @@ -51,7 +52,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
data, err := abilityServiceGateway.ReceiverTaskCallback(taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.TaskId, referenceResourceIds, taskRobedEvent.RobInfo.Receiver.Uid, taskRobedEvent.RobInfo.ReceiveTime)
if err != nil {
fmt.Println(err.Error())
return err
return nil
}
fmt.Println(data)
break
... ... @@ -64,7 +65,7 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
data, err := abilityServiceGateway.ReceiverTaskCallback(taskBiddedEvent.BidInfo.SuccessfulBidder.Uid, taskBiddedEvent.TaskId, referenceResourceIds, taskBiddedEvent.Operator.Uid, taskBiddedEvent.BidInfo.WinBidTime)
if err != nil {
fmt.Println(err.Error())
return err
return nil
}
fmt.Println(data)
break
... ... @@ -88,7 +89,8 @@ func (subscriber *AbilityServiceSubscriber) HandleEvent(domainEvent domain.Domai
}
data, err := abilityServiceGateway.CommitQuestionSolution(referenceResourceItem.ReferenceResourceId, taskAcceptancedEvent.Sponsor.Uid, solveUid, taskAcceptancedEvent.SolveReport, scoreSolve, taskAcceptancedEvent.SolvePictureUrls, partners)
if err != nil {
return err
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
}
... ...
package subscriber
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
"time"
)
type NotificationHandleSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *NotificationHandleSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
var notificationRepository domain.NotificationRepository
if value, err := factory.CreateNotificationRepository(map[string]interface{}{
"transactionContext": subscriber.TransactionContext,
}); err != nil {
return err
} else {
notificationRepository = value
}
var sentNotificationRepository domain.SentNotificationRepository
if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
"transactionContext": subscriber.TransactionContext,
}); err != nil {
return err
} else {
sentNotificationRepository = value
}
switch domainEvent.EventType() {
case event.TASK_ROBED_EVENT:
taskRobedEvent := domainEvent.(*event.TaskRobed)
notification := &domain.Notification{
NotificationType: domain.NOTIFICATION_TYPE_INTERACTION,
NotificationTitle: fmt.Sprintf("%s领取了任务", taskRobedEvent.RobInfo.Receiver.EmployeeName),
NotificationContent: taskRobedEvent.TaskName,
NotificationTime: time.Now(),
ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK,
ExternalResource: taskRobedEvent.TaskId,
}
if notification, err := notificationRepository.Save(notification); err != nil {
return err
} else {
sentNotification := &domain.SentNotification{
Notification: notification,
Receiver: taskRobedEvent.Sponsor,
IsRead: false,
ReadTime: time.Time{},
}
if _, err := sentNotificationRepository.Save(sentNotification); err != nil {
return err
}
}
break
case event.TASK_CONFIRMED_EVENT:
taskConfirmedEvent := domainEvent.(*event.TaskConfirmed)
notification := &domain.Notification{
NotificationType: domain.NOTIFICATION_TYPE_INTERACTION,
NotificationTitle: "你已成功领取了任务",
NotificationContent: taskConfirmedEvent.TaskName,
NotificationTime: time.Now(),
ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK,
ExternalResource: taskConfirmedEvent.TaskId,
}
if notification, err := notificationRepository.Save(notification); err != nil {
return err
} else {
sentNotification := &domain.SentNotification{
Notification: notification,
Receiver: taskConfirmedEvent.RobInfo.Receiver,
IsRead: false,
ReadTime: time.Time{},
}
if _, err := sentNotificationRepository.Save(sentNotification); err != nil {
return err
}
}
break
case event.TASK_REJECTED_EVENT:
taskRejectedEvent := domainEvent.(*event.TaskRejected)
notification := &domain.Notification{
NotificationType: domain.NOTIFICATION_TYPE_INTERACTION,
NotificationTitle: "您领取的任务被驳回了,查看理由",
NotificationContent: taskRejectedEvent.TaskName,
NotificationTime: time.Now(),
ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_REJECT_TASK_RECORD,
ExternalResource: taskRejectedEvent.RejectTaskRecord.RejectTaskRecordId,
}
if notification, err := notificationRepository.Save(notification); err != nil {
return err
} else {
var receiver *domain.EmployeeInfo
if taskRejectedEvent.TaskType == domain.TASK_TYPE_ROB {
receiver = taskRejectedEvent.RobInfo.Receiver
}
if taskRejectedEvent.TaskType == domain.TASK_TYPE_BID {
receiver = taskRejectedEvent.BidInfo.SuccessfulBidder
}
sentNotification := &domain.SentNotification{
Notification: notification,
Receiver: receiver,
IsRead: false,
ReadTime: time.Time{},
}
if _, err := sentNotificationRepository.Save(sentNotification); err != nil {
return err
}
}
break
}
return nil
}
func (subscriber *NotificationHandleSubscriber) SubscribedToEventTypes() []string {
return [] string{
event.TASK_ROBED_EVENT,
event.TASK_CONFIRMED_EVENT,
event.TASK_REJECTED_EVENT,
}
}
... ...
... ... @@ -8,12 +8,164 @@ import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/notification/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"time"
)
// 通知服务
type NotificationService struct {
}
//系统通知快到计划完成时间的任务的对应领取人
func (notificationService *NotificationService) SystemNotificationNearThePlannedCompletionTimeTaskReceiver() (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var notificationRepository domain.NotificationRepository
if value, err := factory.CreateNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
notificationRepository = value
}
var sentNotificationRepository domain.SentNotificationRepository
if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
sentNotificationRepository = value
}
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
taskDao = value
}
if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, task := range tasks {
notification := &domain.Notification{
NotificationType: domain.NOTIFICATION_TYPE_SYSTEM,
NotificationTitle: "任务快到计划完成时间,尽快完成哦",
NotificationContent: task.TaskName,
NotificationTime: time.Now(),
ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK,
ExternalResource: task.Id,
}
if notification, err := notificationRepository.Save(notification); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var receiver *domain.EmployeeInfo
if task.TaskType == domain.TASK_TYPE_ROB {
receiver = task.RobInfo.Receiver
}
if task.TaskType == domain.TASK_TYPE_BID {
receiver = task.BidInfo.SuccessfulBidder
}
if task.TaskType == domain.TASK_TYPE_DESIGNATE {
receiver = task.AssignedPerson
}
sentNotification := &domain.SentNotification{
Notification: notification,
Receiver: receiver,
IsRead: false,
ReadTime: time.Time{},
}
if _, err := sentNotificationRepository.Save(sentNotification); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
return true, nil
}
}
}
//系统通知快到竞标截止时间的任务的对应发布人
func (notificationService *NotificationService) SystemNotificationNearBidEndTimeTaskSponsor() (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var notificationRepository domain.NotificationRepository
if value, err := factory.CreateNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
notificationRepository = value
}
var sentNotificationRepository domain.SentNotificationRepository
if value, err := factory.CreateSentNotificationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
sentNotificationRepository = value
}
var taskDao *dao.TaskDao
if value, err := factory.CreateTaskDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
taskDao = value
}
if tasks, err := taskDao.ListNearThePlannedCompletionTimeTask(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, task := range tasks {
notification := &domain.Notification{
NotificationType: domain.NOTIFICATION_TYPE_SYSTEM,
NotificationTitle: "竞标任务截止时间就差一天就结束了",
NotificationContent: task.TaskName,
NotificationTime: time.Now(),
ExternalResourceType: domain.EXTERNAL_RESOURCE_TYPE_TASK,
ExternalResource: task.Id,
}
if notification, err := notificationRepository.Save(notification); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
sentNotification := &domain.SentNotification{
Notification: notification,
Receiver: task.Sponsor,
IsRead: false,
ReadTime: time.Time{},
}
if _, err := sentNotificationRepository.Save(sentNotification); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
return true, nil
}
}
}
// 读取发送出的通知
func (notificationService *NotificationService) ReadSentNotification(readSentNotificationCommand *command.ReadSentNotificationCommand) (interface{}, error) {
if err := readSentNotificationCommand.ValidateCommand(); err != nil {
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
... ... @@ -41,7 +42,9 @@ func (taskService *TaskService) ConfirmRobTask(confirmRobTaskCommand *command.Co
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
confirmRobTaskService = value
//confirmRobTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
confirmRobTaskService.Subscribe(&subscriber.NotificationHandleSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
if task, err := confirmRobTaskService.Confirm(confirmRobTaskCommand.TaskId, confirmRobTaskCommand.Operator, confirmRobTaskCommand.PlannedCompletionTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -75,7 +78,9 @@ func (taskService *TaskService) RejectTaskReceiver(rejectTaskReceiverCommand *co
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
rejectTaskReceiverService = value
//rejectTaskReceiverService.Subscribe(&subscriber.AbilityServiceSubscriber{})
rejectTaskReceiverService.Subscribe(&subscriber.NotificationHandleSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
if task, err := rejectTaskReceiverService.Reject(rejectTaskReceiverCommand.TaskId, rejectTaskReceiverCommand.Operator, rejectTaskReceiverCommand.RejectReason); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -110,6 +115,9 @@ func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand)
} else {
robTaskService = value
robTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
robTaskService.Subscribe(&subscriber.NotificationHandleSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
if task, err := robTaskService.Rob(robTaskCommand.TaskId, robTaskCommand.Receiver); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
package event
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
const TASK_CONFIRMED_EVENT = "task-confirmed-event"
type TaskConfirmed 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"`
// 抢单任务信息
RobInfo *domain.RobInfo `json:"robInfo"`
}
func (event *TaskConfirmed) EventType() string {
return TASK_CONFIRMED_EVENT
}
... ...
package event
import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
)
const TASK_REJECTED_EVENT = "task-rejected-event"
type TaskRejected 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"`
// 抢单任务信息
RobInfo *domain.RobInfo `json:"robInfo"`
// 竞标任务信息
BidInfo *domain.BidInfo `json:"bidInfo"`
//驳回任务记录
RejectTaskRecord *domain.RejectTaskRecord
}
func (event *TaskRejected) EventType() string {
return TASK_REJECTED_EVENT
}
... ...
... ... @@ -14,6 +14,41 @@ type TaskDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (dao *TaskDao) ListNearThePlannedCompletionTimeTask() ([]*models.Task, error) {
tx := dao.transactionContext.PgTx
var taskModels []*models.Task
currentTime := time.Now()
currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location())
after24Hour, _ := time.ParseDuration("24h")
after48Hour, _ := time.ParseDuration("48h")
query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo").
Where("task.planned_completion_time >= ?", currentDay.Add(after24Hour)).
Where("task.planned_completion_time < ?", currentDay.Add(after48Hour))
if err := query.Select(); err != nil {
return make([]*models.Task, 0), err
} else {
return taskModels, nil
}
}
func (dao *TaskDao) ListNearBidEndTimeTask() ([]*models.Task, error) {
tx := dao.transactionContext.PgTx
var taskModels []*models.Task
currentTime := time.Now()
currentDay := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, time.Now().Location())
after24Hour, _ := time.ParseDuration("24h")
after48Hour, _ := time.ParseDuration("48h")
query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo").
Where("task.task_type = ?", domain.TASK_TYPE_BID).
Where("bid_info.bid_end_time >= ?", currentDay.Add(after24Hour)).
Where("bid_info.bid_end_time < ?", currentDay.Add(after48Hour))
if err := query.Select(); err != nil {
return make([]*models.Task, 0), err
} else {
return taskModels, nil
}
}
func (dao *TaskDao) AddRobInfo(taskId int64, receiver *domain.EmployeeInfo) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
... ...
... ... @@ -139,7 +139,7 @@ func (service *AcceptanceTaskService) Acceptance(taskId int64, operatorUid int64
taskAcceptancedEvent.SolveReport = task.SolveReport
taskAcceptancedEvent.SolvePictureUrls = task.SolvePictureUrls
if err := service.Publish(taskAcceptancedEvent); err != nil {
println(err.Error())
return nil, err
}
return task, nil
}
... ...
... ... @@ -86,7 +86,7 @@ func (service *ChooseSuccessfulBidderService) Choose(taskId int64, successfulBid
taskBiddedEvent.BidInfo = task.BidInfo
taskBiddedEvent.Operator = operator.EmployeeInfo
if err := service.Publish(taskBiddedEvent); err != nil {
println(err.Error())
return nil, err
}
return task, nil
}
... ...
... ... @@ -5,6 +5,7 @@ import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
"time"
)
... ... @@ -54,6 +55,18 @@ func (service *ConfirmRobTaskService) Confirm(taskId int64, operatorUid int64, p
if task, err := taskRepository.Save(task); err != nil {
return nil, err
} else {
taskConfirmed := new(event.TaskConfirmed)
taskConfirmed.OccurredOn = time.Now()
taskConfirmed.TaskId = task.TaskId
taskConfirmed.CompanyId = task.CompanyId
taskConfirmed.TaskName = task.TaskName
taskConfirmed.TaskType = task.TaskType
taskConfirmed.Sponsor = task.Sponsor
taskConfirmed.TaskStatus = task.TaskStatus
taskConfirmed.RobInfo = task.RobInfo
if err := service.Publish(taskConfirmed); err != nil {
return nil, err
}
return task, nil
}
}
... ...
... ... @@ -80,7 +80,7 @@ func (service *OffTaskService) Off(taskId int64, operatorUid int64, offReason st
taskClosedEvent.TaskStatus = task.TaskStatus
taskClosedEvent.ReferenceResource = task.ReferenceResource
if err := service.Publish(taskClosedEvent); err != nil {
println(err.Error())
return nil, err
}
return task, nil
}
... ...
... ... @@ -5,6 +5,7 @@ import (
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
"time"
)
... ... @@ -69,6 +70,20 @@ func (service *RejectTaskReceiverService) Reject(taskId int64, operatorUid int64
if task, err := taskRepository.Save(task); err != nil {
return nil, err
} else {
taskRejectedEvent := new(event.TaskRejected)
taskRejectedEvent.OccurredOn = time.Now()
taskRejectedEvent.TaskId = task.TaskId
taskRejectedEvent.CompanyId = task.CompanyId
taskRejectedEvent.TaskName = task.TaskName
taskRejectedEvent.TaskType = task.TaskType
taskRejectedEvent.Sponsor = task.Sponsor
taskRejectedEvent.TaskStatus = task.TaskStatus
taskRejectedEvent.RobInfo = task.RobInfo
taskRejectedEvent.BidInfo = task.BidInfo
taskRejectedEvent.RejectTaskRecord = rejectTaskRecord
if err := service.Publish(taskRejectedEvent); err != nil {
return nil, err
}
return task, nil
}
}
... ...
... ... @@ -94,7 +94,7 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
taskReleasedEvent.TaskDescription = task.TaskDescription
taskReleasedEvent.BidInfo = task.BidInfo
if err := service.Publish(taskReleasedEvent); err != nil {
println(err.Error())
return nil, err
}
return task, nil
}
... ...
... ... @@ -79,7 +79,7 @@ func (service *RobTaskService) Rob(taskId int64, receiverUid int64) (*domain.Tas
taskRobedEvent.ReferenceResource = task.ReferenceResource
taskRobedEvent.RobInfo = task.RobInfo
if err := service.Publish(taskRobedEvent); err != nil {
println(err.Error())
return nil, err
}
return task, nil
}
... ...
... ... @@ -39,6 +39,14 @@ var _ = Describe("对抢单任务进行确认", func() {
"INSERT INTO employees (id, company_id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?, ?)",
2, 101, 2499036607974745099, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (id, task_id ,receiver) VALUES (?, ?, ?)",
1, 1, &domain.EmployeeInfo{
Uid: 2499036607974745099,
EmployeeName: "员工",
})
Expect(err3).NotTo(HaveOccurred())
})
Describe("对抢单任务进行确认", func() {
Context("任务发布人对抢单任务进行确认", func() {
... ...