This commit is contained in:
苏尹岚
2020-10-30 18:05:54 +08:00
parent cc1071a22a
commit 9ddfe8e284
3 changed files with 41 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
package dao
import (
"encoding/json"
"fmt"
"time"
@@ -27,7 +28,7 @@ type GetJobsResult struct {
CategoryName string `json:"CategoryName"` //分类名
}
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int, includeStep bool, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types []int, includeStep bool, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
var jobs []*GetJobsResult
sql := `
SELECT SQL_CALC_FOUND_ROWS a.*, b.name
@@ -52,6 +53,10 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int,
sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)`
sqlParams = append(sqlParams, vendorIDs)
}
if len(types) > 0 {
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
sqlParams = append(sqlParams, types)
}
if fromTime != utils.ZeroTimeValue {
sql += ` AND a.created_at >= ?`
sqlParams = append(sqlParams, fromTime)
@@ -100,7 +105,18 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int,
return pagedInfo, err
}
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) {
func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (job *model.Job, err error) {
jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, includeStep)
if err != nil {
return job, err
}
if data, err := json.Marshal(jobs[0]); err == nil {
json.Unmarshal(data, job)
}
return job, err
}
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) {
sql := `
SELECT a.*, b.name
FROM job a
@@ -120,6 +136,10 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss []int, from
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
sqlParams = append(sqlParams, statuss)
}
if len(types) > 0 {
sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)`
sqlParams = append(sqlParams, types)
}
if fromTime != utils.ZeroTimeValue {
sql += ` AND a.created_at >= ?`
sqlParams = append(sqlParams, fromTime)