Просмотр исходного кода

增加是否存在的判断

晋江
OCEAN 2 месяцев назад
Родитель
Сommit
80c8c6ce75
2 измененных файлов: 35 добавлений и 3 удалений
  1. +4
    -3
      tcp_client/config.toml
  2. +31
    -0
      tcp_server/src/main.rs

+ 4
- 3
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"


+ 31
- 0
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,


Загрузка…
Отмена
Сохранить