diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index b1ef0694f..520a8b441 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -3,6 +3,8 @@ package cms import ( "fmt" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/globals/api" @@ -56,3 +58,7 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) { dao.Commit(db) return err } + +func GetJobs(ctx *jxcontext.Context, userIDs []string, categoryIDs []int, includeStep bool, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) { + return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset) +} diff --git a/business/model/dao/job.go b/business/model/dao/job.go index ca5c1ad09..4586f2958 100644 --- a/business/model/dao/job.go +++ b/business/model/dao/job.go @@ -1,7 +1,10 @@ package dao import ( + "time" + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model" ) @@ -17,3 +20,122 @@ func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategor err = GetRows(db, &jobCategories, sql, sqlParams) return jobCategories, err } + +type GetJobsResult struct { + model.Job + CategoryName string `json:"CategoryName"` //分类名 +} + +func GetJobs(db *DaoDB, userIDs []string, categoryIDs []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 + FROM job a + JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ? + WHERE 1 = 1 + ` + sqlParams := []interface{}{utils.DefaultTimeValue} + if len(userIDs) > 0 { + sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)` + sqlParams = append(sqlParams, userIDs) + } + if len(categoryIDs) > 0 { + sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)` + sqlParams = append(sqlParams, categoryIDs) + } + if fromTime != utils.ZeroTimeValue { + sql += ` AND a.created_at >= ?` + sqlParams = append(sqlParams, fromTime) + } + if toTime != utils.ZeroTimeValue { + sql += ` AND a.created_at <= ?` + sqlParams = append(sqlParams, toTime) + } + sql += " LIMIT ? OFFSET ?" + pageSize = jxutils.FormalizePageSize(pageSize) + sqlParams = append(sqlParams, pageSize, offset) + Begin(db) + defer Commit(db) + if err = GetRows(db, &jobs, sql, sqlParams...); err == nil { + pagedInfo = &model.PagedInfo{ + TotalCount: GetLastTotalRowCount(db), + // Data: jobs, + } + if includeStep { + for _, v := range jobs { + var jobSteps []*model.JobStep + sql2 := ` + SELECT * + FROM job_step + WHERE job_id = ? + AND deleted_at = ? + ` + sqlParams2 := []interface{}{v.ID, utils.DefaultTimeValue} + err = GetRows(db, &jobSteps, sql2, sqlParams2) + v.JobSteps = jobSteps + } + } + pagedInfo.Data = jobs + } + return pagedInfo, err +} + +func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs []int, includeStep bool) (jobs []*GetJobsResult, err error) { + sql := ` + SELECT a.*, b.name + FROM job a + JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ? + WHERE 1 = 1 + ` + sqlParams := []interface{}{utils.DefaultTimeValue} + if len(userIDs) > 0 { + sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)` + sqlParams = append(sqlParams, userIDs) + } + if len(categoryIDs) > 0 { + sql += ` AND a.job_category_id IN (` + GenQuestionMarks(len(categoryIDs)) + `)` + sqlParams = append(sqlParams, categoryIDs) + } + err = GetRows(db, &jobs, sql, sqlParams...) + if includeStep { + for _, v := range jobs { + var jobSteps []*model.JobStep + sql2 := ` + SELECT * + FROM job_step + WHERE job_id = ? + AND deleted_at = ? + ` + sqlParams2 := []interface{}{v.ID, utils.DefaultTimeValue} + err = GetRows(db, &jobSteps, sql2, sqlParams2) + v.JobSteps = jobSteps + } + } + return jobs, err +} + +func GetJobDetail(db *DaoDB, jobID int) (job *GetJobsResult, err error) { + var jobSteps []*model.JobStep + sql := ` + SELECT a.*, b.name + FROM job a + JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ? + WHERE 1 = 1 + ` + sqlParams := []interface{}{utils.DefaultTimeValue} + if jobID != 0 { + sql += ` AND a.id = ?` + sqlParams = append(sqlParams, jobID) + } + err = GetRow(db, &job, sql, sqlParams...) + sql2 := ` + SELECT * + FROM job_step + WHERE job_id = ? + AND deleted_at = ? + ` + sqlParams2 := []interface{}{job.ID, utils.DefaultTimeValue} + err = GetRows(db, &jobSteps, sql2, sqlParams2) + job.JobSteps = jobSteps + return job, err +} diff --git a/conf/app.conf b/conf/app.conf index 0223e293f..1154d9d97 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -1,6 +1,6 @@ appname = jx-callback httpport = 8080 -runmode = rsm +runmode = dev autorender = false copyrequestbody = true EnableDocs = true diff --git a/controllers/job_controller.go b/controllers/job_controller.go index ba18ec753..86a6de697 100644 --- a/controllers/job_controller.go +++ b/controllers/job_controller.go @@ -42,3 +42,43 @@ func (c *JobController) GetJobCategories() { return retVal, "", err }) } + +// @Title 查看任务列表 +// @Description 查看任务列表 +// @Param token header string true "认证token" +// @Param userIDs query string false "用户IDs" +// @Param categoryIDs query string false "分类IDs" +// @Param includeStep query bool false "是否查询步骤,默认否" +// @Param fromTime query string false "开始时间" +// @Param toTime query string false "结束时间" +// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetJobs [get] +func (c *JobController) GetJobs() { + c.callGetJobs(func(params *tJobGetJobsParams) (retVal interface{}, errCode string, err error) { + var ( + userIDs []string + categoryIDs []int + ) + if err = jxutils.Strings2Objs(params.UserIDs, &userIDs, params.CategoryIDs, categoryIDs); err == nil { + retVal, err = cms.GetJobs(params.Ctx, userIDs, categoryIDs, params.IncludeStep, params.FromTime, params.ToTime, params.PageSize, params.Offset) + } + return retVal, "", err + }) +} + +// @Title 查看任务 +// @Description 查看任务 +// @Param token header string true "认证token" +// @Param jobID query int false "任务ID" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetJobDetail [get] +func (c *JobController) GetJobDetail() { + c.callGetJobDetail(func(params *tJobGetJobDetailParams) (retVal interface{}, errCode string, err error) { + retVal, err = dao.GetJobDetail(dao.GetDB(), params.JobID) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 6ee1c1a23..a4c3d4cd1 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -160,6 +160,24 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"], + beego.ControllerComments{ + Method: "GetJobDetail", + Router: `/GetJobDetail`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"], + beego.ControllerComments{ + Method: "GetJobs", + Router: `/GetJobs`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"], beego.ControllerComments{ Method: "PublishJob",