| | |
| | | } |
| | | processModel, err := taskService.GetProcessParams(procedure, order) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.Fail(ecode.UnknownErr) |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | } |
| | | |
| | |
| | | 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 { |
| | |
| | | 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请求失败,请检查PLC配置!") |
| | | return |
| | | } |
| | | ctx.Ok() |
| | | } |
| | | |
| | | func SendParams(paramsMap map[string]interface{}, plcConfig *model.DevicePlc) error { |
| | | if len(paramsMap) == 0 { |
| | | return errors.New("empty params") |
| | |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/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": { |
| | |
| | | }, |
| | | "data": {}, |
| | | "msg": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "response.Message": { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": {}, |
| | | "event": { |
| | | "type": "string" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/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": { |
| | |
| | | }, |
| | | "data": {}, |
| | | "msg": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "response.Message": { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": {}, |
| | | "event": { |
| | | "type": "string" |
| | | } |
| | | } |
| | |
| | | msg: |
| | | type: string |
| | | type: object |
| | | response.Message: |
| | | properties: |
| | | data: {} |
| | | event: |
| | | type: string |
| | | type: object |
| | | response.ProcessParams: |
| | | properties: |
| | | key: |
| | |
| | | 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" |
| | |
| | | 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) |