|
|
@@ -41,6 +41,21 @@ async fn connect_db(config: &Config) -> Result<tokio_postgres::Client, PgError> |
|
|
|
} |
|
|
|
|
|
|
|
async fn insert_instrument(client: &tokio_postgres::Client, info: &InstrumentInfo) -> Result<(), PgError> { |
|
|
|
// 先检查 ID 是否存在 |
|
|
|
let exists = client |
|
|
|
.query_one( |
|
|
|
"SELECT EXISTS(SELECT 1 FROM public.hy_instrument WHERE id = $1)", |
|
|
|
&[&info.id], |
|
|
|
) |
|
|
|
.await? |
|
|
|
.get::<_, bool>(0); |
|
|
|
|
|
|
|
if exists { |
|
|
|
println!("ID {} 已存在,跳过插入", info.id); |
|
|
|
return Ok(()); |
|
|
|
} |
|
|
|
|
|
|
|
// ID 不存在,执行插入 |
|
|
|
client.execute( |
|
|
|
"INSERT INTO public.hy_instrument (id, informationid, instrumentcode, laboratoryid, name, remark, specification) |
|
|
|
OVERRIDING SYSTEM VALUE |
|
|
@@ -57,7 +72,7 @@ async fn insert_instrument(client: &tokio_postgres::Client, info: &InstrumentInf |
|
|
|
) |
|
|
|
.await?; |
|
|
|
|
|
|
|
println!("成功插入仪器信息: {}", info.instrumentcode); |
|
|
|
println!("成功插入仪器信息: {} (ID: {})", info.instrumentcode, info.id); |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|