zhangqian
2023-10-21 5a9e2e97e78a05209a57a75a75678d67c32c58d5
nsq/msg_handler.go
@@ -281,7 +281,7 @@
      return err
   }
   if msg.PlcConfig.Method == "" {
   if msg.PlcConfig == nil || msg.PlcConfig.Method == "" {
      return nil
   }
@@ -297,8 +297,16 @@
   }
   detail, err := json.Marshal(record.Details)
   record.Detail = string(detail)
   record.ID = 1
   err = model.NewDevicePlcSearch().SetId(record.ID).Save(&record)
   record.DeviceID = msg.ID
   oldPlcRecord, err := model.NewDevicePlcSearch().SetDeviceId(msg.ID).First()
   if err == gorm.ErrRecordNotFound {
      err = model.NewDevicePlcSearch().Create(&record)
   } else if record.Port != oldPlcRecord.Port ||
      record.Method != oldPlcRecord.Method ||
      record.Address != oldPlcRecord.Address ||
      record.Detail != oldPlcRecord.Detail {
      err = model.NewDevicePlcSearch().SetDeviceId(msg.ID).Save(&record)
   }
   if err != nil {
      return err
   }