refresh job

This commit is contained in:
苏尹岚
2020-10-16 15:16:26 +08:00
parent cc9ac79e45
commit 8c7806bf3d
3 changed files with 32 additions and 3 deletions

View File

@@ -78,7 +78,7 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
if job.UserID == "" { if job.UserID == "" {
return fmt.Errorf("任务发起人不能为空!") return fmt.Errorf("任务发起人不能为空!")
} }
jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, utils.Str2Time(fromTime), utils.Str2Time(toTime), false) jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, utils.Str2Time(fromTime), utils.Str2Time(toTime), false)
if len(jobs) > 0 { if len(jobs) > 0 {
members, err := dao.GetUserMember(db, job.UserID, 0, 0, true) members, err := dao.GetUserMember(db, job.UserID, 0, 0, true)
if err != nil { if err != nil {
@@ -424,3 +424,23 @@ func AuditJob(ctx *jxcontext.Context, jobOrderID, status int, comment string) (e
dao.Commit(db) dao.Commit(db)
return err return err
} }
func RefreshJobStatus(ctx *jxcontext.Context) (err error) {
var (
db = dao.GetDB()
)
globals.SugarLogger.Debugf("RefreshJobStatus begin...")
jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, utils.ZeroTimeValue, utils.ZeroTimeValue, false)
if err != nil {
globals.SugarLogger.Debugf("RefreshJobStatus err :%v", err)
return
}
for _, job := range jobs {
if time.Now().Sub(job.FinishedAt) >= 0 {
job.Status = model.JobStatusOverdue
dao.UpdateEntity(db, job, "Status")
}
}
globals.SugarLogger.Debugf("RefreshJobStatus end...")
return err
}

View File

@@ -3,6 +3,9 @@ package misc
import ( import (
"time" "time"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
@@ -10,7 +13,7 @@ import (
var ( var (
dailyWorkTimeList = []string{ dailyWorkTimeList = []string{
"20:30:00", "00:00:30",
} }
) )
@@ -22,6 +25,8 @@ func Init() {
func doDailyWork() { func doDailyWork() {
globals.SugarLogger.Debug("doDailyWork") globals.SugarLogger.Debug("doDailyWork")
//刷新任务过期状态
cms.RefreshUserMemberStatus(jxcontext.AdminCtx)
} }
// 按时间序列循环 // 按时间序列循环

View File

@@ -88,7 +88,7 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int,
return pagedInfo, err return pagedInfo, err
} }
func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) { func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) {
sql := ` sql := `
SELECT a.*, b.name SELECT a.*, b.name
FROM job a FROM job a
@@ -104,6 +104,10 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs []int, fromTime, toT
sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)` sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)`
sqlParams = append(sqlParams, categoryIDs) sqlParams = append(sqlParams, categoryIDs)
} }
if len(statuss) > 0 {
sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)`
sqlParams = append(sqlParams, statuss)
}
if fromTime != utils.ZeroTimeValue { if fromTime != utils.ZeroTimeValue {
sql += ` AND a.created_at >= ?` sql += ` AND a.created_at >= ?`
sqlParams = append(sqlParams, fromTime) sqlParams = append(sqlParams, fromTime)