Ver código fonte

增加发货计划及明细

晋江
OCEAN 1 mês atrás
pai
commit
89fa91e1d3
5 arquivos alterados com 219 adições e 7 exclusões
  1. +3
    -3
      tcp_client/config.toml
  2. +215
    -3
      tcp_server/src/main.rs
  3. +1
    -1
      tcp_server/target/.rustc_info.json
  4. BIN
      tcp_server/target/debug/tcp_server.exe
  5. BIN
      tcp_server/target/debug/tcp_server.pdb

+ 3
- 3
tcp_client/config.toml Ver arquivo

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

[[tables]]
name = "erp_shipping_plan"
query = "SELECT id, cust_id, material_id, plan_type, plan_start_date, plan_end_date, plan_days, plan_quantity::text as plan_quantity, through_put::text as through_put, calorific_value::text as calorific_value, sulfur_content::text as sulfur_content, transport_vehicles, sample_code, batch_code, update_by, update_time, review, review_by, review_date, cancel, cancel_by, cancel_time, remarks, plan_number, order_number, warehouse_id, order_type, cust_name, material_name, plan_name, warehouse_name FROM public.erp_shipping_plan"
name = "erp_shipping_details"
query = "SELECT id, plan_id, vehicle_id, vehicle_number, gross_weight::text as gross_weight, tare_weight::text as tare_weight, net_weight::text as net_weight, card_number, appointment_number, appointment_time, appointment_weight::text as appointment_weight, is_cancel, is_end, driver_phone, remarks, create_time, create_by, update_time, update_by FROM public.erp_shipping_details"
incremental = false
key_field = "UpdateTime"
key_field = "UpdateTime"

+ 215
- 3
tcp_server/src/main.rs Ver arquivo

@@ -533,6 +533,68 @@ struct ErpMatlMaterial {
deletion_time: Option<NaiveDateTime>
}

#[derive(Debug, Deserialize)]
struct ErpShippingPlan {
id: i64,
cust_id: i64,
material_id: i64,
plan_type: i64,
plan_start_date: NaiveDateTime,
plan_end_date: Option<NaiveDateTime>,
plan_days: Option<i64>,
plan_quantity: Option<Decimal>,
through_put: Option<Decimal>,
calorific_value: Option<Decimal>,
sulfur_content: Option<Decimal>,
transport_vehicles: Option<i64>,
sample_code: Option<String>,
batch_code: Option<String>,
update_by: Option<String>,
update_time: Option<NaiveDateTime>,
#[serde(deserialize_with = "deserialize_string_to_bool")]
review: bool,
review_by: Option<String>,
review_date: Option<NaiveDateTime>,
#[serde(deserialize_with = "deserialize_string_to_bool")]
cancel: bool,
cancel_by: Option<String>,
cancel_time: Option<NaiveDateTime>,
remarks: Option<String>,
plan_number: String,
order_number: Option<String>,
warehouse_id: Option<i64>,
order_type: Option<String>,
cust_name: Option<String>,
material_name: Option<String>,
plan_name: Option<String>,
warehouse_name: Option<String>
}

#[derive(Debug, Deserialize)]
struct ErpShippingDetails {
id: i64,
plan_id: i64,
vehicle_id: Option<i64>,
vehicle_number: Option<String>,
gross_weight: Option<Decimal>,
tare_weight: Option<Decimal>,
net_weight: Option<Decimal>,
card_number: Option<String>,
appointment_number: Option<String>,
appointment_time: Option<NaiveDateTime>,
appointment_weight: Option<Decimal>,
#[serde(deserialize_with = "deserialize_string_to_bool")]
is_cancel: bool,
#[serde(deserialize_with = "deserialize_string_to_bool")]
is_end: bool,
driver_phone: Option<String>,
remarks: Option<String>,
create_time: Option<NaiveDateTime>,
create_by: Option<String>,
update_time: Option<NaiveDateTime>,
update_by: Option<String>
}

#[derive(Debug, Deserialize)]
struct CommBmVehicleinfo {
id: i32,
@@ -822,7 +884,7 @@ async fn insert_erp_co_supply(client: &tokio_postgres::Client, info: &ErpCoSuppl
description, status, enabled, enabler_id, enablement_time,
creator_id, creation_time, last_modifier_id, last_modification_time,
deleted, deleter_id, deletion_time
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14,
) OVERRIDING SYSTEM VALUE 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)",
&[
@@ -885,7 +947,7 @@ async fn insert_erp_matl_material(client: &tokio_postgres::Client, info: &ErpMat
status, enabled, enabler_id, enablement_time, creator_id,
creation_time, last_modifier_id, last_modification_time,
deleted, deleter_id, deletion_time
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13,
) OVERRIDING SYSTEM VALUE 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)",
&[
@@ -903,6 +965,126 @@ async fn insert_erp_matl_material(client: &tokio_postgres::Client, info: &ErpMat
Ok(())
}

async fn insert_erp_shipping_plan(client: &tokio_postgres::Client, info: &ErpShippingPlan) -> Result<(), PgError> {
// Check if record exists
let exists = client
.query_one(
"SELECT COUNT(*) FROM public.erp_shipping_plan WHERE id = $1",
&[&info.id]
)
.await?
.get::<_, i64>(0) > 0;

if exists {
// Update existing record
client.execute(
"UPDATE public.erp_shipping_plan SET
cust_id = $2, material_id = $3, plan_type = $4, plan_start_date = $5,
plan_end_date = $6, plan_days = $7, plan_quantity = $8, through_put = $9,
calorific_value = $10, sulfur_content = $11, transport_vehicles = $12,
sample_code = $13, batch_code = $14, update_by = $15, update_time = $16,
review = $17, review_by = $18, review_date = $19, cancel = $20,
cancel_by = $21, cancel_time = $22, remarks = $23, plan_number = $24,
order_number = $25, warehouse_id = $26, order_type = $27, cust_name = $28,
material_name = $29, plan_name = $30, warehouse_name = $31
WHERE id = $1",
&[
&info.id, &info.cust_id, &info.material_id, &info.plan_type,
&info.plan_start_date, &info.plan_end_date, &info.plan_days,
&info.plan_quantity, &info.through_put, &info.calorific_value,
&info.sulfur_content, &info.transport_vehicles, &info.sample_code,
&info.batch_code, &info.update_by, &info.update_time, &info.review,
&info.review_by, &info.review_date, &info.cancel, &info.cancel_by,
&info.cancel_time, &info.remarks, &info.plan_number, &info.order_number,
&info.warehouse_id, &info.order_type, &info.cust_name, &info.material_name,
&info.plan_name, &info.warehouse_name
],
).await?;
} else {
// Insert new record, note that id is GENERATED ALWAYS AS IDENTITY
client.execute(
"INSERT INTO public.erp_shipping_plan (
cust_id, material_id, plan_type, plan_start_date,
plan_end_date, plan_days, plan_quantity, through_put,
calorific_value, sulfur_content, transport_vehicles,
sample_code, batch_code, update_by, update_time,
review, review_by, review_date, cancel,
cancel_by, cancel_time, remarks, plan_number,
order_number, warehouse_id, order_type, cust_name,
material_name, plan_name, warehouse_name
) OVERRIDING SYSTEM VALUE 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)",
&[
&info.cust_id, &info.material_id, &info.plan_type,
&info.plan_start_date, &info.plan_end_date, &info.plan_days,
&info.plan_quantity, &info.through_put, &info.calorific_value,
&info.sulfur_content, &info.transport_vehicles, &info.sample_code,
&info.batch_code, &info.update_by, &info.update_time, &info.review,
&info.review_by, &info.review_date, &info.cancel, &info.cancel_by,
&info.cancel_time, &info.remarks, &info.plan_number, &info.order_number,
&info.warehouse_id, &info.order_type, &info.cust_name, &info.material_name,
&info.plan_name, &info.warehouse_name
],
).await?;
}
Ok(())
}

async fn insert_erp_shipping_details(client: &tokio_postgres::Client, info: &ErpShippingDetails) -> Result<(), PgError> {
// Check if record exists using plan_id and vehicle_number
let exists = client
.query_one(
"SELECT COUNT(*) FROM public.erp_shipping_details WHERE plan_id = $1 ",
&[&info.plan_id]
)
.await?
.get::<_, i64>(0) > 0;

if exists {
// Update existing record
client.execute(
"UPDATE public.erp_shipping_details SET
vehicle_id = $1, gross_weight = $2, tare_weight = $3,
net_weight = $4, card_number = $5, appointment_number = $6,
appointment_time = $7, appointment_weight = $8, is_cancel = $9,
is_end = $10, driver_phone = $11, remarks = $12,
create_time = $13, create_by = $14, update_time = $15,
update_by = $16, vehicle_number = $18,plan_id = $17
WHERE id = $19 ",
&[
&info.vehicle_id, &info.gross_weight, &info.tare_weight,
&info.net_weight, &info.card_number, &info.appointment_number,
&info.appointment_time, &info.appointment_weight, &info.is_cancel,
&info.is_end, &info.driver_phone, &info.remarks,
&info.create_time, &info.create_by, &info.update_time,
&info.update_by, &info.plan_id, &info.vehicle_number,&info.id
],
).await?;
} else {
// Insert new record
client.execute(
"INSERT INTO public.erp_shipping_details (
plan_id, vehicle_id, vehicle_number, gross_weight,
tare_weight, net_weight, card_number, appointment_number,
appointment_time, appointment_weight, is_cancel, is_end,
driver_phone, remarks, create_time, create_by,
update_time, update_by,id
) OVERRIDING SYSTEM VALUE VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12,
$13, $14, $15, $16, $17, $18,$19)",
&[
&info.plan_id, &info.vehicle_id, &info.vehicle_number,
&info.gross_weight, &info.tare_weight, &info.net_weight,
&info.card_number, &info.appointment_number, &info.appointment_time,
&info.appointment_weight, &info.is_cancel, &info.is_end,
&info.driver_phone, &info.remarks, &info.create_time,
&info.create_by, &info.update_time, &info.update_by, &info.id
],
).await?;
}
Ok(())
}

async fn insert_vehicle_info(client: &tokio_postgres::Client, info: &CommBmVehicleinfo) -> Result<(), PgError> {
let exists = client
.query_one(
@@ -956,7 +1138,7 @@ async fn insert_vehicle_info(client: &tokio_postgres::Client, info: &CommBmVehic
rfidgranttime, samplingpoints, drawbar, carriagelength, carriagewidth,
carriageheight, underbodyheight, frontsampling, backsampling, rod1, rod2,
rod3, rod4, rod5, rod6, supplier_id, supplier_name, material_id, material_name
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15,
) OVERRIDING SYSTEM VALUE 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, $37, $38, $39, $40, $41,
$42, $43, $44, $45, $46, $47)",
@@ -2147,6 +2329,36 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client)
false
}
},
"erp_shipping_plan" => {
if let Ok(info) = serde_json::from_str::<ErpShippingPlan>(data_str) {
println!("接收到发运计划信息: {:?}", info);
match insert_erp_shipping_plan(client, &info).await {
Ok(_) => true,
Err(e) => {
eprintln!("插入发运计划信息失败: {}", e);
false
}
}
} else {
eprintln!("解析发运计划信息失败");
false
}
},
"erp_shipping_details" => {
if let Ok(info) = serde_json::from_str::<ErpShippingDetails>(data_str) {
println!("接收到发运明细信息: {:?}", info);
match insert_erp_shipping_details(client, &info).await {
Ok(_) => true,
Err(e) => {
eprintln!("插入发运明细信息失败: {}", e);
false
}
}
} else {
eprintln!("解析发运明细信息失败");
false
}
},
_ => {
eprintln!("未知的表名: {}", table_name);
false


+ 1
- 1
tcp_server/target/.rustc_info.json Ver arquivo

@@ -1 +1 @@
{"rustc_fingerprint":3807311574931242264,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.0 (4d91de4e4 2025-02-17)\nbinary: rustc\ncommit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688\ncommit-date: 2025-02-17\nhost: x86_64-pc-windows-msvc\nrelease: 1.85.0\nLLVM version: 19.1.7\n","stderr":""},"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\qq101\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
{"rustc_fingerprint":3807311574931242264,"outputs":{"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\qq101\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.0 (4d91de4e4 2025-02-17)\nbinary: rustc\ncommit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688\ncommit-date: 2025-02-17\nhost: x86_64-pc-windows-msvc\nrelease: 1.85.0\nLLVM version: 19.1.7\n","stderr":""}},"successes":{}}

BIN
tcp_server/target/debug/tcp_server.exe Ver arquivo


BIN
tcp_server/target/debug/tcp_server.pdb Ver arquivo


Carregando…
Cancelar
Salvar