zhangqian
2023-09-15 e67802cd15e273da46bfb734e339a947b7d1eceb
api/v1/task.go
@@ -12,6 +12,7 @@
   "apsClient/pkg/convertx"
   "apsClient/pkg/ecode"
   "apsClient/pkg/logx"
   "apsClient/pkg/safe"
   "apsClient/service"
   "apsClient/service/plc_address"
   "errors"
@@ -116,6 +117,16 @@
         Value: v,
      })
   }
   safe.Go(func() {
      caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicGetPlcAddress, conf.Conf.NsqConf.NodeId), fmt.Sprintf(constvar.NsqTopicSendPlcAddress, conf.Conf.NsqConf.NodeId))
      var addressResult common.ResponsePlcAddress
      err := caller.Call(common.RequestPlcAddress{DeviceId: conf.Conf.System.DeviceId}, &addressResult, time.Second*3)
      if err != nil {
         logx.Infof("get plc address err: %v", err.Error())
      }
   })
   resp := response.ProcessParamsResponse{
      Number: processModel.Number,
      Params: processParamsArr,
@@ -146,7 +157,7 @@
      ctx.Fail(code)
      return
   }
   err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished)
   err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Position)
   if err != nil {
      logx.Errorf("UpdateProcedureStatus err: %v", err.Error())
      ctx.Fail(ecode.UnknownErr)
@@ -176,7 +187,7 @@
// @Produce   application/json
// @Param     object  body    request.SendProcessParams true  "查询参数"
// @Success   200   {object}  contextx.Response{service.GetProcessModel}  "成功"
// @Router    /v1/task/sendProcessParams/{id} [post]
// @Router    /v1/task/sendProcessParams [post]
func (slf *TaskApi) TaskStart(c *gin.Context) {
   var params request.SendProcessParams
   ctx, ok := contextx.NewContext(c, &params)
@@ -211,11 +222,12 @@
      if err != nil {
         return err
      }
      procedure.Position = params.Position
      err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusProcessing)
      if err != nil {
         return err
      }
      return service.NewProgressService().AddProgress(db, procedure, order)
      return service.NewProgressService().Upsert(db, procedure, order)
   })
   if err != nil {
      logx.Errorf("SendProcessParams update order and procedure status error:%v", err.Error())
@@ -231,6 +243,18 @@
   err = SendParams(processModel.ParamsMap, plcConfig)
   if err != nil {
      logx.Errorf("SendProcessParams: %v", err.Error())
      err = model.WithTransaction(func(db *gorm.DB) error {
         err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusWaitProcess, params.Position)
         if err != nil {
            return err
         }
         procedure.Position = params.Position
         err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusWaitProcess)
         if err != nil {
            return err
         }
         return nil
      })
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "糟糕,工艺下发失败。")
      return
   }
@@ -239,7 +263,7 @@
      return
   }
   plcConfig.CurrentTryTimes = 0
   err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, order.Amount.IntPart())
   err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Position, order.Amount.IntPart())
   if err != nil {
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "糟糕,工艺下发失败。")
      return