diff --git a/tcp_client/config.toml b/tcp_client/config.toml index f03e68b..222034a 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -15,15 +15,14 @@ retry_delay_secs = 2 [database] host = "10.180.4.100" port = 5432 -name = "Auseft_old" +name = "Auseft_RL_Web" user = "postgres" password = "Auseft@2025qwer" # 要同步的表配置 - [[tables]] -name = "erp_co_supply" -query = "SELECT id, tenant_id, category_id, company_id, code, name, abbreviate, transport_type, departure_name, departure_address, departure_longitude::text as departure_longitude, departure_latitude::text as departure_latitude, destination_name, destination_address, destination_longitude::text as destination_longitude, destination_latitude::text as destination_latitude, sort, extra_properties, description, status, enabled, enabler_id, enablement_time, creator_id, creation_time, last_modifier_id, last_modification_time, deleted, deleter_id, deletion_time FROM public.erp_co_supply" +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" incremental = false -key_field = "UpdateTime" +key_field = "UpdateTime" \ No newline at end of file diff --git a/tcp_client/config_send.toml b/tcp_client/config_send.toml index 731605a..cddc6ec 100644 --- a/tcp_client/config_send.toml +++ b/tcp_client/config_send.toml @@ -20,9 +20,11 @@ user = "postgres" password = "Auseft@2025qwer" # 要同步的表配置 + + [[tables]] -name = "comm_bm_vehicleinfo" -query = "SELECT id, licenseplate, type, grosswt::text as grosswt, tarewt::text as tarewt, owner, dl, supervision, outage, insurancedate, insurancenum, lock, transcompany, createdby, creationtime, modifiedby, modifiedtime, reviewed, reviewedby, reviewedtime, remarks, phonenumber, electronicnumber, rfidmodifiedtime, rfidstop, rfidstopby, rfidstoptime, rfidgrantby, rfidgranttime, samplingpoints, drawbar, carriagelength::text as carriagelength , carriagewidth::text as carriagewidth, carriageheight::text as carriageheight, underbodyheight::text as underbodyheight, frontsampling, backsampling, rod1::text as rod1, rod2::text as rod2, rod3::text as rod3, rod4::text as rod4, rod5::text as rod5, rod6::text as rod6, supplier_id, supplier_name, material_id, material_name FROM public.comm_bm_vehicleinfo" +name = "erp_matl_material" +query = "SELECT id, tenant_id, category_id, code, name, manufacturer, model, specification, color, unit, warehouse_id, expiration_date, expiration_date_unit, sort, extra_properties, description, status, enabled, enabler_id, enablement_time, creator_id, creation_time, last_modifier_id, last_modification_time, deleted, deleter_id, deletion_time FROM public.erp_matl_material" incremental = false key_field = "UpdateTime" @@ -34,23 +36,26 @@ incremental = false key_field = "UpdateTime" [[tables]] -name = "erp_matl_material" -query = "SELECT id, tenant_id, category_id, code, name, manufacturer, model, specification, color, unit, warehouse_id, expiration_date, expiration_date_unit, sort, extra_properties, description, status, enabled, enabler_id, enablement_time, creator_id, creation_time, last_modifier_id, last_modification_time, deleted, deleter_id, deletion_time FROM public.erp_matl_material" +name = "comm_bm_vehicleinfo" +query = "SELECT id, licenseplate, type, grosswt::text as grosswt, tarewt::text as tarewt, owner, dl, supervision, outage, insurancedate, insurancenum, lock, transcompany, createdby, creationtime, modifiedby, modifiedtime, reviewed, reviewedby, reviewedtime, remarks, phonenumber, electronicnumber, rfidmodifiedtime, rfidstop, rfidstopby, rfidstoptime, rfidgrantby, rfidgranttime, samplingpoints, drawbar, carriagelength::text as carriagelength , carriagewidth::text as carriagewidth, carriageheight::text as carriageheight, underbodyheight::text as underbodyheight, frontsampling, backsampling, rod1::text as rod1, rod2::text as rod2, rod3::text as rod3, rod4::text as rod4, rod5::text as rod5, rod6::text as rod6, supplier_id, supplier_name, material_id, material_name FROM public.comm_bm_vehicleinfo" incremental = false key_field = "UpdateTime" + [[tables]] -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" +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" incremental = false key_field = "UpdateTime" [[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" + + [[tables]] name = "erp_total_shipping_plan" query = "SELECT id, order_number, start_time, end_time, finish, ship_name, voyage, total_quantity::text as total_quantity, deviation_quantity::text as deviation_quantity, supplier_code, supplier_name, material_code, material_name, shipping_station_code, shipping_station_name, departure_port, departure_time, port_destination, berthing_time, supplier_id, material_id FROM public.erp_total_shipping_plan" diff --git a/tcp_server/config.toml b/tcp_server/config.toml index 1f487c9..92bea40 100644 --- a/tcp_server/config.toml +++ b/tcp_server/config.toml @@ -5,6 +5,6 @@ port = 9090 [database] host = "10.180.4.100" port = 5432 -name = "Auseft_new_web_20250514" +name = "Auseft_old" user = "postgres" password = "Auseft@2025qwer" diff --git a/tcp_server/src/main.rs b/tcp_server/src/main.rs index a653fa5..6074087 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -500,6 +500,39 @@ struct ErpCoSupply { deletion_time: Option } +#[derive(Debug, Deserialize)] +struct ErpMatlMaterial { + id: i64, + tenant_id: Option, + category_id: i64, + code: String, + name: String, + manufacturer: Option, + model: Option, + specification: Option, + color: Option, + unit: Option, + warehouse_id: Option, + expiration_date: Option, + expiration_date_unit: Option, + sort: Option, + extra_properties: Option, + description: Option, + status: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + enabled: bool, + enabler_id: Option, + enablement_time: Option, + creator_id: Option, + creation_time: NaiveDateTime, + last_modifier_id: Option, + last_modification_time: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + deleted: bool, + deleter_id: Option, + deletion_time: Option +} + #[derive(Debug, Deserialize)] struct CommBmVehicleinfo { id: i32, @@ -808,6 +841,68 @@ async fn insert_erp_co_supply(client: &tokio_postgres::Client, info: &ErpCoSuppl Ok(()) } +async fn insert_erp_matl_material(client: &tokio_postgres::Client, info: &ErpMatlMaterial) -> Result<(), PgError> { + // Check if record exists + let exists = client + .query_one( + "SELECT COUNT(*) FROM public.erp_matl_material WHERE id = $1", + &[&info.id] + ) + .await? + .get::<_, i64>(0) > 0; + + if exists { + // Update existing record + client.execute( + "UPDATE public.erp_matl_material SET + tenant_id = $2, category_id = $3, code = $4, name = $5, + manufacturer = $6, model = $7, specification = $8, color = $9, + unit = $10, warehouse_id = $11, expiration_date = $12, + expiration_date_unit = $13, sort = $14, extra_properties = $15, + description = $16, status = $17, enabled = $18, enabler_id = $19, + enablement_time = $20, creator_id = $21, creation_time = $22, + last_modifier_id = $23, last_modification_time = $24, deleted = $25, + deleter_id = $26, deletion_time = $27 + WHERE id = $1", + &[ + &info.id, &info.tenant_id, &info.category_id, &info.code, + &info.name, &info.manufacturer, &info.model, &info.specification, + &info.color, &info.unit, &info.warehouse_id, &info.expiration_date, + &info.expiration_date_unit, &info.sort, &info.extra_properties, + &info.description, &info.status, &info.enabled, &info.enabler_id, + &info.enablement_time, &info.creator_id, &info.creation_time, + &info.last_modifier_id, &info.last_modification_time, &info.deleted, + &info.deleter_id, &info.deletion_time + ], + ).await?; + } else { + // Insert new record + client.execute( + "INSERT INTO public.erp_matl_material ( + id, tenant_id, category_id, code, name, manufacturer, model, + specification, color, unit, warehouse_id, expiration_date, + expiration_date_unit, sort, extra_properties, 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, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, + $25, $26, $27)", + &[ + &info.id, &info.tenant_id, &info.category_id, &info.code, + &info.name, &info.manufacturer, &info.model, &info.specification, + &info.color, &info.unit, &info.warehouse_id, &info.expiration_date, + &info.expiration_date_unit, &info.sort, &info.extra_properties, + &info.description, &info.status, &info.enabled, &info.enabler_id, + &info.enablement_time, &info.creator_id, &info.creation_time, + &info.last_modifier_id, &info.last_modification_time, &info.deleted, + &info.deleter_id, &info.deletion_time + ], + ).await?; + } + Ok(()) +} + async fn insert_vehicle_info(client: &tokio_postgres::Client, info: &CommBmVehicleinfo) -> Result<(), PgError> { let exists = client .query_one( @@ -2037,6 +2132,21 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client) false } }, + "erp_matl_material" => { + if let Ok(info) = serde_json::from_str::(data_str) { + println!("接收到物料信息: {:?}", info); + match insert_erp_matl_material(client, &info).await { + Ok(_) => true, + Err(e) => { + eprintln!("插入物料信息失败: {}", e); + false + } + } + } else { + eprintln!("解析物料信息失败"); + false + } + }, _ => { eprintln!("未知的表名: {}", table_name); false diff --git a/tcp_server/target/debug/tcp_server.exe b/tcp_server/target/debug/tcp_server.exe index 08975ee..64fc80e 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 4991038..89866e8 100644 Binary files a/tcp_server/target/debug/tcp_server.pdb and b/tcp_server/target/debug/tcp_server.pdb differ