diff --git a/tcp_client/config.toml b/tcp_client/config.toml index 29be5d1..6fe994f 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -20,9 +20,8 @@ user = "postgres" password = "Auseft@2025qwer" # 要同步的表配置 - [[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" +name = "wt_weight_info" +query = "SELECT id, unit_id, materiel_id, weigh_type, associated_order_id, warehouse_id, receive_company_id, transit_company_id, vehicle_id, bill_no, supply_id, card_no, rfid_no, vehicle_no, order_no, ship_type, issued_device_no, issued_by, issued_time, sample_device_no, sample_by, sample_time, gw::text as gw, gw_scale_no, gw_time, gw_by, accept_by, accept_time, t::text as t, t_scale_no, t_time, t_by, review_by, review_time, deduction::text as deduction, nw::text as nw, aw::text as aw, card_return_time, flow_id, is_invoice, is_end, is_cancel, cancel_by, cancel_time, is_manual_data, first_identify_vehicle_no, second_identify_vehicle_no, comment, is_inbound, is_outbound, is_settle_and_review, is_settle, settle_id, settle_time, vehicle_and_vessel_no, shipping_location, destination, entry_no, batch_no, lane_id, queue_id, tax_rate::text as tax_rate, itax_unit_price::text as itax_unit_price, iunit_price::text as iunit_price, operate_time, is_special_batch, total::text as total, arrival_time, leave_time, ash_start_time, is_rejected, train_shipping_detail_id, sample1_collection, sample1_collection_id, sample2_collection, samplecard1, samplecard2, cabno1, cabno2, entry_time2, cab2_card, entry_time1, cab1_card, sampleout_time1, sampleout_time2, sample2_collection_id, supply_id_name, sample_type, sample_code, sample_done, load_type, load_weight::text as load_weight, sample1_incab_by, sample2_incab_by, cabname1, cabname2, samplepoint, is_reviewed, deduction1::text as deduction1, deduction2::text as deduction2, material_name, is_accept_and_receive FROM public.wt_weight_info" 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 48b5225..c500e76 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -571,6 +571,139 @@ struct ErpShippingPlan { warehouse_name: Option } +#[derive(Debug, Deserialize)] +struct WtWeightInfo { + id: i32, + unit_id: Option, + materiel_id: Option, + weigh_type: i32, + associated_order_id: Option, + warehouse_id: Option, + receive_company_id: Option, + transit_company_id: Option, + vehicle_id: Option, + bill_no: String, + supply_id: Option, + card_no: Option, + rfid_no: Option, + vehicle_no: String, + order_no: Option, + ship_type: Option, + issued_device_no: Option, + issued_by: Option, + issued_time: Option, + sample_device_no: Option, + sample_by: Option, + sample_time: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + gw: Option, + gw_scale_no: Option, + gw_time: Option, + gw_by: Option, + accept_by: Option, + accept_time: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + t: Option, + t_scale_no: Option, + t_time: Option, + t_by: Option, + review_by: Option, + review_time: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + deduction: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + nw: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + aw: Option, + card_return_time: Option, + flow_id: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_invoice: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_end: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_cancel: bool, + cancel_by: Option, + cancel_time: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_manual_data: bool, + first_identify_vehicle_no: Option, + second_identify_vehicle_no: Option, + comment: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_inbound: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_outbound: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_settle_and_review: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_settle: bool, + settle_id: Option, + settle_time: Option, + vehicle_and_vessel_no: Option, + shipping_location: Option, + destination: Option, + entry_no: Option, + batch_no: Option, + lane_id: Option, + queue_id: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + tax_rate: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + itax_unit_price: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + iunit_price: Option, + operate_time: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_special_batch: bool, + #[serde(deserialize_with = "deserialize_option_decimal")] + total: Option, + arrival_time: Option, + leave_time: Option, + ash_start_time: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_rejected: bool, + train_shipping_detail_id: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + sample1_collection: bool, + sample1_collection_id: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + sample2_collection: bool, + samplecard1: Option, + samplecard2: Option, + cabno1: Option, + cabno2: Option, + entry_time2: Option, + cab2_card: Option, + entry_time1: Option, + cab1_card: Option, + sampleout_time1: Option, + sampleout_time2: Option, + sample2_collection_id: Option, + supply_id_name: Option, + sample_type: Option, + sample_code: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + sample_done: bool, + load_type: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + load_weight: Option, + sample1_incab_by: Option, + sample2_incab_by: Option, + cabname1: Option, + cabname2: Option, + samplepoint: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_reviewed: bool, + #[serde(deserialize_with = "deserialize_option_decimal")] + deduction1: Option, + #[serde(deserialize_with = "deserialize_option_decimal")] + deduction2: Option, + material_name: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + is_accept_and_receive: bool +} + #[derive(Debug, Deserialize)] struct ErpTotalShippingPlan { id: i32, @@ -1091,6 +1224,152 @@ where } } +async fn insert_wt_weight_info(client: &tokio_postgres::Client, info: &WtWeightInfo) -> Result<(), PgError> { + // Check if record exists using bill_no and vehicle_no + let exists = client + .query_one( + "SELECT COUNT(*) FROM public.wt_weight_info WHERE id=$1", + &[&info.id] + ) + .await? + .get::<_, i64>(0) > 0; + + if exists { + // Update existing record + client.execute( + "UPDATE public.wt_weight_info SET + unit_id = $1, materiel_id = $2, weigh_type = $3, associated_order_id = $4, + warehouse_id = $5, receive_company_id = $6, transit_company_id = $7, + vehicle_id = $8, supply_id = $9, card_no = $10, rfid_no = $11, + order_no = $12, ship_type = $13, issued_device_no = $14, issued_by = $15, + issued_time = $16, sample_device_no = $17, sample_by = $18, sample_time = $19, + gw = $20, gw_scale_no = $21, gw_time = $22, gw_by = $23, accept_by = $24, + accept_time = $25, t = $26, t_scale_no = $27, t_time = $28, t_by = $29, + review_by = $30, review_time = $31, deduction = $32, nw = $33, aw = $34, + card_return_time = $35, flow_id = $36, is_invoice = $37, is_end = $38, + is_cancel = $39, cancel_by = $40, cancel_time = $41, is_manual_data = $42, + first_identify_vehicle_no = $43, second_identify_vehicle_no = $44, + comment = $45, is_inbound = $46, is_outbound = $47, is_settle_and_review = $48, + is_settle = $49, settle_id = $50, settle_time = $51, vehicle_and_vessel_no = $52, + shipping_location = $53, destination = $54, entry_no = $55, batch_no = $56, + lane_id = $57, queue_id = $58, tax_rate = $59, itax_unit_price = $60, + iunit_price = $61, operate_time = $62, is_special_batch = $63, total = $64, + arrival_time = $65, leave_time = $66, ash_start_time = $67, is_rejected = $68, + train_shipping_detail_id = $69, sample1_collection = $70, + sample1_collection_id = $71, sample2_collection = $72, samplecard1 = $73, + samplecard2 = $74, cabno1 = $75, cabno2 = $76, entry_time2 = $77, + cab2_card = $78, entry_time1 = $79, cab1_card = $80, sampleout_time1 = $81, + sampleout_time2 = $82, sample2_collection_id = $83, supply_id_name = $84, + sample_type = $85, sample_code = $86, sample_done = $87, load_type = $88, + load_weight = $89, sample1_incab_by = $90, sample2_incab_by = $91, + cabname1 = $92, cabname2 = $93, samplepoint = $94, is_reviewed = $95, + deduction1 = $96, deduction2 = $97, material_name = $98, + is_accept_and_receive = $99, bill_no = $100 ,vehicle_no = $101 + WHERE id=$102", + &[ + &info.unit_id, &info.materiel_id, &info.weigh_type, &info.associated_order_id, + &info.warehouse_id, &info.receive_company_id, &info.transit_company_id, + &info.vehicle_id, &info.supply_id, &info.card_no, &info.rfid_no, + &info.order_no, &info.ship_type, &info.issued_device_no, &info.issued_by, + &info.issued_time, &info.sample_device_no, &info.sample_by, &info.sample_time, + &info.gw, &info.gw_scale_no, &info.gw_time, &info.gw_by, &info.accept_by, + &info.accept_time, &info.t, &info.t_scale_no, &info.t_time, &info.t_by, + &info.review_by, &info.review_time, &info.deduction, &info.nw, &info.aw, + &info.card_return_time, &info.flow_id, &info.is_invoice, &info.is_end, + &info.is_cancel, &info.cancel_by, &info.cancel_time, &info.is_manual_data, + &info.first_identify_vehicle_no, &info.second_identify_vehicle_no, + &info.comment, &info.is_inbound, &info.is_outbound, &info.is_settle_and_review, + &info.is_settle, &info.settle_id, &info.settle_time, &info.vehicle_and_vessel_no, + &info.shipping_location, &info.destination, &info.entry_no, &info.batch_no, + &info.lane_id, &info.queue_id, &info.tax_rate, &info.itax_unit_price, + &info.iunit_price, &info.operate_time, &info.is_special_batch, &info.total, + &info.arrival_time, &info.leave_time, &info.ash_start_time, &info.is_rejected, + &info.train_shipping_detail_id, &info.sample1_collection, + &info.sample1_collection_id, &info.sample2_collection, &info.samplecard1, + &info.samplecard2, &info.cabno1, &info.cabno2, &info.entry_time2, + &info.cab2_card, &info.entry_time1, &info.cab1_card, &info.sampleout_time1, + &info.sampleout_time2, &info.sample2_collection_id, &info.supply_id_name, + &info.sample_type, &info.sample_code, &info.sample_done, &info.load_type, + &info.load_weight, &info.sample1_incab_by, &info.sample2_incab_by, + &info.cabname1, &info.cabname2, &info.samplepoint, &info.is_reviewed, + &info.deduction1, &info.deduction2, &info.material_name, + &info.is_accept_and_receive, &info.bill_no, &info.vehicle_no,&info.id + ], + ).await?; + } else { + // Insert new record + client.execute( + "INSERT INTO public.wt_weight_info (id, + unit_id, materiel_id, weigh_type, associated_order_id, + warehouse_id, receive_company_id, transit_company_id, + vehicle_id, bill_no, supply_id, card_no, rfid_no, + vehicle_no, order_no, ship_type, issued_device_no, issued_by, + issued_time, sample_device_no, sample_by, sample_time, + gw, gw_scale_no, gw_time, gw_by, accept_by, + accept_time, t, t_scale_no, t_time, t_by, + review_by, review_time, deduction, nw, aw, + card_return_time, flow_id, is_invoice, is_end, + is_cancel, cancel_by, cancel_time, is_manual_data, + first_identify_vehicle_no, second_identify_vehicle_no, + comment, is_inbound, is_outbound, is_settle_and_review, + is_settle, settle_id, settle_time, vehicle_and_vessel_no, + shipping_location, destination, entry_no, batch_no, + lane_id, queue_id, tax_rate, itax_unit_price, + iunit_price, operate_time, is_special_batch, total, + arrival_time, leave_time, ash_start_time, is_rejected, + train_shipping_detail_id, sample1_collection, + sample1_collection_id, sample2_collection, samplecard1, + samplecard2, cabno1, cabno2, entry_time2, + cab2_card, entry_time1, cab1_card, sampleout_time1, + sampleout_time2, sample2_collection_id, supply_id_name, + sample_type, sample_code, sample_done, load_type, + load_weight, sample1_incab_by, sample2_incab_by, + cabname1, cabname2, samplepoint, is_reviewed, + deduction1, deduction2, material_name, + is_accept_and_receive + ) 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, $48, $49, $50, $51, $52, $53, $54, $55, $56, $57, + $58, $59, $60, $61, $62, $63, $64, $65, $66, $67, $68, + $69, $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, + $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $90, + $91, $92, $93, $94, $95, $96, $97, $98, $99,$100,$101,$102)", + &[ &info.id, + &info.unit_id, &info.materiel_id, &info.weigh_type, &info.associated_order_id, + &info.warehouse_id, &info.receive_company_id, &info.transit_company_id, + &info.vehicle_id, &info.bill_no, &info.supply_id, &info.card_no, &info.rfid_no, + &info.vehicle_no, &info.order_no, &info.ship_type, &info.issued_device_no, + &info.issued_by, &info.issued_time, &info.sample_device_no, &info.sample_by, + &info.sample_time, &info.gw, &info.gw_scale_no, &info.gw_time, &info.gw_by, + &info.accept_by, &info.accept_time, &info.t, &info.t_scale_no, &info.t_time, + &info.t_by, &info.review_by, &info.review_time, &info.deduction, &info.nw, + &info.aw, &info.card_return_time, &info.flow_id, &info.is_invoice, &info.is_end, + &info.is_cancel, &info.cancel_by, &info.cancel_time, &info.is_manual_data, + &info.first_identify_vehicle_no, &info.second_identify_vehicle_no, + &info.comment, &info.is_inbound, &info.is_outbound, &info.is_settle_and_review, + &info.is_settle, &info.settle_id, &info.settle_time, &info.vehicle_and_vessel_no, + &info.shipping_location, &info.destination, &info.entry_no, &info.batch_no, + &info.lane_id, &info.queue_id, &info.tax_rate, &info.itax_unit_price, + &info.iunit_price, &info.operate_time, &info.is_special_batch, &info.total, + &info.arrival_time, &info.leave_time, &info.ash_start_time, &info.is_rejected, + &info.train_shipping_detail_id, &info.sample1_collection, + &info.sample1_collection_id, &info.sample2_collection, &info.samplecard1, + &info.samplecard2, &info.cabno1, &info.cabno2, &info.entry_time2, + &info.cab2_card, &info.entry_time1, &info.cab1_card, &info.sampleout_time1, + &info.sampleout_time2, &info.sample2_collection_id, &info.supply_id_name, + &info.sample_type, &info.sample_code, &info.sample_done, &info.load_type, + &info.load_weight, &info.sample1_incab_by, &info.sample2_incab_by, + &info.cabname1, &info.cabname2, &info.samplepoint, &info.is_reviewed, + &info.deduction1, &info.deduction2, &info.material_name, + &info.is_accept_and_receive + ], + ).await?; + } + Ok(()) +} + async fn insert_erp_total_shipping_plan(client: &tokio_postgres::Client, info: &ErpTotalShippingPlan) -> Result<(), PgError> { // Check if record exists using order_number let exists = client @@ -2495,6 +2774,21 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client) false } }, + "wt_weight_info" => { + if let Ok(info) = serde_json::from_str::(data_str) { + println!("接收到wt_weight_info信息: {:?}", info); + match insert_wt_weight_info(client, &info).await { + Ok(_) => true, + Err(e) => { + eprintln!("插入wt_weight_info信息失败: {}", e); + false + } + } + } else { + eprintln!("解析wt_weight_info信息失败"); + false + } + }, _ => { eprintln!("未知的表名: {}", table_name); false diff --git a/tcp_server/target/debug/tcp_server.exe b/tcp_server/target/debug/tcp_server.exe index 1eb3874..3004b2c 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 9260091..c0f1b48 100644 Binary files a/tcp_server/target/debug/tcp_server.pdb and b/tcp_server/target/debug/tcp_server.pdb differ