From 1f3164832d554ae74147312bf6b86b803594aa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 17 Dec 2020 17:35:57 +0800 Subject: [PATCH] a --- business/jxstore/cms/job.go | 27 +++++++++++++++++++++++++-- business/model/dao/dao_job.go | 11 +++++++++-- controllers/job_controller.go | 6 ++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index bf09bb2c1..27c28f1da 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -109,7 +109,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e if job.UserID == "" { return errCode, fmt.Errorf("任务发起人不能为空!") } - jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, false) + jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, 0, false) if len(jobs) > 0 { members, err := dao.GetUserMember(db, job.UserID, model.MemberTypeNormal) if err != nil { @@ -625,7 +625,7 @@ func RefreshJobStatus(ctx *jxcontext.Context) (err error) { db = dao.GetDB() ) globals.SugarLogger.Debugf("RefreshJobStatus begin...") - jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, false) + jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, 0, false) if err != nil { globals.SugarLogger.Debugf("RefreshJobStatus err :%v", err) return @@ -1147,3 +1147,26 @@ func RefreshJobSpan(ctx *jxcontext.Context) (err error) { task.GetID() return err } + +func ReloadJobSpan(ctx *jxcontext.Context, jobIDs []int) (err error) { + var ( + db = dao.GetDB() + ) + jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, model.JobSpanTop, false) + if len(jobs) != len(jobIDs) { + return fmt.Errorf("传入的任务IDs有误!") + } + for k, v := range jobIDs { + job := &model.Job{} + job.ID = v + if err = dao.GetEntity(db, job); err == nil { + if job.JobSpanTop == model.JobSpanTop { + job.TopSeq = k + 1 + dao.UpdateEntity(db, job, "TopSeq") + } else { + continue + } + } + } + return err +} diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index 110badbe5..c5032ae00 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -154,7 +154,7 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types } 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) + jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, 0, includeStep) if err != nil { return job, err } @@ -167,7 +167,7 @@ func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, from return job, err } -func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) { +func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, span int, includeStep bool) (jobs []*GetJobsResult, err error) { sql := ` SELECT a.*, b.name FROM job a @@ -199,6 +199,13 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []in sql += ` AND a.created_at <= ?` sqlParams = append(sqlParams, toTime) } + if span != 0 { + if span == model.JobSpanTop { + sql += ` AND a.job_span_top = 1` + } else { + sql += ` AND a.job_span_recmd = 1` + } + } err = GetRows(db, &jobs, sql, sqlParams...) for _, v := range jobs { if includeStep { diff --git a/controllers/job_controller.go b/controllers/job_controller.go index b463a9853..94ad37f0d 100644 --- a/controllers/job_controller.go +++ b/controllers/job_controller.go @@ -427,6 +427,12 @@ func (c *JobController) CreateJobSpan() { // @router /ReloadJobSpan [post] func (c *JobController) ReloadJobSpan() { c.callReloadJobSpan(func(params *tJobReloadJobSpanParams) (retVal interface{}, errCode string, err error) { + var ( + jobIDs []int + ) + if err = jxutils.Strings2Objs(params.JobIDs, &jobIDs); err == nil { + err = cms.ReloadJobSpan(params.Ctx, jobIDs) + } return retVal, "", err }) }