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,