diff --git a/tcp_client/config.toml b/tcp_client/config.toml index 222034a..aca9148 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -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" \ No newline at end of file +key_field = "UpdateTime" diff --git a/tcp_server/src/main.rs b/tcp_server/src/main.rs index 6074087..05e2589 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -533,6 +533,68 @@ struct ErpMatlMaterial { deletion_time: Option } +#[derive(Debug, Deserialize)] +struct ErpShippingPlan { + id: i64, + cust_id: i64, + material_id: i64, + plan_type: i64, + plan_start_date: NaiveDateTime, + plan_end_date: Option, + plan_days: Option, + plan_quantity: Option, + through_put: Option, + calorific_value: Option, + sulfur_content: Option, + transport_vehicles: Option, + sample_code: Option, + batch_code: Option, + update_by: Option, + update_time: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + review: bool, + review_by: Option, + review_date: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + cancel: bool, + cancel_by: Option, + cancel_time: Option, + remarks: Option, + plan_number: String, + order_number: Option, + warehouse_id: Option, + order_type: Option, + cust_name: Option, + material_name: Option, + plan_name: Option, + warehouse_name: Option +} + +#[derive(Debug, Deserialize)] +struct ErpShippingDetails { + id: i64, + plan_id: i64, + vehicle_id: Option, + vehicle_number: Option, + gross_weight: Option, + tare_weight: Option, + net_weight: Option, + card_number: Option, + appointment_number: Option, + appointment_time: Option, + appointment_weight: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_cancel: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_end: bool, + driver_phone: Option, + remarks: Option, + create_time: Option, + create_by: Option, + update_time: Option, + update_by: Option +} + #[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::(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::(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 diff --git a/tcp_server/target/.rustc_info.json b/tcp_server/target/.rustc_info.json index bba1d7b..88b1e62 100644 --- a/tcp_server/target/.rustc_info.json +++ b/tcp_server/target/.rustc_info.json @@ -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":{}} \ No newline at end of file +{"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":{}} \ No newline at end of file diff --git a/tcp_server/target/debug/tcp_server.exe b/tcp_server/target/debug/tcp_server.exe index 64fc80e..e0d7520 100644 Binary files a/tcp_server/target/debug/tcp_server.exe and b/tcp_server/target/debug/tcp_server.exe differ diff --git a/tcp_server/target/debug/tcp_server.pdb b/tcp_server/target/debug/tcp_server.pdb index 89866e8..4a7c74e 100644 Binary files a/tcp_server/target/debug/tcp_server.pdb and b/tcp_server/target/debug/tcp_server.pdb differ