From 68cde61a449b7ff2a332cf74ed5e0c0422521b44 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Wed, 13 Sep 2023 11:02:50 +0800 Subject: [PATCH] =?UTF-8?q?model=E5=B1=82=E9=83=A8=E5=88=86=E8=A1=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 269c3fa7e6b90f6df8ecdbcea312bfac4394eb04 --- api/desc/core/pcm-core.api | 2 +- api/internal/handler/core/gethashcathandler.go | 10 +++++++++- api/internal/handler/core/scheduletaskbyyamlhandler.go | 2 +- api/internal/logic/core/gethashcatlogic.go | 6 +++--- api/internal/logic/core/scheduletaskbyyamllogic.go | 7 +++---- api/internal/logic/core/scheduletasklogic.go | 2 -- api/internal/types/types.go | 2 +- model/taskmodel_gen.go | 7 +------ 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index a229a5a8..adbe4db4 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -468,7 +468,7 @@ type SaveHashcatReq { } type getHashcatHandlerReq { - CrackTaskId int64 `json:"crackTaskId"` // 任务id + CrackTaskId string `path:"crackTaskId"` // 任务id } type getHashcatHandlerResp { diff --git a/api/internal/handler/core/gethashcathandler.go b/api/internal/handler/core/gethashcathandler.go index 6e618833..d7712d78 100644 --- a/api/internal/handler/core/gethashcathandler.go +++ b/api/internal/handler/core/gethashcathandler.go @@ -4,14 +4,22 @@ import ( "gitlink.org.cn/jcce-pcm/utils/result" "net/http" + "github.com/zeromicro/go-zero/rest/httpx" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types" ) func GetHashcatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + var req types.GetHashcatHandlerReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + l := core.NewGetHashcatLogic(r.Context(), svcCtx) - resp, err := l.GetHashcat() + resp, err := l.GetHashcat(&req) result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/handler/core/scheduletaskbyyamlhandler.go b/api/internal/handler/core/scheduletaskbyyamlhandler.go index 9f7e4067..27f3607c 100644 --- a/api/internal/handler/core/scheduletaskbyyamlhandler.go +++ b/api/internal/handler/core/scheduletaskbyyamlhandler.go @@ -15,7 +15,7 @@ func ScheduleTaskByYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req types.ScheduleTaskByYamlReq if err := httpx.Parse(r, &req); err != nil { - httpx.ErrorCtx(r.Context(), w, err) + result.HttpResult(r, w, nil, err) return } // 解析yaml文件 diff --git a/api/internal/logic/core/gethashcatlogic.go b/api/internal/logic/core/gethashcatlogic.go index ececafbc..09a65aaf 100644 --- a/api/internal/logic/core/gethashcatlogic.go +++ b/api/internal/logic/core/gethashcatlogic.go @@ -25,10 +25,10 @@ func NewGetHashcatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetHas } } -func (l *GetHashcatLogic) GetHashcat() (resp *types.GetHashcatHandlerResp, err error) { - +func (l *GetHashcatLogic) GetHashcat(req *types.GetHashcatHandlerReq) (resp *types.GetHashcatHandlerResp, err error) { + // todo: add your logic here and delete this line var hashcatList []*model.THashcat - tx := l.svcCtx.DbEngin.Find(&hashcatList) + tx := l.svcCtx.DbEngin.Where("crack_task_id = ?", req.CrackTaskId).Find(&hashcatList) if tx.Error != nil { return nil, tx.Error } diff --git a/api/internal/logic/core/scheduletaskbyyamllogic.go b/api/internal/logic/core/scheduletaskbyyamllogic.go index f9b90077..15c08250 100644 --- a/api/internal/logic/core/scheduletaskbyyamllogic.go +++ b/api/internal/logic/core/scheduletaskbyyamllogic.go @@ -32,17 +32,15 @@ func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYa if err != nil { return err } - // construct task info + // 构建任务结构体 taskModel := model.Task{ Status: "Saved", Description: req.Description, Name: req.Name, YamlString: string(bytes), StartTime: time.Now(), - CreatedTime: time.Now(), - UpdatedTime: time.Now(), } - // save the task in mysql and return id + // 保存任务数据到数据库 tx := l.svcCtx.DbEngin.Create(&taskModel) if tx.Error != nil { return tx.Error @@ -51,6 +49,7 @@ func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYa // push message into topic for _, task := range req.Tasks { task.TaskId = taskModel.Id + // 将任务数据转换成消息体 reqMessage, err := json.Marshal(task) if err != nil { logx.Error(err) diff --git a/api/internal/logic/core/scheduletasklogic.go b/api/internal/logic/core/scheduletasklogic.go index be489322..b104ee34 100644 --- a/api/internal/logic/core/scheduletasklogic.go +++ b/api/internal/logic/core/scheduletasklogic.go @@ -44,8 +44,6 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (err error) Name: req.Name, YamlString: string(bytes), StartTime: time.Now(), - CreatedTime: time.Now(), - UpdatedTime: time.Now(), } // save the task in mysql and return id tx := l.svcCtx.DbEngin.Create(&taskModel) diff --git a/api/internal/types/types.go b/api/internal/types/types.go index a467d806..17214f21 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -437,7 +437,7 @@ type SaveHashcatReq struct { } type GetHashcatHandlerReq struct { - CrackTaskId int64 `json:"crackTaskId"` // 任务id + CrackTaskId string `path:"crackTaskId"` // 任务id } type GetHashcatHandlerResp struct { diff --git a/model/taskmodel_gen.go b/model/taskmodel_gen.go index 0a89a4dd..5ff3e48c 100644 --- a/model/taskmodel_gen.go +++ b/model/taskmodel_gen.go @@ -44,12 +44,7 @@ type ( EndTime string `db:"end_time"` // 结束运行时间 RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) YamlString string `db:"yaml_string"` - Result string `db:"result"` // 作业结果 - CreatedBy int64 `db:"created_by"` // 创建人 - CreatedTime time.Time `db:"created_time"` // 创建时间 - UpdatedBy int64 `db:"updated_by"` // 更新人 - UpdatedTime time.Time `db:"updated_time"` // 更新时间 - DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是) + Result string `db:"result"` // 作业结果 } )