From 44a78f184ca10fba46df2567496895e179d4ac6c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期日, 08 十月 2023 11:47:47 +0800 Subject: [PATCH] 增加更新工艺参数接口 --- api/v1/task.go | 73 ++++++++++++++++++++++++++++++++---- 1 files changed, 64 insertions(+), 9 deletions(-) diff --git a/api/v1/task.go b/api/v1/task.go index 419316b..44aa2fb 100644 --- a/api/v1/task.go +++ b/api/v1/task.go @@ -68,10 +68,14 @@ return } + taskCount := service.NewTaskService().NewTaskCount() params.Page = 1 - if params.PageSize <= 0 { - params.PageSize = channelAmount + if params.TaskMode == constvar.TaskModeUnStarted { + params.PageSize = int(taskCount) + } else { + params.PageSize = channelAmount + } } taskMode := constvar.TaskModeCurrent @@ -107,15 +111,18 @@ return taskResponse.Tasks[i].Channel < taskResponse.Tasks[i].Channel }) + nowTs := time.Now().Unix() + flagMap := make(map[int32]struct{}, 0) for _, task := range taskResponse.Tasks { - if !service.TaskFlagGet(task.Channel) { + if _, ok := flagMap[task.Channel]; !ok && !service.TaskFlagGet(task.Channel) && task.Procedure.StartTime <= nowTs { task.CanStarted = true + flagMap[task.Channel] = struct{}{} } } taskResponse.Prompt = conf.Conf.Prompt taskResponse.ChannelAmount = channelAmount - taskResponse.TaskCount = service.NewTaskService().NewTaskCount() + taskResponse.TaskCount = taskCount ctx.OkWithDetailed(taskResponse) } @@ -272,7 +279,7 @@ } processModel, err := taskService.GetProcessParams(procedure, order) if err != nil || processModel == nil || processModel.ParamsMap == nil { - ctx.Fail(ecode.UnknownErr) + ctx.FailWithMsg(ecode.ParamsErr, "鏈幏鍙栧埌宸ヨ壓鍙傛暟锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") return } @@ -317,10 +324,6 @@ ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC璇锋眰澶辫触锛岃妫�鏌LC閰嶇疆锛�") return } - if code != ecode.OK { - logx.Errorf("get plcConfig err: %v", err.Error()) - return - } plcConfig.CurrentTryTimes = 0 err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Channel, order.Amount.IntPart()) if err != nil { @@ -345,6 +348,58 @@ ctx.Ok() } +// UpdateProcessParams +// @Tags Task +// @Summary 鏇存柊宸ヨ壓鍙傛暟锛堣繘琛屼腑鐨勪换鍔★級 +// @Produce application/json +// @Param object body request.SendProcessParams true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} "鎴愬姛" +// @Router /v1/task/updateProcessParams [post] +func (slf *TaskApi) UpdateProcessParams(c *gin.Context) { + mutex.Lock() + defer mutex.Unlock() + var params request.SendProcessParams + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + taskService := service.NewTaskService() + procedure, code := taskService.GetProcedureById(params.ProcedureId) + if code != ecode.OK { + ctx.Fail(code) + return + } + order, err := taskService.GetOrderByWorkOrderId(procedure.WorkOrderID) + if err != nil { + ctx.Fail(ecode.UnknownErr) + return + } + + if procedure.Status != model.ProcedureStatusProcessing { //鍙兘杩涜涓殑鍙互鏇存柊 + ctx.FailWithMsg(ecode.ParamsErr, "鍙兘杩涜涓殑宸ュ簭鍙互鏇存柊宸ヨ壓鍙傛暟") + return + } + processModel, err := taskService.GetProcessParams(procedure, order) + if err != nil || processModel == nil || processModel.ParamsMap == nil { + ctx.FailWithMsg(ecode.ParamsErr, "鏈幏鍙栧埌宸ヨ壓鍙傛暟锛岃鍦ㄥ伐鑹烘ā鍨嬪簱涓笂浼狅紒") + return + } + + plcConfig, code := service.NewDevicePlcService().GetDevicePlc() + if code != ecode.OK || plcConfig.Id == 0 { + ctx.FailWithMsg(ecode.NeedConfirmedErr, "璇峰厛閰嶇疆PLC") + return + } + plcConfig.MaxTryTimes = 2 + err = SendParams(processModel.ParamsMap, plcConfig) + if err != nil { + logx.Errorf("update process params err: %v", err.Error()) + ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC璇锋眰澶辫触锛岃妫�鏌LC閰嶇疆锛�") + return + } + ctx.Ok() +} + func SendParams(paramsMap map[string]interface{}, plcConfig *model.DevicePlc) error { if len(paramsMap) == 0 { return errors.New("empty params") -- Gitblit v1.8.0