| 259 | #[async_trait] |
| 260 | impl IntegrationTrait for Integration { |
| 261 | async fn uplink_event( |
| 262 | &self, |
| 263 | _vars: &HashMap<String, String>, |
| 264 | pl: &integration::UplinkEvent, |
| 265 | ) -> Result<()> { |
| 266 | let di = pl.device_info.as_ref().unwrap(); |
| 267 | info!(dev_eui = %di.dev_eui, event = "up", "Inserting event"); |
| 268 | |
| 269 | let e = EventUp { |
| 270 | deduplication_id: Uuid::from_str(&pl.deduplication_id)?, |
| 271 | time: (*pl.time.as_ref().unwrap()) |
| 272 | .try_into() |
| 273 | .map_err(anyhow::Error::msg)?, |
| 274 | tenant_id: Uuid::from_str(&di.tenant_id)?, |
| 275 | tenant_name: di.tenant_name.clone(), |
| 276 | application_id: Uuid::from_str(&di.application_id)?, |
| 277 | application_name: di.application_name.clone(), |
| 278 | device_profile_id: Uuid::from_str(&di.device_profile_id)?, |
| 279 | device_profile_name: di.device_profile_name.clone(), |
| 280 | device_name: di.device_name.clone(), |
| 281 | dev_eui: di.dev_eui.clone(), |
| 282 | tags: serde_json::to_value(&di.tags)?, |
| 283 | dev_addr: pl.dev_addr.clone(), |
| 284 | adr: pl.adr, |
| 285 | dr: pl.dr as i16, |
| 286 | f_cnt: pl.f_cnt as i64, |
| 287 | f_port: pl.f_port as i16, |
| 288 | confirmed: pl.confirmed, |
| 289 | data: pl.data.clone(), |
| 290 | object: serde_json::to_value(&pl.object)?, |
| 291 | rx_info: serde_json::to_value(&pl.rx_info)?, |
| 292 | tx_info: serde_json::to_value(&pl.tx_info)?, |
| 293 | }; |
| 294 | let mut c = self.pg_pool.get().await?; |
| 295 | |
| 296 | diesel::insert_into(event_up::table) |
| 297 | .values(&e) |
| 298 | .execute(&mut c) |
| 299 | .await?; |
| 300 | Ok(()) |
| 301 | } |
| 302 | |
| 303 | async fn join_event( |
| 304 | &self, |