正在显示
42 个修改的文件
包含
2502 行增加
和
45 行删除
pkg/application/factory/dao.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" | ||
6 | +) | ||
7 | + | ||
8 | +func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | ||
9 | + var transactionContext *pg.TransactionContext | ||
10 | + if value, ok := options["transactionContext"]; ok { | ||
11 | + transactionContext = value.(*pg.TransactionContext) | ||
12 | + } | ||
13 | + return dao.NewTaskDao(transactionContext) | ||
14 | +} |
1 | package factory | 1 | package factory |
2 | + | ||
3 | +import ( | ||
4 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" | ||
6 | + domainService "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/domain_service" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateReleaseTaskService(options map[string]interface{}) (service.ReleaseTaskService, error) { | ||
10 | + var transactionContext *pgTransaction.TransactionContext | ||
11 | + if value, ok := options["transactionContext"]; ok { | ||
12 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
13 | + } | ||
14 | + return domainService.NewReleaseTaskService(transactionContext) | ||
15 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/validation" | ||
8 | +) | ||
9 | + | ||
10 | +type AcceptanceTaskCommand struct { | ||
11 | + // 任务ID | ||
12 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
13 | + // 操作人uid | ||
14 | + Operator int64 `json:"operator" valid:"Required"` | ||
15 | + // 任务参与者UID列表 | ||
16 | + Participators []int64 `json:"participators,omitempty"` | ||
17 | + // 任务贡献占比 | ||
18 | + TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"` | ||
19 | + // 解决报告 | ||
20 | + SolveReport string `json:"solveReport,omitempty"` | ||
21 | + // 解决图片URL列表 | ||
22 | + SolvePictureUrls []string `json:"solvePictureUrls,omitempty"` | ||
23 | +} | ||
24 | + | ||
25 | +//func (acceptanceTaskCommand *AcceptanceTaskCommand) Valid(validation *validation.Validation) { | ||
26 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
27 | +//} | ||
28 | + | ||
29 | +func (acceptanceTaskCommand *AcceptanceTaskCommand) ValidateCommand() error { | ||
30 | + valid := validation.Validation{} | ||
31 | + b, err := valid.Valid(acceptanceTaskCommand) | ||
32 | + if err != nil { | ||
33 | + return err | ||
34 | + } | ||
35 | + if !b { | ||
36 | + for _, validErr := range valid.Errors { | ||
37 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
38 | + } | ||
39 | + } | ||
40 | + return nil | ||
41 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ApplyCompleteTaskCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | + // 领取人或者中标人uid | ||
13 | + Receiver int64 `json:"receiver" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +//func (applyCompleteTaskCommand *ApplyCompleteTaskCommand) Valid(validation *validation.Validation) { | ||
17 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +//} | ||
19 | + | ||
20 | +func (applyCompleteTaskCommand *ApplyCompleteTaskCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(applyCompleteTaskCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
pkg/application/task/command/bid_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type BidTaskCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | + // 竞标人uid | ||
13 | + Bidder int64 `json:"bidder" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +//func (bidTaskCommand *BidTaskCommand) Valid(validation *validation.Validation) { | ||
17 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +//} | ||
19 | + | ||
20 | +func (bidTaskCommand *BidTaskCommand) ValidateCommand() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(bidTaskCommand) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ChooseSuccessfulBidderCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | + // 操作人uid | ||
13 | + Operator int64 `json:"operator" valid:"Required"` | ||
14 | + // 中标者uid | ||
15 | + SuccessfulBidder int64 `json:"successfulBidder" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +//func (chooseSuccessfulBidderCommand *ChooseSuccessfulBidderCommand) Valid(validation *validation.Validation) { | ||
19 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +//} | ||
21 | + | ||
22 | +func (chooseSuccessfulBidderCommand *ChooseSuccessfulBidderCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(chooseSuccessfulBidderCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
pkg/application/task/command/create_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/astaxie/beego/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type CreateTaskCommand struct { | ||
12 | + // 公司ID | ||
13 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
14 | + // 任务名称 | ||
15 | + TaskName string `json:"taskName" valid:"Required"` | ||
16 | + // 任务类型 | ||
17 | + TaskType int `json:"taskType" valid:"Required"` | ||
18 | + // 任务发起者uid | ||
19 | + Sponsor int64 `json:"sponsor" valid:"Required"` | ||
20 | + // 引用类型 | ||
21 | + ReferenceResourceType int `json:"referenceResourceType,omitempty"` | ||
22 | + // 引用资源项列表 | ||
23 | + ReferenceResourceItems []*domain.ReferenceResourceItem `json:"referenceResourceItems,omitempty"` | ||
24 | + // 客户价值列表 | ||
25 | + CustomerValue []string `json:"customerValue" valid:"Required"` | ||
26 | + // 任务性质 | ||
27 | + TaskNature string `json:"taskNature" valid:"Required"` | ||
28 | + // 奖励素币 | ||
29 | + SuMoney float64 `json:"suMoney,omitempty"` | ||
30 | + // 验收标准 | ||
31 | + AcceptanceStandard string `json:"acceptanceStandard" valid:"Required"` | ||
32 | + // 任务描述 | ||
33 | + TaskDescription string `json:"taskDescription" valid:"Required"` | ||
34 | + // 任务图片URL列表 | ||
35 | + TaskPictureUrls []string `json:"taskPictureUrls,omitempty"` | ||
36 | + // 是否悬赏任务 | ||
37 | + IsRewardTake bool `json:"isRewardTake,omitempty"` | ||
38 | + // 竞标开始时间 | ||
39 | + BidStartTime time.Time `json:"bidStartTime,omitempty"` | ||
40 | + // 竞标结束时间 | ||
41 | + BidEndTime time.Time `json:"bidEndTime,omitempty"` | ||
42 | +} | ||
43 | + | ||
44 | +//func (createTaskCommand *CreateTaskCommand) Valid(validation *validation.Validation) { | ||
45 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
46 | +//} | ||
47 | + | ||
48 | +func (createTaskCommand *CreateTaskCommand) ValidateCommand() error { | ||
49 | + valid := validation.Validation{} | ||
50 | + b, err := valid.Valid(createTaskCommand) | ||
51 | + if err != nil { | ||
52 | + return err | ||
53 | + } | ||
54 | + if !b { | ||
55 | + for _, validErr := range valid.Errors { | ||
56 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
57 | + } | ||
58 | + } | ||
59 | + return nil | ||
60 | +} |
pkg/application/task/command/off_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type OffTaskCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | + // 操作人uid | ||
13 | + Operator int64 `json:"operator" valid:"Required"` | ||
14 | + // 关闭理由 | ||
15 | + OffReason string `json:"offReason" valid:"Required"` | ||
16 | +} | ||
17 | + | ||
18 | +//func (offTaskCommand *OffTaskCommand) Valid(validation *validation.Validation) { | ||
19 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +//} | ||
21 | + | ||
22 | +func (offTaskCommand *OffTaskCommand) ValidateCommand() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(offTaskCommand) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
pkg/application/task/command/release_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/astaxie/beego/validation" | ||
6 | +) | ||
7 | + | ||
8 | +type ReleaseTaskCommand struct { | ||
9 | + // 任务ID | ||
10 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
11 | + // 操作人uid | ||
12 | + Operator int64 `json:"operator" valid:"Required"` | ||
13 | +} | ||
14 | + | ||
15 | +func (releaseTaskCommand *ReleaseTaskCommand) ValidateCommand() error { | ||
16 | + valid := validation.Validation{} | ||
17 | + b, err := valid.Valid(releaseTaskCommand) | ||
18 | + if err != nil { | ||
19 | + return err | ||
20 | + } | ||
21 | + if !b { | ||
22 | + for _, validErr := range valid.Errors { | ||
23 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
24 | + } | ||
25 | + } | ||
26 | + return nil | ||
27 | +} |
pkg/application/task/command/remove_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RemoveTaskCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (removeTaskCommand *RemoveTaskCommand) ValidateCommand() error { | ||
15 | + valid := validation.Validation{} | ||
16 | + b, err := valid.Valid(removeTaskCommand) | ||
17 | + if err != nil { | ||
18 | + return err | ||
19 | + } | ||
20 | + if !b { | ||
21 | + for _, validErr := range valid.Errors { | ||
22 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | + } | ||
24 | + } | ||
25 | + return nil | ||
26 | +} |
pkg/application/task/command/rob_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type RobTaskCommand struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | + // 领取人uid | ||
13 | + Receiver int64 `json:"receiver" valid:"Required"` | ||
14 | +} | ||
15 | + | ||
16 | +func (robTaskCommand *RobTaskCommand) ValidateCommand() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(robTaskCommand) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
pkg/application/task/command/update_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/astaxie/beego/validation" | ||
9 | +) | ||
10 | + | ||
11 | +type UpdateTaskCommand struct { | ||
12 | + // 任务ID | ||
13 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
14 | + // 任务名称 | ||
15 | + TaskName string `json:"taskName,omitempty"` | ||
16 | + // 引用类型 | ||
17 | + ReferenceResourceType int `json:"referenceResourceType,omitempty"` | ||
18 | + // 引用资源项列表 | ||
19 | + ReferenceResourceItems []*domain.ReferenceResourceItem `json:"referenceResourceItems,omitempty"` | ||
20 | + // 客户价值列表 | ||
21 | + CustomerValue []string `json:"customerValue,omitempty"` | ||
22 | + // 任务性质 | ||
23 | + TaskNature string `json:"taskNature,omitempty"` | ||
24 | + // 奖励素币 | ||
25 | + SuMoney float64 `json:"suMoney,omitempty"` | ||
26 | + // 验收标准 | ||
27 | + AcceptanceStandard string `json:"acceptanceStandard,omitempty"` | ||
28 | + // 任务描述 | ||
29 | + TaskDescription string `json:"taskDescription,omitempty"` | ||
30 | + // 任务图片URL列表 | ||
31 | + TaskPictureUrls []string `json:"taskPictureUrls,omitempty"` | ||
32 | + // 是否悬赏任务 | ||
33 | + IsRewardTake bool `json:"isRewardTake,omitempty"` | ||
34 | + // 竞标开始时间 | ||
35 | + BidStartTime time.Time `json:"bidStartTime,omitempty"` | ||
36 | + // 竞标结束时间 | ||
37 | + BidEndTime time.Time `json:"bidEndTime,omitempty"` | ||
38 | +} | ||
39 | + | ||
40 | +//func (updateTaskCommand *UpdateTaskCommand) Valid(validation *validation.Validation) { | ||
41 | +// validation.SetError("CustomValid", "未实现的自定义认证") | ||
42 | +//} | ||
43 | + | ||
44 | +func (updateTaskCommand *UpdateTaskCommand) ValidateCommand() error { | ||
45 | + valid := validation.Validation{} | ||
46 | + b, err := valid.Valid(updateTaskCommand) | ||
47 | + if err != nil { | ||
48 | + return err | ||
49 | + } | ||
50 | + if !b { | ||
51 | + for _, validErr := range valid.Errors { | ||
52 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
53 | + } | ||
54 | + } | ||
55 | + return nil | ||
56 | +} |
pkg/application/task/query/get_task.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetTaskQuery struct { | ||
10 | + // 任务ID | ||
11 | + TaskId int64 `json:"taskId" valid:"Required"` | ||
12 | +} | ||
13 | + | ||
14 | +func (getTaskQuery *GetTaskQuery) ValidateQuery() error { | ||
15 | + valid := validation.Validation{} | ||
16 | + b, err := valid.Valid(getTaskQuery) | ||
17 | + if err != nil { | ||
18 | + return err | ||
19 | + } | ||
20 | + if !b { | ||
21 | + for _, validErr := range valid.Errors { | ||
22 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
23 | + } | ||
24 | + } | ||
25 | + return nil | ||
26 | +} |
pkg/application/task/query/list_task.go
0 → 100644
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type ListTaskQuery struct { | ||
10 | + // 公司ID | ||
11 | + CompanyId int64 `json:"companyId" valid:"Required"` | ||
12 | + // 任务发起者 | ||
13 | + Sponsor int64 `json:"sponsor,omitempty"` | ||
14 | + // 任务内容匹配 | ||
15 | + TaskContentMatch string `json:"taskContentMatch,omitempty"` | ||
16 | + // 任务类型 | ||
17 | + TaskType int `json:"taskType,omitempty"` | ||
18 | + // 统一用户UID | ||
19 | + Uid int64 `json:"uid,omitempty"` | ||
20 | + // 任务状态 | ||
21 | + TaskStatus int `json:"taskStatus,omitempty"` | ||
22 | + // 客户价值 | ||
23 | + CustomerValue string `json:"customerValue,omitempty"` | ||
24 | + // 任务性质 | ||
25 | + TaskNature string `json:"taskNature,omitempty"` | ||
26 | + // 是否悬赏任务 | ||
27 | + IsRewardTake bool `json:"isRewardTake,omitempty"` | ||
28 | + // 竞标时间(1全部,2已截止,3未截止) | ||
29 | + BidTimeMatch int `json:"bidTimeMatch,omitempty"` | ||
30 | + // 任务领取人 | ||
31 | + Receiver int64 `json:"receiver,omitempty"` | ||
32 | + // 任务参与者 | ||
33 | + Participator int64 `json:"participator,omitempty"` | ||
34 | + // 查询偏离量 | ||
35 | + Offset int `json:"offset,omitempty"` | ||
36 | + // 查询限制 | ||
37 | + Limit int `json:"limit,omitempty"` | ||
38 | +} | ||
39 | + | ||
40 | +func (listTaskQuery *ListTaskQuery) ValidateQuery() error { | ||
41 | + valid := validation.Validation{} | ||
42 | + b, err := valid.Valid(listTaskQuery) | ||
43 | + if err != nil { | ||
44 | + return err | ||
45 | + } | ||
46 | + if !b { | ||
47 | + for _, validErr := range valid.Errors { | ||
48 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
49 | + } | ||
50 | + } | ||
51 | + return nil | ||
52 | +} |
pkg/application/task/service/task.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/linmadan/egglib-go/core/application" | ||
6 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
7 | + "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/query" | ||
10 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
11 | +) | ||
12 | + | ||
13 | +// 任务服务 | ||
14 | +type TaskService struct { | ||
15 | +} | ||
16 | + | ||
17 | +// 对任务进行抢单 | ||
18 | +func (taskService *TaskService) RobTask(robTaskCommand *command.RobTaskCommand) (interface{}, error) { | ||
19 | + if err := robTaskCommand.ValidateCommand(); err != nil { | ||
20 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
21 | + } | ||
22 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
23 | + if err != nil { | ||
24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
25 | + } | ||
26 | + if err := transactionContext.StartTransaction(); err != nil { | ||
27 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
28 | + } | ||
29 | + defer func() { | ||
30 | + transactionContext.RollbackTransaction() | ||
31 | + }() | ||
32 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
33 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
34 | + } | ||
35 | + return nil, nil | ||
36 | +} | ||
37 | + | ||
38 | +// 对任务进行竞标 | ||
39 | +func (taskService *TaskService) BidTask(bidTaskCommand *command.BidTaskCommand) (interface{}, error) { | ||
40 | + if err := bidTaskCommand.ValidateCommand(); err != nil { | ||
41 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
42 | + } | ||
43 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
44 | + if err != nil { | ||
45 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
46 | + } | ||
47 | + if err := transactionContext.StartTransaction(); err != nil { | ||
48 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
49 | + } | ||
50 | + defer func() { | ||
51 | + transactionContext.RollbackTransaction() | ||
52 | + }() | ||
53 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
54 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
55 | + } | ||
56 | + return nil, nil | ||
57 | +} | ||
58 | + | ||
59 | +// 选择竞标任务的中标人 | ||
60 | +func (taskService *TaskService) ChooseSuccessfulBidder(chooseSuccessfulBidderCommand *command.ChooseSuccessfulBidderCommand) (interface{}, error) { | ||
61 | + if err := chooseSuccessfulBidderCommand.ValidateCommand(); err != nil { | ||
62 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
63 | + } | ||
64 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
65 | + if err != nil { | ||
66 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
67 | + } | ||
68 | + if err := transactionContext.StartTransaction(); err != nil { | ||
69 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
70 | + } | ||
71 | + defer func() { | ||
72 | + transactionContext.RollbackTransaction() | ||
73 | + }() | ||
74 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
75 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
76 | + } | ||
77 | + return nil, nil | ||
78 | +} | ||
79 | + | ||
80 | +// 申请完成任务 | ||
81 | +func (taskService *TaskService) ApplyCompleteTask(applyCompleteTaskCommand *command.ApplyCompleteTaskCommand) (interface{}, error) { | ||
82 | + if err := applyCompleteTaskCommand.ValidateCommand(); err != nil { | ||
83 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
84 | + } | ||
85 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
86 | + if err != nil { | ||
87 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
88 | + } | ||
89 | + if err := transactionContext.StartTransaction(); err != nil { | ||
90 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
91 | + } | ||
92 | + defer func() { | ||
93 | + transactionContext.RollbackTransaction() | ||
94 | + }() | ||
95 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
96 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
97 | + } | ||
98 | + return nil, nil | ||
99 | +} | ||
100 | + | ||
101 | +// 发布任务 | ||
102 | +func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseTaskCommand) (interface{}, error) { | ||
103 | + if err := releaseTaskCommand.ValidateCommand(); err != nil { | ||
104 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
105 | + } | ||
106 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
107 | + if err != nil { | ||
108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
109 | + } | ||
110 | + if err := transactionContext.StartTransaction(); err != nil { | ||
111 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
112 | + } | ||
113 | + defer func() { | ||
114 | + transactionContext.RollbackTransaction() | ||
115 | + }() | ||
116 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
117 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
118 | + } | ||
119 | + return nil, nil | ||
120 | +} | ||
121 | + | ||
122 | +// 关闭任务 | ||
123 | +func (taskService *TaskService) OffTask(offTaskCommand *command.OffTaskCommand) (interface{}, error) { | ||
124 | + if err := offTaskCommand.ValidateCommand(); err != nil { | ||
125 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
126 | + } | ||
127 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
128 | + if err != nil { | ||
129 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
130 | + } | ||
131 | + if err := transactionContext.StartTransaction(); err != nil { | ||
132 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
133 | + } | ||
134 | + defer func() { | ||
135 | + transactionContext.RollbackTransaction() | ||
136 | + }() | ||
137 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
138 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
139 | + } | ||
140 | + return nil, nil | ||
141 | +} | ||
142 | + | ||
143 | +// 验收任务 | ||
144 | +func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.AcceptanceTaskCommand) (interface{}, error) { | ||
145 | + if err := acceptanceTaskCommand.ValidateCommand(); err != nil { | ||
146 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
147 | + } | ||
148 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
149 | + if err != nil { | ||
150 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
151 | + } | ||
152 | + if err := transactionContext.StartTransaction(); err != nil { | ||
153 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
154 | + } | ||
155 | + defer func() { | ||
156 | + transactionContext.RollbackTransaction() | ||
157 | + }() | ||
158 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
159 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
160 | + } | ||
161 | + return nil, nil | ||
162 | +} | ||
163 | + | ||
164 | +// 创建新任务 | ||
165 | +func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { | ||
166 | + if err := createTaskCommand.ValidateCommand(); err != nil { | ||
167 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
168 | + } | ||
169 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
170 | + if err != nil { | ||
171 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
172 | + } | ||
173 | + if err := transactionContext.StartTransaction(); err != nil { | ||
174 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
175 | + } | ||
176 | + defer func() { | ||
177 | + transactionContext.RollbackTransaction() | ||
178 | + }() | ||
179 | + var employeeRepository domain.EmployeeRepository | ||
180 | + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ | ||
181 | + "transactionContext": transactionContext, | ||
182 | + }); err != nil { | ||
183 | + return nil, err | ||
184 | + } else { | ||
185 | + employeeRepository = value | ||
186 | + } | ||
187 | + sponsor, err := employeeRepository.FindOne(map[string]interface{}{ | ||
188 | + "uid": createTaskCommand.Sponsor, | ||
189 | + }) | ||
190 | + if err != nil { | ||
191 | + return nil, err | ||
192 | + } | ||
193 | + if sponsor == nil { | ||
194 | + return nil, fmt.Errorf("无效的发布者") | ||
195 | + } | ||
196 | + var bidInfo *domain.BidInfo | ||
197 | + if createTaskCommand.TaskType == domain.TASK_TYPE_BID { | ||
198 | + bidInfo = &domain.BidInfo{ | ||
199 | + BidStartTime: createTaskCommand.BidStartTime, | ||
200 | + BidEndTime: createTaskCommand.BidEndTime, | ||
201 | + } | ||
202 | + } else { | ||
203 | + bidInfo = nil | ||
204 | + } | ||
205 | + newTask := &domain.Task{ | ||
206 | + TaskStatus: domain.TASK_STATUS_UNRELEASED, | ||
207 | + CompanyId: createTaskCommand.CompanyId, | ||
208 | + TaskName: createTaskCommand.TaskName, | ||
209 | + TaskType: createTaskCommand.TaskType, | ||
210 | + Sponsor: sponsor.EmployeeInfo, | ||
211 | + ReferenceResource: &domain.ReferenceResource{ | ||
212 | + ReferenceResourceType: createTaskCommand.ReferenceResourceType, | ||
213 | + ReferenceResourceItems: createTaskCommand.ReferenceResourceItems, | ||
214 | + }, | ||
215 | + CustomerValue: createTaskCommand.CustomerValue, | ||
216 | + TaskNature: createTaskCommand.TaskNature, | ||
217 | + SuMoney: createTaskCommand.SuMoney, | ||
218 | + AcceptanceStandard: createTaskCommand.AcceptanceStandard, | ||
219 | + TaskDescription: createTaskCommand.TaskDescription, | ||
220 | + TaskPictureUrls: createTaskCommand.TaskPictureUrls, | ||
221 | + IsRewardTake: createTaskCommand.IsRewardTake, | ||
222 | + BidInfo: bidInfo, | ||
223 | + } | ||
224 | + var taskRepository domain.TaskRepository | ||
225 | + if value, err := factory.CreateTaskRepository(map[string]interface{}{ | ||
226 | + "transactionContext": transactionContext, | ||
227 | + }); err != nil { | ||
228 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
229 | + } else { | ||
230 | + taskRepository = value | ||
231 | + } | ||
232 | + if task, err := taskRepository.Save(newTask); err != nil { | ||
233 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
234 | + } else { | ||
235 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
236 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
237 | + } | ||
238 | + return task, nil | ||
239 | + } | ||
240 | +} | ||
241 | + | ||
242 | +// 返回任务 | ||
243 | +func (taskService *TaskService) GetTask(getTaskQuery *query.GetTaskQuery) (interface{}, error) { | ||
244 | + if err := getTaskQuery.ValidateQuery(); err != nil { | ||
245 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
246 | + } | ||
247 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
248 | + if err != nil { | ||
249 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
250 | + } | ||
251 | + if err := transactionContext.StartTransaction(); err != nil { | ||
252 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
253 | + } | ||
254 | + defer func() { | ||
255 | + transactionContext.RollbackTransaction() | ||
256 | + }() | ||
257 | + var taskRepository domain.TaskRepository | ||
258 | + if value, err := factory.CreateTaskRepository(map[string]interface{}{ | ||
259 | + "transactionContext": transactionContext, | ||
260 | + }); err != nil { | ||
261 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
262 | + } else { | ||
263 | + taskRepository = value | ||
264 | + } | ||
265 | + task, err := taskRepository.FindOne(map[string]interface{}{"taskId": getTaskQuery.TaskId}) | ||
266 | + if err != nil { | ||
267 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
268 | + } | ||
269 | + if task == nil { | ||
270 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getTaskQuery.TaskId))) | ||
271 | + } else { | ||
272 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
273 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
274 | + } | ||
275 | + return task, nil | ||
276 | + } | ||
277 | +} | ||
278 | + | ||
279 | +// 更新任务 | ||
280 | +func (taskService *TaskService) UpdateTask(updateTaskCommand *command.UpdateTaskCommand) (interface{}, error) { | ||
281 | + if err := updateTaskCommand.ValidateCommand(); err != nil { | ||
282 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
283 | + } | ||
284 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
285 | + if err != nil { | ||
286 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
287 | + } | ||
288 | + if err := transactionContext.StartTransaction(); err != nil { | ||
289 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
290 | + } | ||
291 | + defer func() { | ||
292 | + transactionContext.RollbackTransaction() | ||
293 | + }() | ||
294 | + var taskRepository domain.TaskRepository | ||
295 | + if value, err := factory.CreateTaskRepository(map[string]interface{}{ | ||
296 | + "transactionContext": transactionContext, | ||
297 | + }); err != nil { | ||
298 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
299 | + } else { | ||
300 | + taskRepository = value | ||
301 | + } | ||
302 | + task, err := taskRepository.FindOne(map[string]interface{}{"taskId": updateTaskCommand.TaskId}) | ||
303 | + if err != nil { | ||
304 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
305 | + } | ||
306 | + if task == nil { | ||
307 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateTaskCommand.TaskId))) | ||
308 | + } | ||
309 | + if err := task.Update(tool_funs.SimpleStructToMap(updateTaskCommand)); err != nil { | ||
310 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
311 | + } | ||
312 | + if task, err := taskRepository.Save(task); err != nil { | ||
313 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
314 | + } else { | ||
315 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
316 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
317 | + } | ||
318 | + return task, nil | ||
319 | + } | ||
320 | +} | ||
321 | + | ||
322 | +// 移除任务 | ||
323 | +func (taskService *TaskService) RemoveTask(removeTaskCommand *command.RemoveTaskCommand) (interface{}, error) { | ||
324 | + if err := removeTaskCommand.ValidateCommand(); err != nil { | ||
325 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
326 | + } | ||
327 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
328 | + if err != nil { | ||
329 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
330 | + } | ||
331 | + if err := transactionContext.StartTransaction(); err != nil { | ||
332 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
333 | + } | ||
334 | + defer func() { | ||
335 | + transactionContext.RollbackTransaction() | ||
336 | + }() | ||
337 | + var taskRepository domain.TaskRepository | ||
338 | + if value, err := factory.CreateTaskRepository(map[string]interface{}{ | ||
339 | + "transactionContext": transactionContext, | ||
340 | + }); err != nil { | ||
341 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
342 | + } else { | ||
343 | + taskRepository = value | ||
344 | + } | ||
345 | + task, err := taskRepository.FindOne(map[string]interface{}{"taskId": removeTaskCommand.TaskId}) | ||
346 | + if err != nil { | ||
347 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
348 | + } | ||
349 | + if task == nil { | ||
350 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeTaskCommand.TaskId))) | ||
351 | + } | ||
352 | + if task, err := taskRepository.Remove(task); err != nil { | ||
353 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
354 | + } else { | ||
355 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
356 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
357 | + } | ||
358 | + return task, nil | ||
359 | + } | ||
360 | +} | ||
361 | + | ||
362 | +// 返回任务列表 | ||
363 | +func (taskService *TaskService) ListTask(listTaskQuery *query.ListTaskQuery) (interface{}, error) { | ||
364 | + if err := listTaskQuery.ValidateQuery(); err != nil { | ||
365 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
366 | + } | ||
367 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
368 | + if err != nil { | ||
369 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
370 | + } | ||
371 | + if err := transactionContext.StartTransaction(); err != nil { | ||
372 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
373 | + } | ||
374 | + defer func() { | ||
375 | + transactionContext.RollbackTransaction() | ||
376 | + }() | ||
377 | + var taskRepository domain.TaskRepository | ||
378 | + if value, err := factory.CreateTaskRepository(map[string]interface{}{ | ||
379 | + "transactionContext": transactionContext, | ||
380 | + }); err != nil { | ||
381 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
382 | + } else { | ||
383 | + taskRepository = value | ||
384 | + } | ||
385 | + if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(listTaskQuery)); err != nil { | ||
386 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
387 | + } else { | ||
388 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
389 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
390 | + } | ||
391 | + return map[string]interface{}{ | ||
392 | + "count": count, | ||
393 | + "tasks": tasks, | ||
394 | + }, nil | ||
395 | + } | ||
396 | +} | ||
397 | + | ||
398 | +func NewTaskService(options map[string]interface{}) *TaskService { | ||
399 | + newTaskService := &TaskService{} | ||
400 | + return newTaskService | ||
401 | +} |
@@ -5,7 +5,7 @@ import "time" | @@ -5,7 +5,7 @@ import "time" | ||
5 | // 竞标任务信息 | 5 | // 竞标任务信息 |
6 | type BidInfo struct { | 6 | type BidInfo struct { |
7 | // 竞标人员列表 | 7 | // 竞标人员列表 |
8 | - Bidders []*EmployeeInfo `json:"bidders"` | 8 | + BidderInfos []*BidderInfo `json:"bidderInfos"` |
9 | // 中标人 | 9 | // 中标人 |
10 | SuccessfulBidder *EmployeeInfo `json:"successfulBidder"` | 10 | SuccessfulBidder *EmployeeInfo `json:"successfulBidder"` |
11 | // 竞标开始时间 | 11 | // 竞标开始时间 |
pkg/domain/bidder_info.go
0 → 100644
pkg/domain/service/release_task.go
0 → 100644
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "fmt" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +const ( | ||
9 | + TASK_TYPE_ROB = iota + 1 //抢单任务 | ||
10 | + TASK_TYPE_BID //竞标任务 | ||
11 | +) | ||
4 | 12 | ||
5 | const ( | 13 | const ( |
6 | - TASK_TYPE_TO_BE_RELEASED = iota + 1 //待发布 | 14 | + REFERENCE_RESOURCE_TYPE_ISSUE = iota + 1 //问题引用类型 |
15 | + REFERENCE_RESOURCE_TYPE_CHANCE //机会引用类型 | ||
16 | +) | ||
17 | + | ||
18 | +const ( | ||
19 | + TASK_STATUS_UNRELEASED = iota + 1 //待发布 | ||
20 | + TASK_STATUS_UNCLAIMED //待领取 | ||
21 | + TASK_STATUS_UNDERWAY //进行中 | ||
22 | + TASK_STATUS_UNACCEPTANCE //待验收 | ||
23 | + TASK_STATUS_COMPLETED //已完成 | ||
24 | + TASK_STATUS_CLOSED //关闭 | ||
7 | ) | 25 | ) |
8 | 26 | ||
9 | // 任务 | 27 | // 任务 |
10 | type Task struct { | 28 | type Task struct { |
11 | // 任务ID | 29 | // 任务ID |
12 | - TakeId int64 `json:"takeId"` | 30 | + TaskId int64 `json:"taskId"` |
31 | + // 公司ID | ||
32 | + CompanyId int64 `json:"companyId"` | ||
13 | // 任务名称 | 33 | // 任务名称 |
14 | TaskName string `json:"taskName"` | 34 | TaskName string `json:"taskName"` |
15 | // 任务类型Type | 35 | // 任务类型Type |
@@ -34,42 +54,48 @@ type Task struct { | @@ -34,42 +54,48 @@ type Task struct { | ||
34 | TaskPictureUrls []string `json:"taskPictureUrls"` | 54 | TaskPictureUrls []string `json:"taskPictureUrls"` |
35 | // 是否悬赏任务 | 55 | // 是否悬赏任务 |
36 | IsRewardTake bool `json:"isRewardTake"` | 56 | IsRewardTake bool `json:"isRewardTake"` |
37 | - // 创建时间 | ||
38 | - CreateTime time.Time `json:"createTime"` | ||
39 | // 抢单任务信息 | 57 | // 抢单任务信息 |
40 | RobInfo *RobInfo `json:"robInfo"` | 58 | RobInfo *RobInfo `json:"robInfo"` |
41 | // 竞标任务信息 | 59 | // 竞标任务信息 |
42 | BidInfo *BidInfo `json:"bidInfo"` | 60 | BidInfo *BidInfo `json:"bidInfo"` |
43 | // 任务参与者列表 | 61 | // 任务参与者列表 |
44 | - Participants []*EmployeeInfo `json:"participants"` | 62 | + Participators []*EmployeeInfo `json:"participators"` |
45 | // 任务贡献占比 | 63 | // 任务贡献占比 |
46 | TaskPercentage []*TaskPercentageItem `json:"taskPercentage"` | 64 | TaskPercentage []*TaskPercentageItem `json:"taskPercentage"` |
47 | // 解决报告 | 65 | // 解决报告 |
48 | SolveReport string `json:"solveReport"` | 66 | SolveReport string `json:"solveReport"` |
49 | // 解决图片URL列表 | 67 | // 解决图片URL列表 |
50 | SolvePictureUrls []string `json:"solvePictureUrls"` | 68 | SolvePictureUrls []string `json:"solvePictureUrls"` |
69 | + // 创建时间 | ||
70 | + CreateTime time.Time `json:"createTime"` | ||
71 | + // 发布时间 | ||
72 | + ReleaseTime time.Time `json:"releaseTime"` | ||
73 | + //当前状态 | ||
74 | + CurrentStatus TaskStatus `json:"-"` | ||
51 | } | 75 | } |
52 | 76 | ||
53 | -type TaskRepository interface { | ||
54 | - Save(task *Task) (*Task, error) | ||
55 | - Remove(task *Task) (*Task, error) | ||
56 | - FindOne(queryOptions map[string]interface{}) (*Task, error) | ||
57 | - Find(queryOptions map[string]interface{}) (int64, []*Task, error) | 77 | +type TaskStatus interface { |
78 | + Update(task *Task, data map[string]interface{}) error | ||
79 | + Release(task *Task) error | ||
80 | + Rob(task *Task, receiver *EmployeeInfo) error | ||
81 | + Bib(task *Task, bidder *EmployeeInfo) error | ||
82 | + ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error | ||
83 | + ApplyComplete(task *Task) error | ||
84 | + Off(task *Task) error | ||
85 | + Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error | ||
58 | } | 86 | } |
59 | 87 | ||
60 | -func (task *Task) Identify() interface{} { | ||
61 | - if task.TakeId == 0 { | ||
62 | - return nil | ||
63 | - } | ||
64 | - return task.TakeId | ||
65 | -} | 88 | +type UnReleasedStatus struct{} |
66 | 89 | ||
67 | -func (task *Task) Update(data map[string]interface{}) error { | 90 | +func (status *UnReleasedStatus) Update(task *Task, data map[string]interface{}) error { |
68 | if taskName, ok := data["taskName"]; ok { | 91 | if taskName, ok := data["taskName"]; ok { |
69 | task.TaskName = taskName.(string) | 92 | task.TaskName = taskName.(string) |
70 | } | 93 | } |
71 | - if taskType, ok := data["taskType"]; ok { | ||
72 | - task.TaskType = taskType.(int) | 94 | + if referenceResourceType, ok := data["referenceResourceType"]; ok { |
95 | + task.ReferenceResource.ReferenceResourceType = referenceResourceType.(int) | ||
96 | + } | ||
97 | + if referenceResourceItems, ok := data["referenceResourceItems"]; ok { | ||
98 | + task.ReferenceResource.ReferenceResourceItems = referenceResourceItems.([]*ReferenceResourceItem) | ||
73 | } | 99 | } |
74 | if customerValue, ok := data["customerValue"]; ok { | 100 | if customerValue, ok := data["customerValue"]; ok { |
75 | task.CustomerValue = customerValue.([]string) | 101 | task.CustomerValue = customerValue.([]string) |
@@ -80,6 +106,14 @@ func (task *Task) Update(data map[string]interface{}) error { | @@ -80,6 +106,14 @@ func (task *Task) Update(data map[string]interface{}) error { | ||
80 | if suMoney, ok := data["suMoney"]; ok { | 106 | if suMoney, ok := data["suMoney"]; ok { |
81 | task.SuMoney = suMoney.(float64) | 107 | task.SuMoney = suMoney.(float64) |
82 | } | 108 | } |
109 | + if task.TaskType == TASK_TYPE_BID { | ||
110 | + if bidStartTime, ok := data["bidStartTime"]; ok { | ||
111 | + task.BidInfo.BidStartTime = bidStartTime.(time.Time) | ||
112 | + } | ||
113 | + if bidEndTime, ok := data["bidEndTime"]; ok { | ||
114 | + task.BidInfo.BidEndTime = bidEndTime.(time.Time) | ||
115 | + } | ||
116 | + } | ||
83 | if acceptanceStandard, ok := data["acceptanceStandard"]; ok { | 117 | if acceptanceStandard, ok := data["acceptanceStandard"]; ok { |
84 | task.AcceptanceStandard = acceptanceStandard.(string) | 118 | task.AcceptanceStandard = acceptanceStandard.(string) |
85 | } | 119 | } |
@@ -94,3 +128,308 @@ func (task *Task) Update(data map[string]interface{}) error { | @@ -94,3 +128,308 @@ func (task *Task) Update(data map[string]interface{}) error { | ||
94 | } | 128 | } |
95 | return nil | 129 | return nil |
96 | } | 130 | } |
131 | + | ||
132 | +func (status *UnReleasedStatus) Release(task *Task) error { | ||
133 | + task.ReleaseTime = time.Now() | ||
134 | + task.TaskStatus = TASK_STATUS_UNCLAIMED | ||
135 | + task.CurrentStatus = &UnClaimedStatus{} | ||
136 | + return nil | ||
137 | +} | ||
138 | + | ||
139 | +func (status *UnReleasedStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
140 | + return fmt.Errorf("待发布的任务不允许抢单") | ||
141 | +} | ||
142 | + | ||
143 | +func (status *UnReleasedStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
144 | + return fmt.Errorf("待发布的任务不允许竞标") | ||
145 | +} | ||
146 | + | ||
147 | +func (status *UnReleasedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
148 | + return fmt.Errorf("待发布的任务不允许选择竞标任务的中标人") | ||
149 | +} | ||
150 | + | ||
151 | +func (status *UnReleasedStatus) ApplyComplete(task *Task) error { | ||
152 | + return fmt.Errorf("待发布的任务不允许申请完成任务") | ||
153 | +} | ||
154 | + | ||
155 | +func (status *UnReleasedStatus) Off(task *Task) error { | ||
156 | + return fmt.Errorf("待发布的任务不允许关闭") | ||
157 | +} | ||
158 | + | ||
159 | +func (status *UnReleasedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
160 | + return fmt.Errorf("待发布的任务不允许验收") | ||
161 | +} | ||
162 | + | ||
163 | +type UnClaimedStatus struct{} | ||
164 | + | ||
165 | +func (status *UnClaimedStatus) Update(task *Task, data map[string]interface{}) error { | ||
166 | + return fmt.Errorf("待领取的任务不允许编辑") | ||
167 | +} | ||
168 | + | ||
169 | +func (status *UnClaimedStatus) Release(task *Task) error { | ||
170 | + return fmt.Errorf("待领取的任务不允许重新发布") | ||
171 | +} | ||
172 | + | ||
173 | +func (status *UnClaimedStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
174 | + if task.TaskType != TASK_TYPE_ROB { | ||
175 | + return fmt.Errorf("类型不符合的任务不允许抢单") | ||
176 | + } | ||
177 | + task.RobInfo = &RobInfo{ | ||
178 | + Receiver: receiver, | ||
179 | + ReceiveTime: time.Now(), | ||
180 | + } | ||
181 | + task.TaskStatus = TASK_STATUS_UNDERWAY | ||
182 | + task.CurrentStatus = &UnderwayStatus{} | ||
183 | + return nil | ||
184 | +} | ||
185 | + | ||
186 | +func (status *UnClaimedStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
187 | + if task.TaskType != TASK_TYPE_BID { | ||
188 | + return fmt.Errorf("类型不符合的任务不允许竞标") | ||
189 | + } | ||
190 | + if task.BidInfo == nil { | ||
191 | + return fmt.Errorf("无效的竞标信息") | ||
192 | + } else { | ||
193 | + bidTime := time.Now() | ||
194 | + if bidTime.Before(task.BidInfo.BidStartTime) { | ||
195 | + return fmt.Errorf("竞标还没开始") | ||
196 | + } | ||
197 | + if bidTime.After(task.BidInfo.BidEndTime) { | ||
198 | + return fmt.Errorf("竞标已经结束") | ||
199 | + } | ||
200 | + task.BidInfo.BidderInfos = append(task.BidInfo.BidderInfos, &BidderInfo{ | ||
201 | + Bidder: bidder, | ||
202 | + BidTime: bidTime, | ||
203 | + }) | ||
204 | + return nil | ||
205 | + } | ||
206 | +} | ||
207 | + | ||
208 | +func (status *UnClaimedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
209 | + if task.TaskType != TASK_TYPE_BID { | ||
210 | + return fmt.Errorf("类型不符合的任务不允许选择竞中标人") | ||
211 | + } | ||
212 | + if task.BidInfo == nil { | ||
213 | + return fmt.Errorf("无效的竞标信息") | ||
214 | + } else { | ||
215 | + winBidTime := time.Now() | ||
216 | + if winBidTime.Before(task.BidInfo.BidEndTime) { | ||
217 | + return fmt.Errorf("竞标还没有结束") | ||
218 | + } | ||
219 | + task.BidInfo.SuccessfulBidder = successfulBidder | ||
220 | + task.BidInfo.WinBidTime = winBidTime | ||
221 | + task.TaskStatus = TASK_STATUS_UNDERWAY | ||
222 | + task.CurrentStatus = &UnderwayStatus{} | ||
223 | + return nil | ||
224 | + } | ||
225 | +} | ||
226 | + | ||
227 | +func (status *UnClaimedStatus) ApplyComplete(task *Task) error { | ||
228 | + return fmt.Errorf("待领取的任务不允许申请完成任务") | ||
229 | +} | ||
230 | + | ||
231 | +func (status *UnClaimedStatus) Off(task *Task) error { | ||
232 | + task.TaskStatus = TASK_STATUS_CLOSED | ||
233 | + task.CurrentStatus = &ClosedStatus{} | ||
234 | + return nil | ||
235 | +} | ||
236 | + | ||
237 | +func (status *UnClaimedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
238 | + return fmt.Errorf("待领取的任务不允许验收") | ||
239 | +} | ||
240 | + | ||
241 | +type UnderwayStatus struct{} | ||
242 | + | ||
243 | +func (status *UnderwayStatus) Update(task *Task, data map[string]interface{}) error { | ||
244 | + return fmt.Errorf("进行中的任务不允许编辑") | ||
245 | +} | ||
246 | + | ||
247 | +func (status *UnderwayStatus) Release(task *Task) error { | ||
248 | + return fmt.Errorf("进行中的任务不允许重新发布") | ||
249 | +} | ||
250 | + | ||
251 | +func (status *UnderwayStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
252 | + return fmt.Errorf("进行中的任务不允许抢单") | ||
253 | +} | ||
254 | + | ||
255 | +func (status *UnderwayStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
256 | + return fmt.Errorf("进行中的任务不允许竞标") | ||
257 | +} | ||
258 | + | ||
259 | +func (status *UnderwayStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
260 | + return fmt.Errorf("进行中的任务不允许选择竞标任务的中标人") | ||
261 | +} | ||
262 | + | ||
263 | +func (status *UnderwayStatus) ApplyComplete(task *Task) error { | ||
264 | + task.TaskStatus = TASK_STATUS_UNACCEPTANCE | ||
265 | + task.CurrentStatus = &UnAcceptanceStatus{} | ||
266 | + return nil | ||
267 | +} | ||
268 | + | ||
269 | +func (status *UnderwayStatus) Off(task *Task) error { | ||
270 | + task.TaskStatus = TASK_STATUS_CLOSED | ||
271 | + task.CurrentStatus = &ClosedStatus{} | ||
272 | + return nil | ||
273 | +} | ||
274 | + | ||
275 | +func (status *UnderwayStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
276 | + return fmt.Errorf("进行中的任务不允许验收") | ||
277 | +} | ||
278 | + | ||
279 | +type UnAcceptanceStatus struct{} | ||
280 | + | ||
281 | +func (status *UnAcceptanceStatus) Update(task *Task, data map[string]interface{}) error { | ||
282 | + return fmt.Errorf("待验收的任务不允许编辑") | ||
283 | +} | ||
284 | + | ||
285 | +func (status *UnAcceptanceStatus) Release(task *Task) error { | ||
286 | + return fmt.Errorf("待验收的任务不允许重新发布") | ||
287 | +} | ||
288 | + | ||
289 | +func (status *UnAcceptanceStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
290 | + return fmt.Errorf("待验收的任务不允许抢单") | ||
291 | +} | ||
292 | + | ||
293 | +func (status *UnAcceptanceStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
294 | + return fmt.Errorf("待验收的任务不允许竞标") | ||
295 | +} | ||
296 | + | ||
297 | +func (status *UnAcceptanceStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
298 | + return fmt.Errorf("待验收的任务不允许选择竞标任务的中标人") | ||
299 | +} | ||
300 | + | ||
301 | +func (status *UnAcceptanceStatus) ApplyComplete(task *Task) error { | ||
302 | + return fmt.Errorf("待验收的任务不允许申请完成任务") | ||
303 | +} | ||
304 | + | ||
305 | +func (status *UnAcceptanceStatus) Off(task *Task) error { | ||
306 | + task.TaskStatus = TASK_STATUS_CLOSED | ||
307 | + task.CurrentStatus = &ClosedStatus{} | ||
308 | + return nil | ||
309 | +} | ||
310 | + | ||
311 | +func (status *UnAcceptanceStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
312 | + task.Participators = participators | ||
313 | + task.TaskPercentage = taskPercentage | ||
314 | + task.SolveReport = solveReport | ||
315 | + task.SolvePictureUrls = solvePictureUrls | ||
316 | + task.TaskStatus = TASK_STATUS_COMPLETED | ||
317 | + task.CurrentStatus = &CompletedStatus{} | ||
318 | + return nil | ||
319 | +} | ||
320 | + | ||
321 | +type CompletedStatus struct{} | ||
322 | + | ||
323 | +func (status *CompletedStatus) Update(task *Task, data map[string]interface{}) error { | ||
324 | + return fmt.Errorf("已完成的任务不允许编辑") | ||
325 | +} | ||
326 | + | ||
327 | +func (status *CompletedStatus) Release(task *Task) error { | ||
328 | + return fmt.Errorf("已完成的任务不允许重新发布") | ||
329 | +} | ||
330 | + | ||
331 | +func (status *CompletedStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
332 | + return fmt.Errorf("已完成的任务不允许抢单") | ||
333 | +} | ||
334 | + | ||
335 | +func (status *CompletedStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
336 | + return fmt.Errorf("已完成的任务不允许竞标") | ||
337 | +} | ||
338 | + | ||
339 | +func (status *CompletedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
340 | + return fmt.Errorf("已完成的任务不允许选择竞标任务的中标人") | ||
341 | +} | ||
342 | + | ||
343 | +func (status *CompletedStatus) ApplyComplete(task *Task) error { | ||
344 | + return fmt.Errorf("已完成的任务不允许申请完成任务") | ||
345 | +} | ||
346 | + | ||
347 | +func (status *CompletedStatus) Off(task *Task) error { | ||
348 | + task.TaskStatus = TASK_STATUS_CLOSED | ||
349 | + task.CurrentStatus = &ClosedStatus{} | ||
350 | + return nil | ||
351 | +} | ||
352 | + | ||
353 | +func (status *CompletedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
354 | + return fmt.Errorf("已完成的任务不允许验收") | ||
355 | +} | ||
356 | + | ||
357 | +type ClosedStatus struct{} | ||
358 | + | ||
359 | +func (status *ClosedStatus) Update(task *Task, data map[string]interface{}) error { | ||
360 | + return fmt.Errorf("已关闭的任务不允许编辑") | ||
361 | +} | ||
362 | + | ||
363 | +func (status *ClosedStatus) Release(task *Task) error { | ||
364 | + return fmt.Errorf("已关闭的任务不允许重新发布") | ||
365 | +} | ||
366 | + | ||
367 | +func (status *ClosedStatus) Rob(task *Task, receiver *EmployeeInfo) error { | ||
368 | + return fmt.Errorf("已关闭的任务不允许抢单") | ||
369 | +} | ||
370 | + | ||
371 | +func (status *ClosedStatus) Bib(task *Task, bidder *EmployeeInfo) error { | ||
372 | + return fmt.Errorf("已关闭的任务不允许竞标") | ||
373 | +} | ||
374 | + | ||
375 | +func (status *ClosedStatus) ChooseSuccessfulBidder(task *Task, successfulBidder *EmployeeInfo) error { | ||
376 | + return fmt.Errorf("已关闭的任务不允许选择竞标任务的中标人") | ||
377 | +} | ||
378 | + | ||
379 | +func (status *ClosedStatus) ApplyComplete(task *Task) error { | ||
380 | + return fmt.Errorf("已关闭的任务不允许申请完成任务") | ||
381 | +} | ||
382 | + | ||
383 | +func (status *ClosedStatus) Off(task *Task) error { | ||
384 | + return fmt.Errorf("已关闭的任务不允许关闭") | ||
385 | +} | ||
386 | + | ||
387 | +func (status *ClosedStatus) Acceptance(task *Task, participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
388 | + return fmt.Errorf("已关闭的任务不允许验收") | ||
389 | +} | ||
390 | + | ||
391 | +type TaskRepository interface { | ||
392 | + Save(task *Task) (*Task, error) | ||
393 | + Remove(task *Task) (*Task, error) | ||
394 | + FindOne(queryOptions map[string]interface{}) (*Task, error) | ||
395 | + Find(queryOptions map[string]interface{}) (int64, []*Task, error) | ||
396 | +} | ||
397 | + | ||
398 | +func (task *Task) Identify() interface{} { | ||
399 | + if task.TaskId == 0 { | ||
400 | + return nil | ||
401 | + } | ||
402 | + return task.TaskId | ||
403 | +} | ||
404 | + | ||
405 | +func (task *Task) Update(data map[string]interface{}) error { | ||
406 | + return task.CurrentStatus.Update(task, data) | ||
407 | +} | ||
408 | + | ||
409 | +func (task *Task) Release() error { | ||
410 | + return task.CurrentStatus.Release(task) | ||
411 | +} | ||
412 | + | ||
413 | +func (task *Task) Rob(receiver *EmployeeInfo) error { | ||
414 | + return task.CurrentStatus.Rob(task, receiver) | ||
415 | +} | ||
416 | + | ||
417 | +func (task *Task) Bib(bidder *EmployeeInfo) error { | ||
418 | + return task.CurrentStatus.Bib(task, bidder) | ||
419 | +} | ||
420 | + | ||
421 | +func (task *Task) ChooseSuccessfulBidder(successfulBidder *EmployeeInfo) error { | ||
422 | + return task.CurrentStatus.ChooseSuccessfulBidder(task, successfulBidder) | ||
423 | +} | ||
424 | + | ||
425 | +func (task *Task) ApplyComplete() error { | ||
426 | + return task.CurrentStatus.ApplyComplete(task) | ||
427 | +} | ||
428 | + | ||
429 | +func (task *Task) Off() error { | ||
430 | + return task.CurrentStatus.Off(task) | ||
431 | +} | ||
432 | + | ||
433 | +func (task *Task) Acceptance(participators []*EmployeeInfo, taskPercentage []*TaskPercentageItem, solveReport string, solvePictureUrls []string) error { | ||
434 | + return task.CurrentStatus.Acceptance(task, participators, taskPercentage, solveReport, solvePictureUrls) | ||
435 | +} |
pkg/infrastructure/dao/pg_task_dao.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/go-pg/pg" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
10 | +) | ||
11 | + | ||
12 | +type TaskDao struct { | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (dao *TaskDao) addRobInfo(taskId int64, receiver *domain.EmployeeInfo) error { | ||
17 | + tx := dao.transactionContext.PgTx | ||
18 | + _, err := tx.QueryOne( | ||
19 | + pg.Scan(), | ||
20 | + "INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?) RETURNING id", | ||
21 | + taskId, receiver, time.Now()) | ||
22 | + return err | ||
23 | +} | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | +func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) { | ||
28 | + if transactionContext == nil { | ||
29 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
30 | + } else { | ||
31 | + return &TaskDao{ | ||
32 | + transactionContext: transactionContext, | ||
33 | + }, nil | ||
34 | + } | ||
35 | +} |
1 | +package domain_service | ||
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/domain" | ||
8 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository" | ||
9 | +) | ||
10 | + | ||
11 | +type ReleaseTaskService struct { | ||
12 | + coreDomain.BaseEventPublisher | ||
13 | + transactionContext *pgTransaction.TransactionContext | ||
14 | +} | ||
15 | + | ||
16 | +func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*domain.Task, error) { | ||
17 | + var employeeRepository domain.EmployeeRepository | ||
18 | + var taskRepository domain.TaskRepository | ||
19 | + if repository, err := repository.NewEmployeeRepository(service.transactionContext); err != nil { | ||
20 | + return nil, err | ||
21 | + } else { | ||
22 | + employeeRepository = repository | ||
23 | + } | ||
24 | + if repository, err := repository.NewTaskRepository(service.transactionContext); err != nil { | ||
25 | + return nil, err | ||
26 | + } else { | ||
27 | + taskRepository = repository | ||
28 | + } | ||
29 | + operator, err := employeeRepository.FindOne(map[string]interface{}{ | ||
30 | + "uid": operatorUid, | ||
31 | + }) | ||
32 | + if err != nil { | ||
33 | + return nil, err | ||
34 | + } | ||
35 | + if operator == nil { | ||
36 | + return nil, fmt.Errorf("无效的发布者") | ||
37 | + } | ||
38 | + task, err := taskRepository.FindOne(map[string]interface{}{ | ||
39 | + "taskId": taskId, | ||
40 | + }) | ||
41 | + if err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + if task == nil { | ||
45 | + return nil, fmt.Errorf("无效的任务") | ||
46 | + } | ||
47 | + if operator.EmployeeId != task.Sponsor.Uid { | ||
48 | + return nil, fmt.Errorf("无效的发布者") | ||
49 | + } | ||
50 | + if err := task.Release(); err != nil { | ||
51 | + return nil, err | ||
52 | + } | ||
53 | + if task, err := taskRepository.Save(task); err != nil { | ||
54 | + return nil, err | ||
55 | + } else { | ||
56 | + return task, nil | ||
57 | + } | ||
58 | +} | ||
59 | + | ||
60 | +func NewReleaseTaskService(transactionContext *pgTransaction.TransactionContext) (*ReleaseTaskService, error) { | ||
61 | + if transactionContext == nil { | ||
62 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
63 | + } else { | ||
64 | + return &ReleaseTaskService{ | ||
65 | + transactionContext: transactionContext, | ||
66 | + }, nil | ||
67 | + } | ||
68 | +} |
@@ -24,6 +24,9 @@ func init() { | @@ -24,6 +24,9 @@ func init() { | ||
24 | if !constant.DISABLE_CREATE_TABLE { | 24 | if !constant.DISABLE_CREATE_TABLE { |
25 | for _, model := range []interface{}{ | 25 | for _, model := range []interface{}{ |
26 | (*models.Employee)(nil), | 26 | (*models.Employee)(nil), |
27 | + (*models.RobInfo)(nil), | ||
28 | + (*models.BidderInfo)(nil), | ||
29 | + (*models.BidInfo)(nil), | ||
27 | (*models.Task)(nil), | 30 | (*models.Task)(nil), |
28 | } { | 31 | } { |
29 | err := DB.CreateTable(model, &orm.CreateTableOptions{ | 32 | err := DB.CreateTable(model, &orm.CreateTableOptions{ |
pkg/infrastructure/pg/models/bid_info.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type BidInfo struct { | ||
9 | + TableName string `pg:"bid_infos,alias:bid_info"` | ||
10 | + Id int64 `pg:",pk"` | ||
11 | + // 竞标人员列表 | ||
12 | + BidderInfos []*BidderInfo | ||
13 | + // 中标人 | ||
14 | + SuccessfulBidder *domain.EmployeeInfo | ||
15 | + // 竞标开始时间 | ||
16 | + BidStartTime time.Time | ||
17 | + // 竞标结束时间 | ||
18 | + BidEndTime time.Time | ||
19 | + // 中标时间 | ||
20 | + WinBidTime time.Time | ||
21 | + TaskId int64 `pg:",unique"` | ||
22 | +} |
pkg/infrastructure/pg/models/bidder_info.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type BidderInfo struct { | ||
9 | + TableName string `pg:"bidder_infos,alias:bidder_info"` | ||
10 | + Id int64 `pg:",pk"` | ||
11 | + // 竞标人员 | ||
12 | + Bidder *domain.EmployeeInfo | ||
13 | + // 竞标时间 | ||
14 | + BidTime time.Time | ||
15 | + BidInfoId int64 | ||
16 | + TaskId int64 | ||
17 | +} |
pkg/infrastructure/pg/models/rob_info.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +type RobInfo struct { | ||
9 | + TableName string `pg:"rob_infos,alias:rob_info"` | ||
10 | + Id int64 `pg:",pk"` | ||
11 | + // 领取人 | ||
12 | + Receiver *domain.EmployeeInfo | ||
13 | + // 领取时间 | ||
14 | + ReceiveTime time.Time | ||
15 | + TaskId int64 `pg:",unique"` | ||
16 | +} |
@@ -9,6 +9,8 @@ type Task struct { | @@ -9,6 +9,8 @@ type Task struct { | ||
9 | TableName string `pg:"tasks,alias:task"` | 9 | TableName string `pg:"tasks,alias:task"` |
10 | // 任务ID | 10 | // 任务ID |
11 | Id int64 `pg:",pk"` | 11 | Id int64 `pg:",pk"` |
12 | + // 公司ID | ||
13 | + CompanyId int64 | ||
12 | // 任务名称 | 14 | // 任务名称 |
13 | TaskName string | 15 | TaskName string |
14 | // 任务类型 | 16 | // 任务类型 |
@@ -33,19 +35,20 @@ type Task struct { | @@ -33,19 +35,20 @@ type Task struct { | ||
33 | TaskPictureUrls []string `pg:",array"` | 35 | TaskPictureUrls []string `pg:",array"` |
34 | // 是否悬赏任务 | 36 | // 是否悬赏任务 |
35 | IsRewardTake bool | 37 | IsRewardTake bool |
36 | - // 创建时间 | ||
37 | - CreateTime time.Time | ||
38 | - // 抢单任务信息 | ||
39 | - RobInfo *domain.RobInfo | ||
40 | - // 竞标任务信息 | ||
41 | - BidInfo *domain.BidInfo | ||
42 | // 任务参与者列表 | 38 | // 任务参与者列表 |
43 | - Participants []*domain.EmployeeInfo | 39 | + Participators []*domain.EmployeeInfo |
44 | // 任务贡献占比 | 40 | // 任务贡献占比 |
45 | TaskPercentage []*domain.TaskPercentageItem | 41 | TaskPercentage []*domain.TaskPercentageItem |
46 | // 解决报告 | 42 | // 解决报告 |
47 | SolveReport string | 43 | SolveReport string |
48 | // 解决图片URL列表 | 44 | // 解决图片URL列表 |
49 | SolvePictureUrls []string `pg:",array"` | 45 | SolvePictureUrls []string `pg:",array"` |
46 | + // 抢单任务信息 | ||
47 | + RobInfo *RobInfo | ||
48 | + // 竞标任务信息 | ||
49 | + BidInfo *BidInfo | ||
50 | + // 创建时间 | ||
51 | + CreateTime time.Time | ||
52 | + ReleaseTime time.Time | ||
50 | RemoveTime time.Time `pg:",soft_delete"` | 53 | RemoveTime time.Time `pg:",soft_delete"` |
51 | } | 54 | } |
@@ -24,21 +24,21 @@ func (repository *TaskRepository) nextIdentify() (int64, error) { | @@ -24,21 +24,21 @@ func (repository *TaskRepository) nextIdentify() (int64, error) { | ||
24 | func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) { | 24 | func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) { |
25 | tx := repository.transactionContext.PgTx | 25 | tx := repository.transactionContext.PgTx |
26 | if task.Identify() == nil { | 26 | if task.Identify() == nil { |
27 | - _, err := repository.nextIdentify() | 27 | + takeId, err := repository.nextIdentify() |
28 | if err != nil { | 28 | if err != nil { |
29 | return task, err | 29 | return task, err |
30 | } | 30 | } |
31 | if _, err := tx.QueryOne( | 31 | if _, err := tx.QueryOne( |
32 | - pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)), | ||
33 | - "INSERT INTO tasks (id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls", | ||
34 | - task.TakeId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls)); err != nil { | 32 | + pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime, &task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls)), |
33 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls", | ||
34 | + takeId, task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls)); err != nil { | ||
35 | return task, err | 35 | return task, err |
36 | } | 36 | } |
37 | } else { | 37 | } else { |
38 | if _, err := tx.QueryOne( | 38 | if _, err := tx.QueryOne( |
39 | - pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)), | ||
40 | - "UPDATE tasks SET task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, customer_value=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, create_time=?, rob_info=?, bid_info=?, participants=?, task_percentage=?, solve_report=?, solve_picture_urls=? WHERE id=? RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls", | ||
41 | - task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil { | 39 | + pg.Scan(&task.TaskId, &task.CompanyId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.ReleaseTime,&task.Participators, &task.TaskPercentage, &task.SolveReport, pg.Array(&task.SolvePictureUrls)), |
40 | + "UPDATE tasks SET company_id=?, task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, customer_value=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, create_time=?, release_time=?, participators=?, task_percentage=?, solve_report=?, solve_picture_urls=? WHERE id=? RETURNING id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, release_time, participators, task_percentage, solve_report, solve_picture_urls", | ||
41 | + task.CompanyId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil { | ||
42 | return task, err | 42 | return task, err |
43 | } | 43 | } |
44 | } | 44 | } |
@@ -56,7 +56,7 @@ func (repository *TaskRepository) Remove(task *domain.Task) (*domain.Task, error | @@ -56,7 +56,7 @@ func (repository *TaskRepository) Remove(task *domain.Task) (*domain.Task, error | ||
56 | func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) { | 56 | func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) { |
57 | tx := repository.transactionContext.PgTx | 57 | tx := repository.transactionContext.PgTx |
58 | taskModel := new(models.Task) | 58 | taskModel := new(models.Task) |
59 | - query := tx.Model(taskModel) | 59 | + query := tx.Model(taskModel).Relation("RobInfo").Relation("BidInfo") |
60 | if taskId, ok := queryOptions["taskId"]; ok { | 60 | if taskId, ok := queryOptions["taskId"]; ok { |
61 | query = query.Where("task.id = ?", taskId) | 61 | query = query.Where("task.id = ?", taskId) |
62 | } | 62 | } |
@@ -66,8 +66,48 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -66,8 +66,48 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | ||
66 | if taskModel.Id == 0 { | 66 | if taskModel.Id == 0 { |
67 | return nil, nil | 67 | return nil, nil |
68 | } else { | 68 | } else { |
69 | + //robInfo := &domain.RobInfo{ | ||
70 | + // Receiver: taskModel.RobInfo.Receiver, | ||
71 | + // ReceiveTime: taskModel.RobInfo.ReceiveTime, | ||
72 | + //} | ||
73 | + //bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos)) | ||
74 | + //for _, bidderInfo := range taskModel.BidInfo.BidderInfos { | ||
75 | + // bidderInfos = append(bidderInfos, &domain.BidderInfo{ | ||
76 | + // Bidder: bidderInfo.Bidder, | ||
77 | + // BidTime: bidderInfo.BidTime, | ||
78 | + // }) | ||
79 | + //} | ||
80 | + //bidInfo := &domain.BidInfo{ | ||
81 | + // BidderInfos: bidderInfos, | ||
82 | + // BidStartTime: taskModel.BidInfo.BidStartTime, | ||
83 | + // BidEndTime: taskModel.BidInfo.BidEndTime, | ||
84 | + // SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder, | ||
85 | + // WinBidTime: taskModel.BidInfo.WinBidTime, | ||
86 | + //} | ||
87 | + var currentStatus domain.TaskStatus | ||
88 | + switch taskModel.TaskStatus { | ||
89 | + case domain.TASK_STATUS_UNRELEASED: | ||
90 | + currentStatus = &domain.UnReleasedStatus{} | ||
91 | + break | ||
92 | + case domain.TASK_STATUS_UNCLAIMED: | ||
93 | + currentStatus = &domain.UnClaimedStatus{} | ||
94 | + break | ||
95 | + case domain.TASK_STATUS_UNDERWAY: | ||
96 | + currentStatus = &domain.UnderwayStatus{} | ||
97 | + break | ||
98 | + case domain.TASK_STATUS_UNACCEPTANCE: | ||
99 | + currentStatus = &domain.UnAcceptanceStatus{} | ||
100 | + break | ||
101 | + case domain.TASK_STATUS_COMPLETED: | ||
102 | + currentStatus = &domain.CompletedStatus{} | ||
103 | + break | ||
104 | + case domain.TASK_STATUS_CLOSED: | ||
105 | + currentStatus = &domain.ClosedStatus{} | ||
106 | + break | ||
107 | + } | ||
69 | return &domain.Task{ | 108 | return &domain.Task{ |
70 | - TakeId: taskModel.Id, | 109 | + TaskId: taskModel.Id, |
110 | + CompanyId: taskModel.CompanyId, | ||
71 | TaskName: taskModel.TaskName, | 111 | TaskName: taskModel.TaskName, |
72 | TaskType: taskModel.TaskType, | 112 | TaskType: taskModel.TaskType, |
73 | Sponsor: taskModel.Sponsor, | 113 | Sponsor: taskModel.Sponsor, |
@@ -81,12 +121,13 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -81,12 +121,13 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | ||
81 | TaskPictureUrls: taskModel.TaskPictureUrls, | 121 | TaskPictureUrls: taskModel.TaskPictureUrls, |
82 | IsRewardTake: taskModel.IsRewardTake, | 122 | IsRewardTake: taskModel.IsRewardTake, |
83 | CreateTime: taskModel.CreateTime, | 123 | CreateTime: taskModel.CreateTime, |
84 | - RobInfo: taskModel.RobInfo, | ||
85 | - BidInfo: taskModel.BidInfo, | ||
86 | - Participants: taskModel.Participants, | 124 | + //RobInfo: robInfo, |
125 | + //BidInfo: bidInfo, | ||
126 | + Participators: taskModel.Participators, | ||
87 | TaskPercentage: taskModel.TaskPercentage, | 127 | TaskPercentage: taskModel.TaskPercentage, |
88 | SolveReport: taskModel.SolveReport, | 128 | SolveReport: taskModel.SolveReport, |
89 | SolvePictureUrls: taskModel.SolvePictureUrls, | 129 | SolvePictureUrls: taskModel.SolvePictureUrls, |
130 | + CurrentStatus: currentStatus, | ||
90 | }, nil | 131 | }, nil |
91 | } | 132 | } |
92 | } | 133 | } |
@@ -94,7 +135,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -94,7 +135,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
94 | tx := repository.transactionContext.PgTx | 135 | tx := repository.transactionContext.PgTx |
95 | var taskModels []*models.Task | 136 | var taskModels []*models.Task |
96 | var tasks []*domain.Task | 137 | var tasks []*domain.Task |
97 | - query := tx.Model(&taskModels) | 138 | + query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo") |
98 | if offset, ok := queryOptions["offset"]; ok { | 139 | if offset, ok := queryOptions["offset"]; ok { |
99 | offset := offset.(int) | 140 | offset := offset.(int) |
100 | if offset > -1 { | 141 | if offset > -1 { |
@@ -115,8 +156,48 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -115,8 +156,48 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
115 | return 0, nil, err | 156 | return 0, nil, err |
116 | } else { | 157 | } else { |
117 | for _, taskModel := range taskModels { | 158 | for _, taskModel := range taskModels { |
159 | + robInfo := &domain.RobInfo{ | ||
160 | + Receiver: taskModel.RobInfo.Receiver, | ||
161 | + ReceiveTime: taskModel.RobInfo.ReceiveTime, | ||
162 | + } | ||
163 | + bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos)) | ||
164 | + for _, bidderInfo := range taskModel.BidInfo.BidderInfos { | ||
165 | + bidderInfos = append(bidderInfos, &domain.BidderInfo{ | ||
166 | + Bidder: bidderInfo.Bidder, | ||
167 | + BidTime: bidderInfo.BidTime, | ||
168 | + }) | ||
169 | + } | ||
170 | + bidInfo := &domain.BidInfo{ | ||
171 | + BidderInfos: bidderInfos, | ||
172 | + BidStartTime: taskModel.BidInfo.BidStartTime, | ||
173 | + BidEndTime: taskModel.BidInfo.BidEndTime, | ||
174 | + SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder, | ||
175 | + WinBidTime: taskModel.BidInfo.WinBidTime, | ||
176 | + } | ||
177 | + var currentStatus domain.TaskStatus | ||
178 | + switch taskModel.TaskStatus { | ||
179 | + case domain.TASK_STATUS_UNRELEASED: | ||
180 | + currentStatus = &domain.UnReleasedStatus{} | ||
181 | + break | ||
182 | + case domain.TASK_STATUS_UNCLAIMED: | ||
183 | + currentStatus = &domain.UnClaimedStatus{} | ||
184 | + break | ||
185 | + case domain.TASK_STATUS_UNDERWAY: | ||
186 | + currentStatus = &domain.UnderwayStatus{} | ||
187 | + break | ||
188 | + case domain.TASK_STATUS_UNACCEPTANCE: | ||
189 | + currentStatus = &domain.UnAcceptanceStatus{} | ||
190 | + break | ||
191 | + case domain.TASK_STATUS_COMPLETED: | ||
192 | + currentStatus = &domain.CompletedStatus{} | ||
193 | + break | ||
194 | + case domain.TASK_STATUS_CLOSED: | ||
195 | + currentStatus = &domain.ClosedStatus{} | ||
196 | + break | ||
197 | + } | ||
118 | tasks = append(tasks, &domain.Task{ | 198 | tasks = append(tasks, &domain.Task{ |
119 | - TakeId: taskModel.Id, | 199 | + TaskId: taskModel.Id, |
200 | + CompanyId: taskModel.CompanyId, | ||
120 | TaskName: taskModel.TaskName, | 201 | TaskName: taskModel.TaskName, |
121 | TaskType: taskModel.TaskType, | 202 | TaskType: taskModel.TaskType, |
122 | Sponsor: taskModel.Sponsor, | 203 | Sponsor: taskModel.Sponsor, |
@@ -130,12 +211,13 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -130,12 +211,13 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
130 | TaskPictureUrls: taskModel.TaskPictureUrls, | 211 | TaskPictureUrls: taskModel.TaskPictureUrls, |
131 | IsRewardTake: taskModel.IsRewardTake, | 212 | IsRewardTake: taskModel.IsRewardTake, |
132 | CreateTime: taskModel.CreateTime, | 213 | CreateTime: taskModel.CreateTime, |
133 | - RobInfo: taskModel.RobInfo, | ||
134 | - BidInfo: taskModel.BidInfo, | ||
135 | - Participants: taskModel.Participants, | 214 | + RobInfo: robInfo, |
215 | + BidInfo: bidInfo, | ||
216 | + Participators: taskModel.Participators, | ||
136 | TaskPercentage: taskModel.TaskPercentage, | 217 | TaskPercentage: taskModel.TaskPercentage, |
137 | SolveReport: taskModel.SolveReport, | 218 | SolveReport: taskModel.SolveReport, |
138 | SolvePictureUrls: taskModel.SolvePictureUrls, | 219 | SolvePictureUrls: taskModel.SolvePictureUrls, |
220 | + CurrentStatus: currentStatus, | ||
139 | }) | 221 | }) |
140 | } | 222 | } |
141 | return int64(count), tasks, nil | 223 | return int64(count), tasks, nil |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + | ||
6 | + "github.com/astaxie/beego" | ||
7 | + "github.com/linmadan/egglib-go/web/beego/utils" | ||
8 | + "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/service" | ||
11 | +) | ||
12 | + | ||
13 | +type TaskController struct { | ||
14 | + beego.Controller | ||
15 | +} | ||
16 | + | ||
17 | +func (controller *TaskController) RobTask() { | ||
18 | + taskService := service.NewTaskService(nil) | ||
19 | + robTaskCommand := &command.RobTaskCommand{} | ||
20 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), robTaskCommand) | ||
21 | + taskId, _ := controller.GetInt64(":taskId") | ||
22 | + robTaskCommand.TaskId = taskId | ||
23 | + data, err := taskService.RobTask(robTaskCommand) | ||
24 | + var response utils.JsonResponse | ||
25 | + if err != nil { | ||
26 | + response = utils.ResponseError(controller.Ctx, err) | ||
27 | + } else { | ||
28 | + response = utils.ResponseData(controller.Ctx, data) | ||
29 | + } | ||
30 | + controller.Data["json"] = response | ||
31 | + controller.ServeJSON() | ||
32 | +} | ||
33 | + | ||
34 | +func (controller *TaskController) BidTask() { | ||
35 | + taskService := service.NewTaskService(nil) | ||
36 | + bidTaskCommand := &command.BidTaskCommand{} | ||
37 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), bidTaskCommand) | ||
38 | + taskId, _ := controller.GetInt64(":taskId") | ||
39 | + bidTaskCommand.TaskId = taskId | ||
40 | + data, err := taskService.BidTask(bidTaskCommand) | ||
41 | + var response utils.JsonResponse | ||
42 | + if err != nil { | ||
43 | + response = utils.ResponseError(controller.Ctx, err) | ||
44 | + } else { | ||
45 | + response = utils.ResponseData(controller.Ctx, data) | ||
46 | + } | ||
47 | + controller.Data["json"] = response | ||
48 | + controller.ServeJSON() | ||
49 | +} | ||
50 | + | ||
51 | +func (controller *TaskController) ApplyCompleteTask() { | ||
52 | + taskService := service.NewTaskService(nil) | ||
53 | + applyCompleteTaskCommand := &command.ApplyCompleteTaskCommand{} | ||
54 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), applyCompleteTaskCommand) | ||
55 | + taskId, _ := controller.GetInt64(":taskId") | ||
56 | + applyCompleteTaskCommand.TaskId = taskId | ||
57 | + data, err := taskService.ApplyCompleteTask(applyCompleteTaskCommand) | ||
58 | + var response utils.JsonResponse | ||
59 | + if err != nil { | ||
60 | + response = utils.ResponseError(controller.Ctx, err) | ||
61 | + } else { | ||
62 | + response = utils.ResponseData(controller.Ctx, data) | ||
63 | + } | ||
64 | + controller.Data["json"] = response | ||
65 | + controller.ServeJSON() | ||
66 | +} | ||
67 | + | ||
68 | +func (controller *TaskController) ReleaseTask() { | ||
69 | + taskService := service.NewTaskService(nil) | ||
70 | + releaseTaskCommand := &command.ReleaseTaskCommand{} | ||
71 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), releaseTaskCommand) | ||
72 | + taskId, _ := controller.GetInt64(":taskId") | ||
73 | + releaseTaskCommand.TaskId = taskId | ||
74 | + data, err := taskService.ReleaseTask(releaseTaskCommand) | ||
75 | + var response utils.JsonResponse | ||
76 | + if err != nil { | ||
77 | + response = utils.ResponseError(controller.Ctx, err) | ||
78 | + } else { | ||
79 | + response = utils.ResponseData(controller.Ctx, data) | ||
80 | + } | ||
81 | + controller.Data["json"] = response | ||
82 | + controller.ServeJSON() | ||
83 | +} | ||
84 | + | ||
85 | +func (controller *TaskController) ChooseSuccessfulBidder() { | ||
86 | + taskService := service.NewTaskService(nil) | ||
87 | + chooseSuccessfulBidderCommand := &command.ChooseSuccessfulBidderCommand{} | ||
88 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), chooseSuccessfulBidderCommand) | ||
89 | + taskId, _ := controller.GetInt64(":taskId") | ||
90 | + chooseSuccessfulBidderCommand.TaskId = taskId | ||
91 | + data, err := taskService.ChooseSuccessfulBidder(chooseSuccessfulBidderCommand) | ||
92 | + var response utils.JsonResponse | ||
93 | + if err != nil { | ||
94 | + response = utils.ResponseError(controller.Ctx, err) | ||
95 | + } else { | ||
96 | + response = utils.ResponseData(controller.Ctx, data) | ||
97 | + } | ||
98 | + controller.Data["json"] = response | ||
99 | + controller.ServeJSON() | ||
100 | +} | ||
101 | + | ||
102 | +func (controller *TaskController) OffTask() { | ||
103 | + taskService := service.NewTaskService(nil) | ||
104 | + offTaskCommand := &command.OffTaskCommand{} | ||
105 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), offTaskCommand) | ||
106 | + taskId, _ := controller.GetInt64(":taskId") | ||
107 | + offTaskCommand.TaskId = taskId | ||
108 | + data, err := taskService.OffTask(offTaskCommand) | ||
109 | + var response utils.JsonResponse | ||
110 | + if err != nil { | ||
111 | + response = utils.ResponseError(controller.Ctx, err) | ||
112 | + } else { | ||
113 | + response = utils.ResponseData(controller.Ctx, data) | ||
114 | + } | ||
115 | + controller.Data["json"] = response | ||
116 | + controller.ServeJSON() | ||
117 | +} | ||
118 | + | ||
119 | +func (controller *TaskController) AcceptanceTask() { | ||
120 | + taskService := service.NewTaskService(nil) | ||
121 | + acceptanceTaskCommand := &command.AcceptanceTaskCommand{} | ||
122 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), acceptanceTaskCommand) | ||
123 | + taskId, _ := controller.GetInt64(":taskId") | ||
124 | + acceptanceTaskCommand.TaskId = taskId | ||
125 | + data, err := taskService.AcceptanceTask(acceptanceTaskCommand) | ||
126 | + var response utils.JsonResponse | ||
127 | + if err != nil { | ||
128 | + response = utils.ResponseError(controller.Ctx, err) | ||
129 | + } else { | ||
130 | + response = utils.ResponseData(controller.Ctx, data) | ||
131 | + } | ||
132 | + controller.Data["json"] = response | ||
133 | + controller.ServeJSON() | ||
134 | +} | ||
135 | + | ||
136 | +func (controller *TaskController) CreateTask() { | ||
137 | + taskService := service.NewTaskService(nil) | ||
138 | + createTaskCommand := &command.CreateTaskCommand{} | ||
139 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createTaskCommand) | ||
140 | + data, err := taskService.CreateTask(createTaskCommand) | ||
141 | + var response utils.JsonResponse | ||
142 | + if err != nil { | ||
143 | + response = utils.ResponseError(controller.Ctx, err) | ||
144 | + } else { | ||
145 | + response = utils.ResponseData(controller.Ctx, data) | ||
146 | + } | ||
147 | + controller.Data["json"] = response | ||
148 | + controller.ServeJSON() | ||
149 | +} | ||
150 | + | ||
151 | +func (controller *TaskController) UpdateTask() { | ||
152 | + taskService := service.NewTaskService(nil) | ||
153 | + updateTaskCommand := &command.UpdateTaskCommand{} | ||
154 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateTaskCommand) | ||
155 | + taskId, _ := controller.GetInt64(":taskId") | ||
156 | + updateTaskCommand.TaskId = taskId | ||
157 | + data, err := taskService.UpdateTask(updateTaskCommand) | ||
158 | + var response utils.JsonResponse | ||
159 | + if err != nil { | ||
160 | + response = utils.ResponseError(controller.Ctx, err) | ||
161 | + } else { | ||
162 | + response = utils.ResponseData(controller.Ctx, data) | ||
163 | + } | ||
164 | + controller.Data["json"] = response | ||
165 | + controller.ServeJSON() | ||
166 | +} | ||
167 | + | ||
168 | +func (controller *TaskController) GetTask() { | ||
169 | + taskService := service.NewTaskService(nil) | ||
170 | + getTaskQuery := &query.GetTaskQuery{} | ||
171 | + taskId, _ := controller.GetInt64(":taskId") | ||
172 | + getTaskQuery.TaskId = taskId | ||
173 | + data, err := taskService.GetTask(getTaskQuery) | ||
174 | + var response utils.JsonResponse | ||
175 | + if err != nil { | ||
176 | + response = utils.ResponseError(controller.Ctx, err) | ||
177 | + } else { | ||
178 | + response = utils.ResponseData(controller.Ctx, data) | ||
179 | + } | ||
180 | + controller.Data["json"] = response | ||
181 | + controller.ServeJSON() | ||
182 | +} | ||
183 | + | ||
184 | +func (controller *TaskController) RemoveTask() { | ||
185 | + taskService := service.NewTaskService(nil) | ||
186 | + removeTaskCommand := &command.RemoveTaskCommand{} | ||
187 | + taskId, _ := controller.GetInt64(":taskId") | ||
188 | + removeTaskCommand.TaskId = taskId | ||
189 | + data, err := taskService.RemoveTask(removeTaskCommand) | ||
190 | + var response utils.JsonResponse | ||
191 | + if err != nil { | ||
192 | + response = utils.ResponseError(controller.Ctx, err) | ||
193 | + } else { | ||
194 | + response = utils.ResponseData(controller.Ctx, data) | ||
195 | + } | ||
196 | + controller.Data["json"] = response | ||
197 | + controller.ServeJSON() | ||
198 | +} | ||
199 | + | ||
200 | +func (controller *TaskController) ListTask() { | ||
201 | + taskService := service.NewTaskService(nil) | ||
202 | + listTaskQuery := &query.ListTaskQuery{} | ||
203 | + companyId, _ := controller.GetInt64("companyId") | ||
204 | + listTaskQuery.CompanyId = companyId | ||
205 | + sponsor, _ := controller.GetInt64("sponsor") | ||
206 | + listTaskQuery.Sponsor = sponsor | ||
207 | + taskContentMatch := controller.GetString("taskContentMatch") | ||
208 | + listTaskQuery.TaskContentMatch = taskContentMatch | ||
209 | + taskType, _ := controller.GetInt("taskType") | ||
210 | + listTaskQuery.TaskType = taskType | ||
211 | + taskStatus, _ := controller.GetInt("taskStatus") | ||
212 | + listTaskQuery.TaskStatus = taskStatus | ||
213 | + customerValue := controller.GetString("customerValue") | ||
214 | + listTaskQuery.CustomerValue = customerValue | ||
215 | + taskNature := controller.GetString("taskNature") | ||
216 | + listTaskQuery.TaskNature = taskNature | ||
217 | + isRewardTake, _ := controller.GetBool("isRewardTake") | ||
218 | + listTaskQuery.IsRewardTake = isRewardTake | ||
219 | + bidTimeMatch, _ := controller.GetInt("bidTimeMatch") | ||
220 | + listTaskQuery.BidTimeMatch = bidTimeMatch | ||
221 | + receiver, _ := controller.GetInt64("receiver") | ||
222 | + listTaskQuery.Receiver = receiver | ||
223 | + participator, _ := controller.GetInt64("participator") | ||
224 | + listTaskQuery.Participator = participator | ||
225 | + offset, _ := controller.GetInt("offset") | ||
226 | + listTaskQuery.Offset = offset | ||
227 | + limit, _ := controller.GetInt("limit") | ||
228 | + listTaskQuery.Limit = limit | ||
229 | + data, err := taskService.ListTask(listTaskQuery) | ||
230 | + var response utils.JsonResponse | ||
231 | + if err != nil { | ||
232 | + response = utils.ResponseError(controller.Ctx, err) | ||
233 | + } else { | ||
234 | + response = utils.ResponseData(controller.Ctx, data) | ||
235 | + } | ||
236 | + controller.Data["json"] = response | ||
237 | + controller.ServeJSON() | ||
238 | +} |
pkg/port/beego/routers/task_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego" | ||
5 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + beego.Router("/tasks/:taskId/rob", &controllers.TaskController{}, "Post:RobTask") | ||
10 | + beego.Router("/tasks/:taskId/bid", &controllers.TaskController{}, "Post:BidTask") | ||
11 | + beego.Router("/tasks/:taskId/apply-complete", &controllers.TaskController{}, "Post:ApplyCompleteTask") | ||
12 | + beego.Router("/tasks/:taskId/release", &controllers.TaskController{}, "Post:ReleaseTask") | ||
13 | + beego.Router("/tasks/:taskId/choose-successful-bidder", &controllers.TaskController{}, "Post:ChooseSuccessfulBidder") | ||
14 | + beego.Router("/tasks/:taskId/dff", &controllers.TaskController{}, "Post:OffTask") | ||
15 | + beego.Router("/tasks/:taskId/acceptance", &controllers.TaskController{}, "Post:AcceptanceTask") | ||
16 | + beego.Router("/tasks/", &controllers.TaskController{}, "Post:CreateTask") | ||
17 | + beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Put:UpdateTask") | ||
18 | + beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask") | ||
19 | + beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Delete:RemoveTask") | ||
20 | + beego.Router("/tasks/", &controllers.TaskController{}, "Get:ListTask") | ||
21 | +} |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("验收任务", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("验收任务", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "operator": "int64", | ||
28 | + "participators": "array", | ||
29 | + "taskPercentage": "array", | ||
30 | + "solveReport": "string", | ||
31 | + "solvePictureUrls": "array", | ||
32 | + } | ||
33 | + httpExpect.POST("/tasks/{taskId}/acceptance"). | ||
34 | + WithJSON(body). | ||
35 | + Expect(). | ||
36 | + Status(http.StatusOK). | ||
37 | + JSON(). | ||
38 | + Object(). | ||
39 | + ContainsKey("code").ValueEqual("code", 0). | ||
40 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
41 | + ContainsKey("data").Value("data").Object() | ||
42 | + }) | ||
43 | + }) | ||
44 | + }) | ||
45 | + AfterEach(func() { | ||
46 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
47 | + Expect(err).NotTo(HaveOccurred()) | ||
48 | + }) | ||
49 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("申请完成任务", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("申请完成任务", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "receiver": "int64", | ||
28 | + } | ||
29 | + httpExpect.POST("/tasks/{taskId}/apply-complete"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
test/integration/beego/task/bid_task_test.go
0 → 100644
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("对任务进行竞标", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("对任务进行竞标", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "bidder": "int64", | ||
28 | + } | ||
29 | + httpExpect.POST("/tasks/{taskId}/bid"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("选择竞标任务的中标人", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("选择竞标任务的中标人", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "operator": "int64", | ||
28 | + "successfulBidder": "int64", | ||
29 | + } | ||
30 | + httpExpect.POST("/tasks/{taskId}/choose-successful-bidder"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg" | ||
5 | + "net/http" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/gavv/httpexpect" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
12 | +) | ||
13 | + | ||
14 | +var _ = Describe("创建新任务", func() { | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(), | ||
18 | + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)", | ||
19 | + 1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0) | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("提交数据创建新任务", func() { | ||
23 | + Context("提交正确的抢单类型任务数据", func() { | ||
24 | + It("返回抢单类型任务数据", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "companyId": 101, | ||
28 | + "taskName": "抢单任务", | ||
29 | + "taskType": 1, | ||
30 | + "sponsor": 2499036607974745088, | ||
31 | + "referenceResourceType": 1, | ||
32 | + "referenceResourceItems": []map[string]interface{}{ | ||
33 | + {"serialNumber": 1, "title": "问题标题1"}, | ||
34 | + {"serialNumber": 2, "title": "问题标题2"}, | ||
35 | + {"serialNumber": 3, "title": "问题标题3"}, | ||
36 | + }, | ||
37 | + "customerValue": []string{ | ||
38 | + "口味", | ||
39 | + "色泽", | ||
40 | + "商务服务", | ||
41 | + }, | ||
42 | + "taskNature": "线", | ||
43 | + "suMoney": 1000.00, | ||
44 | + "acceptanceStandard": "验收标准", | ||
45 | + "taskDescription": "任务描述", | ||
46 | + "taskPictureUrls": []string{ | ||
47 | + "url-1", | ||
48 | + "url-2", | ||
49 | + "url-3", | ||
50 | + }, | ||
51 | + "isRewardTake": false, | ||
52 | + } | ||
53 | + httpExpect.POST("/tasks/"). | ||
54 | + WithJSON(body). | ||
55 | + Expect(). | ||
56 | + Status(http.StatusOK). | ||
57 | + JSON(). | ||
58 | + Object(). | ||
59 | + ContainsKey("code").ValueEqual("code", 0). | ||
60 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
61 | + ContainsKey("data").Value("data").Object(). | ||
62 | + ContainsKey("taskId").ValueNotEqual("taskId", BeZero()) | ||
63 | + }) | ||
64 | + }) | ||
65 | + Context("提交正确的竞标类型任务数据", func() { | ||
66 | + It("返回竞标类型任务数据", func() { | ||
67 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
68 | + dayAfter, _ := time.ParseDuration("72h") | ||
69 | + body := map[string]interface{}{ | ||
70 | + "companyId": 101, | ||
71 | + "taskName": "竞标任务", | ||
72 | + "taskType": 2, | ||
73 | + "sponsor": 2499036607974745088, | ||
74 | + "referenceResourceType": 2, | ||
75 | + "referenceResourceItems": []map[string]interface{}{ | ||
76 | + {"serialNumber": 1, "title": "机会标题1"}, | ||
77 | + {"serialNumber": 2, "title": "机会标题2"}, | ||
78 | + {"serialNumber": 3, "title": "机会标题3"}, | ||
79 | + }, | ||
80 | + "customerValue": []string{ | ||
81 | + "口味", | ||
82 | + "色泽", | ||
83 | + "商务服务", | ||
84 | + }, | ||
85 | + "taskNature": "线", | ||
86 | + "suMoney": 1000.00, | ||
87 | + "acceptanceStandard": "验收标准", | ||
88 | + "taskDescription": "任务描述", | ||
89 | + "taskPictureUrls": []string{ | ||
90 | + "url-1", | ||
91 | + "url-2", | ||
92 | + "url-3", | ||
93 | + }, | ||
94 | + "isRewardTake": true, | ||
95 | + "bidStartTime": time.Now(), | ||
96 | + "bidEndTime": time.Now().Add( dayAfter), | ||
97 | + } | ||
98 | + httpExpect.POST("/tasks/"). | ||
99 | + WithJSON(body). | ||
100 | + Expect(). | ||
101 | + Status(http.StatusOK). | ||
102 | + JSON(). | ||
103 | + Object(). | ||
104 | + ContainsKey("code").ValueEqual("code", 0). | ||
105 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
106 | + ContainsKey("data").Value("data").Object(). | ||
107 | + ContainsKey("taskId").ValueNotEqual("taskId", BeZero()) | ||
108 | + }) | ||
109 | + }) | ||
110 | + }) | ||
111 | + AfterEach(func() { | ||
112 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
113 | + Expect(err).NotTo(HaveOccurred()) | ||
114 | + _, err1 := pG.DB.Exec("DELETE FROM employees WHERE true") | ||
115 | + Expect(err1).NotTo(HaveOccurred()) | ||
116 | + }) | ||
117 | +}) |
test/integration/beego/task/get_task_test.go
0 → 100644
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回任务", func() { | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(), | ||
17 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
18 | + 1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false) | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("根据taskId参数返回任务", func() { | ||
22 | + Context("传入有效的taskId", func() { | ||
23 | + It("返回任务数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + httpExpect.GET("/tasks/1"). | ||
26 | + Expect(). | ||
27 | + Status(http.StatusOK). | ||
28 | + JSON(). | ||
29 | + Object(). | ||
30 | + ContainsKey("code").ValueEqual("code", 0). | ||
31 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
32 | + ContainsKey("data").Value("data").Object() | ||
33 | + }) | ||
34 | + }) | ||
35 | + }) | ||
36 | + AfterEach(func() { | ||
37 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
38 | + Expect(err).NotTo(HaveOccurred()) | ||
39 | + }) | ||
40 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("返回任务列表", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("根据参数返回任务列表", func() { | ||
23 | + Context("传入有效的参数", func() { | ||
24 | + It("返回任务数据列表", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + httpExpect.GET("/tasks/"). | ||
27 | + WithQuery("companyId", "int64"). | ||
28 | + WithQuery("sponsor", "int64"). | ||
29 | + WithQuery("taskContentMatch", "string"). | ||
30 | + WithQuery("taskType", "int"). | ||
31 | + WithQuery("taskStatus", "int"). | ||
32 | + WithQuery("customerValue", "string"). | ||
33 | + WithQuery("taskNature", "string"). | ||
34 | + WithQuery("isRewardTake", "boolean"). | ||
35 | + WithQuery("bidTimeMatch", "int"). | ||
36 | + WithQuery("receiver", "int64"). | ||
37 | + WithQuery("participator", "int64"). | ||
38 | + WithQuery("offset", "int"). | ||
39 | + WithQuery("limit", "int"). | ||
40 | + Expect(). | ||
41 | + Status(http.StatusOK). | ||
42 | + JSON(). | ||
43 | + Object(). | ||
44 | + ContainsKey("code").ValueEqual("code", 0). | ||
45 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
46 | + ContainsKey("data").Value("data").Object(). | ||
47 | + ContainsKey("count").ValueEqual("count", 1). | ||
48 | + ContainsKey("tasks").Value("tasks").Array() | ||
49 | + }) | ||
50 | + }) | ||
51 | + }) | ||
52 | + AfterEach(func() { | ||
53 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
54 | + Expect(err).NotTo(HaveOccurred()) | ||
55 | + }) | ||
56 | +}) |
test/integration/beego/task/off_task_test.go
0 → 100644
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("关闭任务", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("关闭任务", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "operator": "int64", | ||
28 | + "offReason": "string", | ||
29 | + } | ||
30 | + httpExpect.POST("/tasks/{taskId}/dff"). | ||
31 | + WithJSON(body). | ||
32 | + Expect(). | ||
33 | + Status(http.StatusOK). | ||
34 | + JSON(). | ||
35 | + Object(). | ||
36 | + ContainsKey("code").ValueEqual("code", 0). | ||
37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
38 | + ContainsKey("data").Value("data").Object() | ||
39 | + }) | ||
40 | + }) | ||
41 | + }) | ||
42 | + AfterEach(func() { | ||
43 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
44 | + Expect(err).NotTo(HaveOccurred()) | ||
45 | + }) | ||
46 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("发布任务", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("发布任务", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "operator": "int64", | ||
28 | + } | ||
29 | + httpExpect.POST("/tasks/{taskId}/release"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("移除任务", func() { | ||
14 | + BeforeEach(func() { | ||
15 | + _, err := pG.DB.QueryOne( | ||
16 | + pg.Scan(), | ||
17 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
18 | + 1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false) | ||
19 | + Expect(err).NotTo(HaveOccurred()) | ||
20 | + }) | ||
21 | + Describe("根据参数移除任务", func() { | ||
22 | + Context("传入有效的taskId", func() { | ||
23 | + It("返回被移除任务的数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + httpExpect.DELETE("/tasks/1"). | ||
26 | + Expect(). | ||
27 | + Status(http.StatusOK). | ||
28 | + JSON(). | ||
29 | + Object(). | ||
30 | + ContainsKey("code").ValueEqual("code", 0). | ||
31 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
32 | + ContainsKey("data").Value("data").Object() | ||
33 | + }) | ||
34 | + }) | ||
35 | + }) | ||
36 | + AfterEach(func() { | ||
37 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
38 | + Expect(err).NotTo(HaveOccurred()) | ||
39 | + }) | ||
40 | +}) |
test/integration/beego/task/rob_task_test.go
0 → 100644
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/gavv/httpexpect" | ||
7 | + "github.com/go-pg/pg" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("对任务进行抢单", func() { | ||
14 | + var taskId int64 | ||
15 | + BeforeEach(func() { | ||
16 | + _, err := pG.DB.QueryOne( | ||
17 | + pg.Scan(&taskId), | ||
18 | + "INSERT INTO tasks (task_id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, rob_info, bid_info, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id", | ||
19 | + "testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime") | ||
20 | + Expect(err).NotTo(HaveOccurred()) | ||
21 | + }) | ||
22 | + Describe("对任务进行抢单", func() { | ||
23 | + Context("", func() { | ||
24 | + It("", func() { | ||
25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
26 | + body := map[string]interface{}{ | ||
27 | + "receiver": "int64", | ||
28 | + } | ||
29 | + httpExpect.POST("/tasks/{taskId}/rob"). | ||
30 | + WithJSON(body). | ||
31 | + Expect(). | ||
32 | + Status(http.StatusOK). | ||
33 | + JSON(). | ||
34 | + Object(). | ||
35 | + ContainsKey("code").ValueEqual("code", 0). | ||
36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
37 | + ContainsKey("data").Value("data").Object() | ||
38 | + }) | ||
39 | + }) | ||
40 | + }) | ||
41 | + AfterEach(func() { | ||
42 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
43 | + Expect(err).NotTo(HaveOccurred()) | ||
44 | + }) | ||
45 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + "net/http/httptest" | ||
6 | + "testing" | ||
7 | + | ||
8 | + "github.com/astaxie/beego" | ||
9 | + . "github.com/onsi/ginkgo" | ||
10 | + . "github.com/onsi/gomega" | ||
11 | + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
12 | + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego" | ||
13 | +) | ||
14 | + | ||
15 | +func TestTask(t *testing.T) { | ||
16 | + RegisterFailHandler(Fail) | ||
17 | + RunSpecs(t, "Beego Port Task Correlations Test Case Suite") | ||
18 | +} | ||
19 | + | ||
20 | +var handler http.Handler | ||
21 | +var server *httptest.Server | ||
22 | + | ||
23 | +var _ = BeforeSuite(func() { | ||
24 | + handler = beego.BeeApp.Handlers | ||
25 | + server = httptest.NewServer(handler) | ||
26 | +}) | ||
27 | + | ||
28 | +var _ = AfterSuite(func() { | ||
29 | + server.Close() | ||
30 | +}) |
1 | +package task | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/go-pg/pg" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/gavv/httpexpect" | ||
8 | + . "github.com/onsi/ginkgo" | ||
9 | + . "github.com/onsi/gomega" | ||
10 | + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" | ||
11 | +) | ||
12 | + | ||
13 | +var _ = Describe("更新任务", func() { | ||
14 | + Describe("提交数据更新任务", func() { | ||
15 | + Context("任务未发布状态下提交正确的任务数据", func() { | ||
16 | + BeforeEach(func() { | ||
17 | + _, err := pG.DB.QueryOne( | ||
18 | + pg.Scan(), | ||
19 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
20 | + 1, 101, "testTaskName", 1, "{}", 1, "{}", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false) | ||
21 | + Expect(err).NotTo(HaveOccurred()) | ||
22 | + }) | ||
23 | + It("返回更新后的任务数据", func() { | ||
24 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
25 | + body := map[string]interface{}{ | ||
26 | + "taskName": "抢单任务", | ||
27 | + "taskType": 1, | ||
28 | + "sponsor": 2499036607974745088, | ||
29 | + "referenceResourceType": 1, | ||
30 | + "referenceResourceItems": []map[string]interface{}{ | ||
31 | + {"serialNumber": 1, "title": "问题标题1"}, | ||
32 | + {"serialNumber": 2, "title": "问题标题2"}, | ||
33 | + {"serialNumber": 3, "title": "问题标题3"}, | ||
34 | + }, | ||
35 | + "customerValue": []string{ | ||
36 | + "口味", | ||
37 | + "色泽", | ||
38 | + "商务服务", | ||
39 | + }, | ||
40 | + "taskNature": "线", | ||
41 | + "suMoney": 1000.00, | ||
42 | + "acceptanceStandard": "验收标准", | ||
43 | + "taskDescription": "任务描述", | ||
44 | + "taskPictureUrls": []string{ | ||
45 | + "url-1", | ||
46 | + "url-2", | ||
47 | + "url-3", | ||
48 | + }, | ||
49 | + "isRewardTake": false, | ||
50 | + } | ||
51 | + httpExpect.PUT("/tasks/1"). | ||
52 | + WithJSON(body). | ||
53 | + Expect(). | ||
54 | + Status(http.StatusOK). | ||
55 | + JSON(). | ||
56 | + Object(). | ||
57 | + ContainsKey("code").ValueEqual("code", 0). | ||
58 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
59 | + ContainsKey("data").Value("data").Object(). | ||
60 | + ContainsKey("taskId").ValueEqual("taskId", 1) | ||
61 | + }) | ||
62 | + }) | ||
63 | + Context("任务不在未发布状态下提交正确的任务数据", func() { | ||
64 | + BeforeEach(func() { | ||
65 | + _, err := pG.DB.QueryOne( | ||
66 | + pg.Scan(), | ||
67 | + "INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
68 | + 1, 101, "testTaskName", 1, "{}", 3, "null", pg.Array([]string{"口感"}), "testTaskNature", 100.00, "testAcceptanceStandard", "testTaskDescription", pg.Array([]string{"url"}), false) | ||
69 | + Expect(err).NotTo(HaveOccurred()) | ||
70 | + }) | ||
71 | + It("返回当前状态不能进行编辑操作的提示", func() { | ||
72 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
73 | + body := map[string]interface{}{ | ||
74 | + "taskName": "抢单任务", | ||
75 | + "taskType": 1, | ||
76 | + "sponsor": 2499036607974745088, | ||
77 | + "referenceResourceType": 1, | ||
78 | + "referenceResourceItems": []map[string]interface{}{ | ||
79 | + {"serialNumber": 1, "title": "问题标题1"}, | ||
80 | + {"serialNumber": 2, "title": "问题标题2"}, | ||
81 | + {"serialNumber": 3, "title": "问题标题3"}, | ||
82 | + }, | ||
83 | + "customerValue": []string{ | ||
84 | + "口味", | ||
85 | + "色泽", | ||
86 | + "商务服务", | ||
87 | + }, | ||
88 | + "taskNature": "线", | ||
89 | + "suMoney": 1000.00, | ||
90 | + "acceptanceStandard": "验收标准", | ||
91 | + "taskDescription": "任务描述", | ||
92 | + "taskPictureUrls": []string{ | ||
93 | + "url-1", | ||
94 | + "url-2", | ||
95 | + "url-3", | ||
96 | + }, | ||
97 | + "isRewardTake": false, | ||
98 | + } | ||
99 | + httpExpect.PUT("/tasks/1"). | ||
100 | + WithJSON(body). | ||
101 | + Expect(). | ||
102 | + Status(http.StatusOK). | ||
103 | + JSON(). | ||
104 | + Object(). | ||
105 | + ContainsKey("code").ValueEqual("code", 506). | ||
106 | + ContainsKey("msg").ValueEqual("msg", "业务逻辑错误:进行中的任务不允许编辑") | ||
107 | + }) | ||
108 | + }) | ||
109 | + }) | ||
110 | + AfterEach(func() { | ||
111 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
112 | + Expect(err).NotTo(HaveOccurred()) | ||
113 | + }) | ||
114 | +}) |
-
请 注册 或 登录 后发表评论