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

增加comm_sp_delivering_sampling的同步

晋江
OCEAN 1 месяц назад
Родитель
Сommit
cf6d91d541
2 измененных файлов: 156 добавлений и 9 удалений
  1. +1
    -2
      tcp_server/config.toml
  2. +155
    -7
      tcp_server/src/main.rs

+ 1
- 2
tcp_server/config.toml Просмотреть файл

@@ -4,8 +4,7 @@ port = 9090

[database]
host = "10.180.4.100"
#host = "192.168.0.100"
port = 5432
name = "Auseft_RL_WEB_3"
name = "Auseft_new_web_20250514"
user = "postgres"
password = "Auseft@2025qwer"

+ 155
- 7
tcp_server/src/main.rs Просмотреть файл

@@ -2,7 +2,19 @@ use tokio::net::{TcpListener, TcpStream};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use config::Config;
use tokio_postgres::{NoTls, Error as PgError};
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, Deserializer};

fn deserialize_string_to_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
match s.as_str() {
"1" | "true" => Ok(true),
"0" | "false" => Ok(false),
_ => Err(serde::de::Error::custom(format!("无效的布尔值: {}", s))),
}
}
use std::sync::Arc;
use chrono::{NaiveDateTime, NaiveDate};
use std::error::Error;
@@ -462,12 +474,12 @@ struct HySpotcheck {
coal_sample_code: Option<String>,
sample_custodian: Option<String>,
sampling_time: Option<NaiveDateTime>,
quality_incoming: Option<Decimal>,
quality_incoming: Option<String>,
granularity: Option<String>,
spotcheck_compare: Option<String>,
mt: Option<Decimal>,
mad: Option<Decimal>,
aad: Decimal,
aad: Option<Decimal>,
ad: Option<Decimal>,
vad: Option<Decimal>,
vdaf: Option<Decimal>,
@@ -486,7 +498,50 @@ struct HySpotcheck {
hd: Option<Decimal>,
fcad: Option<Decimal>,
crc: Option<Decimal>,
st_daf: Option<Decimal>
st_daf: Option<Decimal>,
}

///
#[derive(Debug, Deserialize)]
struct CommSpDeliveringSampling {
id: i64,
tenant_id: Option<i64>,
supply_id: i64,
material_id: i64,
sample_type: i32,
bch_ds_id: i64,
operation_type: i32,
business_type: i32,
delivering_type: i32,
delivering_code: String,
delivering_quantity: i32,
delivering_unit: String,
delivering_weight: Option<Decimal>,
delivering_weights: Option<String>,
delivering_remark: Option<String>,
deliverer: String,
delivery_time: NaiveDateTime,
#[serde(deserialize_with = "deserialize_string_to_bool")]
sampling: bool,
sampling_type: i32,
sampling_code: String,
sampling_quantity: i32,
sampling_unit: String,
sampling_weight: Option<Decimal>,
sampling_weights: Option<String>,
sampling_remark: Option<String>,
sampler: String,
sample_time: NaiveDateTime,
creator_id: Option<i64>,
creation_time: NaiveDateTime,
last_modifier_id: Option<i64>,
last_modification_reason: Option<String>,
last_modification_time: Option<NaiveDateTime>,
#[serde(deserialize_with = "deserialize_string_to_bool")]
deleted: bool,
deleter_id: Option<i64>,
deletion_reason: Option<String>,
deletion_time: Option<NaiveDateTime>
}

async fn connect_db(config: &Config) -> Result<tokio_postgres::Client, PgError> {
@@ -978,17 +1033,95 @@ async fn insert_weight_input(client: &tokio_postgres::Client, info: &HyWeightInp
.get::<_, bool>(0);

if exists {
println!("ID {} 已存在,跳过插入", info.id);
client.execute(
"UPDATE public.hy_weight_input
SET information_id = $2, information_norm_id = $3
WHERE id = $1",
&[&info.id, &info.information_id, &info.information_norm_id],
).await?;
println!("成功更新重量输入信息: ID {}", info.id);
return Ok(());
}

client.execute(
"INSERT INTO public.hy_weight_input (id, information_id, information_norm_id) OVERRIDING SYSTEM VALUE
"INSERT INTO public.hy_weight_input (id, information_id, information_norm_id)
VALUES ($1, $2, $3)",
&[&info.id, &info.information_id, &info.information_norm_id],
).await?;

println!("成功插入重量输入: ID {}", info.id);
println!("成功插入重量输入信息: ID {}", info.id);
Ok(())
}

async fn insert_comm_sp_delivering_sampling(client: &tokio_postgres::Client, info: &CommSpDeliveringSampling) -> Result<(), PgError> {
let exists = client
.query_one(
"SELECT EXISTS(SELECT 1 FROM public.comm_sp_delivering_sampling WHERE id = $1)",
&[&info.id],
)
.await?
.get::<_, bool>(0);

if exists {
// 如果记录存在,执行更新操作
client.execute(
"UPDATE public.comm_sp_delivering_sampling
SET tenant_id = $2, supply_id = $3, material_id = $4, sample_type = $5,
bch_ds_id = $6, operation_type = $7, business_type = $8, delivering_type = $9,
delivering_code = $10, delivering_quantity = $11, delivering_unit = $12,
delivering_weight = $13, delivering_weights = $14, delivering_remark = $15,
deliverer = $16, delivery_time = $17, sampling = $18, sampling_type = $19,
sampling_code = $20, sampling_quantity = $21, sampling_unit = $22,
sampling_weight = $23, sampling_weights = $24, sampling_remark = $25,
sampler = $26, sample_time = $27, creator_id = $28, creation_time = $29,
last_modifier_id = $30, last_modification_reason = $31, last_modification_time = $32,
deleted = $33, deleter_id = $34, deletion_reason = $35, deletion_time = $36
WHERE id = $1",
&[
&info.id, &info.tenant_id, &info.supply_id, &info.material_id, &info.sample_type,
&info.bch_ds_id, &info.operation_type, &info.business_type, &info.delivering_type,
&info.delivering_code, &info.delivering_quantity, &info.delivering_unit,
&info.delivering_weight, &info.delivering_weights, &info.delivering_remark,
&info.deliverer, &info.delivery_time, &info.sampling, &info.sampling_type,
&info.sampling_code, &info.sampling_quantity, &info.sampling_unit,
&info.sampling_weight, &info.sampling_weights, &info.sampling_remark,
&info.sampler, &info.sample_time, &info.creator_id, &info.creation_time,
&info.last_modifier_id, &info.last_modification_reason, &info.last_modification_time,
&info.deleted, &info.deleter_id, &info.deletion_reason, &info.deletion_time
],
).await?;
println!("成功更新特殊交付采样信息: ID {}", info.id);
return Ok(());
}

// 如果记录不存在,执行插入操作
client.execute(
"INSERT INTO public.comm_sp_delivering_sampling (
id, tenant_id, supply_id, material_id, sample_type, bch_ds_id, operation_type,
business_type, delivering_type, delivering_code, delivering_quantity, delivering_unit,
delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time,
sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit,
sampling_weight, sampling_weights, sampling_remark, sampler, sample_time,
creator_id, creation_time, last_modifier_id, last_modification_reason,
last_modification_time, deleted, deleter_id, deletion_reason, deletion_time
) 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)",
&[
&info.id, &info.tenant_id, &info.supply_id, &info.material_id, &info.sample_type,
&info.bch_ds_id, &info.operation_type, &info.business_type, &info.delivering_type,
&info.delivering_code, &info.delivering_quantity, &info.delivering_unit,
&info.delivering_weight, &info.delivering_weights, &info.delivering_remark,
&info.deliverer, &info.delivery_time, &info.sampling, &info.sampling_type,
&info.sampling_code, &info.sampling_quantity, &info.sampling_unit,
&info.sampling_weight, &info.sampling_weights, &info.sampling_remark,
&info.sampler, &info.sample_time, &info.creator_id, &info.creation_time,
&info.last_modifier_id, &info.last_modification_reason, &info.last_modification_time,
&info.deleted, &info.deleter_id, &info.deletion_reason, &info.deletion_time
],
).await?;

println!("成功插入特殊交付采样信息: ID {}", info.id);
Ok(())
}

@@ -1385,6 +1518,21 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client)
false
}
},
"comm_sp_delivering_sampling" => {
if let Ok(info) = serde_json::from_str::<CommSpDeliveringSampling>(data_str) {
println!("接收到特殊交付采样信息: {:?}", info);
match insert_comm_sp_delivering_sampling(client, &info).await {
Ok(_) => true,
Err(e) => {
eprintln!("插入特殊交付采样信息失败: {}", e);
false
}
}
} else {
eprintln!("解析特殊交付采样信息失败");
false
}
},
"hy_laboratoryinstrument" => {
if let Ok(info) = serde_json::from_str::<HyLaboratoryInstrument>(data_str) {
println!("接收到实验室仪器信息: {:?}", info);


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