zhangqian
2023-10-21 30f35de47284269b475c3aa307d06c033b67aa27
nsq/msg_handler.go
@@ -384,34 +384,5 @@
}
func (slf *PullDataResponse) DealDeviceData(data interface{}) error {
   var devices []*model.Device
   err := mapstructure.Decode(data, &devices)
   if err != nil {
      return err
   }
   numbers := make([]string, 0, len(devices))
   for _, item := range devices {
      numbers = append(numbers, item.DeviceID)
   }
   existsDevices, err := model.NewDeviceSearch().SetDeviceIds(numbers).FindNotTotal()
   if err != nil {
      return err
   }
   existsDeviceMap := make(map[string]*model.Device, len(existsDevices))
   for _, device := range existsDevices {
      existsDeviceMap[device.DeviceID] = device
   }
   for _, device := range devices {
      if oldDevice, exists := existsDeviceMap[device.DeviceID]; exists {
         if oldDevice.ExtChannelAmount != device.ExtChannelAmount || //todo to be continued
            oldDevice.Procedures != device.Procedures {
            err = model.NewDeviceSearch().SetDeviceId(device.DeviceID).Save(device)
         }
      } else {
         err = model.NewDeviceSearch().Create(device)
      }
   }
   return err
   return nil
}