diff --git a/tcp_client/config.toml b/tcp_client/config.toml index bbabbb1..3a434ee 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -1,6 +1,7 @@ [server] -host = "10.180.4.88" -#host = "127.0.0.1" +#host = "10.180.4.88" +host = "127.0.0.1" + port = 9090 [client] diff --git a/tcp_server/src/main.rs b/tcp_server/src/main.rs index 35db11f..8ce889a 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -33,19 +33,15 @@ struct RecordInfo { id: i32, hy_code: Option, r#type: Option, - hy_check: Option, - hy_approve: Option, - #[serde(default)] - check_time: Option, - #[serde(default)] - approve_time: Option, + hy_check: i32, + hy_approve: i32, + check_time: Option, + approve_time: Option, approve_user: Option, check_user: Option, - #[serde(default)] - hy_time: Option, + hy_time: Option, hy_values: Option, - #[serde(default)] - accept_time: Option, + accept_time: Option, accept_user: Option, mt: Option, mad: Option, @@ -74,9 +70,9 @@ struct RecordInfo { st_daf: Option, cad: Option, cd: Option, - isauto: Option, + isauto: Option, hy_type: Option, - isnormal: Option, + isnormal: i32, } #[derive(Debug, Deserialize)] @@ -602,6 +598,16 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re .await? .get::<_, bool>(0); + // 解析时间字段 + let check_time = info.check_time.as_deref() + .and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok()); + let approve_time = info.approve_time.as_deref() + .and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok()); + let hy_time = info.hy_time.as_deref() + .and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok()); + let accept_time = info.accept_time.as_deref() + .and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok()); + if exists { // 如果记录存在,执行更新操作 client.execute( @@ -617,15 +623,15 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re cd = $40, isauto = $41, hy_type = $42, isnormal = $43 WHERE id = $1", &[ - &info.id, &info.hy_code, &info.r#type, &info.hy_check, &info.hy_approve, - &info.check_time, &info.approve_time, &info.approve_user, &info.check_user, - &info.hy_time, &info.hy_values, &info.accept_time, &info.accept_user, - &info.mt, &info.mad, &info.aad, &info.ad, &info.vad, &info.vd, - &info.var, &info.vdaf, &info.fcad, &info.st_ar, &info.st_ad, - &info.st_d, &info.had, &info.hd, &info.qb_ad, &info.qgr_ad, - &info.qgr_d, &info.qnet_ar_mj_kg, &info.qnet_ar_j_cal, &info.v, - &info.aar, &info.qnet_ar, &info.qnet_ar1, &info.crc, &info.st_daf, - &info.cad, &info.cd, &info.isauto, &info.hy_type, &info.isnormal + &info.id, &info.hy_code, &info.r#type, &(info.hy_check as i16), &(info.hy_approve as i16), + &check_time, &approve_time, &info.approve_user, &info.check_user, + &hy_time, &info.hy_values, &accept_time, &info.accept_user, + &info.mt, &info.mad, &info.aad, &info.ad, &info.vad, &info.vd, &info.var, + &info.vdaf, &info.fcad, &info.st_ar, &info.st_ad, &info.st_d, + &info.had, &info.hd, &info.qb_ad, &info.qgr_ad, &info.qgr_d, + &info.qnet_ar_mj_kg, &info.qnet_ar_j_cal, &info.v, &info.aar, + &info.qnet_ar, &info.qnet_ar1, &info.crc, &info.st_daf, &info.cad, + &info.cd, &info.isauto.map(|x| x as i16), &info.hy_type, &(info.isnormal as i32) ], ).await?; println!("成功更新记录信息: ID {}", info.id); @@ -645,21 +651,22 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re qnet_ar, qnet_ar1, crc, st_daf, cad, cd, isauto, hy_type, isnormal ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, - $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, - $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, - $39, $40, $41, $42, $43 + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, + $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, + $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, + $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, + $41, $42, $43 )", &[ - &info.id, &info.hy_code, &info.r#type, &info.hy_check, &info.hy_approve, - &info.check_time, &info.approve_time, &info.approve_user, &info.check_user, - &info.hy_time, &info.hy_values, &info.accept_time, &info.accept_user, - &info.mt, &info.mad, &info.aad, &info.ad, &info.vad, &info.vd, - &info.var, &info.vdaf, &info.fcad, &info.st_ar, &info.st_ad, - &info.st_d, &info.had, &info.hd, &info.qb_ad, &info.qgr_ad, - &info.qgr_d, &info.qnet_ar_mj_kg, &info.qnet_ar_j_cal, &info.v, - &info.aar, &info.qnet_ar, &info.qnet_ar1, &info.crc, &info.st_daf, - &info.cad, &info.cd, &info.isauto, &info.hy_type, &info.isnormal + &info.id, &info.hy_code, &info.r#type, &(info.hy_check as i16), &(info.hy_approve as i16), + &check_time, &approve_time, &info.approve_user, &info.check_user, + &hy_time, &info.hy_values, &accept_time, &info.accept_user, + &info.mt, &info.mad, &info.aad, &info.ad, &info.vad, &info.vd, &info.var, + &info.vdaf, &info.fcad, &info.st_ar, &info.st_ad, &info.st_d, + &info.had, &info.hd, &info.qb_ad, &info.qgr_ad, &info.qgr_d, + &info.qnet_ar_mj_kg, &info.qnet_ar_j_cal, &info.v, &info.aar, + &info.qnet_ar, &info.qnet_ar1, &info.crc, &info.st_daf, &info.cad, + &info.cd, &info.isauto.map(|x| x as i16), &info.hy_type, &(info.isnormal as i32) ], ).await?; diff --git a/tcp_server/target/debug/tcp_server.exe b/tcp_server/target/debug/tcp_server.exe index ca96acb..e611ed0 100644 Binary files a/tcp_server/target/debug/tcp_server.exe and b/tcp_server/target/debug/tcp_server.exe differ diff --git a/tcp_server/target/debug/tcp_server.pdb b/tcp_server/target/debug/tcp_server.pdb index 0f481d9..e4d785b 100644 Binary files a/tcp_server/target/debug/tcp_server.pdb and b/tcp_server/target/debug/tcp_server.pdb differ