作者 linmadan

完成任务搜索功能

... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/task/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
)
// 任务服务
... ... @@ -113,6 +114,14 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
defer func() {
transactionContext.RollbackTransaction()
}()
var releaseTaskService service.ReleaseTaskService
if value, err := factory.CreateReleaseTaskService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
releaseTaskService = value
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -176,10 +185,25 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
defer func() {
transactionContext.RollbackTransaction()
}()
var taskRepository domain.TaskRepository
if value, err := factory.CreateTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
taskRepository = value
}
if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return map[string]interface{}{
"count": count,
"tasks": tasks,
}, nil
}
}
// 创建新任务
... ...
... ... @@ -17,12 +17,19 @@ func (dao *TaskDao) addRobInfo(taskId int64, receiver *domain.EmployeeInfo) erro
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?) RETURNING id",
"INSERT INTO rob_infos (task_id, receiver, receive_time) VALUES (?, ?, ?)",
taskId, receiver, time.Now())
return err
}
func (dao *TaskDao) addBidInfo(taskId int64, bidStartTime time.Time, bidEndTime time.Time) error {
tx := dao.transactionContext.PgTx
_, err := tx.QueryOne(
pg.Scan(),
"INSERT INTO rob_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
taskId, bidStartTime, bidEndTime)
return err
}
func NewTaskDao(transactionContext *pgTransaction.TransactionContext) (*TaskDao, error) {
if transactionContext == nil {
... ...
... ... @@ -49,6 +49,7 @@ type Task struct {
BidInfo *BidInfo
// 创建时间
CreateTime time.Time
ReceiverUid int64
ReleaseTime time.Time
RemoveTime time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -3,10 +3,12 @@ package repository
import (
"fmt"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
"time"
)
type TaskRepository struct {
... ... @@ -35,10 +37,17 @@ func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error)
return task, err
}
} else {
var taskReceiverUid int64
if task.RobInfo != nil {
taskReceiverUid = task.RobInfo.Receiver.Uid
}
if task.BidInfo != nil && task.BidInfo.SuccessfulBidder != nil {
taskReceiverUid = task.BidInfo.SuccessfulBidder.Uid
}
if _, err := tx.QueryOne(
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)),
"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",
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 {
"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",
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 {
return task, err
}
}
... ... @@ -86,6 +95,50 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
if companyId, ok := queryOptions["companyId"]; ok {
query = query.Where("task.company_id = ?", companyId)
}
if sponsor, ok := queryOptions["sponsor"]; ok && (sponsor != int64(0)) {
query = query.Where(`task.sponsor @> '{"uid":?}'`, sponsor)
}
if taskStatus, ok := queryOptions["taskStatus"]; ok && (taskStatus != 0) {
query = query.Where(`task.task_status = ?`, taskStatus)
}
if taskType, ok := queryOptions["taskType"]; ok && (taskType != 0) {
query = query.Where(`task.task_type = ?`, taskType)
}
if taskNature, ok := queryOptions["taskNature"]; ok && (taskNature != "") {
query = query.Where(`task.task_nature = ?`, taskNature)
}
if customerValue, ok := queryOptions["customerValue"]; ok && (customerValue != "") {
query = query.Where("task.customer_value @> ?", pg.Array([]string{customerValue.(string)}))
}
if taskContentMatch, ok := queryOptions["taskContentMatch"]; ok && (taskContentMatch != "") {
query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q = q.WhereOr("task.task_name LIKE ?", fmt.Sprintf("%%%s%%", taskContentMatch.(string))).
WhereOr("task.task_nature = ?", taskContentMatch.(string)).
WhereOr("task.customer_value @> ?", pg.Array([]string{taskContentMatch.(string)}))
return q, nil
})
}
if isRewardTake, ok := queryOptions["isRewardTake"]; ok && (isRewardTake != false) {
query = query.Where(`task.is_reward_take = ?`, isRewardTake)
}
if bidTimeMatch, ok := queryOptions["bidTimeMatch"]; ok && (bidTimeMatch != 0) {
query = query.Join("JOIN bid_infos ON bid_info.task_id = task.id")
if bidTimeMatch == 1 {
query = query.Where("bid_info.bid_end_time < ?", time.Now())
}
if bidTimeMatch == 2 {
query = query.Where("bid_info.bid_end_time > ?", time.Now())
}
}
if receiver, ok := queryOptions["receiver"]; ok && (receiver != int64(0)) {
query = query.Where(`task.receiver_uid = ?`, receiver)
}
if participator, ok := queryOptions["participator"]; ok && (participator != int64(0)) {
query = query.Where(`task.participators @> '[{"uid":?}]'`, participator)
}
if taskIds, ok := queryOptions["taskIds"]; ok {
query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64)))
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ...
... ... @@ -139,6 +139,7 @@ func (controller *TaskController) SearchTask() {
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), searchTaskCommand)
data, err := taskService.SearchTask(searchTaskCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
... ...
... ... @@ -17,42 +17,49 @@ var _ = Describe("返回任务列表", func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
2, 101, "抢单任务2", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err1).NotTo(HaveOccurred())
_, err11 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bid_infos (id, task_id) VALUES (?, ?)",
1, 2)
Expect(err11).NotTo(HaveOccurred())
_, err22 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)",
1, 1, 2)
Expect(err22).NotTo(HaveOccurred())
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
_, err2 := pG.DB.QueryOne(
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
3, 102, "抢单任务1", 1, &domain.EmployeeInfo{
3, 102, "竞标任务1", 2, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.QueryOne(
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
4, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
Uid: 2499036607974745099,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err3).NotTo(HaveOccurred())
Expect(err1).NotTo(HaveOccurred())
_, err11 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bid_infos (id, task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?, ?)",
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()))
Expect(err11).NotTo(HaveOccurred())
_, err22 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bidder_infos (id, bid_info_id, task_id) VALUES (?, ?, ?)",
1, 1, 4)
Expect(err22).NotTo(HaveOccurred())
})
Describe("根据参数返回任务列表", func() {
Context("传入有效的参数", func() {
... ... @@ -72,20 +79,11 @@ var _ = Describe("返回任务列表", func() {
ContainsKey("count").ValueEqual("count", 3).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定companyId公司的任务数据列表", func() {
It("返回指定sponsor的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
//WithQuery("sponsor", "int64").
//WithQuery("taskContentMatch", "string").
//WithQuery("taskType", "int").
//WithQuery("taskStatus", "int").
//WithQuery("customerValue", "string").
//WithQuery("taskNature", "string").
//WithQuery("isRewardTake", "boolean").
//WithQuery("bidTimeMatch", "int").
//WithQuery("receiver", "int64").
//WithQuery("participator", "int64").
WithQuery("sponsor", 2499036607974745088).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
... ... @@ -95,7 +93,116 @@ var _ = Describe("返回任务列表", func() {
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 3).
ContainsKey("count").ValueEqual("count", 2).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定taskType与taskContentMatch的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("sponsor", 2499036607974745088).
WithQuery("taskContentMatch", "抢单").
WithQuery("taskType", 1).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 2).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定taskType与taskContentMatch的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("sponsor", 2499036607974745088).
WithQuery("taskContentMatch", "售后服务").
WithQuery("taskType", 1).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回公司悬赏的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("sponsor", 2499036607974745088).
WithQuery("isRewardTake", true).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定竞标时间的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("sponsor", 2499036607974745099).
WithQuery("taskType", 2).
WithQuery("bidTimeMatch", 1).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定领取人的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("receiver", 2499036607974745099).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
It("返回指定参与者的任务数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/tasks/").
WithQuery("companyId", 101).
WithQuery("participator", 2499036607974745066).
WithQuery("offset", 0).
WithQuery("limit", 20).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("tasks").Value("tasks").Array()
})
})
... ...
package task
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
"net/http"
"time"
)
var _ = Describe("发布任务", func() {
var taskId int64
Describe("发布任务", func() {
Context("任务发起者发布待发布的任务", func() {
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(&taskId),
"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",
"testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime")
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
})
Describe("发布任务", func() {
Context("", func() {
It("", func() {
FIt("发布任务成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": "int64",
"operator": 2499036607974745088,
}
httpExpect.POST("/tasks/{taskId}/release").
httpExpect.POST("/tasks/1/release").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -41,5 +51,9 @@ var _ = Describe("发布任务", func() {
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
Expect(err2).NotTo(HaveOccurred())
})
})
... ...
package task
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"net/http"
"time"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg"
... ... @@ -11,12 +13,21 @@ import (
)
var _ = Describe("搜索任务", func() {
var taskId int64
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(&taskId),
"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",
"testTaskId", "testCompanyId", "testTaskName", "testTaskType", "testSponsor", "testTaskStatus", "testReferenceResource", "testCustomerValue", "testTaskNature", "testSuMoney", "testAcceptanceStandard", "testTaskDescription", "testTaskPictureUrls", "testIsRewardTake", "testRobInfo", "testBidInfo", "testParticipators", "testTaskPercentage", "testSolveReport", "testSolvePictureUrls", "testCreateTime", "testReleaseTime")
pg.Scan(),
"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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "抢单任务1", 1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
})
Describe("搜索任务", func() {
... ... @@ -24,19 +35,10 @@ var _ = Describe("搜索任务", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": "int64",
"sponsor": "int64",
"taskContentMatch": "string",
"taskType": "int",
"taskStatus": "int",
"customerValue": "string",
"taskNature": "string",
"isRewardTake": "boolean",
"bidTimeMatch": "int",
"receiver": "int64",
"participator": "int64",
"offset": "int",
"limit": "int",
"companyId": 101,
"sponsor": 2499036607974745088,
"offset": 0,
"limit": 20,
}
httpExpect.POST("/tasks/search").
WithJSON(body).
... ... @@ -53,5 +55,9 @@ var _ = Describe("搜索任务", func() {
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.Exec("DELETE FROM bid_infos WHERE true")
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
Expect(err2).NotTo(HaveOccurred())
})
})
... ...