diff --git a/src/mes_service.rs b/src/mes_service.rs index 1634b49..5a1b51f 100644 --- a/src/mes_service.rs +++ b/src/mes_service.rs @@ -36,18 +36,26 @@ impl MesService { download_type: DownloadType, ) -> Result { match download_type { - DownloadType::App => Ok(true), DownloadType::Rail => { let mut conn = self.pool.get_conn()?; let check_result: Vec = conn.query(format!( - "SELECT `Station1` FROM {work_order} WHERE `Barcode` = {label}" + "SELECT `Station2` FROM {work_order} WHERE `Barcode` = {label}" ))?; if check_result.is_empty() { return Ok(false); } Ok(check_result[0] == "1") } - DownloadType::Bootloader => Err(Error::msg("Not implemented yet")), + _ => { + let mut conn = self.pool.get_conn()?; + let check_result: Vec = conn.query(format!( + "SELECT * FROM {work_order} WHERE `Barcode` = {label}" + ))?; + if check_result.is_empty() { + return Ok(true); + } + Ok(false) + } } } @@ -67,7 +75,7 @@ impl MesService { if let Some(work_order_id) = work_order_id.first() { let _: Vec = conn.exec( format!( - "INSERT INTO {work_order} (`ID`, `Barcode`, `IMEI_1`, `Station1`) VALUES ({work_order_id}, {label}, {label}, '1') \ + "INSERT INTO `{work_order}` (`ID`, `Barcode`, `IMEI_1`, `Station1`) VALUES ( {work_order_id}, '{label}', '{label}', '1') \ ON DUPLICATE KEY UPDATE `Barcode` = VALUES(`Barcode`), `IMEI_1` = VALUES(`IMEI_1`), `Station1` = VALUES(`Station1`)" ), () @@ -79,7 +87,7 @@ impl MesService { DownloadType::Rail => { let mut conn = self.pool.get_conn()?; let _: Vec = conn.exec( - format!("UPDATE {work_order} SET `Station2` = 1 WHERE `Barcode` = {label}"), + format!("UPDATE {work_order} SET `Station3` = 1 WHERE `Barcode` = '{label}'"), (), )?; }