作者 linmadan

修复级联查询bug

@@ -137,11 +137,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int @@ -137,11 +137,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
137 query = query.Where(`task.is_reward_take = ?`, isRewardTake) 137 query = query.Where(`task.is_reward_take = ?`, isRewardTake)
138 } 138 }
139 if bidTimeMatch, ok := queryOptions["bidTimeMatch"]; ok && (bidTimeMatch != 0) { 139 if bidTimeMatch, ok := queryOptions["bidTimeMatch"]; ok && (bidTimeMatch != 0) {
140 - query = query.Join("JOIN bid_infos ON bid_info.task_id = task.id")  
141 - if bidTimeMatch == 1 { 140 + if bidTimeMatch == 2 {
142 query = query.Where("bid_info.bid_end_time < ?", time.Now()) 141 query = query.Where("bid_info.bid_end_time < ?", time.Now())
143 } 142 }
144 - if bidTimeMatch == 2 { 143 + if bidTimeMatch == 3 {
145 query = query.Where("bid_info.bid_end_time > ?", time.Now()) 144 query = query.Where("bid_info.bid_end_time > ?", time.Now())
146 } 145 }
147 } 146 }
@@ -43,6 +43,11 @@ var _ = Describe("搜索任务", func() { @@ -43,6 +43,11 @@ var _ = Describe("搜索任务", func() {
43 Uid: 2499036607974745088, 43 Uid: 2499036607974745088,
44 }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter)) 44 }, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
45 Expect(err2).NotTo(HaveOccurred()) 45 Expect(err2).NotTo(HaveOccurred())
  46 + _, err3 := pG.DB.QueryOne(
  47 + pg.Scan(),
  48 + "INSERT INTO bid_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
  49 + 1, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Now().Add(dayAfter))
  50 + Expect(err3).NotTo(HaveOccurred())
46 }) 51 })
47 Describe("搜索任务", func() { 52 Describe("搜索任务", func() {
48 Context("", func() { 53 Context("", func() {
@@ -91,6 +96,27 @@ var _ = Describe("搜索任务", func() { @@ -91,6 +96,27 @@ var _ = Describe("搜索任务", func() {
91 ContainsKey("data").Value("data").Object() 96 ContainsKey("data").Value("data").Object()
92 }) 97 })
93 }) 98 })
  99 + Context("", func() {
  100 + It("", func() {
  101 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  102 + body := map[string]interface{}{
  103 + "companyId": 101,
  104 + "sponsor": 2499036607974745088,
  105 + "bidTimeMatch": 1,
  106 + "offset": 0,
  107 + "limit": 20,
  108 + }
  109 + httpExpect.POST("/tasks/search").
  110 + WithJSON(body).
  111 + Expect().
  112 + Status(http.StatusOK).
  113 + JSON().
  114 + Object().
  115 + ContainsKey("code").ValueEqual("code", 0).
  116 + ContainsKey("msg").ValueEqual("msg", "ok").
  117 + ContainsKey("data").Value("data").Object()
  118 + })
  119 + })
94 }) 120 })
95 AfterEach(func() { 121 AfterEach(func() {
96 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true") 122 _, err := pG.DB.Exec("DELETE FROM tasks WHERE true")