zhangqian
2023-11-03 53d80c839ad2aad0a0482ca43fca1fc3a95b9d1c
nsq/msg_handler.go
@@ -267,12 +267,15 @@
      DeviceID:         msg.ID,
      Procedures:       strings.Join(procedures, ","),
      ExtChannelAmount: msg.ExtChannelAmount,
      DeviceMac:        msg.DeviceMac,
   }
   oldRecord, err := model.NewDeviceSearch().SetDeviceId(msg.ID).First()
   if err == gorm.ErrRecordNotFound {
      err = model.NewDeviceSearch().Create(deviceRecord)
   } else if oldRecord.ExtChannelAmount != deviceRecord.ExtChannelAmount || oldRecord.Procedures != deviceRecord.Procedures {
   } else if oldRecord.ExtChannelAmount != deviceRecord.ExtChannelAmount ||
      oldRecord.Procedures != deviceRecord.Procedures ||
      oldRecord.DeviceMac != deviceRecord.DeviceMac {
      err = model.NewDeviceSearch().SetDeviceId(msg.ID).Save(deviceRecord)
   }
@@ -291,25 +294,31 @@
   if err != nil {
      logx.Infof("decode from PlcAddressList to DevicePlc  Details err:%v", err)
   }
   err = mapstructure.Decode(msg.PlcAddressList, &record.Details)
   if err != nil {
      logx.Infof("decode from PlcAddressList to DevicePlc  Details err:%v", err)
   }
   detail, err := json.Marshal(record.Details)
   record.Detail = string(detail)
   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 ||
   } else if record.Port != oldPlcRecord.Port || record.Method != oldPlcRecord.Method ||
      record.Address != oldPlcRecord.Address ||
      record.Detail != oldPlcRecord.Detail {
      record.Detail != oldPlcRecord.Detail ||
      record.BaudRate != oldPlcRecord.BaudRate ||
      record.SerialName != oldPlcRecord.SerialName ||
      record.DataBit != oldPlcRecord.DataBit ||
      record.StopBit != oldPlcRecord.StopBit ||
      record.Parity != oldPlcRecord.Parity {
      oldPlcRecord.Port = record.Port
      oldPlcRecord.Method = record.Method
      oldPlcRecord.Address = record.Address
      oldPlcRecord.Port = record.Port
      oldPlcRecord.Detail = record.Detail
      oldPlcRecord.BaudRate = record.BaudRate
      oldPlcRecord.SerialName = record.SerialName
      oldPlcRecord.DataBit = record.DataBit
      oldPlcRecord.StopBit = record.StopBit
      oldPlcRecord.Parity = record.Parity
      err = model.NewDevicePlcSearch().Save(oldPlcRecord)
   }
   if err != nil {