@@ -20,8 +20,10 @@ user = "postgres" | |||||
password = "Auseft@2025qwer" | password = "Auseft@2025qwer" | ||||
# 要同步的表配置 | # 要同步的表配置 | ||||
[[tables]] | [[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_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" | |||||
incremental = false | incremental = false | ||||
key_field = "UpdateTime" | |||||
key_field = "UpdateTime" |
@@ -20,6 +20,50 @@ user = "postgres" | |||||
password = "Auseft@2025qwer" | 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" | |||||
incremental = false | |||||
key_field = "UpdateTime" | |||||
[[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" | |||||
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" | |||||
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" | |||||
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" | |||||
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" | |||||
incremental = false | |||||
key_field = "UpdateTime" | |||||
[[tables]] | |||||
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" | |||||
[[tables]] | [[tables]] | ||||
name = "comm_bch_batch" | name = "comm_bch_batch" | ||||
@@ -464,6 +464,42 @@ struct HyWeightInput { | |||||
information_norm_id: i32 | information_norm_id: i32 | ||||
} | } | ||||
#[derive(Debug, Deserialize)] | |||||
struct ErpCoSupply { | |||||
id: i64, | |||||
tenant_id: Option<i64>, | |||||
category_id: i64, | |||||
company_id: i64, | |||||
code: String, | |||||
name: String, | |||||
abbreviate: Option<String>, | |||||
transport_type: Option<i32>, | |||||
departure_name: Option<String>, | |||||
departure_address: Option<String>, | |||||
departure_longitude: Option<Decimal>, | |||||
departure_latitude: Option<Decimal>, | |||||
destination_name: Option<String>, | |||||
destination_address: Option<String>, | |||||
destination_longitude: Option<Decimal>, | |||||
destination_latitude: Option<Decimal>, | |||||
sort: Option<i64>, | |||||
extra_properties: Option<String>, | |||||
description: Option<String>, | |||||
status: Option<i32>, | |||||
#[serde(deserialize_with = "deserialize_string_to_bool")] | |||||
enabled: bool, | |||||
enabler_id: Option<i64>, | |||||
enablement_time: Option<NaiveDateTime>, | |||||
creator_id: Option<i64>, | |||||
creation_time: NaiveDateTime, | |||||
last_modifier_id: Option<i64>, | |||||
last_modification_time: Option<NaiveDateTime>, | |||||
#[serde(deserialize_with = "deserialize_string_to_bool")] | |||||
deleted: bool, | |||||
deleter_id: Option<i64>, | |||||
deletion_time: Option<NaiveDateTime> | |||||
} | |||||
#[derive(Debug, Deserialize)] | #[derive(Debug, Deserialize)] | ||||
struct CommBmVehicleinfo { | struct CommBmVehicleinfo { | ||||
id: i32, | id: i32, | ||||
@@ -706,6 +742,72 @@ async fn insert_instrument(client: &tokio_postgres::Client, info: &InstrumentInf | |||||
Ok(()) | Ok(()) | ||||
} | } | ||||
async fn insert_erp_co_supply(client: &tokio_postgres::Client, info: &ErpCoSupply) -> Result<(), PgError> { | |||||
// Check if record exists | |||||
let exists = client | |||||
.query_one( | |||||
"SELECT COUNT(*) FROM public.erp_co_supply WHERE id = $1", | |||||
&[&info.id] | |||||
) | |||||
.await? | |||||
.get::<_, i64>(0) > 0; | |||||
if exists { | |||||
// Update existing record | |||||
client.execute( | |||||
"UPDATE public.erp_co_supply SET | |||||
tenant_id = $2, category_id = $3, company_id = $4, code = $5, | |||||
name = $6, abbreviate = $7, transport_type = $8, departure_name = $9, | |||||
departure_address = $10, departure_longitude = $11, departure_latitude = $12, | |||||
destination_name = $13, destination_address = $14, destination_longitude = $15, | |||||
destination_latitude = $16, sort = $17, extra_properties = $18, | |||||
description = $19, status = $20, enabled = $21, enabler_id = $22, | |||||
enablement_time = $23, creator_id = $24, creation_time = $25, | |||||
last_modifier_id = $26, last_modification_time = $27, deleted = $28, | |||||
deleter_id = $29, deletion_time = $30 | |||||
WHERE id = $1", | |||||
&[ | |||||
&info.id, &info.tenant_id, &info.category_id, &info.company_id, | |||||
&info.code, &info.name, &info.abbreviate, &info.transport_type, | |||||
&info.departure_name, &info.departure_address, &info.departure_longitude, | |||||
&info.departure_latitude, &info.destination_name, &info.destination_address, | |||||
&info.destination_longitude, &info.destination_latitude, &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_co_supply ( | |||||
id, tenant_id, category_id, company_id, code, name, abbreviate, | |||||
transport_type, departure_name, departure_address, departure_longitude, | |||||
departure_latitude, destination_name, destination_address, | |||||
destination_longitude, 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 | |||||
) 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.id, &info.tenant_id, &info.category_id, &info.company_id, | |||||
&info.code, &info.name, &info.abbreviate, &info.transport_type, | |||||
&info.departure_name, &info.departure_address, &info.departure_longitude, | |||||
&info.departure_latitude, &info.destination_name, &info.destination_address, | |||||
&info.destination_longitude, &info.destination_latitude, &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> { | async fn insert_vehicle_info(client: &tokio_postgres::Client, info: &CommBmVehicleinfo) -> Result<(), PgError> { | ||||
let exists = client | let exists = client | ||||
.query_one( | .query_one( | ||||
@@ -1920,6 +2022,21 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client) | |||||
false | false | ||||
} | } | ||||
}, | }, | ||||
"erp_co_supply" => { | |||||
if let Ok(info) = serde_json::from_str::<ErpCoSupply>(data_str) { | |||||
println!("接收到供应商信息: {:?}", info); | |||||
match insert_erp_co_supply(client, &info).await { | |||||
Ok(_) => true, | |||||
Err(e) => { | |||||
eprintln!("插入供应商信息失败: {}", e); | |||||
false | |||||
} | |||||
} | |||||
} else { | |||||
eprintln!("解析供应商信息失败"); | |||||
false | |||||
} | |||||
}, | |||||
_ => { | _ => { | ||||
eprintln!("未知的表名: {}", table_name); | eprintln!("未知的表名: {}", table_name); | ||||
false | false | ||||