From 040cd381f2e8475e9b4eb336b704ad878f56f4fa Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 14 九月 2023 20:42:01 +0800 Subject: [PATCH] 适应性改动 --- api/v1/task.go | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/api/v1/task.go b/api/v1/task.go index 7fb3b50..9da9503 100644 --- a/api/v1/task.go +++ b/api/v1/task.go @@ -5,6 +5,7 @@ "apsClient/constvar" "apsClient/model" "apsClient/model/common" + "apsClient/model/request" "apsClient/model/response" "apsClient/nsq" "apsClient/pkg/contextx" @@ -48,20 +49,28 @@ // @Tags Task // @Summary 鑾峰彇浠诲姟 // @Produce application/json +// @Param object query request.TaskList true "鏌ヨ鍙傛暟" // @Success 200 {object} contextx.Response{data=response.TaskData} "鎴愬姛" // @Router /v1/task/get [get] func (slf *TaskApi) TaskGet(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) + var params request.TaskList + ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } + if params.Page <= 0 { + params.Page = 1 + } + if params.PageSize <= 0 { + params.PageSize = 1 + } - taskData, code := service.NewTaskService().GetTask() + taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize) if code != ecode.OK { ctx.Fail(code) return } - ctx.OkWithDetailed(taskData) + ctx.OkWithDetailed(taskResponse) } // GetProcessParams @@ -137,7 +146,7 @@ ctx.Fail(code) return } - err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished) + err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Position) if err != nil { logx.Errorf("UpdateProcedureStatus err: %v", err.Error()) ctx.Fail(ecode.UnknownErr) @@ -165,22 +174,17 @@ // @Tags Task // @Summary 涓嬪彂宸ヨ壓鍙傛暟锛堝紑濮嬩换鍔★級 // @Produce application/json -// @Param id path int true "宸ュ簭id" +// @Param object body request.SendProcessParams true "鏌ヨ鍙傛暟" // @Success 200 {object} contextx.Response{service.GetProcessModel} "鎴愬姛" // @Router /v1/task/sendProcessParams/{id} [post] func (slf *TaskApi) TaskStart(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) + var params request.SendProcessParams + ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } - idx := c.Param("id") - if idx == "" { - ctx.Fail(ecode.ParamsErr) - return - } - id := convertx.Atoi(idx) taskService := service.NewTaskService() - procedure, code := taskService.GetProcedureById(id) + procedure, code := taskService.GetProcedureById(params.ProcedureId) if code != ecode.OK { ctx.Fail(code) return @@ -203,10 +207,11 @@ } err = model.WithTransaction(func(db *gorm.DB) error { - err = taskService.UpdateProcedureStatus(db, id, model.ProcedureStatusProcessing) + err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Position) if err != nil { return err } + procedure.Position = params.Position err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusProcessing) if err != nil { return err @@ -235,7 +240,7 @@ return } plcConfig.CurrentTryTimes = 0 - err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, order.Amount.IntPart()) + err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Position, order.Amount.IntPart()) if err != nil { ctx.FailWithMsg(ecode.NeedConfirmedErr, "绯熺硶锛屽伐鑹轰笅鍙戝け璐ャ��") return -- Gitblit v1.8.0