Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: 74bdba75d1474724857fd31f7ff7f97853ce7905
This commit is contained in:
jagger 2024-05-07 17:55:43 +08:00
parent 8f381d5030
commit 576df04079
3 changed files with 17 additions and 5 deletions

View File

@ -338,7 +338,7 @@ type (
}
TaskModel {
Id int64 `json:"id,omitempty" db:"id"` // id
Id int64 `json:"id,omitempty,string" db:"id"` // id
Name string `json:"name,omitempty" db:"name"` // 作业名称
Description string `json:"description,omitempty" db:"description"` // 作业描述
Status string `json:"status,omitempty" db:"status"` // 作业状态

View File

@ -3,6 +3,7 @@ package core
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"time"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
@ -28,7 +29,7 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
limit := req.PageSize
offset := req.PageSize * (req.PageNum - 1)
resp = &types.PageResult{}
var list []types.TaskModel
var list []*types.TaskModel
db := l.svcCtx.DbEngin.Model(&types.TaskModel{}).Table("task")
db = db.Where("deleted_at is null")
@ -48,8 +49,19 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
if err != nil {
return nil, result.NewDefaultError(err.Error())
}
resp.List = list
const layout = "2006-01-02 15:04:05"
for _, model := range list {
if model.EndTime != "" && model.StartTime != "" {
starTime, _ := time.Parse(layout, model.StartTime)
endTime, _ := time.Parse(layout, model.EndTime)
model.RunningTime = int64(endTime.Sub(starTime).Seconds())
}
if model.StartTime != "" {
starTime, _ := time.Parse(layout, model.StartTime)
model.RunningTime = int64(time.Now().Sub(starTime).Seconds())
}
}
resp.List = &list
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total

View File

@ -261,7 +261,7 @@ type PageTaskReq struct {
}
type TaskModel struct {
Id int64 `json:"id,omitempty" db:"id"` // id
Id int64 `json:"id,omitempty,string" db:"id"` // id
Name string `json:"name,omitempty" db:"name"` // 作业名称
Description string `json:"description,omitempty" db:"description"` // 作业描述
Status string `json:"status,omitempty" db:"status"` // 作业状态