Bläddra i källkod

规批交接样同步

晋江
OCEAN 1 månad sedan
förälder
incheckning
65b1fa7b6c
3 ändrade filer med 144 tillägg och 7 borttagningar
  1. +3
    -3
      tcp_client/config.toml
  2. +5
    -0
      tcp_client/config_send.toml
  3. +136
    -4
      tcp_server/src/main.rs

+ 3
- 3
tcp_client/config.toml Visa fil

@@ -20,9 +20,9 @@ user = "postgres"
password = "Auseft@2025qwer"

# 要同步的表配置

[[tables]]
name = "comm_sp_delivering_sampling"
query = "SELECT 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::text as delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time, sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit, sampling_weight::text as 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 FROM comm_sp_delivering_sampling "
name = "comm_bch_delivering_sampling"
query = "SELECT id, tenant_id, supply_id, material_id, sample_type, operation_type, business_type, delivering_type, delivering_code, delivering_quantity, delivering_unit, delivering_weight::text as delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time, sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit, sampling_weight::text as 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 FROM comm_bch_delivering_sampling "
incremental = false
key_field = "UpdateTime"


+ 5
- 0
tcp_client/config_send.toml Visa fil

@@ -22,6 +22,11 @@ password = "Auseft@2025qwer"
# 要同步的表配置


[[tables]]
name = "comm_sp_delivering_sampling"
query = "SELECT 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::text as delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time, sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit, sampling_weight::text as 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 FROM comm_sp_delivering_sampling "
incremental = false
key_field = "UpdateTime"





+ 136
- 4
tcp_server/src/main.rs Visa fil

@@ -501,7 +501,7 @@ struct HySpotcheck {
st_daf: Option<Decimal>,
}

///
#[derive(Debug, Deserialize)]
struct CommSpDeliveringSampling {
id: i64,
@@ -544,6 +544,49 @@ struct CommSpDeliveringSampling {
deletion_time: Option<NaiveDateTime>
}



#[derive(Debug, Deserialize)]
struct CommBchDeliveringSampling {
id: i64,
tenant_id: Option<i64>,
supply_id: i64,
material_id: i64,
sample_type: i32,
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> {
let host = config.get_string("database.host").unwrap();
let port = config.get_int("database.port").unwrap() as u16;
@@ -1125,6 +1168,80 @@ async fn insert_comm_sp_delivering_sampling(client: &tokio_postgres::Client, inf
Ok(())
}



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

if exists {
// 如果记录存在,执行更新操作
client.execute(
"UPDATE public.comm_bch_delivering_sampling
SET tenant_id = $2, supply_id = $3, material_id = $4, sample_type = $5,
deletion_time = $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
WHERE id = $1",
&[
&info.id, &info.tenant_id, &info.supply_id, &info.material_id, &info.sample_type,
&info.deletion_time, &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
],
).await?;
println!("成功更新归批交接样信息: ID {}", info.id);
return Ok(());
}

// 如果记录不存在,执行插入操作
client.execute(
"INSERT INTO public.comm_bch_delivering_sampling (
id, tenant_id, supply_id, material_id, sample_type, deletion_time, 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
) 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)",
&[
&info.id, &info.tenant_id, &info.supply_id, &info.material_id, &info.sample_type, &info.deletion_time,
&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
],
).await?;

println!("成功插入归批交接样信息: ID {}", info.id);
Ok(())
}

async fn insert_laboratory_instrument(client: &tokio_postgres::Client, info: &HyLaboratoryInstrument) -> Result<(), PgError> {
let exists = client
.query_one(
@@ -1520,16 +1637,31 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client)
},
"comm_sp_delivering_sampling" => {
if let Ok(info) = serde_json::from_str::<CommSpDeliveringSampling>(data_str) {
println!("接收到特殊交付采样信息: {:?}", info);
println!("接收到制样交接样信息: {:?}", info);
match insert_comm_sp_delivering_sampling(client, &info).await {
Ok(_) => true,
Err(e) => {
eprintln!("插入特殊交付采样信息失败: {}", e);
eprintln!("插入制样交接样信息失败: {}", e);
false
}
}
} else {
eprintln!("解析制样交接样信息失败");
false
}
},
"comm_bch_delivering_sampling" => {
if let Ok(info) = serde_json::from_str::<CommBchDeliveringSampling>(data_str) {
println!("接收到归批交接样信息: {:?}", info);
match insert_comm_bch_delivering_sampling(client, &info).await {
Ok(_) => true,
Err(e) => {
eprintln!("插入归批交接样信息失败: {}", e);
false
}
}
} else {
eprintln!("解析特殊交付采样信息失败");
eprintln!("解析归批交接样信息失败");
false
}
},


Laddar…
Avbryt
Spara