zhangqian
2023-10-08 44a78f184ca10fba46df2567496895e179d4ac6c
增加更新工艺参数接口
5个文件已修改
172 ■■■■ 已修改文件
api/v1/task.go 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/task.go
@@ -279,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
    }
@@ -324,10 +324,6 @@
        ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!")
        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 {
@@ -352,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, &params)
    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请求失败,请检查PLC配置!")
        return
    }
    ctx.Ok()
}
func SendParams(paramsMap map[string]interface{}, plcConfig *model.DevicePlc) error {
    if len(paramsMap) == 0 {
        return errors.New("empty params")
docs/docs.go
@@ -618,6 +618,36 @@
                    }
                }
            }
        },
        "/v1/task/updateProcessParams": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Task"
                ],
                "summary": "更新工艺参数(进行中的任务)",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SendProcessParams"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
@@ -1132,15 +1162,6 @@
                },
                "data": {},
                "msg": {
                    "type": "string"
                }
            }
        },
        "response.Message": {
            "type": "object",
            "properties": {
                "data": {},
                "event": {
                    "type": "string"
                }
            }
docs/swagger.json
@@ -606,6 +606,36 @@
                    }
                }
            }
        },
        "/v1/task/updateProcessParams": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Task"
                ],
                "summary": "更新工艺参数(进行中的任务)",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SendProcessParams"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
@@ -1120,15 +1150,6 @@
                },
                "data": {},
                "msg": {
                    "type": "string"
                }
            }
        },
        "response.Message": {
            "type": "object",
            "properties": {
                "data": {},
                "event": {
                    "type": "string"
                }
            }
docs/swagger.yaml
@@ -354,12 +354,6 @@
      msg:
        type: string
    type: object
  response.Message:
    properties:
      data: {}
      event:
        type: string
    type: object
  response.ProcessParams:
    properties:
      key:
@@ -802,4 +796,23 @@
      summary: 任务开始(获取工艺参数)
      tags:
      - Task
  /v1/task/updateProcessParams:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.SendProcessParams'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新工艺参数(进行中的任务)
      tags:
      - Task
swagger: "2.0"
router/index.go
@@ -35,11 +35,12 @@
    taskApi := new(v1.TaskApi)
    taskGroup := v1Group.Group("task")
    {
        taskGroup.GET("countdown", taskApi.TaskCountdown)      // 新任务倒计时
        taskGroup.GET("get", taskApi.TaskGet)                  // 获取工序
        taskGroup.GET("start/:id", taskApi.GetProcessParams)   // 获取工艺参数
        taskGroup.POST("sendProcessParams", taskApi.TaskStart) // 下发工艺参数并开始工序
        taskGroup.PUT("finish/:id", taskApi.TaskFinish)        // 完成工序
        taskGroup.GET("countdown", taskApi.TaskCountdown)                  // 新任务倒计时
        taskGroup.GET("get", taskApi.TaskGet)                              // 获取工序
        taskGroup.GET("start/:id", taskApi.GetProcessParams)               // 获取工艺参数
        taskGroup.POST("sendProcessParams", taskApi.TaskStart)             // 下发工艺参数并开始工序
        taskGroup.POST("updateProcessParams", taskApi.UpdateProcessParams) // 更新工艺参数
        taskGroup.PUT("finish/:id", taskApi.TaskFinish)                    // 完成工序
    }
    configApi := new(v1.ConfigApi)