| | |
| | | record.Detail = string(detail) |
| | | record.DeviceID = msg.ID |
| | | oldPlcRecord, err := model.NewDevicePlcSearch().SetDeviceId(msg.ID).First() |
| | | logx.Errorf("-------------------------------plc record not found:%v", err) |
| | | if err == gorm.ErrRecordNotFound { |
| | | logx.Errorf("-------------------------------plc record not found:%v", err) |
| | | 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) |
| | | |
| | | oldPlcRecord.Port = record.Port |
| | | oldPlcRecord.Method = record.Method |
| | | oldPlcRecord.Address = record.Address |
| | | oldPlcRecord.Detail = record.Detail |
| | | err = model.NewDevicePlcSearch().Save(oldPlcRecord) |
| | | } |
| | | if err != nil { |
| | | return err |