正在显示
9 个修改的文件
包含
290 行增加
和
95 行删除
pkg/application/task/command/search_task.go
0 → 100644
1 | +package command | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type SearchTaskCommand 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 | + // 任务状态 | ||
19 | + TaskStatus int `json:"taskStatus,omitempty"` | ||
20 | + // 客户价值 | ||
21 | + CustomerValue string `json:"customerValue,omitempty"` | ||
22 | + // 任务性质 | ||
23 | + TaskNature string `json:"taskNature,omitempty"` | ||
24 | + // 是否悬赏任务 | ||
25 | + IsRewardTake bool `json:"isRewardTake,omitempty"` | ||
26 | + // 竞标时间(1全部,2已截止,3未截止) | ||
27 | + BidTimeMatch int `json:"bidTimeMatch,omitempty"` | ||
28 | + // 任务领取人 | ||
29 | + Receiver int64 `json:"receiver,omitempty"` | ||
30 | + // 任务参与者 | ||
31 | + Participator int64 `json:"participator,omitempty"` | ||
32 | + // 查询偏离量 | ||
33 | + Offset int `json:"offset,omitempty"` | ||
34 | + // 查询限制 | ||
35 | + Limit int `json:"limit,omitempty"` | ||
36 | +} | ||
37 | + | ||
38 | +func (searchTaskCommand *SearchTaskCommand) ValidateCommand() error { | ||
39 | + valid := validation.Validation{} | ||
40 | + b, err := valid.Valid(searchTaskCommand) | ||
41 | + if err != nil { | ||
42 | + return err | ||
43 | + } | ||
44 | + if !b { | ||
45 | + for _, validErr := range valid.Errors { | ||
46 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
47 | + } | ||
48 | + } | ||
49 | + return nil | ||
50 | +} |
@@ -161,6 +161,27 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac | @@ -161,6 +161,27 @@ func (taskService *TaskService) AcceptanceTask(acceptanceTaskCommand *command.Ac | ||
161 | return nil, nil | 161 | return nil, nil |
162 | } | 162 | } |
163 | 163 | ||
164 | +// 搜索任务 | ||
165 | +func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTaskCommand) (interface{}, error) { | ||
166 | + if err := searchTaskCommand.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 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
180 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
181 | + } | ||
182 | + return nil, nil | ||
183 | +} | ||
184 | + | ||
164 | // 创建新任务 | 185 | // 创建新任务 |
165 | func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { | 186 | func (taskService *TaskService) CreateTask(createTaskCommand *command.CreateTaskCommand) (interface{}, error) { |
166 | if err := createTaskCommand.ValidateCommand(); err != nil { | 187 | if err := createTaskCommand.ValidateCommand(); err != nil { |
@@ -36,7 +36,7 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) | @@ -36,7 +36,7 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) | ||
36 | } | 36 | } |
37 | } else { | 37 | } else { |
38 | if _, err := tx.QueryOne( | 38 | if _, err := tx.QueryOne( |
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)), | 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", | 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 { | 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 |
@@ -59,83 +59,33 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -59,83 +59,33 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | ||
59 | query := tx.Model(taskModel).Relation("RobInfo").Relation("BidInfo") | 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 | } | 63 | } |
63 | - if err := query.Limit(1).Select(); err != nil { | 64 | + if err := query.First(); err != nil { |
64 | return nil, err | 65 | return nil, err |
65 | } | 66 | } |
66 | if taskModel.Id == 0 { | 67 | if taskModel.Id == 0 { |
67 | return nil, nil | 68 | return nil, nil |
68 | } else { | 69 | } 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 | 70 | + if taskModel.BidInfo != nil { |
71 | + var bidderInfoModels []*models.BidderInfo | ||
72 | + bidderInfoQuery := tx.Model(&bidderInfoModels) | ||
73 | + if err := bidderInfoQuery.Where("bid_info_id = ?", taskModel.BidInfo.Id).Select(); err != nil { | ||
74 | + return nil, err | ||
107 | } | 75 | } |
108 | - return &domain.Task{ | ||
109 | - TaskId: taskModel.Id, | ||
110 | - CompanyId: taskModel.CompanyId, | ||
111 | - TaskName: taskModel.TaskName, | ||
112 | - TaskType: taskModel.TaskType, | ||
113 | - Sponsor: taskModel.Sponsor, | ||
114 | - TaskStatus: taskModel.TaskStatus, | ||
115 | - ReferenceResource: taskModel.ReferenceResource, | ||
116 | - CustomerValue: taskModel.CustomerValue, | ||
117 | - TaskNature: taskModel.TaskNature, | ||
118 | - SuMoney: taskModel.SuMoney, | ||
119 | - AcceptanceStandard: taskModel.AcceptanceStandard, | ||
120 | - TaskDescription: taskModel.TaskDescription, | ||
121 | - TaskPictureUrls: taskModel.TaskPictureUrls, | ||
122 | - IsRewardTake: taskModel.IsRewardTake, | ||
123 | - CreateTime: taskModel.CreateTime, | ||
124 | - //RobInfo: robInfo, | ||
125 | - //BidInfo: bidInfo, | ||
126 | - Participators: taskModel.Participators, | ||
127 | - TaskPercentage: taskModel.TaskPercentage, | ||
128 | - SolveReport: taskModel.SolveReport, | ||
129 | - SolvePictureUrls: taskModel.SolvePictureUrls, | ||
130 | - CurrentStatus: currentStatus, | ||
131 | - }, nil | 76 | + taskModel.BidInfo.BidderInfos = bidderInfoModels |
77 | + } | ||
78 | + return repository.transformPgModelToDomainModel(taskModel) | ||
132 | } | 79 | } |
133 | } | 80 | } |
134 | func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) { | 81 | func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) { |
135 | tx := repository.transactionContext.PgTx | 82 | tx := repository.transactionContext.PgTx |
136 | var taskModels []*models.Task | 83 | var taskModels []*models.Task |
137 | - var tasks []*domain.Task | 84 | + tasks := make([]*domain.Task, 0) |
138 | query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo") | 85 | query := tx.Model(&taskModels).Relation("RobInfo").Relation("BidInfo") |
86 | + if companyId, ok := queryOptions["companyId"]; ok { | ||
87 | + query = query.Where("task.company_id = ?", companyId) | ||
88 | + } | ||
139 | if offset, ok := queryOptions["offset"]; ok { | 89 | if offset, ok := queryOptions["offset"]; ok { |
140 | offset := offset.(int) | 90 | offset := offset.(int) |
141 | if offset > -1 { | 91 | if offset > -1 { |
@@ -153,13 +103,41 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -153,13 +103,41 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
153 | query = query.Limit(20) | 103 | query = query.Limit(20) |
154 | } | 104 | } |
155 | if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | 105 | if count, err := query.Order("id DESC").SelectAndCount(); err != nil { |
156 | - return 0, nil, err | 106 | + return 0, tasks, err |
157 | } else { | 107 | } else { |
158 | for _, taskModel := range taskModels { | 108 | for _, taskModel := range taskModels { |
159 | - robInfo := &domain.RobInfo{ | 109 | + if taskModel.BidInfo != nil { |
110 | + var bidderInfoModels []*models.BidderInfo | ||
111 | + bidderInfoQuery := tx.Model(&bidderInfoModels) | ||
112 | + if err := bidderInfoQuery.Where("bid_info_id = ?", taskModel.BidInfo.Id).Select(); err != nil { | ||
113 | + return int64(count), tasks, nil | ||
114 | + } | ||
115 | + taskModel.BidInfo.BidderInfos = bidderInfoModels | ||
116 | + } | ||
117 | + if take, err := repository.transformPgModelToDomainModel(taskModel); err == nil { | ||
118 | + tasks = append(tasks, take) | ||
119 | + } else { | ||
120 | + return 0, tasks, err | ||
121 | + } | ||
122 | + } | ||
123 | + return int64(count), tasks, nil | ||
124 | + } | ||
125 | +} | ||
126 | + | ||
127 | +func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *models.Task) (*domain.Task, error) { | ||
128 | + var robInfo *domain.RobInfo | ||
129 | + if taskModel.RobInfo == nil { | ||
130 | + robInfo = nil | ||
131 | + } else { | ||
132 | + robInfo = &domain.RobInfo{ | ||
160 | Receiver: taskModel.RobInfo.Receiver, | 133 | Receiver: taskModel.RobInfo.Receiver, |
161 | ReceiveTime: taskModel.RobInfo.ReceiveTime, | 134 | ReceiveTime: taskModel.RobInfo.ReceiveTime, |
162 | } | 135 | } |
136 | + } | ||
137 | + var bidInfo *domain.BidInfo | ||
138 | + if taskModel.BidInfo == nil { | ||
139 | + bidInfo = nil | ||
140 | + } else { | ||
163 | bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos)) | 141 | bidderInfos := make([]*domain.BidderInfo, len(taskModel.BidInfo.BidderInfos)) |
164 | for _, bidderInfo := range taskModel.BidInfo.BidderInfos { | 142 | for _, bidderInfo := range taskModel.BidInfo.BidderInfos { |
165 | bidderInfos = append(bidderInfos, &domain.BidderInfo{ | 143 | bidderInfos = append(bidderInfos, &domain.BidderInfo{ |
@@ -167,13 +145,14 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -167,13 +145,14 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
167 | BidTime: bidderInfo.BidTime, | 145 | BidTime: bidderInfo.BidTime, |
168 | }) | 146 | }) |
169 | } | 147 | } |
170 | - bidInfo := &domain.BidInfo{ | 148 | + bidInfo = &domain.BidInfo{ |
171 | BidderInfos: bidderInfos, | 149 | BidderInfos: bidderInfos, |
172 | BidStartTime: taskModel.BidInfo.BidStartTime, | 150 | BidStartTime: taskModel.BidInfo.BidStartTime, |
173 | BidEndTime: taskModel.BidInfo.BidEndTime, | 151 | BidEndTime: taskModel.BidInfo.BidEndTime, |
174 | SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder, | 152 | SuccessfulBidder: taskModel.BidInfo.SuccessfulBidder, |
175 | WinBidTime: taskModel.BidInfo.WinBidTime, | 153 | WinBidTime: taskModel.BidInfo.WinBidTime, |
176 | } | 154 | } |
155 | + } | ||
177 | var currentStatus domain.TaskStatus | 156 | var currentStatus domain.TaskStatus |
178 | switch taskModel.TaskStatus { | 157 | switch taskModel.TaskStatus { |
179 | case domain.TASK_STATUS_UNRELEASED: | 158 | case domain.TASK_STATUS_UNRELEASED: |
@@ -195,7 +174,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -195,7 +174,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
195 | currentStatus = &domain.ClosedStatus{} | 174 | currentStatus = &domain.ClosedStatus{} |
196 | break | 175 | break |
197 | } | 176 | } |
198 | - tasks = append(tasks, &domain.Task{ | 177 | + return &domain.Task{ |
199 | TaskId: taskModel.Id, | 178 | TaskId: taskModel.Id, |
200 | CompanyId: taskModel.CompanyId, | 179 | CompanyId: taskModel.CompanyId, |
201 | TaskName: taskModel.TaskName, | 180 | TaskName: taskModel.TaskName, |
@@ -218,11 +197,9 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | @@ -218,11 +197,9 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int | ||
218 | SolveReport: taskModel.SolveReport, | 197 | SolveReport: taskModel.SolveReport, |
219 | SolvePictureUrls: taskModel.SolvePictureUrls, | 198 | SolvePictureUrls: taskModel.SolvePictureUrls, |
220 | CurrentStatus: currentStatus, | 199 | CurrentStatus: currentStatus, |
221 | - }) | ||
222 | - } | ||
223 | - return int64(count), tasks, nil | ||
224 | - } | 200 | + }, nil |
225 | } | 201 | } |
202 | + | ||
226 | func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) (*TaskRepository, error) { | 203 | func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) (*TaskRepository, error) { |
227 | if transactionContext == nil { | 204 | if transactionContext == nil { |
228 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 205 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
@@ -133,6 +133,21 @@ func (controller *TaskController) AcceptanceTask() { | @@ -133,6 +133,21 @@ func (controller *TaskController) AcceptanceTask() { | ||
133 | controller.ServeJSON() | 133 | controller.ServeJSON() |
134 | } | 134 | } |
135 | 135 | ||
136 | +func (controller *TaskController) SearchTask() { | ||
137 | + taskService := service.NewTaskService(nil) | ||
138 | + searchTaskCommand := &command.SearchTaskCommand{} | ||
139 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchTaskCommand) | ||
140 | + data, err := taskService.SearchTask(searchTaskCommand) | ||
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 | + | ||
136 | func (controller *TaskController) CreateTask() { | 151 | func (controller *TaskController) CreateTask() { |
137 | taskService := service.NewTaskService(nil) | 152 | taskService := service.NewTaskService(nil) |
138 | createTaskCommand := &command.CreateTaskCommand{} | 153 | createTaskCommand := &command.CreateTaskCommand{} |
@@ -13,6 +13,7 @@ func init() { | @@ -13,6 +13,7 @@ func init() { | ||
13 | beego.Router("/tasks/:taskId/choose-successful-bidder", &controllers.TaskController{}, "Post:ChooseSuccessfulBidder") | 13 | beego.Router("/tasks/:taskId/choose-successful-bidder", &controllers.TaskController{}, "Post:ChooseSuccessfulBidder") |
14 | beego.Router("/tasks/:taskId/dff", &controllers.TaskController{}, "Post:OffTask") | 14 | beego.Router("/tasks/:taskId/dff", &controllers.TaskController{}, "Post:OffTask") |
15 | beego.Router("/tasks/:taskId/acceptance", &controllers.TaskController{}, "Post:AcceptanceTask") | 15 | beego.Router("/tasks/:taskId/acceptance", &controllers.TaskController{}, "Post:AcceptanceTask") |
16 | + beego.Router("/tasks/search", &controllers.TaskController{}, "Post:SearchTask") | ||
16 | beego.Router("/tasks/", &controllers.TaskController{}, "Post:CreateTask") | 17 | beego.Router("/tasks/", &controllers.TaskController{}, "Post:CreateTask") |
17 | beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Put:UpdateTask") | 18 | beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Put:UpdateTask") |
18 | beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask") | 19 | beego.Router("/tasks/:taskId", &controllers.TaskController{}, "Get:GetTask") |
@@ -93,7 +93,7 @@ var _ = Describe("创建新任务", func() { | @@ -93,7 +93,7 @@ var _ = Describe("创建新任务", func() { | ||
93 | }, | 93 | }, |
94 | "isRewardTake": true, | 94 | "isRewardTake": true, |
95 | "bidStartTime": time.Now(), | 95 | "bidStartTime": time.Now(), |
96 | - "bidEndTime": time.Now().Add( dayAfter), | 96 | + "bidEndTime": time.Now().Add(dayAfter), |
97 | } | 97 | } |
98 | httpExpect.POST("/tasks/"). | 98 | httpExpect.POST("/tasks/"). |
99 | WithJSON(body). | 99 | WithJSON(body). |
1 | package task | 1 | package task |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
4 | "net/http" | 5 | "net/http" |
6 | + "time" | ||
5 | 7 | ||
6 | "github.com/gavv/httpexpect" | 8 | "github.com/gavv/httpexpect" |
7 | "github.com/go-pg/pg" | 9 | "github.com/go-pg/pg" |
@@ -12,11 +14,24 @@ import ( | @@ -12,11 +14,24 @@ import ( | ||
12 | 14 | ||
13 | var _ = Describe("返回任务", func() { | 15 | var _ = Describe("返回任务", func() { |
14 | BeforeEach(func() { | 16 | BeforeEach(func() { |
17 | + dayAfter, _ := time.ParseDuration("72h") | ||
15 | _, err := pG.DB.QueryOne( | 18 | _, err := pG.DB.QueryOne( |
16 | pg.Scan(), | 19 | 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) | 20 | + "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, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", |
21 | + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
22 | + Uid: 2499036607974745088, | ||
23 | + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) | ||
19 | Expect(err).NotTo(HaveOccurred()) | 24 | Expect(err).NotTo(HaveOccurred()) |
25 | + _, err1 := pG.DB.QueryOne( | ||
26 | + pg.Scan(), | ||
27 | + "INSERT INTO bid_infos (id, task_id) VALUES (?, ?)", | ||
28 | + 1, 1) | ||
29 | + Expect(err1).NotTo(HaveOccurred()) | ||
30 | + _, err2 := pG.DB.QueryOne( | ||
31 | + pg.Scan(), | ||
32 | + "INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)", | ||
33 | + 1, 1, 1) | ||
34 | + Expect(err2).NotTo(HaveOccurred()) | ||
20 | }) | 35 | }) |
21 | Describe("根据taskId参数返回任务", func() { | 36 | Describe("根据taskId参数返回任务", func() { |
22 | Context("传入有效的taskId", func() { | 37 | Context("传入有效的taskId", func() { |
@@ -36,5 +51,9 @@ var _ = Describe("返回任务", func() { | @@ -36,5 +51,9 @@ var _ = Describe("返回任务", func() { | ||
36 | AfterEach(func() { | 51 | AfterEach(func() { |
37 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | 52 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") |
38 | Expect(err).NotTo(HaveOccurred()) | 53 | Expect(err).NotTo(HaveOccurred()) |
54 | + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true") | ||
55 | + Expect(err1).NotTo(HaveOccurred()) | ||
56 | + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true") | ||
57 | + Expect(err2).NotTo(HaveOccurred()) | ||
39 | }) | 58 | }) |
40 | }) | 59 | }) |
1 | package task | 1 | package task |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" | ||
4 | "net/http" | 5 | "net/http" |
6 | + "time" | ||
5 | 7 | ||
6 | "github.com/gavv/httpexpect" | 8 | "github.com/gavv/httpexpect" |
7 | "github.com/go-pg/pg" | 9 | "github.com/go-pg/pg" |
@@ -11,32 +13,55 @@ import ( | @@ -11,32 +13,55 @@ import ( | ||
11 | ) | 13 | ) |
12 | 14 | ||
13 | var _ = Describe("返回任务列表", func() { | 15 | var _ = Describe("返回任务列表", func() { |
14 | - var taskId int64 | ||
15 | BeforeEach(func() { | 16 | BeforeEach(func() { |
17 | + dayAfter, _ := time.ParseDuration("72h") | ||
16 | _, err := pG.DB.QueryOne( | 18 | _, 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") | 19 | + pg.Scan(), |
20 | + "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, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
21 | + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
22 | + Uid: 2499036607974745088, | ||
23 | + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) | ||
20 | Expect(err).NotTo(HaveOccurred()) | 24 | Expect(err).NotTo(HaveOccurred()) |
25 | + _, err1 := pG.DB.QueryOne( | ||
26 | + pg.Scan(), | ||
27 | + "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, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
28 | + 2, 101, "抢单任务2", 1, &domain.EmployeeInfo{ | ||
29 | + Uid: 2499036607974745088, | ||
30 | + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) | ||
31 | + Expect(err1).NotTo(HaveOccurred()) | ||
32 | + _, err11 := pG.DB.QueryOne( | ||
33 | + pg.Scan(), | ||
34 | + "INSERT INTO bid_infos (id, task_id) VALUES (?, ?)", | ||
35 | + 1, 2) | ||
36 | + Expect(err11).NotTo(HaveOccurred()) | ||
37 | + _, err22 := pG.DB.QueryOne( | ||
38 | + pg.Scan(), | ||
39 | + "INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)", | ||
40 | + 1, 1, 2) | ||
41 | + Expect(err22).NotTo(HaveOccurred()) | ||
42 | + _, err2 := pG.DB.QueryOne( | ||
43 | + pg.Scan(), | ||
44 | + "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, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
45 | + 3, 102, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
46 | + Uid: 2499036607974745088, | ||
47 | + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) | ||
48 | + Expect(err2).NotTo(HaveOccurred()) | ||
49 | + _, err3 := pG.DB.QueryOne( | ||
50 | + pg.Scan(), | ||
51 | + "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, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||
52 | + 4, 101, "抢单任务1", 1, &domain.EmployeeInfo{ | ||
53 | + Uid: 2499036607974745088, | ||
54 | + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) | ||
55 | + Expect(err3).NotTo(HaveOccurred()) | ||
21 | }) | 56 | }) |
22 | Describe("根据参数返回任务列表", func() { | 57 | Describe("根据参数返回任务列表", func() { |
23 | Context("传入有效的参数", func() { | 58 | Context("传入有效的参数", func() { |
24 | - It("返回任务数据列表", func() { | 59 | + It("返回指定companyId公司的任务数据列表", func() { |
25 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 60 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
26 | httpExpect.GET("/tasks/"). | 61 | 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"). | 62 | + WithQuery("companyId", 101). |
63 | + WithQuery("offset", 0). | ||
64 | + WithQuery("limit", 20). | ||
40 | Expect(). | 65 | Expect(). |
41 | Status(http.StatusOK). | 66 | Status(http.StatusOK). |
42 | JSON(). | 67 | JSON(). |
@@ -44,7 +69,33 @@ var _ = Describe("返回任务列表", func() { | @@ -44,7 +69,33 @@ var _ = Describe("返回任务列表", func() { | ||
44 | ContainsKey("code").ValueEqual("code", 0). | 69 | ContainsKey("code").ValueEqual("code", 0). |
45 | ContainsKey("msg").ValueEqual("msg", "ok"). | 70 | ContainsKey("msg").ValueEqual("msg", "ok"). |
46 | ContainsKey("data").Value("data").Object(). | 71 | ContainsKey("data").Value("data").Object(). |
47 | - ContainsKey("count").ValueEqual("count", 1). | 72 | + ContainsKey("count").ValueEqual("count", 3). |
73 | + ContainsKey("tasks").Value("tasks").Array() | ||
74 | + }) | ||
75 | + It("返回指定companyId公司的任务数据列表", func() { | ||
76 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
77 | + httpExpect.GET("/tasks/"). | ||
78 | + WithQuery("companyId", 101). | ||
79 | + //WithQuery("sponsor", "int64"). | ||
80 | + //WithQuery("taskContentMatch", "string"). | ||
81 | + //WithQuery("taskType", "int"). | ||
82 | + //WithQuery("taskStatus", "int"). | ||
83 | + //WithQuery("customerValue", "string"). | ||
84 | + //WithQuery("taskNature", "string"). | ||
85 | + //WithQuery("isRewardTake", "boolean"). | ||
86 | + //WithQuery("bidTimeMatch", "int"). | ||
87 | + //WithQuery("receiver", "int64"). | ||
88 | + //WithQuery("participator", "int64"). | ||
89 | + WithQuery("offset", 0). | ||
90 | + WithQuery("limit", 20). | ||
91 | + Expect(). | ||
92 | + Status(http.StatusOK). | ||
93 | + JSON(). | ||
94 | + Object(). | ||
95 | + ContainsKey("code").ValueEqual("code", 0). | ||
96 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
97 | + ContainsKey("data").Value("data").Object(). | ||
98 | + ContainsKey("count").ValueEqual("count", 3). | ||
48 | ContainsKey("tasks").Value("tasks").Array() | 99 | ContainsKey("tasks").Value("tasks").Array() |
49 | }) | 100 | }) |
50 | }) | 101 | }) |
@@ -52,5 +103,9 @@ var _ = Describe("返回任务列表", func() { | @@ -52,5 +103,9 @@ var _ = Describe("返回任务列表", func() { | ||
52 | AfterEach(func() { | 103 | AfterEach(func() { |
53 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | 104 | _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") |
54 | Expect(err).NotTo(HaveOccurred()) | 105 | Expect(err).NotTo(HaveOccurred()) |
106 | + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true") | ||
107 | + Expect(err1).NotTo(HaveOccurred()) | ||
108 | + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true") | ||
109 | + Expect(err2).NotTo(HaveOccurred()) | ||
55 | }) | 110 | }) |
56 | }) | 111 | }) |
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 | + "companyId": "int64", | ||
28 | + "sponsor": "int64", | ||
29 | + "taskContentMatch": "string", | ||
30 | + "taskType": "int", | ||
31 | + "taskStatus": "int", | ||
32 | + "customerValue": "string", | ||
33 | + "taskNature": "string", | ||
34 | + "isRewardTake": "boolean", | ||
35 | + "bidTimeMatch": "int", | ||
36 | + "receiver": "int64", | ||
37 | + "participator": "int64", | ||
38 | + "offset": "int", | ||
39 | + "limit": "int", | ||
40 | + } | ||
41 | + httpExpect.POST("/tasks/search"). | ||
42 | + WithJSON(body). | ||
43 | + Expect(). | ||
44 | + Status(http.StatusOK). | ||
45 | + JSON(). | ||
46 | + Object(). | ||
47 | + ContainsKey("code").ValueEqual("code", 0). | ||
48 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
49 | + ContainsKey("data").Value("data").Object() | ||
50 | + }) | ||
51 | + }) | ||
52 | + }) | ||
53 | + AfterEach(func() { | ||
54 | + _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") | ||
55 | + Expect(err).NotTo(HaveOccurred()) | ||
56 | + }) | ||
57 | +}) |
-
请 注册 或 登录 后发表评论