修改model写法
This commit is contained in:
1 parent
05b53c0710
commit
78417c2d33
3 files changed
+17
-27
No files matched your search
@@ -31,10 +31,11 @@ func GetSysJobList(c *gin.Context) {
|
|||||||
tools.HasError(err, "数据解析失败", 422)
|
tools.HasError(err, "数据解析失败", 422)
|
||||||
|
|
||||||
data.DataScope = tools.GetUserIdStr(c)
|
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)
|
tools.HasError(err, "", -1)
|
||||||
|
|
||||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
app.PageOK(c, list, count, pageIndex, pageSize, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSysJob(c *gin.Context) {
|
func GetSysJob(c *gin.Context) {
|
||||||
@@ -64,7 +65,7 @@ func UpdateSysJob(c *gin.Context) {
|
|||||||
err := c.ShouldBindJSON(&data)
|
err := c.ShouldBindJSON(&data)
|
||||||
tools.HasError(err, "数据解析失败", -1)
|
tools.HasError(err, "数据解析失败", -1)
|
||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
_, err = data.Update(data.JobId)
|
err = data.Update(data.JobId)
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
|
|
||||||
app.OK(c, data, "")
|
app.OK(c, data, "")
|
||||||
@@ -131,7 +132,7 @@ func StartJob(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tools.HasError(err, "", 500)
|
tools.HasError(err, "", 500)
|
||||||
_, err = data.Update(data.JobId)
|
err = data.Update(data.JobId)
|
||||||
tools.HasError(err, "", 500)
|
tools.HasError(err, "", 500)
|
||||||
app.OK(c, nil, msg.DeletedSuccess)
|
app.OK(c, nil, msg.DeletedSuccess)
|
||||||
}
|
}
|
||||||
+3
-2
@@ -93,7 +93,8 @@ func Setup() {
|
|||||||
global.GADMCron = cronjob.NewWithSeconds()
|
global.GADMCron = cronjob.NewWithSeconds()
|
||||||
|
|
||||||
sysJob := models.SysJob{}
|
sysJob := models.SysJob{}
|
||||||
jobList, err := sysJob.GetList()
|
jobList := make([]models.SysJob, 0)
|
||||||
|
err := sysJob.GetList(&jobList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(time.Now().Format(timeFormat), " [ERROR] JobCore init error", err)
|
fmt.Println(time.Now().Format(timeFormat), " [ERROR] JobCore init error", err)
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ func Setup() {
|
|||||||
j.Args = jobList[i].Args
|
j.Args = jobList[i].Args
|
||||||
sysJob.EntryId, err = AddJob(j)
|
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带分页
|
// 获取SysJob带分页
|
||||||
func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}) ([]SysJob, int, error) {
|
func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}, list interface{}) (int, error) {
|
||||||
var doc []SysJob
|
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName()).Scopes(tools.MakeCondition(v))
|
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)
|
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||||
table, err := dataPermission.GetDataScope(e.TableName(), table)
|
table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
if err := table.Scopes(tools.Paginate(pageSize, pageIndex)).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
if err := table.Scopes(tools.Paginate(pageSize, pageIndex)).Find(list).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||||
return nil, 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return doc, int(count), nil
|
return int(count), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysJob) GetList() ([]SysJob, error) {
|
func (e *SysJob) GetList(list interface{}) (err error) {
|
||||||
var doc []SysJob
|
return orm.Eloquent.Table(e.TableName()).Where("status = ?", 2).Find(list).Error
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新SysJob
|
// 更新SysJob
|
||||||
func (e *SysJob) Update(id interface{}) (rowsAffected int64, err error) {
|
func (e *SysJob) Update(id interface{}) (err error) {
|
||||||
result := orm.Eloquent.Table(e.TableName()).Where(id).Updates(&e)
|
return orm.Eloquent.Table(e.TableName()).Where(id).Updates(&e).Error
|
||||||
return result.RowsAffected, result.Error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysJob) RemoveAllEntryID() (update SysJob, err error) {
|
func (e *SysJob) RemoveAllEntryID() (update SysJob, err error) {
|
||||||
|
|||||||
Reference in new issue
Block a user