作者 linmadan

完成任务搜索功能

@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query"
10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
11 ) 12 )
12 13
13 // 任务服务 14 // 任务服务
@@ -113,6 +114,14 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT @@ -113,6 +114,14 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
113 defer func() { 114 defer func() {
114 transactionContext.RollbackTransaction() 115 transactionContext.RollbackTransaction()
115 }() 116 }()
  117 + var releaseTaskService service.ReleaseTaskService
  118 + if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
  119 + "transactionContext": transactionContext,
  120 + }); err != nil {
  121 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  122 + } else {
  123 + releaseTaskService = value
  124 + }
116 if err := transactionContext.CommitTransaction(); err != nil { 125 if err := transactionContext.CommitTransaction(); err != nil {
117 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 126 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
118 } 127 }
@@ -176,10 +185,25 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -176,10 +185,25 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
176 defer func() { 185 defer func() {
177 transactionContext.RollbackTransaction() 186 transactionContext.RollbackTransaction()
178 }() 187 }()
  188 + var taskRepository domain.TaskRepository
  189 + if value, err := factory.CreateTaskRepository(map[string]interface{}{
  190 + "transactionContext": transactionContext,
  191 + }); err != nil {
  192 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  193 + } else {
  194 + taskRepository = value
  195 + }
  196 + if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil {
  197 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  198 + } else {
179 if err := transactionContext.CommitTransaction(); err != nil { 199 if err := transactionContext.CommitTransaction(); err != nil {
180 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 200 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
181 } 201 }
182 - return nil, nil 202 + return map[string]interface{}{
  203 + "count": count,
  204 + "tasks": tasks,
  205 + }, nil
  206 + }
183 } 207 }
184 208
185 // 创建新任务 209 // 创建新任务
@@ -17,12 +17,19 @@ func (dao *TaskDao) addRobInfo(taskId int64, receiver *domain.EmployeeInfo) erro @@ -17,12 +17,19 @@ func (dao *TaskDao) addRobInfo(taskId int64, receiver *domain.EmployeeInfo) erro
17 tx := dao.transactionContext.PgTx 17 tx := dao.transactionContext.PgTx
18 _, err := tx.QueryOne( 18 _, err := tx.QueryOne(
19 pg.Scan(), 19 pg.Scan(),
20 - "INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?) RETURNING id", 20 + "INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?)",
21 taskId, receiver, time.Now()) 21 taskId, receiver, time.Now())
22 return err 22 return err
23 } 23 }
24 24
25 - 25 +func (dao *TaskDao) addBidInfo(taskId int64, bidStartTime time.Time, bidEndTime time.Time) error {
  26 + tx := dao.transactionContext.PgTx
  27 + _, err := tx.QueryOne(
  28 + pg.Scan(),
  29 + "INSERT INTO rob_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
  30 + taskId, bidStartTime, bidEndTime)
  31 + return err
  32 +}
26 33
27 func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) { 34 func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
28 if transactionContext == nil { 35 if transactionContext == nil {
@@ -49,6 +49,7 @@ type Task struct { @@ -49,6 +49,7 @@ type Task struct {
49 BidInfo *BidInfo 49 BidInfo *BidInfo
50 // 创建时间 50 // 创建时间
51 CreateTime time.Time 51 CreateTime time.Time
  52 + ReceiverUid int64
52 ReleaseTime time.Time 53 ReleaseTime time.Time
53 RemoveTime time.Time `pg:",soft_delete"` 54 RemoveTime time.Time `pg:",soft_delete"`
54 } 55 }
@@ -3,10 +3,12 @@ package repository @@ -3,10 +3,12 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
  6 + "github.com/go-pg/pg/orm"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "github.com/linmadan/egglib-go/utils/snowflake" 8 "github.com/linmadan/egglib-go/utils/snowflake"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" 10 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  11 + "time"
10 ) 12 )
11 13
12 type TaskRepository struct { 14 type TaskRepository struct {
@@ -35,10 +37,17 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) @@ -35,10 +37,17 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error)
35 return task, err 37 return task, err
36 } 38 }
37 } else { 39 } else {
  40 + var taskReceiverUid int64
  41 + if task.RobInfo != nil {
  42 + taskReceiverUid = task.RobInfo.Receiver.Uid
  43 + }
  44 + if task.BidInfo != nil && task.BidInfo.SuccessfulBidder != nil {
  45 + taskReceiverUid = task.BidInfo.SuccessfulBidder.Uid
  46 + }
38 if _, err := tx.QueryOne( 47 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)), 48 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 { 49 + "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=?, receiver_uid=?, 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",
  50 + 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, taskReceiverUid, task.CreateTime, task.ReleaseTime, task.Participators, task.TaskPercentage, task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil {
42 return task, err 51 return task, err
43 } 52 }
44 } 53 }
@@ -86,6 +95,50 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -86,6 +95,50 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
86 if companyId, ok := queryOptions["companyId"]; ok { 95 if companyId, ok := queryOptions["companyId"]; ok {
87 query = query.Where("task.company_id = ?", companyId) 96 query = query.Where("task.company_id = ?", companyId)
88 } 97 }
  98 + if sponsor, ok := queryOptions["sponsor"]; ok && (sponsor != int64(0)) {
  99 + query = query.Where(`task.sponsor @> '{"uid":?}'`, sponsor)
  100 + }
  101 + if taskStatus, ok := queryOptions["taskStatus"]; ok && (taskStatus != 0) {
  102 + query = query.Where(`task.task_status = ?`, taskStatus)
  103 + }
  104 + if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) {
  105 + query = query.Where(`task.task_type = ?`, taskType)
  106 + }
  107 + if taskNature, ok := queryOptions["taskNature"]; ok && (taskNature != "") {
  108 + query = query.Where(`task.task_nature = ?`, taskNature)
  109 + }
  110 + if customerValue, ok := queryOptions["customerValue"]; ok && (customerValue != "") {
  111 + query = query.Where("task.customer_value @> ?", pg.Array([]string{customerValue.(string)}))
  112 + }
  113 + if taskContentMatch, ok := queryOptions["taskContentMatch"]; ok && (taskContentMatch != "") {
  114 + query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  115 + q = q.WhereOr("task.task_name LIKE ?", fmt.Sprintf("%%%s%%", taskContentMatch.(string))).
  116 + WhereOr("task.task_nature = ?", taskContentMatch.(string)).
  117 + WhereOr("task.customer_value @> ?", pg.Array([]string{taskContentMatch.(string)}))
  118 + return q, nil
  119 + })
  120 + }
  121 + if isRewardTake, ok := queryOptions["isRewardTake"]; ok && (isRewardTake != false) {
  122 + query = query.Where(`task.is_reward_take = ?`, isRewardTake)
  123 + }
  124 + if bidTimeMatch, ok := queryOptions["bidTimeMatch"]; ok && (bidTimeMatch != 0) {
  125 + query = query.Join("JOIN bid_infos ON bid_info.task_id = task.id")
  126 + if bidTimeMatch == 1 {
  127 + query = query.Where("bid_info.bid_end_time < ?", time.Now())
  128 + }
  129 + if bidTimeMatch == 2 {
  130 + query = query.Where("bid_info.bid_end_time > ?", time.Now())
  131 + }
  132 + }
  133 + if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) {
  134 + query = query.Where(`task.receiver_uid = ?`, receiver)
  135 + }
  136 + if participator, ok := queryOptions["participator"]; ok && (participator != int64(0)) {
  137 + query = query.Where(`task.participators @> '[{"uid":?}]'`, participator)
  138 + }
  139 + if taskIds, ok := queryOptions["taskIds"]; ok {
  140 + query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64)))
  141 + }
89 if offset, ok := queryOptions["offset"]; ok { 142 if offset, ok := queryOptions["offset"]; ok {
90 offset := offset.(int) 143 offset := offset.(int)
91 if offset > -1 { 144 if offset > -1 {
@@ -139,6 +139,7 @@ func (controller *TaskController) SearchTask() { @@ -139,6 +139,7 @@ func (controller *TaskController) SearchTask() {
139 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchTaskCommand) 139 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchTaskCommand)
140 data, err := taskService.SearchTask(searchTaskCommand) 140 data, err := taskService.SearchTask(searchTaskCommand)
141 var response utils.JsonResponse 141 var response utils.JsonResponse
  142 +
142 if err != nil { 143 if err != nil {
143 response = utils.ResponseError(controller.Ctx, err) 144 response = utils.ResponseError(controller.Ctx, err)
144 } else { 145 } else {
@@ -17,42 +17,49 @@ var _ = Describe("返回任务列表", func() { @@ -17,42 +17,49 @@ var _ = Describe("返回任务列表", func() {
17 dayAfter, _ := time.ParseDuration("72h") 17 dayAfter, _ := time.ParseDuration("72h")
18 _, err := pG.DB.QueryOne( 18 _, err := pG.DB.QueryOne(
19 pg.Scan(), 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 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, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
21 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{ 21 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
22 Uid: 2499036607974745088, 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)) 23 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  24 + {
  25 + Uid: 2499036607974745077,
  26 + },
  27 + {
  28 + Uid: 2499036607974745066,
  29 + },
  30 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
24 Expect(err).NotTo(HaveOccurred()) 31 Expect(err).NotTo(HaveOccurred())
25 _, err1 := pG.DB.QueryOne( 32 _, err1 := pG.DB.QueryOne(
26 pg.Scan(), 33 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 34 "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{ 35 2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
29 Uid: 2499036607974745088, 36 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()) 37 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
42 _, err2 := pG.DB.QueryOne( 38 _, err2 := pG.DB.QueryOne(
43 pg.Scan(), 39 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 40 "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{ 41 + 3, 102, "竞标任务1", 2, &domain.EmployeeInfo{
46 Uid: 2499036607974745088, 42 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)) 43 }, 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()) 44 Expect(err2).NotTo(HaveOccurred())
49 _, err3 := pG.DB.QueryOne( 45 _, err3 := pG.DB.QueryOne(
50 pg.Scan(), 46 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 47 "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)) 48 + 4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
  49 + Uid: 2499036607974745099,
  50 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
55 Expect(err3).NotTo(HaveOccurred()) 51 Expect(err3).NotTo(HaveOccurred())
  52 + Expect(err1).NotTo(HaveOccurred())
  53 + _, err11 := pG.DB.QueryOne(
  54 + pg.Scan(),
  55 + "INSERT INTO bid_infos (id, task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?, ?)",
  56 + 1, 4, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Date(2020, time.Month(4), 10, 8, 0, 0, 0, time.Now().Location()))
  57 + Expect(err11).NotTo(HaveOccurred())
  58 + _, err22 := pG.DB.QueryOne(
  59 + pg.Scan(),
  60 + "INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)",
  61 + 1, 1, 4)
  62 + Expect(err22).NotTo(HaveOccurred())
56 }) 63 })
57 Describe("根据参数返回任务列表", func() { 64 Describe("根据参数返回任务列表", func() {
58 Context("传入有效的参数", func() { 65 Context("传入有效的参数", func() {
@@ -72,20 +79,11 @@ var _ = Describe("返回任务列表", func() { @@ -72,20 +79,11 @@ var _ = Describe("返回任务列表", func() {
72 ContainsKey("count").ValueEqual("count", 3). 79 ContainsKey("count").ValueEqual("count", 3).
73 ContainsKey("tasks").Value("tasks").Array() 80 ContainsKey("tasks").Value("tasks").Array()
74 }) 81 })
75 - It("返回指定companyId公司的任务数据列表", func() { 82 + It("返回指定sponsor的任务数据列表", func() {
76 httpExpect := httpexpect.New(GinkgoT(), server.URL) 83 httpExpect := httpexpect.New(GinkgoT(), server.URL)
77 httpExpect.GET("/tasks/"). 84 httpExpect.GET("/tasks/").
78 WithQuery("companyId", 101). 85 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"). 86 + WithQuery("sponsor", 2499036607974745088).
89 WithQuery("offset", 0). 87 WithQuery("offset", 0).
90 WithQuery("limit", 20). 88 WithQuery("limit", 20).
91 Expect(). 89 Expect().
@@ -95,7 +93,116 @@ var _ = Describe("返回任务列表", func() { @@ -95,7 +93,116 @@ var _ = Describe("返回任务列表", func() {
95 ContainsKey("code").ValueEqual("code", 0). 93 ContainsKey("code").ValueEqual("code", 0).
96 ContainsKey("msg").ValueEqual("msg", "ok"). 94 ContainsKey("msg").ValueEqual("msg", "ok").
97 ContainsKey("data").Value("data").Object(). 95 ContainsKey("data").Value("data").Object().
98 - ContainsKey("count").ValueEqual("count", 3). 96 + ContainsKey("count").ValueEqual("count", 2).
  97 + ContainsKey("tasks").Value("tasks").Array()
  98 + })
  99 + It("返回指定taskType与taskContentMatch的任务数据列表", func() {
  100 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  101 + httpExpect.GET("/tasks/").
  102 + WithQuery("companyId", 101).
  103 + WithQuery("sponsor", 2499036607974745088).
  104 + WithQuery("taskContentMatch", "抢单").
  105 + WithQuery("taskType", 1).
  106 + WithQuery("offset", 0).
  107 + WithQuery("limit", 20).
  108 + Expect().
  109 + Status(http.StatusOK).
  110 + JSON().
  111 + Object().
  112 + ContainsKey("code").ValueEqual("code", 0).
  113 + ContainsKey("msg").ValueEqual("msg", "ok").
  114 + ContainsKey("data").Value("data").Object().
  115 + ContainsKey("count").ValueEqual("count", 2).
  116 + ContainsKey("tasks").Value("tasks").Array()
  117 + })
  118 + It("返回指定taskType与taskContentMatch的任务数据列表", func() {
  119 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  120 + httpExpect.GET("/tasks/").
  121 + WithQuery("companyId", 101).
  122 + WithQuery("sponsor", 2499036607974745088).
  123 + WithQuery("taskContentMatch", "售后服务").
  124 + WithQuery("taskType", 1).
  125 + WithQuery("offset", 0).
  126 + WithQuery("limit", 20).
  127 + Expect().
  128 + Status(http.StatusOK).
  129 + JSON().
  130 + Object().
  131 + ContainsKey("code").ValueEqual("code", 0).
  132 + ContainsKey("msg").ValueEqual("msg", "ok").
  133 + ContainsKey("data").Value("data").Object().
  134 + ContainsKey("count").ValueEqual("count", 1).
  135 + ContainsKey("tasks").Value("tasks").Array()
  136 + })
  137 + It("返回公司悬赏的任务数据列表", func() {
  138 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  139 + httpExpect.GET("/tasks/").
  140 + WithQuery("companyId", 101).
  141 + WithQuery("sponsor", 2499036607974745088).
  142 + WithQuery("isRewardTake", true).
  143 + WithQuery("offset", 0).
  144 + WithQuery("limit", 20).
  145 + Expect().
  146 + Status(http.StatusOK).
  147 + JSON().
  148 + Object().
  149 + ContainsKey("code").ValueEqual("code", 0).
  150 + ContainsKey("msg").ValueEqual("msg", "ok").
  151 + ContainsKey("data").Value("data").Object().
  152 + ContainsKey("count").ValueEqual("count", 1).
  153 + ContainsKey("tasks").Value("tasks").Array()
  154 + })
  155 + It("返回指定竞标时间的任务数据列表", func() {
  156 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  157 + httpExpect.GET("/tasks/").
  158 + WithQuery("companyId", 101).
  159 + WithQuery("sponsor", 2499036607974745099).
  160 + WithQuery("taskType", 2).
  161 + WithQuery("bidTimeMatch", 1).
  162 + WithQuery("offset", 0).
  163 + WithQuery("limit", 20).
  164 + Expect().
  165 + Status(http.StatusOK).
  166 + JSON().
  167 + Object().
  168 + ContainsKey("code").ValueEqual("code", 0).
  169 + ContainsKey("msg").ValueEqual("msg", "ok").
  170 + ContainsKey("data").Value("data").Object().
  171 + ContainsKey("count").ValueEqual("count", 1).
  172 + ContainsKey("tasks").Value("tasks").Array()
  173 + })
  174 + It("返回指定领取人的任务数据列表", func() {
  175 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  176 + httpExpect.GET("/tasks/").
  177 + WithQuery("companyId", 101).
  178 + WithQuery("receiver", 2499036607974745099).
  179 + WithQuery("offset", 0).
  180 + WithQuery("limit", 20).
  181 + Expect().
  182 + Status(http.StatusOK).
  183 + JSON().
  184 + Object().
  185 + ContainsKey("code").ValueEqual("code", 0).
  186 + ContainsKey("msg").ValueEqual("msg", "ok").
  187 + ContainsKey("data").Value("data").Object().
  188 + ContainsKey("count").ValueEqual("count", 1).
  189 + ContainsKey("tasks").Value("tasks").Array()
  190 + })
  191 + It("返回指定参与者的任务数据列表", func() {
  192 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  193 + httpExpect.GET("/tasks/").
  194 + WithQuery("companyId", 101).
  195 + WithQuery("participator", 2499036607974745066).
  196 + WithQuery("offset", 0).
  197 + WithQuery("limit", 20).
  198 + Expect().
  199 + Status(http.StatusOK).
  200 + JSON().
  201 + Object().
  202 + ContainsKey("code").ValueEqual("code", 0).
  203 + ContainsKey("msg").ValueEqual("msg", "ok").
  204 + ContainsKey("data").Value("data").Object().
  205 + ContainsKey("count").ValueEqual("count", 1).
99 ContainsKey("tasks").Value("tasks").Array() 206 ContainsKey("tasks").Value("tasks").Array()
100 }) 207 })
101 }) 208 })
1 package task 1 package task
2 2
3 import ( 3 import (
4 - "net/http"  
5 -  
6 "github.com/gavv/httpexpect" 4 "github.com/gavv/httpexpect"
7 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
8 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/ginkgo"
9 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
10 pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg" 9 pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  10 + "net/http"
  11 + "time"
11 ) 12 )
12 13
13 var _ = Describe("发布任务", func() { 14 var _ = Describe("发布任务", func() {
14 - var taskId int64 15 + Describe("发布任务", func() {
  16 + Context("任务发起者发布待发布的任务", func() {
15 BeforeEach(func() { 17 BeforeEach(func() {
  18 + dayAfter, _ := time.ParseDuration("72h")
16 _, err := pG.DB.QueryOne( 19 _, 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 + pg.Scan(),
  21 + "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, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  22 + 1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
  23 + Uid: 2499036607974745088,
  24 + }, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
  25 + {
  26 + Uid: 2499036607974745077,
  27 + },
  28 + {
  29 + Uid: 2499036607974745066,
  30 + },
  31 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
20 Expect(err).NotTo(HaveOccurred()) 32 Expect(err).NotTo(HaveOccurred())
21 }) 33 })
22 - Describe("发布任务", func() {  
23 - Context("", func() {  
24 - It("", func() { 34 + FIt("发布任务成功", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 35 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 body := map[string]interface{}{ 36 body := map[string]interface{}{
27 - "operator": "int64", 37 + "operator": 2499036607974745088,
28 } 38 }
29 - httpExpect.POST("/tasks/{taskId}/release"). 39 + httpExpect.POST("/tasks/1/release").
30 WithJSON(body). 40 WithJSON(body).
31 Expect(). 41 Expect().
32 Status(http.StatusOK). 42 Status(http.StatusOK).
@@ -41,5 +51,9 @@ var _ = Describe("发布任务", func() { @@ -41,5 +51,9 @@ var _ = Describe("发布任务", func() {
41 AfterEach(func() { 51 AfterEach(func() {
42 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") 52 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
43 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())
44 }) 58 })
45 }) 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,12 +13,21 @@ import ( @@ -11,12 +13,21 @@ 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, receiver_uid, 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, []*domain.EmployeeInfo{
  24 + {
  25 + Uid: 2499036607974745077,
  26 + },
  27 + {
  28 + Uid: 2499036607974745066,
  29 + },
  30 + }, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
20 Expect(err).NotTo(HaveOccurred()) 31 Expect(err).NotTo(HaveOccurred())
21 }) 32 })
22 Describe("搜索任务", func() { 33 Describe("搜索任务", func() {
@@ -24,19 +35,10 @@ var _ = Describe("搜索任务", func() { @@ -24,19 +35,10 @@ var _ = Describe("搜索任务", func() {
24 It("", func() { 35 It("", func() {
25 httpExpect := httpexpect.New(GinkgoT(), server.URL) 36 httpExpect := httpexpect.New(GinkgoT(), server.URL)
26 body := map[string]interface{}{ 37 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", 38 + "companyId": 101,
  39 + "sponsor": 2499036607974745088,
  40 + "offset": 0,
  41 + "limit": 20,
40 } 42 }
41 httpExpect.POST("/tasks/search"). 43 httpExpect.POST("/tasks/search").
42 WithJSON(body). 44 WithJSON(body).
@@ -53,5 +55,9 @@ var _ = Describe("搜索任务", func() { @@ -53,5 +55,9 @@ var _ = Describe("搜索任务", func() {
53 AfterEach(func() { 55 AfterEach(func() {
54 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") 56 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
55 Expect(err).NotTo(HaveOccurred()) 57 Expect(err).NotTo(HaveOccurred())
  58 + _, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
  59 + Expect(err1).NotTo(HaveOccurred())
  60 + _, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
  61 + Expect(err2).NotTo(HaveOccurred())
56 }) 62 })
57 }) 63 })