From 80c8c6ce75e4a08ddf783ef84357bdeae1b5a5e9 Mon Sep 17 00:00:00 2001 From: OCEAN <1010331798@qq.com> Date: Mon, 21 Apr 2025 10:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tcp_client/config.toml | 7 ++++--- tcp_server/src/main.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tcp_client/config.toml b/tcp_client/config.toml index 8fa73db..9cda355 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -1,6 +1,6 @@ [server] -#host = "10.180.4.88" -host = "127.0.0.1" +host = "10.180.4.88" +#host = "127.0.0.1" port = 9090 [client] @@ -10,7 +10,8 @@ read_timeout_secs = 5 write_timeout_secs = 5 [database] -host = "10.180.4.100" +#host = "10.180.4.100" +host = "192.168.0.100" port = 5432 name = "Auseft_RL_Web" user = "postgres" diff --git a/tcp_server/src/main.rs b/tcp_server/src/main.rs index 1a0b937..379561d 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -812,6 +812,22 @@ async fn insert_spotcheck(client: &tokio_postgres::Client, info: &HySpotcheck) - } async fn insert_sample_delivery(client: &tokio_postgres::Client, info: &HySampleDelivery) -> Result<(), PgError> { + + // 先检查 ID 是否存在 + let exists = client + .query_one( + "SELECT EXISTS(SELECT 1 FROM public.hy_sample_delivery WHERE id = $1)", + &[&info.id], + ) + .await? + .get::<_, bool>(0); + +if exists { + println!("ID {} 已存在,跳过插入", info.id); + return Ok(()); +} + + client.execute( "INSERT INTO public.hy_sample_delivery ( id, sample_number, coal_sample, sample_weight, sampler_user, state, @@ -838,6 +854,21 @@ async fn insert_sample_delivery(client: &tokio_postgres::Client, info: &HySample } async fn insert_task(client: &tokio_postgres::Client, info: &HyTask) -> Result<(), PgError> { + // 先检查 ID 是否存在 + let exists = client + .query_one( + "SELECT EXISTS(SELECT 1 FROM public.hy_task WHERE id = $1)", + &[&info.id], + ) + .await? + .get::<_, bool>(0); + +if exists { + println!("ID {} 已存在,跳过插入", info.id); + return Ok(()); +} + + client.execute( "INSERT INTO public.hy_task ( id, task_name, task_type, task_num, is_auto, task_time, state,