diff --git a/tcp_client/config.toml b/tcp_client/config.toml index 4ee9cb1..d7e20b7 100644 --- a/tcp_client/config.toml +++ b/tcp_client/config.toml @@ -15,127 +15,13 @@ retry_delay_secs = 2 [database] host = "10.180.4.100" port = 5432 -name = "Auseft_new_web" +name = "Auseft_old" user = "postgres" password = "Auseft@2025qwer" # 要同步的表配置 [[tables]] -name = "comm_bch_batch" -query = "SELECT id, tenant_id, supply_id, material_id, batch_record_id, sample_type, related_code, batching_start_time, batching_end_time, batching_start_ticket, batching_end_ticket, batching_quantity, batching_weight::text, batching_code, batching_code_creator, batching_code_creation_time, preparation_code, preparation_code_creator, preparation_code_creation_time, assay_code, assay_code_creator, assay_code_creation_time, creator_id, creation_time, last_modifier_id, last_modification_reason, last_modification_time, deleted, deleter_id, deletion_reason, deletion_time, source_type FROM comm_bch_batch" -incremental = false -key_field = "UpdateTime" - - - -[[tables]] -name = "comm_bch_delivering_sampling" -query = "SELECT id, tenant_id, supply_id, material_id, sample_type, operation_type, business_type, delivering_type, delivering_code, delivering_quantity, delivering_unit, delivering_weight::text as delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time, sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit, sampling_weight::text as sampling_weight, sampling_weights, sampling_remark, sampler, sample_time, creator_id, creation_time, last_modifier_id, last_modification_reason, last_modification_time, deleted, deleter_id, deletion_reason, deletion_time FROM comm_bch_delivering_sampling " -incremental = false -key_field = "UpdateTime" - - -[[tables]] -name = "comm_sp_delivering_sampling" -query = "SELECT id, tenant_id, supply_id, material_id, sample_type, bch_ds_id, operation_type, business_type, delivering_type, delivering_code, delivering_quantity, delivering_unit, delivering_weight::text as delivering_weight, delivering_weights, delivering_remark, deliverer, delivery_time, sampling, sampling_type, sampling_code, sampling_quantity, sampling_unit, sampling_weight::text as sampling_weight, sampling_weights, sampling_remark, sampler, sample_time, creator_id, creation_time, last_modifier_id, last_modification_reason, last_modification_time, deleted, deleter_id, deletion_reason, deletion_time FROM comm_sp_delivering_sampling " -incremental = false -key_field = "UpdateTime" - - - -[[tables]] -name = "hy_record" -query = "SELECT id, hy_code, type, hy_check, hy_approve, check_time, approve_time, approve_user, check_user, hy_time, hy_values, accept_time, accept_user, mt::text as mt, mad::text as mad, aad::text as aad, ad::text as ad, vad::text as vad, vd::text as vd, var::text as var, vdaf::text as vdaf, fcad::text as fcad, st_ar::text as st_ar, st_ad::text as st_ad, st_d::text as st_d, had::text as had, hd::text as hd, qb_ad::text as qb_ad, qgr_ad::text as qgr_ad, qgr_d::text as qgr_d, qnet_ar_mj_kg::text as qnet_ar_mj_kg, qnet_ar_j_cal::text as qnet_ar_j_cal, v::text as v, aar::text as aar, qnet_ar::text as qnet_ar, qnet_ar1::text as qnet_ar1, crc::text as crc, st_daf::text as st_daf, cad ::text as cad, cd::text as cd, isauto, hy_type, isnormal FROM hy_record where hy_approve=0 and accept_time >= NOW() - INTERVAL '10 days' " -incremental = false -key_field = "UpdateTime" - - -[[tables]] -name = "hy_itemdetail" -query = "SELECT * FROM hy_itemdetail where record_id in (select id from hy_record where hy_approve=0 and accept_time >= NOW() - INTERVAL '10 days') " -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_norm" -query = " select id,norm_id,zbvalues::text as zbvalues,itemdetail_id,hy_user,checktime,\"explain\" from hy_norm where itemdetail_id in (SELECT t1.id FROM hy_itemdetail t1 inner join hy_record t2 on t1.record_id=t2.id where t2.hy_approve=0 and t2.accept_time >= NOW() - INTERVAL '10 days')" -incremental = false -key_field = "UpdateTime" - - -[[tables]] -name = "hy_instrument" -query = "SELECT * FROM \"hy_instrument\"" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_information" -query = "SELECT * FROM \"hy_information\"" -incremental = false -key_field = "UpdateTime" - - - -[[tables]] -name = "hy_allot" -query = "SELECT * FROM \"hy_allot\"" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_cytask" -query = "SELECT * FROM \"hy_cytask\"" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_fullwatersample" -query = "select id,qs_code,qs_tonnage::text as qs_tonnage,mt::text as mt,remark,onecode,towcode,fx_code,fx_onecode,fx_twocode from hy_fullwatersample" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_informationnorm" -query = "SELECT * FROM \"hy_informationnorm\"" -incremental = false -key_field = "UpdateTime" - - - - - - - -[[tables]] -name = "hy_laboratoryinstrument" -query = "SELECT * FROM \"hy_laboratoryinstrument\"" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_materialanalysis_type" -query = "SELECT * FROM \"hy_materialanalysis_type\"" -incremental = false -key_field = "UpdateTime" - -[[tables]] -name = "hy_materialdetail" -query = "SELECT * FROM \"hy_materialdetail\"" -incremental = false -key_field = "UpdateTime" - - - -[[tables]] -name = "hy_weight_input" -query = "SELECT * FROM \"hy_weight_input\"" -incremental = false -key_field = "UpdateTime" - - -[[tables]] -name = "hy_warmhumid" -query = "select id,laboratoryid,temperature::text as temperature,humidity::text humidity,begintime,endtime, username from hy_warmhumid" +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" \ No newline at end of file diff --git a/tcp_server/src/main.rs b/tcp_server/src/main.rs index f6ba9eb..71c1fb8 100644 --- a/tcp_server/src/main.rs +++ b/tcp_server/src/main.rs @@ -464,6 +464,63 @@ struct HyWeightInput { information_norm_id: i32 } +#[derive(Debug, Deserialize)] +struct CommBmVehicleinfo { + id: i32, + licenseplate: Option, + r#type: Option, + grosswt: Option, + tarewt: Option, + owner: Option, + dl: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + supervision: bool, + #[serde(deserialize_with = "deserialize_string_to_bool")] + outage: bool, + insurancedate: Option, + insurancenum: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + lock: bool, + transcompany: Option, + createdby: Option, + creationtime: Option, + modifiedby: Option, + modifiedtime: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + reviewed: bool, + reviewedby: Option, + reviewedtime: Option, + remarks: Option, + phonenumber: Option, + electronicnumber: Option, + rfidmodified_by: Option, + rfidmodifiedtime: Option, + #[serde(deserialize_with = "deserialize_string_to_bool")] + rfidstop: bool, + rfidstopby: Option, + rfidstoptime: Option, + rfidgrantby: Option, + rfidgranttime: Option, + samplingpoints: Option, + drawbar: Option, + carriagelength: Option, + carriagewidth: Option, + carriageheight: Option, + underbodyheight: Option, + frontsampling: Option, + backsampling: Option, + rod1: Option, + rod2: Option, + rod3: Option, + rod4: Option, + rod5: Option, + rod6: Option, + supplier_id: Option, + supplier_name: Option, + material_id: Option, + material_name: Option, +} + #[derive(Debug, Deserialize)] struct HySpotcheck { id: i32, @@ -649,6 +706,84 @@ async fn insert_instrument(client: &tokio_postgres::Client, info: &InstrumentInf Ok(()) } +async fn insert_vehicle_info(client: &tokio_postgres::Client, info: &CommBmVehicleinfo) -> Result<(), PgError> { + let exists = client + .query_one( + "SELECT EXISTS(SELECT 1 FROM public.comm_bm_vehicleinfo WHERE id = $1)", + &[&info.id], + ) + .await? + .get::<_, bool>(0); + + if exists { + // 如果记录存在,执行更新操作 + client.execute( + "UPDATE public.comm_bm_vehicleinfo + SET licenseplate = $2, type = $3, grosswt = $4, tarewt = $5, + owner = $6, dl = $7, supervision = $8, outage = $9, insurancedate = $10, + insurancenum = $11, lock = $12, transcompany = $13, createdby = $14, + creationtime = $15, modifiedby = $16, modifiedtime = $17, reviewed = $18, + reviewedby = $19, reviewedtime = $20, remarks = $21, phonenumber = $22, + electronicnumber = $23, material_name = $24, rfidmodifiedtime = $25, + rfidstop = $26, rfidstopby = $27, rfidstoptime = $28, rfidgrantby = $29, + rfidgranttime = $30, samplingpoints = $31, drawbar = $32, carriagelength = $33, + carriagewidth = $34, carriageheight = $35, underbodyheight = $36, + frontsampling = $37, backsampling = $38, rod1 = $39, rod2 = $40, rod3 = $41, + rod4 = $42, rod5 = $43, rod6 = $44, supplier_id = $45, supplier_name = $46, + material_id = $47 + WHERE id = $1", + &[ + &info.id, &info.licenseplate, &info.r#type, &info.grosswt, &info.tarewt, + &info.owner, &info.dl, &info.supervision, &info.outage, &info.insurancedate, + &info.insurancenum, &info.lock, &info.transcompany, &info.createdby, + &info.creationtime, &info.modifiedby, &info.modifiedtime, &info.reviewed, + &info.reviewedby, &info.reviewedtime, &info.remarks, &info.phonenumber, + &info.electronicnumber, &info.material_name, &info.rfidmodifiedtime, + &info.rfidstop, &info.rfidstopby, &info.rfidstoptime, &info.rfidgrantby, + &info.rfidgranttime, &info.samplingpoints, &info.drawbar, &info.carriagelength, + &info.carriagewidth, &info.carriageheight, &info.underbodyheight, + &info.frontsampling, &info.backsampling, &info.rod1, &info.rod2, &info.rod3, + &info.rod4, &info.rod5, &info.rod6, &info.supplier_id, &info.supplier_name, + &info.material_id + ], + ).await?; + } else { + // 如果记录不存在,执行插入操作 + client.execute( + "INSERT INTO public.comm_bm_vehicleinfo ( + id, licenseplate, type, grosswt, 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, 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, + $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)", + &[ + &info.id, &info.licenseplate, &info.r#type, &info.grosswt, &info.tarewt, + &info.owner, &info.dl, &info.supervision, &info.outage, &info.insurancedate, + &info.insurancenum, &info.lock, &info.transcompany, &info.createdby, + &info.creationtime, &info.modifiedby, &info.modifiedtime, &info.reviewed, + &info.reviewedby, &info.reviewedtime, &info.remarks, &info.phonenumber, + &info.electronicnumber, &info.rfidmodifiedtime, + &info.rfidstop, &info.rfidstopby, &info.rfidstoptime, &info.rfidgrantby, + &info.rfidgranttime, &info.samplingpoints, &info.drawbar, &info.carriagelength, + &info.carriagewidth, &info.carriageheight, &info.underbodyheight, + &info.frontsampling, &info.backsampling, &info.rod1, &info.rod2, &info.rod3, + &info.rod4, &info.rod5, &info.rod6, &info.supplier_id, &info.supplier_name, + &info.material_id, &info.material_name + ], + ).await?; + } + + println!("成功{}车辆信息: ID {}", if exists { "更新" } else { "插入" }, info.id); + Ok(()) +} + async fn insert_information(client: &tokio_postgres::Client, info: &InformationInfo) -> Result<(), PgError> { let exists = client .query_one( @@ -1530,6 +1665,21 @@ async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client) false } }, + "comm_bm_vehicleinfo" => { + if let Ok(info) = serde_json::from_str::(data_str) { + println!("接收到车辆信息: {:?}", info); + match insert_vehicle_info(client, &info).await { + Ok(_) => true, + Err(e) => { + eprintln!("插入车辆信息失败: {}", e); + false + } + } + } else { + eprintln!("解析车辆信息失败"); + false + } + }, "hy_allot" => { if let Ok(info) = serde_json::from_str::(data_str) { println!("接收到分配信息: {:?}", info); diff --git a/tcp_server/target/.rustc_info.json b/tcp_server/target/.rustc_info.json index 585c5e2..bba1d7b 100644 --- a/tcp_server/target/.rustc_info.json +++ b/tcp_server/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":12877487731689626790,"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":""},"17313545009459141857":{"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":""},"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":{"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 diff --git a/tcp_server/target/debug/tcp_server.exe b/tcp_server/target/debug/tcp_server.exe index 887bc25..d0dee70 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 0a8a36c..2f37bdd 100644 Binary files a/tcp_server/target/debug/tcp_server.pdb and b/tcp_server/target/debug/tcp_server.pdb differ