mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-20 17:57:54 +00:00
@@ -31,10 +31,11 @@ func GetSysJobList(c *gin.Context) {
|
||||
tools.HasError(err, "数据解析失败", 422)
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex, v)
|
||||
list := make([]models.SysJob, 0)
|
||||
count, err := data.GetPage(pageSize, pageIndex, v, &list)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||
app.PageOK(c, list, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetSysJob(c *gin.Context) {
|
||||
@@ -64,7 +65,7 @@ func UpdateSysJob(c *gin.Context) {
|
||||
err := c.ShouldBindJSON(&data)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
_, err = data.Update(data.JobId)
|
||||
err = data.Update(data.JobId)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, data, "")
|
||||
@@ -131,7 +132,7 @@ func StartJob(c *gin.Context) {
|
||||
}
|
||||
|
||||
tools.HasError(err, "", 500)
|
||||
_, err = data.Update(data.JobId)
|
||||
err = data.Update(data.JobId)
|
||||
tools.HasError(err, "", 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
+3
-2
@@ -93,7 +93,8 @@ func Setup() {
|
||||
global.GADMCron = cronjob.NewWithSeconds()
|
||||
|
||||
sysJob := models.SysJob{}
|
||||
jobList, err := sysJob.GetList()
|
||||
jobList := make([]models.SysJob, 0)
|
||||
err := sysJob.GetList(&jobList)
|
||||
if err != nil {
|
||||
fmt.Println(time.Now().Format(timeFormat), " [ERROR] JobCore init error", err)
|
||||
}
|
||||
@@ -124,7 +125,7 @@ func Setup() {
|
||||
j.Args = jobList[i].Args
|
||||
sysJob.EntryId, err = AddJob(j)
|
||||
}
|
||||
_, err = sysJob.Update(jobList[i].JobId)
|
||||
err = sysJob.Update(jobList[i].JobId)
|
||||
}
|
||||
|
||||
// 其中任务
|
||||
|
||||
+9
-21
@@ -38,9 +38,7 @@ func (e *SysJob) Get(id interface{}) (err error) {
|
||||
}
|
||||
|
||||
// 获取SysJob带分页
|
||||
func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}) ([]SysJob, int, error) {
|
||||
var doc []SysJob
|
||||
|
||||
func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}, list interface{}) (int, error) {
|
||||
table := orm.Eloquent.Table(e.TableName()).Scopes(tools.MakeCondition(v))
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
@@ -48,33 +46,23 @@ func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}) ([]SysJob,
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return 0, err
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Scopes(tools.Paginate(pageSize, pageIndex)).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
if err := table.Scopes(tools.Paginate(pageSize, pageIndex)).Find(list).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return doc, int(count), nil
|
||||
return int(count), nil
|
||||
}
|
||||
|
||||
func (e *SysJob) GetList() ([]SysJob, error) {
|
||||
var doc []SysJob
|
||||
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
table = table.Where("status = ?", 2)
|
||||
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return doc, nil
|
||||
func (e *SysJob) GetList(list interface{}) (err error) {
|
||||
return orm.Eloquent.Table(e.TableName()).Where("status = ?", 2).Find(list).Error
|
||||
}
|
||||
|
||||
// 更新SysJob
|
||||
func (e *SysJob) Update(id interface{}) (rowsAffected int64, err error) {
|
||||
result := orm.Eloquent.Table(e.TableName()).Where(id).Updates(&e)
|
||||
return result.RowsAffected, result.Error
|
||||
func (e *SysJob) Update(id interface{}) (err error) {
|
||||
return orm.Eloquent.Table(e.TableName()).Where(id).Updates(&e).Error
|
||||
}
|
||||
|
||||
func (e *SysJob) RemoveAllEntryID() (update SysJob, err error) {
|
||||
|
||||
Reference in New Issue
Block a user