mirror of https://github.com/ouqiang/gocron
增加删除N个月前的任务日志API
parent
0dfa998d11
commit
0bc4070762
|
@ -43,7 +43,7 @@
|
||||||
4. 浏览器访问 http://localhost:5920
|
4. 浏览器访问 http://localhost:5920
|
||||||
### 源码安装
|
### 源码安装
|
||||||
1. `go`语言版本1.7+
|
1. `go`语言版本1.7+
|
||||||
2. `go get -d https://github.com/ouqiang/gocron`
|
2. `go get -d github.com/ouqiang/gocron`
|
||||||
3. 编译 `go build`
|
3. 编译 `go build`
|
||||||
4. 启动、访问方式同上
|
4. 启动、访问方式同上
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,14 @@ func (taskLog *TaskLog) List(params CommonMap) ([]TaskLog, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空表
|
// 清空表
|
||||||
func (TaskLog *TaskLog) Clear() (int64, error) {
|
func (taskLog *TaskLog) Clear() (int64, error) {
|
||||||
return Db.Where("1=1").Delete(TaskLog);
|
return Db.Where("1=1").Delete(taskLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除N个月前的日志
|
||||||
|
func (taskLog *TaskLog) Remove(id int) (int64, error) {
|
||||||
|
t := time.Now().AddDate(0, -id, 0)
|
||||||
|
return Db.Where("start_time <= ?", t.Format(DefaultTimeFormat)).Delete(taskLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (taskLog *TaskLog) Total(params CommonMap) (int64, error) {
|
func (taskLog *TaskLog) Total(params CommonMap) (int64, error) {
|
||||||
|
|
|
@ -89,6 +89,7 @@ func Register(m *macaron.Macaron) {
|
||||||
// API
|
// API
|
||||||
m.Group("/api/v1", func() {
|
m.Group("/api/v1", func() {
|
||||||
m.Route("/tasklog/update-status", "GET,POST", tasklog.UpdateStatus)
|
m.Route("/tasklog/update-status", "GET,POST", tasklog.UpdateStatus)
|
||||||
|
m.Post("/tasklog/remove/:id", tasklog.Remove)
|
||||||
});
|
});
|
||||||
|
|
||||||
// 404错误
|
// 404错误
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package tasklog
|
package tasklog
|
||||||
|
|
||||||
|
// 任务日志
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
|
@ -11,9 +13,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @author qiang.ou<qingqianludao@gmail.com>
|
|
||||||
// @date 2017/4/7-21:18
|
|
||||||
|
|
||||||
func Index(ctx *macaron.Context) {
|
func Index(ctx *macaron.Context) {
|
||||||
logModel := new(models.TaskLog)
|
logModel := new(models.TaskLog)
|
||||||
queryParams := parseQueryParams(ctx)
|
queryParams := parseQueryParams(ctx)
|
||||||
|
@ -49,12 +48,29 @@ func Clear(ctx *macaron.Context) string {
|
||||||
return json.Success(utils.SuccessContent, nil)
|
return json.Success(utils.SuccessContent, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除N个月前的日志
|
||||||
|
func Remove(ctx *macaron.Context) string {
|
||||||
|
month := ctx.ParamsInt(":id")
|
||||||
|
json := utils.JsonResponse{}
|
||||||
|
if month < 1 || month > 12 {
|
||||||
|
return json.CommonFailure("参数取值范围1-12")
|
||||||
|
}
|
||||||
|
taskLogModel := new(models.TaskLog)
|
||||||
|
_, err := taskLogModel.Remove(month)
|
||||||
|
if err != nil {
|
||||||
|
return json.CommonFailure("删除失败", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Success("删除成功", nil)
|
||||||
|
}
|
||||||
|
|
||||||
// 更新任务状态
|
// 更新任务状态
|
||||||
func UpdateStatus(ctx *macaron.Context) string {
|
func UpdateStatus(ctx *macaron.Context) string {
|
||||||
id := ctx.QueryTrim("id")
|
id := ctx.QueryTrim("id")
|
||||||
status := ctx.QueryInt("status")
|
status := ctx.QueryInt("status")
|
||||||
result := ctx.QueryTrim("result")
|
result := ctx.QueryTrim("result")
|
||||||
json := utils.JsonResponse{}
|
json := utils.JsonResponse{}
|
||||||
|
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return json.CommonFailure("任务ID不能为空")
|
return json.CommonFailure("任务ID不能为空")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue