diff --git a/src/download_wrapper.rs b/src/download_wrapper.rs index 4170388..c4fc035 100644 --- a/src/download_wrapper.rs +++ b/src/download_wrapper.rs @@ -49,8 +49,8 @@ impl Default for DownloadWrapper { .join("commander/Simplicity Commander/commander.exe"), bin_path: PathBuf::from(std::env::current_dir().unwrap()).join("bin/"), bootloader_name: String::from("RAWM00-2-0-0_silicon-wisun_bootloader_D20241008.s37"), - app_name: String::from("RAWM00-2-0-0_silicon-wisun_APP-V1_D20240927.s37"), - rail_name: String::from("rail_soc_railtest_sisdk.s37"), + app_name: String::from("RAWM00-2-0-0_silicon-combine-V1-D20241230-BZ.hex"), + rail_name: String::from("rail_soc_railtest_sisdk(silabs).hex"), } } } diff --git a/src/main.rs b/src/main.rs index 9894a51..0ca7267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ use std::any::Any; use std::fs; use std::io::Write; use std::sync::{Arc, LazyLock, Mutex}; +use std::thread::sleep; pub fn main() -> iced::Result { iced::application("WisunDownload V0.1", MainWindow::update, MainWindow::view) @@ -208,6 +209,7 @@ impl MainWindow { }else{ self.result_background = Color::from_rgb8(255, 0,0); } + self.label = "".to_string(); Task::none() } Message::WindowEvent(event) => { @@ -297,7 +299,13 @@ impl MainWindow { add_log("请输入Label".to_string()); return; } + if label.contains(":"){ + add_log("Label不合法".to_string()); + self.label = "".to_string(); + return; + } std::thread::spawn(move || { + sleep(std::time::Duration::from_secs(5)); let mut download_wrapper = download_wrapper::DownloadWrapper::new(); let mut mes_service: MesService; sender.send(Message::ClearLog).unwrap(); diff --git a/src/mes_service.rs b/src/mes_service.rs index 5a1b51f..f66c782 100644 --- a/src/mes_service.rs +++ b/src/mes_service.rs @@ -39,23 +39,25 @@ impl MesService { DownloadType::Rail => { let mut conn = self.pool.get_conn()?; let check_result: Vec = conn.query(format!( - "SELECT `Station2` 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::App => { let mut conn = self.pool.get_conn()?; let check_result: Vec = conn.query(format!( - "SELECT * FROM {work_order} WHERE `Barcode` = {label}" + "SELECT `IMEI_1` FROM `{work_order}` WHERE `Barcode` = '{label}';" ))?; if check_result.is_empty() { - return Ok(true); + Ok(true) + } else { + Ok(false) } - Ok(false) } + DownloadType::Bootloader => Ok(true), } } @@ -65,6 +67,7 @@ impl MesService { label: String, download_type: DownloadType, ) -> Result<(), Error> { + let time_now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(); match download_type { DownloadType::Bootloader => {} DownloadType::App => { @@ -75,8 +78,11 @@ 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') \ - ON DUPLICATE KEY UPDATE `Barcode` = VALUES(`Barcode`), `IMEI_1` = VALUES(`IMEI_1`), `Station1` = VALUES(`Station1`)" + "INSERT INTO `{work_order}` (`ID`, `Barcode`, `IMEI_1`, `Station1`, `Station1Time`) VALUES ( {work_order_id}, '{label}', '{label}', '1', '{time_now}') \ + ON DUPLICATE KEY UPDATE `Barcode` = VALUES(`Barcode`), `IMEI_1` = VALUES(`IMEI_1`), `Station1` = VALUES(`Station1`), `Station1Time`= VALUES(`Station1Time`)", + work_order_id = work_order_id, + label = label, + time_now = time_now ), () )?; @@ -87,7 +93,7 @@ impl MesService { DownloadType::Rail => { let mut conn = self.pool.get_conn()?; let _: Vec = conn.exec( - format!("UPDATE {work_order} SET `Station3` = 1 WHERE `Barcode` = '{label}'"), + format!("UPDATE `{work_order}` SET Station3 = 1, Station3Time='{time_now}' WHERE Barcode = '{label}'"), (), )?; } @@ -110,6 +116,7 @@ impl MesService { #[cfg(test)] mod test { use crate::mes_service::MesService; + use mysql::prelude::*; #[test] fn test_mes_service() { @@ -135,4 +142,24 @@ mod test { assert_ne!(work_orders.len(), 0); println!("{:?}", work_orders); } + + #[test] + fn test_check_station() { + let mes = MesService::new( + "192.168.1.17".to_string(), + "3306".to_string(), + "root".to_string(), + "".to_string(), + "MOBILETEK_WISUN".to_string(), + ); + let mut conn = mes.unwrap().pool.get_conn().unwrap(); + let work_order = "3333"; + let label = "202400154Y000016"; + let check_result: Vec = conn + .query(format!( + "SELECT `COUNT` FROM `{work_order}` WHERE `Barcode` = '{label}';" + )) + .unwrap(); + println!("{:?}", check_result); + } }