作者 linmadan

重构中标逻辑

... ... @@ -213,9 +213,6 @@ func (status *UnClaimedStatus) ChooseSuccessfulBidder(task *Task, successfulBidd
return fmt.Errorf("无效的竞标信息")
} else {
winBidTime := time.Now()
if winBidTime.Before(task.BidInfo.BidEndTime) {
return fmt.Errorf("竞标还没有结束")
}
task.BidInfo.SuccessfulBidder = successfulBidder
task.BidInfo.WinBidTime = winBidTime
task.TaskStatus = TASK_STATUS_UNDERWAY
... ...
... ... @@ -156,7 +156,7 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
query = query.Where(`task.participators @> '[{"uid":?}]'`, participator)
}
if taskIds, ok := queryOptions["taskIds"]; ok {
query = query.Where(`task.task_id IN (?)`, pg.In(taskIds.([]int64)))
query = query.Where(`task.id IN (?)`, pg.In(taskIds.([]int64)))
}
if offRangTime, ok := queryOptions["offRangTime"]; ok {
query = query.Join("JOIN off_task_records ON off_task_record.task_id = task.id")
... ... @@ -183,7 +183,12 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
if sortByReleaseTime, ok := queryOptions["sortByReleaseTime"]; ok && (sortByReleaseTime == "ASC" || sortByReleaseTime == "DESC") {
query = query.Order(fmt.Sprintf("task.release_time %s", sortByReleaseTime.(string)))
} else {
query = query.Order("task.id DESC")
}
if count, err := query.SelectAndCount(); err != nil {
return 0, tasks, err
} else {
for _, taskModel := range taskModels {
... ...
package service_gateway
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/httplib"
"strconv"
"strings"
"time"
)
type httplibBaseServiceGateway struct {
baseURL string
connectTimeout time.Duration
readWriteTimeout time.Duration
}
func (serviceGateway *httplibBaseServiceGateway) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
var request *httplib.BeegoHTTPRequest
switch method {
case "get":
request = httplib.Get(url)
break
case "post":
request = httplib.Post(url)
break
case "put":
request = httplib.Put(url)
break
case "delete":
request = httplib.Delete(url)
break
case "head":
request = httplib.Head(url)
break
default:
request = httplib.Get(url)
}
return request.SetTimeout(serviceGateway.connectTimeout, serviceGateway.readWriteTimeout)
}
func (serviceGateway *httplibBaseServiceGateway) responseHandle(response map[string]interface{}) (map[string]interface{}, error) {
data := make(map[string]interface{})
var err error
if code, ok := response["code"]; ok {
code := code.(float64)
if code == 0 {
data = response["data"].(map[string]interface{})
} else {
msg := response["msg"].(string)
err = fmt.Errorf(strings.Join([]string{strconv.FormatFloat(code, 'f', -1, 64), msg}, " "))
}
} else {
jsonBytes, marshalErr := json.Marshal(response)
if marshalErr != nil {
err = marshalErr
}
err = fmt.Errorf("无法解析的网关服务数据返回格式:%s", string(jsonBytes))
}
return data, err
}
... ...
... ... @@ -48,7 +48,7 @@ var _ = Describe("获取个人任务统计", func() {
"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", 2, &domain.EmployeeInfo{
Uid: 2499036607974745099,
}, 2, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
}, 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())
_, err4 := pG.DB.QueryOne(
pg.Scan(),
... ...