zhangqian
2023-11-09 3817b0e527eadc47d7fe32cd5d73278b3d867b58
api/v1/task.go
@@ -271,22 +271,32 @@
      ctx.Ok()
      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)
   device, err := service.GetCurrentDevice()
   if err != nil {
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!")
      ctx.FailWithMsg(ecode.DBErr, err.Error())
      return
   }
   if device.NeedSetProcessParams {
      processModel, err := taskService.GetProcessParams(procedure, order)
      if err != nil || processModel == nil || processModel.ParamsMap == nil {
         ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!")
         return
      }
      err = SendParams(processModel.ParamsMap, plcConfig)
      if err != nil {
         ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!")
         return
      }
   }
   plcConfig.CurrentTryTimes = 0
   err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, procedure.Channel, order.Amount.IntPart())
   if err != nil {