zhangqian
2023-10-08 44a78f184ca10fba46df2567496895e179d4ac6c
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")