zhangqian
2023-10-13 f838162ed0ee7f2832924c2399eddd461760135a
api/v1/task.go
@@ -4,21 +4,17 @@
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/model"
   "apsClient/model/common"
   "apsClient/model/request"
   "apsClient/model/response"
   "apsClient/nsq"
   "apsClient/pkg/contextx"
   "apsClient/pkg/convertx"
   "apsClient/pkg/ecode"
   "apsClient/pkg/logx"
   "apsClient/pkg/safe"
   "apsClient/service"
   "apsClient/service/plc_address"
   "errors"
   "fmt"
   "github.com/gin-gonic/gin"
   "gorm.io/gorm"
   "github.com/jinzhu/gorm"
   "github.com/spf13/cast"
   "sort"
   "sync"
   "time"
@@ -144,7 +140,7 @@
      ctx.Fail(ecode.ParamsErr)
      return
   }
   id := convertx.Atoi(idx)
   id := cast.ToUint(idx)
   procedure, code := service.NewTaskService().GetProcedureById(id)
   if code != ecode.OK {
      ctx.Fail(code)
@@ -179,15 +175,6 @@
      })
   }
   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,
@@ -212,7 +199,7 @@
      ctx.Fail(ecode.ParamsErr)
      return
   }
   id := convertx.Atoi(idx)
   id := cast.ToUint(idx)
   procedure, code := service.NewTaskService().GetProcedureById(id)
   if code != ecode.OK {
      ctx.Fail(code)
@@ -231,20 +218,6 @@
      logx.Errorf("UpdateProcedureStatus err: %v", err.Error())
      ctx.Fail(ecode.UnknownErr)
      return
   }
   msg := &common.MsgTaskStatusUpdate{
      WorkOrderId:  procedure.WorkOrderID,
      ProcedureID:  procedure.ProceduresInfo.ProcedureID,
      DeviceId:     procedure.ProceduresInfo.DeviceID,
      IsProcessing: false,
      IsFinish:     true,
   }
   caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicTaskProcedureStatusUpdate, conf.Conf.NsqConf.NodeId), "")
   err = caller.Send(msg)
   if err != nil {
      logx.Errorf("send task status update msg error:%v", err.Error())
   }
   service.TaskFlagUnset(procedure.Channel)
@@ -308,7 +281,7 @@
      return
   }
   plcConfig, code := service.NewDevicePlcService().GetDevicePlc()
   if code != ecode.OK || plcConfig.Id == 0 {
   if code != ecode.OK || plcConfig.ID == 0 {
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "请先配置PLC")
      return
   }
@@ -331,20 +304,6 @@
   if err != nil {
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置")
      return
   }
   msg := &common.MsgTaskStatusUpdate{
      WorkOrderId:  procedure.WorkOrderID,
      ProcedureID:  procedure.ProceduresInfo.ProcedureID,
      DeviceId:     procedure.ProceduresInfo.DeviceID,
      IsProcessing: true,
      IsFinish:     false,
   }
   caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicTaskProcedureStatusUpdate, conf.Conf.NsqConf.NodeId), "")
   err = caller.Send(msg)
   if err != nil {
      logx.Errorf("send task status update msg error:%v", err.Error())
   }
   service.TaskFlagSet(procedure.Channel)
   ctx.Ok()
@@ -388,7 +347,7 @@
   }
   plcConfig, code := service.NewDevicePlcService().GetDevicePlc()
   if code != ecode.OK || plcConfig.Id == 0 {
   if code != ecode.OK || plcConfig.ID == 0 {
      ctx.FailWithMsg(ecode.NeedConfirmedErr, "请先配置PLC")
      return
   }