@@ -89,9 +89,12 @@ impl Database { | |||
} | |||
} | |||
pub fn format_row_as_json(row: &Row) -> serde_json::Value { | |||
pub fn format_row_as_json(row: &Row, table_name: &str) -> serde_json::Value { | |||
let mut map = serde_json::Map::new(); | |||
// 添加 table_name 字段 | |||
map.insert("table_name".to_string(), serde_json::Value::String(table_name.to_string())); | |||
for (i, column) in row.columns().iter().enumerate() { | |||
let name = column.name(); | |||
let value = match column.type_().name() { | |||
@@ -76,7 +76,7 @@ async fn main() { | |||
println!("成功获取 {} 条记录", rows.len()); | |||
// 将每行数据转换为JSON并发送到服务器 | |||
for row in rows { | |||
let json_data = db::format_row_as_json(&row); | |||
let json_data = db::format_row_as_json(&row, &table.name); | |||
let msg = serde_json::to_string(&json_data).unwrap(); | |||
// 创建TCP连接 | |||
@@ -43,6 +43,18 @@ dependencies = [ | |||
"libc", | |||
] | |||
[[package]] | |||
name = "anyhow" | |||
version = "1.0.98" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" | |||
[[package]] | |||
name = "arc-swap" | |||
version = "1.7.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" | |||
[[package]] | |||
name = "async-trait" | |||
version = "0.1.88" | |||
@@ -51,7 +63,7 @@ checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -200,6 +212,23 @@ dependencies = [ | |||
"typenum", | |||
] | |||
[[package]] | |||
name = "derivative" | |||
version = "2.2.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn 1.0.109", | |||
] | |||
[[package]] | |||
name = "destructure_traitobject" | |||
version = "0.2.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "3c877555693c14d2f84191cfd3ad8582790fc52b5e2274b40b59cf5f5cea25c7" | |||
[[package]] | |||
name = "digest" | |||
version = "0.10.7" | |||
@@ -217,12 +246,24 @@ version = "0.3.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | |||
[[package]] | |||
name = "equivalent" | |||
version = "1.0.2" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" | |||
[[package]] | |||
name = "fallible-iterator" | |||
version = "0.2.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" | |||
[[package]] | |||
name = "fnv" | |||
version = "1.0.7" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" | |||
[[package]] | |||
name = "futures-channel" | |||
version = "0.3.31" | |||
@@ -247,7 +288,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -325,6 +366,12 @@ dependencies = [ | |||
"ahash", | |||
] | |||
[[package]] | |||
name = "hashbrown" | |||
version = "0.15.2" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" | |||
[[package]] | |||
name = "hmac" | |||
version = "0.12.1" | |||
@@ -334,6 +381,12 @@ dependencies = [ | |||
"digest", | |||
] | |||
[[package]] | |||
name = "humantime" | |||
version = "2.2.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" | |||
[[package]] | |||
name = "iana-time-zone" | |||
version = "0.1.63" | |||
@@ -358,6 +411,16 @@ dependencies = [ | |||
"cc", | |||
] | |||
[[package]] | |||
name = "indexmap" | |||
version = "2.9.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" | |||
dependencies = [ | |||
"equivalent", | |||
"hashbrown 0.15.2", | |||
] | |||
[[package]] | |||
name = "itoa" | |||
version = "1.0.15" | |||
@@ -418,6 +481,43 @@ name = "log" | |||
version = "0.4.27" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" | |||
dependencies = [ | |||
"serde", | |||
] | |||
[[package]] | |||
name = "log-mdc" | |||
version = "0.1.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" | |||
[[package]] | |||
name = "log4rs" | |||
version = "1.3.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "0816135ae15bd0391cf284eab37e6e3ee0a6ee63d2ceeb659862bd8d0a984ca6" | |||
dependencies = [ | |||
"anyhow", | |||
"arc-swap", | |||
"chrono", | |||
"derivative", | |||
"fnv", | |||
"humantime", | |||
"libc", | |||
"log", | |||
"log-mdc", | |||
"once_cell", | |||
"parking_lot", | |||
"rand 0.8.5", | |||
"serde", | |||
"serde-value", | |||
"serde_json", | |||
"serde_yaml", | |||
"thiserror 1.0.69", | |||
"thread-id", | |||
"typemap-ors", | |||
"winapi", | |||
] | |||
[[package]] | |||
name = "md-5" | |||
@@ -495,6 +595,15 @@ version = "1.21.3" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" | |||
[[package]] | |||
name = "ordered-float" | |||
version = "2.10.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" | |||
dependencies = [ | |||
"num-traits", | |||
] | |||
[[package]] | |||
name = "ordered-multimap" | |||
version = "0.4.3" | |||
@@ -502,7 +611,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" | |||
dependencies = [ | |||
"dlv-list", | |||
"hashbrown", | |||
"hashbrown 0.12.3", | |||
] | |||
[[package]] | |||
@@ -547,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" | |||
dependencies = [ | |||
"memchr", | |||
"thiserror", | |||
"thiserror 2.0.12", | |||
"ucd-trie", | |||
] | |||
@@ -571,7 +680,7 @@ dependencies = [ | |||
"pest_meta", | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -628,7 +737,7 @@ dependencies = [ | |||
"hmac", | |||
"md-5", | |||
"memchr", | |||
"rand", | |||
"rand 0.9.1", | |||
"sha2", | |||
"stringprep", | |||
] | |||
@@ -680,14 +789,35 @@ version = "5.2.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" | |||
[[package]] | |||
name = "rand" | |||
version = "0.8.5" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | |||
dependencies = [ | |||
"libc", | |||
"rand_chacha 0.3.1", | |||
"rand_core 0.6.4", | |||
] | |||
[[package]] | |||
name = "rand" | |||
version = "0.9.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" | |||
dependencies = [ | |||
"rand_chacha", | |||
"rand_core", | |||
"rand_chacha 0.9.0", | |||
"rand_core 0.9.3", | |||
] | |||
[[package]] | |||
name = "rand_chacha" | |||
version = "0.3.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | |||
dependencies = [ | |||
"ppv-lite86", | |||
"rand_core 0.6.4", | |||
] | |||
[[package]] | |||
@@ -697,7 +827,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" | |||
dependencies = [ | |||
"ppv-lite86", | |||
"rand_core", | |||
"rand_core 0.9.3", | |||
] | |||
[[package]] | |||
name = "rand_core" | |||
version = "0.6.4" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | |||
dependencies = [ | |||
"getrandom 0.2.15", | |||
] | |||
[[package]] | |||
@@ -772,6 +911,16 @@ dependencies = [ | |||
"serde_derive", | |||
] | |||
[[package]] | |||
name = "serde-value" | |||
version = "0.7.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" | |||
dependencies = [ | |||
"ordered-float", | |||
"serde", | |||
] | |||
[[package]] | |||
name = "serde_derive" | |||
version = "1.0.219" | |||
@@ -780,7 +929,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -795,6 +944,19 @@ dependencies = [ | |||
"serde", | |||
] | |||
[[package]] | |||
name = "serde_yaml" | |||
version = "0.9.34+deprecated" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" | |||
dependencies = [ | |||
"indexmap", | |||
"itoa", | |||
"ryu", | |||
"serde", | |||
"unsafe-libyaml", | |||
] | |||
[[package]] | |||
name = "sha2" | |||
version = "0.10.8" | |||
@@ -869,6 +1031,17 @@ version = "2.6.1" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" | |||
[[package]] | |||
name = "syn" | |||
version = "1.0.109" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"unicode-ident", | |||
] | |||
[[package]] | |||
name = "syn" | |||
version = "2.0.100" | |||
@@ -886,19 +1059,40 @@ version = "0.1.0" | |||
dependencies = [ | |||
"chrono", | |||
"config", | |||
"log4rs", | |||
"serde", | |||
"serde_json", | |||
"tokio", | |||
"tokio-postgres", | |||
] | |||
[[package]] | |||
name = "thiserror" | |||
version = "1.0.69" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" | |||
dependencies = [ | |||
"thiserror-impl 1.0.69", | |||
] | |||
[[package]] | |||
name = "thiserror" | |||
version = "2.0.12" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" | |||
dependencies = [ | |||
"thiserror-impl", | |||
"thiserror-impl 2.0.12", | |||
] | |||
[[package]] | |||
name = "thiserror-impl" | |||
version = "1.0.69" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -909,7 +1103,17 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
name = "thread-id" | |||
version = "4.2.2" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "cfe8f25bbdd100db7e1d34acf7fd2dc59c4bf8f7483f505eaa7d4f12f76cc0ea" | |||
dependencies = [ | |||
"libc", | |||
"winapi", | |||
] | |||
[[package]] | |||
@@ -953,7 +1157,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -975,7 +1179,7 @@ dependencies = [ | |||
"pin-project-lite", | |||
"postgres-protocol", | |||
"postgres-types", | |||
"rand", | |||
"rand 0.9.1", | |||
"socket2", | |||
"tokio", | |||
"tokio-util", | |||
@@ -1004,6 +1208,15 @@ dependencies = [ | |||
"serde", | |||
] | |||
[[package]] | |||
name = "typemap-ors" | |||
version = "1.0.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "a68c24b707f02dd18f1e4ccceb9d49f2058c2fb86384ef9972592904d7a28867" | |||
dependencies = [ | |||
"unsafe-any-ors", | |||
] | |||
[[package]] | |||
name = "typenum" | |||
version = "1.18.0" | |||
@@ -1043,6 +1256,21 @@ version = "0.1.3" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" | |||
[[package]] | |||
name = "unsafe-any-ors" | |||
version = "1.0.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "e0a303d30665362d9680d7d91d78b23f5f899504d4f08b3c4cf08d055d87c0ad" | |||
dependencies = [ | |||
"destructure_traitobject", | |||
] | |||
[[package]] | |||
name = "unsafe-libyaml" | |||
version = "0.2.11" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" | |||
[[package]] | |||
name = "version_check" | |||
version = "0.9.5" | |||
@@ -1092,7 +1320,7 @@ dependencies = [ | |||
"log", | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
"wasm-bindgen-shared", | |||
] | |||
@@ -1114,7 +1342,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
"wasm-bindgen-backend", | |||
"wasm-bindgen-shared", | |||
] | |||
@@ -1149,6 +1377,28 @@ dependencies = [ | |||
"web-sys", | |||
] | |||
[[package]] | |||
name = "winapi" | |||
version = "0.3.9" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" | |||
dependencies = [ | |||
"winapi-i686-pc-windows-gnu", | |||
"winapi-x86_64-pc-windows-gnu", | |||
] | |||
[[package]] | |||
name = "winapi-i686-pc-windows-gnu" | |||
version = "0.4.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | |||
[[package]] | |||
name = "winapi-x86_64-pc-windows-gnu" | |||
version = "0.4.0" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" | |||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | |||
[[package]] | |||
name = "windows-core" | |||
version = "0.61.0" | |||
@@ -1170,7 +1420,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -1181,7 +1431,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] | |||
[[package]] | |||
@@ -1316,5 +1566,5 @@ checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" | |||
dependencies = [ | |||
"proc-macro2", | |||
"quote", | |||
"syn", | |||
"syn 2.0.100", | |||
] |
@@ -10,3 +10,4 @@ tokio-postgres = { version = "0.7", features = ["with-serde_json-1", "with-chron | |||
serde = { version = "1.0", features = ["derive"] } | |||
serde_json = "1.0" | |||
chrono = { version = "0.4", features = ["serde"] } | |||
log4rs = "1.1.0" |
@@ -1,10 +1,2 @@ | |||
[server] | |||
address = "127.0.0.1" | |||
port = 9090 | |||
[database] | |||
host = "10.180.4.100" | |||
port = 5432 | |||
name = "postgres" | |||
user = "postgres" | |||
password = "Auseft@2025qwer" | |||
server_addr = "127.0.0.1:9090" | |||
database_url = "host=10.180.4.100 port=5432 user=postgres password=Auseft@2025qwer dbname=postgres" |
@@ -0,0 +1,417 @@ | |||
-- 化验系统相关表结构 | |||
-- Created at 2025-04-20 | |||
CREATE TABLE "public"."hy_record" ( | |||
"id" serial4 NOT NULL, | |||
"hy_code" varchar(255), | |||
"type" varchar(20), | |||
"hy_check" smallint DEFAULT 0, | |||
"hy_approve" smallint DEFAULT 0, | |||
"check_time" timestamp without time zone, | |||
"approve_time" timestamp without time zone, | |||
"approve_user" varchar(50), | |||
"check_user" varchar(50), | |||
"hy_time" timestamp without time zone, | |||
"hy_values" varchar(500), | |||
"accept_time" timestamp without time zone, | |||
"accept_user" varchar(50), | |||
"mt" numeric(18,1), | |||
"mad" numeric(18,2), | |||
"aad" numeric(18,2), | |||
"ad" numeric(18,2), | |||
"vad" numeric(18,2), | |||
"vd" numeric(18,2), | |||
"var" numeric(18,2), | |||
"vdaf" numeric(18,2), | |||
"fcad" numeric(18,2), | |||
"st_ar" numeric(18,2), | |||
"st_ad" numeric(18,2), | |||
"st_d" numeric(18,2), | |||
"had" numeric(18,2), | |||
"hd" numeric(18,2), | |||
"qb_ad" numeric(18,3), | |||
"qgr_ad" numeric(18,3), | |||
"qgr_d" numeric(18,3), | |||
"qnet_ar_mj_kg" numeric(18,2), | |||
"qnet_ar_j_cal" numeric(18,0), | |||
"v" numeric(18,2), | |||
"aar" numeric(18,2), | |||
"qnet_ar" numeric(18,2), | |||
"qnet_ar1" numeric(18,4), | |||
"crc" numeric(18,0), | |||
"st_daf" numeric(18,2), | |||
"cad" numeric(18,2), | |||
"cd" numeric(18,2), | |||
"isauto" smallint, | |||
"hy_type" varchar(255), | |||
"isnormal" int4, | |||
CONSTRAINT "PK_HY_RECORD" PRIMARY KEY ("id") | |||
); | |||
CREATE TABLE "public"."hy_instrument" ( | |||
"id" int4 NOT NULL, | |||
"laboratoryid" int4, | |||
"name" varchar(100), | |||
"instrumentcode" varchar(50), | |||
"informationid" int4, | |||
"specification" varchar(50), | |||
"remark" varchar(50), | |||
CONSTRAINT "PK_HY_Instrument" PRIMARY KEY ("id") | |||
); | |||
-- 分配表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_allot" ( | |||
"id" int4 NOT NULL, | |||
"userid" int4, | |||
"username" varchar(50), | |||
"informationid" int4, | |||
"allottime" timestamp without time zone, | |||
"hy_code" varchar(50), | |||
"hy_type" varchar(50), | |||
"hy_method" varchar(50), | |||
"hy_quest" varchar(50), | |||
CONSTRAINT "PK_HY_Allot" PRIMARY KEY ("id") | |||
); | |||
-- 全水样品表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_fullwatersample" ( | |||
"id" int4 NOT NULL, | |||
"qs_code" varchar(50), | |||
"qs_tonnage" numeric(18,2), | |||
"mt" numeric(18,1), | |||
"remark" varchar(50), | |||
"onecode" varchar(50), | |||
"towcode" varchar(50), | |||
"fx_code" varchar(50), | |||
"fx_onecode" varchar(50), | |||
"fx_twocode" varchar(50), | |||
CONSTRAINT "PK_HY_FullWaterSample" PRIMARY KEY ("id") | |||
); | |||
-- 化验信息规范表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_informationnorm" ( | |||
"id" int4 NOT NULL, | |||
"information_id" int4, | |||
"hy_id" int4, | |||
"norm_name" varchar(50), | |||
"flag" smallint, | |||
"apparatus_id" int4, | |||
"need_compute" smallint, | |||
"formula" varchar(255), | |||
"secondformula" varchar(255), | |||
"mapping" varchar(255), | |||
"input_type" int4, | |||
"round" int4, | |||
"sort" int4 | |||
); | |||
-- 化验项目明细表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_itemdetail" ( | |||
"id" serial4 NOT NULL, | |||
"record_id" int4, | |||
"information_id" int4, | |||
"laboratory_id" int4, | |||
"number" int4, | |||
"cancellation" smallint DEFAULT 0, | |||
"detectionuser" varchar(50), | |||
"detectiontime" timestamp without time zone, | |||
"original_num" varchar(50), | |||
"hy_check" smallint DEFAULT 0, | |||
"checkuser" varchar(50), | |||
"checktime" timestamp without time zone, | |||
"oversize" smallint DEFAULT 0, | |||
CONSTRAINT "PK_HY_ITEMDETAIL" PRIMARY KEY ("id") | |||
); | |||
-- 实验室仪器表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_laboratoryinstrument" ( | |||
"id" serial4 NOT NULL, | |||
"norm_id" int4, | |||
"instrument_id" int4, | |||
CONSTRAINT "hy_laboratoryinstrument_pkey" PRIMARY KEY ("id") | |||
); | |||
-- 物料分析类型表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_materialanalysis_type" ( | |||
"id" int4 NOT NULL, | |||
"name" varchar(255), | |||
"flag" smallint, | |||
"sort" int4, | |||
"createtime" date, | |||
"createuser" varchar(255), | |||
CONSTRAINT "hy_Material_AnalysisType_pkey1" PRIMARY KEY ("id") | |||
); | |||
-- 物料明细表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_materialdetail" ( | |||
"id" int4 NOT NULL, | |||
"name" varchar(255), | |||
"flag" int4, | |||
"sort" int4, | |||
"createtime" date, | |||
"createuser" varchar(255), | |||
"analysistypeid" int4, | |||
"materialid" int4, | |||
CONSTRAINT "hy_Material_AnalysisType_pkey" PRIMARY KEY ("id") | |||
); | |||
-- 化验规范表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_norm" ( | |||
"id" serial4 NOT NULL, | |||
"norm_id" int4, | |||
"zbvalues" numeric(12,4), | |||
"itemdetail_id" int4, | |||
"hy_user" varchar(50), | |||
"checktime" timestamp without time zone, | |||
"explain" varchar(200), | |||
CONSTRAINT "PK_HY_NORM" PRIMARY KEY ("id") | |||
); | |||
-- 样品采集明细表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_sample_collection_detail" ( | |||
"id" serial4 NOT NULL, | |||
"num" int4 NOT NULL, | |||
"unit_num" int4 NOT NULL, | |||
"time" timestamp without time zone, | |||
"type" int4, | |||
"sy_method" int4, | |||
"sy_time" timestamp without time zone, | |||
"one_num" varchar(11), | |||
"two_num" varchar(11), | |||
"three_num" varchar(11), | |||
"sy_starttime" timestamp without time zone, | |||
"sy_endtime" timestamp without time zone, | |||
"cy_startnum" varchar(50), | |||
"cy_endnum" varchar(50), | |||
"sy_user" varchar(20), | |||
"sy_car_count" int4, | |||
"sy_dun_weight" numeric(18,2), | |||
"byz_bag_count" smallint, | |||
"y_liu" smallint, | |||
"zy_user" varchar(20), | |||
"one_num_createtime" timestamp without time zone, | |||
"one_num_user" varchar(20), | |||
"one_num_review_status" smallint, | |||
"one_num_review_user" varchar(20), | |||
"one_num_review_time" timestamp without time zone, | |||
"two_num_createtime" timestamp without time zone, | |||
"two_num_user" varchar(20), | |||
"two_num_review_status" smallint, | |||
"two_num_review_user" varchar(20), | |||
"two_num_review_time" timestamp without time zone, | |||
"three_num_createtime" timestamp without time zone, | |||
"three_num_user" varchar(20), | |||
"three_num_review_status" smallint, | |||
"three_num_review_user" varchar(20), | |||
"three_num_review_time" timestamp without time zone, | |||
"hy_createtime" timestamp without time zone, | |||
"hy_time" timestamp without time zone, | |||
"hy_user" varchar(20), | |||
"hy_review_user" varchar(20), | |||
"hy_review_status" smallint, | |||
"hy_review_time" timestamp without time zone, | |||
"record_sort" int4, | |||
"is_print" smallint, | |||
"print_msg" smallint, | |||
"pring_user" varchar(8), | |||
"hy_approve" smallint, | |||
"hy_approve_time" timestamp without time zone, | |||
"hy_approve_user" varchar(20), | |||
"mt" numeric(18,1), | |||
"mad_clp" numeric(18,4), | |||
"mad_my" numeric(18,4), | |||
"mad_hh" numeric(18,4), | |||
"mad" numeric(18,2), | |||
"a_hm" numeric(18,4), | |||
"a_my" numeric(18,4), | |||
"a_hh" numeric(18,4), | |||
"a_hm1" numeric(18,4), | |||
"a_my1" numeric(18,4), | |||
"a_hh1" numeric(18,4), | |||
"aad" numeric(18,2), | |||
"ad" numeric(18,2), | |||
"v_gg" numeric(18,4), | |||
"v_my" numeric(18,4), | |||
"v_hh" numeric(18,4), | |||
"vad" numeric(18,2), | |||
"vdaf" numeric(18,2), | |||
"var_data" numeric(18,2), | |||
"vd" numeric(18,2), | |||
"fcad" numeric(18,2), | |||
"st_ad" numeric(18,2), | |||
"st_d" numeric(18,2), | |||
"st_ar" numeric(18,2), | |||
"had" numeric(18,2), | |||
"hd" numeric(18,2), | |||
"qb_ad" numeric(18,3), | |||
"qgr_ad" numeric(18,3), | |||
"qnet_ar" numeric(18,2), | |||
"qgr_d" numeric(18,2), | |||
"qnet_ar1" numeric(18,4), | |||
"byz_bag_user" varchar(50), | |||
"byz_bag_time" timestamp without time zone, | |||
"byz_bag_remark" varchar(500), | |||
"fc" smallint, | |||
"fc_reason" varchar(500), | |||
"fc_user" varchar(50), | |||
"fc_time" timestamp without time zone, | |||
"xk_time" timestamp without time zone, | |||
"xk_user" varchar(50), | |||
"xk_card_num" varchar(50), | |||
"allow_sync" smallint, | |||
"sync" smallint, | |||
"sync_time" timestamp without time zone, | |||
"mc_unit" int4, | |||
"mc_review" smallint, | |||
"msg_produce" smallint, | |||
"supply_num" int4, | |||
"v_data" numeric(18,2), | |||
"cc" smallint, | |||
"cc_user" varchar(50), | |||
"cc_time" timestamp without time zone, | |||
"aar" numeric(18,2), | |||
"is_delete" smallint, | |||
"alarm_remark" varchar(500), | |||
"zs" smallint, | |||
"zs_detail" smallint, | |||
"zs_sy_num" int4, | |||
"kf_qs" smallint, | |||
"kf_qs_time" timestamp without time zone, | |||
"kf_qs_reason" varchar(500), | |||
"qs_time" timestamp without time zone, | |||
"crc" numeric(18,0), | |||
"dk_hy" smallint, | |||
"dk_hy_num" varchar(50), | |||
"hy_copy" smallint, | |||
"hy_copy_num" varchar(50), | |||
"hy_copy_user" varchar(50), | |||
"hy_copy_time" timestamp without time zone, | |||
"already_send" smallint, | |||
"send_time" timestamp without time zone, | |||
"st_daf" numeric(18,2), | |||
"st" numeric(18,2), | |||
"two_num_weight" numeric(12,4), | |||
CONSTRAINT "PK_收样明细表" PRIMARY KEY ("id") | |||
); | |||
-- 样品交付表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_sample_delivery" ( | |||
"id" int4 NOT NULL, | |||
"sample_number" varchar(255) DEFAULT '样品编号'::character varying, | |||
"coal_sample" varchar(255), | |||
"sample_weight" numeric, | |||
"sampler_user" varchar(255), | |||
"state" varchar(255), | |||
"check_weight" numeric, | |||
"sample_type" varchar(255), | |||
"time" date, | |||
"entering_type" varchar(255), | |||
"sample_delivery_type" varchar(255), | |||
"granularity" numeric, | |||
"container_weight" numeric, | |||
"sample_delivery_time" date, | |||
"receive_time" date, | |||
"sample_delivery_user" varchar(255), | |||
"receive_user" varchar(255), | |||
"notes" varchar(255), | |||
"serial_number" int4, | |||
"type" varchar(255), | |||
"receive_number" varchar(255), | |||
"samples_number_t" int4, | |||
"samples_number_d" int4, | |||
"coal_sample_d" int4, | |||
"receive_state" varchar(255), | |||
"coal_sample_t" int4, | |||
CONSTRAINT "zy_sample_delivery_pkey" PRIMARY KEY ("id") | |||
); | |||
-- 抽查表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_spotcheck" ( | |||
"Id" int4 NOT NULL, | |||
"Spotcheck_Code" varchar(50), | |||
"Spotcheck_User" character(10), | |||
"Spotcheck_Time" timestamp without time zone, | |||
"Spotcheck_Type" varchar(50), | |||
"CoalSampleCode" varchar(50), | |||
"SampleCustodian" varchar(50), | |||
"SamplingTime" timestamp without time zone, | |||
"QualityIncoming" numeric(18,1), | |||
"Granularity" varchar(20), | |||
"SpotcheckCompare" varchar(50), | |||
"Mt" numeric(18,1), | |||
"Mad" numeric(18,2), | |||
"Aad" numeric(18,2) NOT NULL, | |||
"Ad" numeric(18,2), | |||
"Vad" numeric(18,2), | |||
"Vdaf" numeric(18,2), | |||
"Var" numeric(18,2), | |||
"St_ad" numeric(18,2), | |||
"St_d" numeric(18,2), | |||
"Qb_ad" numeric(18,3), | |||
"Had" numeric(18,2), | |||
"Qnet_ar" numeric(18,2), | |||
"Qnet_ar1" numeric(18,2), | |||
"Qgr_d" numeric(18,2), | |||
"Qgr_ad" numeric(18,3), | |||
"Vd" numeric(18,2), | |||
"Aar" numeric(18,2), | |||
"St_ar" numeric(18,2), | |||
"Hd" numeric(18,2), | |||
"FCad" numeric(18,2), | |||
"CRC" numeric(18,0), | |||
"St_daf" numeric(18,2), | |||
CONSTRAINT "PK_HY_Spotcheck" PRIMARY KEY ("Id") | |||
); | |||
-- 任务表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_task" ( | |||
"id" int4 NOT NULL, | |||
"task_name" varchar(255), | |||
"task_type" varchar(255), | |||
"task_num" varchar(255), | |||
"is_auto" boolean, | |||
"task_time" date, | |||
"state" int4, | |||
"create_by" varchar(64), | |||
"create_time" timestamp without time zone, | |||
"update_by" varchar(64), | |||
"update_time" timestamp without time zone, | |||
CONSTRAINT "hy_task_pkey" PRIMARY KEY ("id") | |||
); | |||
-- 温湿度表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_warmhumid" ( | |||
"id" int4 NOT NULL, | |||
"laboratoryid" int4, | |||
"temperature" numeric(18,2), | |||
"humidity" numeric(18,2), | |||
"begintime" timestamp without time zone, | |||
"endtime" timestamp without time zone, | |||
"username" varchar(50), | |||
CONSTRAINT "PK_HY_warmhumid" PRIMARY KEY ("id") | |||
); | |||
-- 重量输入表 | |||
CREATE TABLE IF NOT EXISTS "public"."hy_weight_input" ( | |||
"id" int4 NOT NULL, | |||
"information_id" int4 NOT NULL, | |||
"information_norm_id" int4 NOT NULL, | |||
CONSTRAINT "PK__hy_weigh__3213E83F7BF969DE" PRIMARY KEY ("id") | |||
); | |||
-- 添加注释 | |||
COMMENT ON TABLE "public"."hy_allot" IS '化验分配表'; | |||
COMMENT ON TABLE "public"."hy_fullwatersample" IS '全水样品表'; | |||
COMMENT ON TABLE "public"."hy_informationnorm" IS '化验信息规范表'; | |||
COMMENT ON TABLE "public"."hy_itemdetail" IS '化验项目明细表'; | |||
COMMENT ON TABLE "public"."hy_laboratoryinstrument" IS '实验室仪器表'; | |||
COMMENT ON TABLE "public"."hy_materialanalysis_type" IS '物料分析类型表'; | |||
COMMENT ON TABLE "public"."hy_materialdetail" IS '物料明细表'; | |||
COMMENT ON TABLE "public"."hy_norm" IS '化验规范表'; | |||
COMMENT ON TABLE "public"."hy_sample_collection_detail" IS '样品采集明细表'; | |||
COMMENT ON TABLE "public"."hy_sample_delivery" IS '样品交付表'; | |||
COMMENT ON TABLE "public"."hy_spotcheck" IS '抽查表'; | |||
COMMENT ON TABLE "public"."hy_task" IS '任务表'; | |||
COMMENT ON TABLE "public"."hy_warmhumid" IS '温湿度表'; | |||
COMMENT ON TABLE "public"."hy_weight_input" IS '重量输入表'; |
@@ -2,93 +2,16 @@ use tokio::net::{TcpListener, TcpStream}; | |||
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |||
use config::Config; | |||
use tokio_postgres::{NoTls, Error as PgError}; | |||
use serde::{Deserialize, Serialize}; | |||
use std::sync::Arc; | |||
use chrono::{DateTime, Utc}; | |||
use std::error::Error; | |||
use std::sync::Arc; | |||
use crate::models::*; | |||
#[derive(Debug, Serialize, Deserialize)] | |||
struct InstrumentInfo { | |||
id: i32, | |||
informationid: i32, | |||
instrumentcode: String, | |||
laboratoryid: i32, | |||
name: String, | |||
remark: String, | |||
specification: String, | |||
} | |||
#[derive(Debug, Deserialize)] | |||
struct InformationInfo { | |||
id: i32, | |||
hy_name: Option<String>, | |||
flag: Option<i16>, | |||
laboratory_id: Option<i32>, | |||
analysistypeid: Option<i32>, | |||
} | |||
#[derive(Debug, Deserialize)] | |||
struct RecordInfo { | |||
id: i32, | |||
hy_code: Option<String>, | |||
r#type: Option<String>, | |||
hy_check: Option<i16>, | |||
hy_approve: Option<i16>, | |||
check_time: Option<DateTime<Utc>>, | |||
approve_time: Option<DateTime<Utc>>, | |||
approve_user: Option<String>, | |||
check_user: Option<String>, | |||
hy_time: Option<DateTime<Utc>>, | |||
hy_values: Option<String>, | |||
accept_time: Option<DateTime<Utc>>, | |||
accept_user: Option<String>, | |||
mt: Option<f64>, | |||
mad: Option<f64>, | |||
aad: Option<f64>, | |||
ad: Option<f64>, | |||
vad: Option<f64>, | |||
vd: Option<f64>, | |||
var: Option<f64>, | |||
vdaf: Option<f64>, | |||
fcad: Option<f64>, | |||
st_ar: Option<f64>, | |||
st_ad: Option<f64>, | |||
st_d: Option<f64>, | |||
had: Option<f64>, | |||
hd: Option<f64>, | |||
qb_ad: Option<f64>, | |||
qgr_ad: Option<f64>, | |||
qgr_d: Option<f64>, | |||
qnet_ar_mj_kg: Option<f64>, | |||
qnet_ar_j_cal: Option<f64>, | |||
v: Option<f64>, | |||
aar: Option<f64>, | |||
qnet_ar: Option<f64>, | |||
qnet_ar1: Option<f64>, | |||
crc: Option<f64>, | |||
st_daf: Option<f64>, | |||
cad: Option<f64>, | |||
cd: Option<f64>, | |||
isauto: Option<i16>, | |||
hy_type: Option<String>, | |||
isnormal: Option<i32>, | |||
} | |||
pub mod models; | |||
async fn connect_db(config: &Config) -> Result<tokio_postgres::Client, PgError> { | |||
let host = config.get_string("database.host").unwrap(); | |||
let port = config.get_int("database.port").unwrap() as u16; | |||
let dbname = config.get_string("database.name").unwrap(); | |||
let user = config.get_string("database.user").unwrap(); | |||
let password = config.get_string("database.password").unwrap(); | |||
let database_url = config.get_string("database_url").unwrap(); | |||
let (client, connection) = tokio_postgres::connect(&database_url, NoTls).await?; | |||
let connection_string = format!( | |||
"host={} port={} dbname={} user={} password={}", | |||
host, port, dbname, user, password | |||
); | |||
let (client, connection) = tokio_postgres::connect(&connection_string, NoTls).await?; | |||
// 在后台运行连接 | |||
tokio::spawn(async move { | |||
if let Err(e) = connection.await { | |||
eprintln!("数据库连接错误: {}", e); | |||
@@ -98,209 +21,313 @@ async fn connect_db(config: &Config) -> Result<tokio_postgres::Client, PgError> | |||
Ok(client) | |||
} | |||
async fn insert_instrument(client: &tokio_postgres::Client, info: &InstrumentInfo) -> Result<(), PgError> { | |||
// 先检查 ID 是否存在 | |||
let exists = client | |||
.query_one( | |||
"SELECT EXISTS(SELECT 1 FROM public.hy_instrument WHERE id = $1)", | |||
&[&info.id], | |||
) | |||
.await? | |||
.get::<_, bool>(0); | |||
if exists { | |||
println!("ID {} 已存在,跳过插入", info.id); | |||
return Ok(()); | |||
} | |||
// ID 不存在,执行插入 | |||
client.execute( | |||
"INSERT INTO public.hy_instrument (id, informationid, instrumentcode, laboratoryid, name, remark, specification) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7)", | |||
&[ | |||
&info.id, | |||
&info.informationid, | |||
&info.instrumentcode, | |||
&info.laboratoryid, | |||
&info.name, | |||
&info.remark, | |||
&info.specification, | |||
], | |||
) | |||
.await?; | |||
println!("成功插入仪器信息: {} (ID: {})", info.instrumentcode, info.id); | |||
Ok(()) | |||
} | |||
async fn insert_information(client: &tokio_postgres::Client, info: &InformationInfo) -> Result<(), PgError> { | |||
// 先检查 ID 是否存在 | |||
let exists = client | |||
.query_one( | |||
"SELECT EXISTS(SELECT 1 FROM public.hy_information WHERE id = $1)", | |||
&[&info.id], | |||
) | |||
.await? | |||
.get::<_, bool>(0); | |||
if exists { | |||
println!("ID {} 已存在,跳过插入", info.id); | |||
return Ok(()); | |||
} | |||
async fn handle_client(socket: &mut TcpStream, client: &Arc<tokio_postgres::Client>) -> Result<(), Box<dyn Error>> { | |||
let mut buffer = Vec::new(); | |||
socket.read_to_end(&mut buffer).await?; | |||
// ID 不存在,执行插入 | |||
client.execute( | |||
"INSERT INTO public.hy_information (id, hy_name, flag, laboratory_id, analysistypeid) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5)", | |||
&[ | |||
&info.id, | |||
&info.hy_name, | |||
&info.flag, | |||
&info.laboratory_id, | |||
&info.analysistypeid, | |||
], | |||
) | |||
.await?; | |||
let data = String::from_utf8_lossy(&buffer); | |||
println!("接收到数据: {}", data); | |||
println!("成功插入信息记录: ID {}", info.id); | |||
Ok(()) | |||
} | |||
async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Result<(), PgError> { | |||
// 先检查 ID 是否存在 | |||
let exists = client | |||
.query_one( | |||
"SELECT EXISTS(SELECT 1 FROM public.hy_record WHERE id = $1)", | |||
&[&info.id], | |||
) | |||
.await? | |||
.get::<_, bool>(0); | |||
if exists { | |||
println!("ID {} 已存在,跳过插入", info.id); | |||
return Ok(()); | |||
} | |||
// ID 不存在,执行插入 | |||
client.execute( | |||
"INSERT INTO public.hy_record ( | |||
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, mad, aad, ad, vad, vd, var, vdaf, fcad, st_ar, st_ad, st_d, | |||
had, hd, qb_ad, qgr_ad, qgr_d, qnet_ar_mj_kg, qnet_ar_j_cal, v, | |||
aar, qnet_ar, qnet_ar1, crc, st_daf, cad, cd, isauto, hy_type, isnormal | |||
) | |||
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 | |||
)", | |||
&[ | |||
&info.id, &info.hy_code, &info.r#type, &info.hy_check, &info.hy_approve, | |||
&info.check_time, &info.approve_time, &info.approve_user, &info.check_user, | |||
&info.hy_time, &info.hy_values, &info.accept_time, &info.accept_user, | |||
&info.mt, &info.mad, &info.aad, &info.ad, &info.vad, &info.vd, &info.var, | |||
&info.vdaf, &info.fcad, &info.st_ar, &info.st_ad, &info.st_d, &info.had, | |||
&info.hd, &info.qb_ad, &info.qgr_ad, &info.qgr_d, &info.qnet_ar_mj_kg, | |||
&info.qnet_ar_j_cal, &info.v, &info.aar, &info.qnet_ar, &info.qnet_ar1, | |||
&info.crc, &info.st_daf, &info.cad, &info.cd, &info.isauto, &info.hy_type, | |||
&info.isnormal | |||
], | |||
) | |||
.await?; | |||
println!("成功插入记录: ID {}", info.id); | |||
Ok(()) | |||
} | |||
async fn handle_client(socket: &mut TcpStream, client: &tokio_postgres::Client) -> Result<(), Box<dyn Error>> { | |||
let mut buf = [0; 1024 * 64]; // 增加缓冲区大小到64KB | |||
loop { | |||
let n = socket.read(&mut buf).await?; | |||
if n == 0 { | |||
break; | |||
} | |||
let data = String::from_utf8_lossy(&buf[..n]); | |||
println!("接收到的数据: {}", data); | |||
// 尝试解析为不同的数据类型并处理 | |||
let result = if let Ok(info) = serde_json::from_str::<InstrumentInfo>(&data) { | |||
println!("接收到仪器信息: {:?}", info); | |||
match insert_instrument(client, &info).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入仪器信息失败: {}", e); | |||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&data) { | |||
let success = match json.get("table_name").and_then(|v| v.as_str()) { | |||
Some("hy_instrument") => { | |||
if let Ok(info) = serde_json::from_str::<InstrumentInfo>(&data) { | |||
println!("接收到仪器信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入仪器信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析仪器信息失败"); | |||
false | |||
} | |||
} | |||
} else if let Ok(info) = serde_json::from_str::<InformationInfo>(&data) { | |||
println!("接收到分析信息: {:?}", info); | |||
match insert_information(client, &info).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入分析信息失败: {}", e); | |||
}, | |||
Some("hy_allot") => { | |||
if let Ok(info) = serde_json::from_str::<HyAllot>(&data) { | |||
println!("接收到分配信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入分配信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析分配信息失败"); | |||
false | |||
} | |||
} | |||
} else if let Ok(info) = serde_json::from_str::<RecordInfo>(&data) { | |||
println!("接收到记录信息: {:?}", info); | |||
match insert_record(client, &info).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入记录信息失败: {}", e); | |||
}, | |||
Some("hy_fullwatersample") => { | |||
if let Ok(info) = serde_json::from_str::<HyFullWaterSample>(&data) { | |||
println!("接收到全水样品信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入全水样品信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析全水样品信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_informationnorm") => { | |||
if let Ok(info) = serde_json::from_str::<HyInformationNorm>(&data) { | |||
println!("接收到化验信息规范: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入化验信息规范失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析化验信息规范失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_itemdetail") => { | |||
if let Ok(info) = serde_json::from_str::<HyItemDetail>(&data) { | |||
println!("接收到化验项目明细: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入化验项目明细失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析化验项目明细失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_laboratoryinstrument") => { | |||
if let Ok(info) = serde_json::from_str::<HyLaboratoryInstrument>(&data) { | |||
println!("接收到实验室仪器信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入实验室仪器信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析实验室仪器信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_materialanalysis_type") => { | |||
if let Ok(info) = serde_json::from_str::<HyMaterialAnalysisType>(&data) { | |||
println!("接收到物料分析类型信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入物料分析类型信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析物料分析类型信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_materialdetail") => { | |||
if let Ok(info) = serde_json::from_str::<HyMaterialDetail>(&data) { | |||
println!("接收到物料明细信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入物料明细信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析物料明细信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_norm") => { | |||
if let Ok(info) = serde_json::from_str::<HyNorm>(&data) { | |||
println!("接收到化验规范信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入化验规范信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析化验规范信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_warmhumid") => { | |||
if let Ok(info) = serde_json::from_str::<HyWarmHumid>(&data) { | |||
println!("接收到温湿度信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入温湿度信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析温湿度信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_task") => { | |||
if let Ok(info) = serde_json::from_str::<HyTask>(&data) { | |||
println!("接收到任务信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入任务信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析任务信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_spotcheck") => { | |||
if let Ok(info) = serde_json::from_str::<HySpotcheck>(&data) { | |||
println!("接收到点检信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入点检信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析点检信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_weight_input") => { | |||
if let Ok(info) = serde_json::from_str::<HyWeightInput>(&data) { | |||
println!("接收到称重输入信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入称重输入信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析称重输入信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_information") => { | |||
if let Ok(info) = serde_json::from_str::<HyInformation>(&data) { | |||
println!("接收到化验信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入化验信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析化验信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_cytask") => { | |||
if let Ok(info) = serde_json::from_str::<HyCyTask>(&data) { | |||
println!("接收到采样任务信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入采样任务信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析采样任务信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_record") => { | |||
if let Ok(info) = serde_json::from_str::<HyRecord>(&data) { | |||
println!("接收到化验记录信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入化验记录信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析化验记录信息失败"); | |||
false | |||
} | |||
}, | |||
Some("hy_sample_collection_detail") => { | |||
if let Ok(info) = serde_json::from_str::<HySampleCollectionDetail>(&data) { | |||
println!("接收到样品采集明细信息: {:?}", info); | |||
match info.insert(client.as_ref()).await { | |||
Ok(_) => true, | |||
Err(e) => { | |||
eprintln!("插入样品采集明细信息失败: {}", e); | |||
false | |||
} | |||
} | |||
} else { | |||
eprintln!("解析样品采集明细信息失败"); | |||
false | |||
} | |||
}, | |||
Some(table_name) => { | |||
eprintln!("未知的表名: {}", table_name); | |||
false | |||
}, | |||
None => { | |||
eprintln!("JSON 数据中缺少 table_name 字段"); | |||
false | |||
} | |||
}; | |||
let response = if success { | |||
"success" | |||
} else { | |||
println!("无法解析JSON数据为任何已知类型"); | |||
false | |||
"error" | |||
}; | |||
// 发送响应 | |||
let response = if result { 0xFF } else { 0x00 }; | |||
if let Err(e) = socket.write_all(&[response]).await { | |||
eprintln!("发送响应失败: {}", e); | |||
break; | |||
} | |||
socket.write_all(response.as_bytes()).await?; | |||
} else { | |||
eprintln!("解析 JSON 数据失败"); | |||
socket.write_all(b"error").await?; | |||
} | |||
println!("客户端断开连接: {}", socket.peer_addr()?); | |||
Ok(()) | |||
} | |||
#[tokio::main] | |||
async fn main() -> Result<(), Box<dyn Error>> { | |||
// 读取配置文件 | |||
let settings = Config::builder() | |||
let config = Config::builder() | |||
.add_source(config::File::with_name("config")) | |||
.build()?; | |||
// 连接数据库 | |||
let client = connect_db(&settings).await?; | |||
let client = Arc::new(client); | |||
println!("数据库连接成功"); | |||
let address = settings.get_string("server.address")?; | |||
let port = settings.get_int("server.port")? as u16; | |||
let bind_address = format!("{}:{}", address, port); | |||
let listener = TcpListener::bind(&bind_address).await?; | |||
println!("服务器监听地址: {}", bind_address); | |||
let client = Arc::new(connect_db(&config).await?); | |||
let addr = config.get_string("server_addr").unwrap(); | |||
let listener = TcpListener::bind(&addr).await?; | |||
println!("服务器启动在: {}", addr); | |||
loop { | |||
let (mut socket, addr) = listener.accept().await?; | |||
println!("新客户端连接: {}", addr); | |||
let (mut socket, _) = listener.accept().await?; | |||
let client = Arc::clone(&client); | |||
tokio::spawn(async move { | |||
if let Err(e) = handle_client(&mut socket, &client).await { | |||
eprintln!("处理客户端错误: {}", e); | |||
eprintln!("处理客户端请求时出错: {}", e); | |||
} | |||
}); | |||
} | |||
@@ -0,0 +1,574 @@ | |||
use serde::{Deserialize, Serialize}; | |||
use tokio_postgres::Error as PgError; | |||
use chrono::NaiveDateTime; | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyAllot { | |||
pub id: i32, | |||
pub userid: Option<i32>, | |||
pub username: Option<String>, | |||
pub informationid: Option<i32>, | |||
pub allottime: Option<NaiveDateTime>, | |||
pub hy_code: Option<String>, | |||
pub hy_type: Option<String>, | |||
pub hy_method: Option<String>, | |||
pub hy_quest: Option<String>, | |||
} | |||
impl HyAllot { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_allot (id, userid, username, informationid, allottime, | |||
hy_code, hy_type, hy_method, hy_quest) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", | |||
&[&self.id, &self.userid, &self.username, &self.informationid, &self.allottime, | |||
&self.hy_code, &self.hy_type, &self.hy_method, &self.hy_quest], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyFullWaterSample { | |||
pub id: i32, | |||
pub qs_code: Option<String>, | |||
pub qs_tonnage: Option<f64>, | |||
pub mt: Option<f64>, | |||
pub remark: Option<String>, | |||
pub onecode: Option<String>, | |||
pub towcode: Option<String>, | |||
pub fx_code: Option<String>, | |||
pub fx_onecode: Option<String>, | |||
pub fx_twocode: Option<String>, | |||
} | |||
impl HyFullWaterSample { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_fullwatersample (id, qs_code, qs_tonnage, mt, remark, | |||
onecode, towcode, fx_code, fx_onecode, fx_twocode) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", | |||
&[&self.id, &self.qs_code, &self.qs_tonnage, &self.mt, &self.remark, | |||
&self.onecode, &self.towcode, &self.fx_code, &self.fx_onecode, &self.fx_twocode], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyInformationNorm { | |||
pub id: i32, | |||
pub information_id: Option<i32>, | |||
pub hy_id: Option<i32>, | |||
pub norm_name: Option<String>, | |||
pub flag: Option<i16>, | |||
pub apparatus_id: Option<i32>, | |||
pub need_compute: Option<i16>, | |||
pub formula: Option<String>, | |||
pub secondformula: Option<String>, | |||
pub mapping: Option<String>, | |||
pub input_type: Option<i32>, | |||
pub round: Option<i32>, | |||
pub sort: Option<i32>, | |||
} | |||
impl HyInformationNorm { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_informationnorm (id, information_id, hy_id, norm_name, | |||
flag, apparatus_id, need_compute, formula, secondformula, mapping, input_type, | |||
round, sort) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", | |||
&[&self.id, &self.information_id, &self.hy_id, &self.norm_name, &self.flag, | |||
&self.apparatus_id, &self.need_compute, &self.formula, &self.secondformula, | |||
&self.mapping, &self.input_type, &self.round, &self.sort], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyItemDetail { | |||
pub id: i32, | |||
pub record_id: Option<i32>, | |||
pub information_id: Option<i32>, | |||
pub laboratory_id: Option<i32>, | |||
pub number: Option<i32>, | |||
pub cancellation: Option<i16>, | |||
pub detectionuser: Option<String>, | |||
pub detectiontime: Option<NaiveDateTime>, | |||
pub original_num: Option<String>, | |||
pub hy_check: Option<i16>, | |||
pub checkuser: Option<String>, | |||
pub checktime: Option<NaiveDateTime>, | |||
pub oversize: Option<i16>, | |||
} | |||
impl HyItemDetail { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_itemdetail (id, record_id, information_id, laboratory_id, | |||
number, cancellation, detectionuser, detectiontime, original_num, hy_check, | |||
checkuser, checktime, oversize) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", | |||
&[&self.id, &self.record_id, &self.information_id, &self.laboratory_id, | |||
&self.number, &self.cancellation, &self.detectionuser, &self.detectiontime, | |||
&self.original_num, &self.hy_check, &self.checkuser, &self.checktime, | |||
&self.oversize], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyLaboratoryInstrument { | |||
pub id: i32, | |||
pub norm_id: Option<i32>, | |||
pub instrument_id: Option<i32>, | |||
} | |||
impl HyLaboratoryInstrument { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_laboratory_instrument (id, norm_id, instrument_id) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3)", | |||
&[&self.id, &self.norm_id, &self.instrument_id], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyMaterialAnalysisType { | |||
pub id: i32, | |||
pub name: Option<String>, | |||
pub flag: Option<i16>, | |||
pub sort: Option<i32>, | |||
pub createtime: Option<NaiveDateTime>, | |||
pub createuser: Option<String>, | |||
} | |||
impl HyMaterialAnalysisType { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_material_analysis_type (id, name, flag, sort, createtime, | |||
createuser) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6)", | |||
&[&self.id, &self.name, &self.flag, &self.sort, &self.createtime, &self.createuser], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyMaterialDetail { | |||
pub id: i32, | |||
pub name: Option<String>, | |||
pub flag: Option<i32>, | |||
pub sort: Option<i32>, | |||
pub createtime: Option<NaiveDateTime>, | |||
pub createuser: Option<String>, | |||
pub analysistypeid: Option<i32>, | |||
pub materialid: Option<i32>, | |||
} | |||
impl HyMaterialDetail { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_material_detail (id, name, flag, sort, createtime, | |||
createuser, analysistypeid, materialid) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", | |||
&[&self.id, &self.name, &self.flag, &self.sort, &self.createtime, &self.createuser, | |||
&self.analysistypeid, &self.materialid], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyNorm { | |||
pub id: i32, | |||
pub norm_id: Option<i32>, | |||
pub zbvalues: Option<f64>, | |||
pub itemdetail_id: Option<i32>, | |||
pub hy_user: Option<String>, | |||
pub checktime: Option<NaiveDateTime>, | |||
pub explain: Option<String>, | |||
} | |||
impl HyNorm { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_norm (id, norm_id, zbvalues, itemdetail_id, hy_user, | |||
checktime, explain) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7)", | |||
&[&self.id, &self.norm_id, &self.zbvalues, &self.itemdetail_id, &self.hy_user, | |||
&self.checktime, &self.explain], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyWarmHumid { | |||
pub id: i32, | |||
pub laboratoryid: Option<i32>, | |||
pub temperature: Option<f64>, | |||
pub humidity: Option<f64>, | |||
pub begintime: Option<NaiveDateTime>, | |||
pub endtime: Option<NaiveDateTime>, | |||
pub username: Option<String>, | |||
} | |||
impl HyWarmHumid { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_warmhumid (id, laboratoryid, temperature, humidity, | |||
begintime, endtime, username) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7)", | |||
&[&self.id, &self.laboratoryid, &self.temperature, &self.humidity, | |||
&self.begintime, &self.endtime, &self.username], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyTask { | |||
pub id: i32, | |||
pub task_name: Option<String>, | |||
pub task_type: Option<String>, | |||
pub task_num: Option<String>, | |||
pub is_auto: Option<bool>, | |||
pub task_time: Option<NaiveDateTime>, | |||
pub state: Option<i32>, | |||
pub create_by: Option<String>, | |||
pub create_time: Option<NaiveDateTime>, | |||
pub update_by: Option<String>, | |||
pub update_time: Option<NaiveDateTime>, | |||
} | |||
impl HyTask { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_task (id, task_name, task_type, task_num, is_auto, | |||
task_time, state, create_by, create_time, update_by, update_time) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)", | |||
&[&self.id, &self.task_name, &self.task_type, &self.task_num, &self.is_auto, | |||
&self.task_time, &self.state, &self.create_by, &self.create_time, | |||
&self.update_by, &self.update_time], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HySpotcheck { | |||
pub id: i32, | |||
pub spotcheck_code: Option<String>, | |||
pub spotcheck_user: Option<String>, | |||
pub spotcheck_time: Option<NaiveDateTime>, | |||
pub spotcheck_type: Option<String>, | |||
pub coal_sample_code: Option<String>, | |||
pub sample_custodian: Option<String>, | |||
pub sampling_time: Option<NaiveDateTime>, | |||
pub quality_incoming: Option<f64>, | |||
pub granularity: Option<String>, | |||
pub spotcheck_compare: Option<String>, | |||
pub mt: Option<f64>, | |||
pub mad: Option<f64>, | |||
pub aad: f64, // NOT NULL | |||
pub ad: Option<f64>, | |||
pub vad: Option<f64>, | |||
pub vdaf: Option<f64>, | |||
pub var_data: Option<f64>, | |||
pub st_ad: Option<f64>, | |||
pub st_d: Option<f64>, | |||
pub qb_ad: Option<f64>, | |||
pub had: Option<f64>, | |||
pub qnet_ar: Option<f64>, | |||
pub qnet_ar1: Option<f64>, | |||
pub qgr_d: Option<f64>, | |||
pub qgr_ad: Option<f64>, | |||
pub vd: Option<f64>, | |||
pub aar: Option<f64>, | |||
pub st_ar: Option<f64>, | |||
pub hd: Option<f64>, | |||
pub fcad: Option<f64>, | |||
pub crc: Option<i64>, | |||
pub st_daf: Option<f64>, | |||
} | |||
impl HySpotcheck { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_spotcheck (id, spotcheck_code, spotcheck_user, | |||
spotcheck_time, spotcheck_type, coal_sample_code, sample_custodian, | |||
sampling_time, quality_incoming, granularity, spotcheck_compare, mt, mad, aad, | |||
ad, vad, vdaf, var_data, st_ad, st_d, qb_ad, had, qnet_ar, qnet_ar1, qgr_d, | |||
qgr_ad, vd, aar, st_ar, hd, fcad, crc, st_daf) | |||
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)", | |||
&[&self.id, &self.spotcheck_code, &self.spotcheck_user, &self.spotcheck_time, | |||
&self.spotcheck_type, &self.coal_sample_code, &self.sample_custodian, | |||
&self.sampling_time, &self.quality_incoming, &self.granularity, | |||
&self.spotcheck_compare, &self.mt, &self.mad, &self.aad, &self.ad, &self.vad, | |||
&self.vdaf, &self.var_data, &self.st_ad, &self.st_d, &self.qb_ad, &self.had, | |||
&self.qnet_ar, &self.qnet_ar1, &self.qgr_d, &self.qgr_ad, &self.vd, &self.aar, | |||
&self.st_ar, &self.hd, &self.fcad, &self.crc, &self.st_daf], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyWeightInput { | |||
pub id: i32, | |||
pub information_id: i32, | |||
pub information_norm_id: i32, | |||
} | |||
impl HyWeightInput { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_weight_input (id, information_id, information_norm_id) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3)", | |||
&[&self.id, &self.information_id, &self.information_norm_id], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Deserialize)] | |||
pub struct InstrumentInfo { | |||
pub id: i32, | |||
pub laboratoryid: Option<i32>, | |||
pub name: Option<String>, | |||
pub instrumentcode: Option<String>, | |||
pub informationid: Option<i32>, | |||
pub specification: Option<String>, | |||
pub remark: Option<String>, | |||
} | |||
impl InstrumentInfo { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_instrument (id, laboratoryid, name, instrumentcode, | |||
informationid, specification, remark) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7)", | |||
&[&self.id, &self.laboratoryid, &self.name, &self.instrumentcode, | |||
&self.informationid, &self.specification, &self.remark], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyInformation { | |||
pub id: i32, | |||
pub hy_name: Option<String>, | |||
pub flag: Option<i32>, | |||
pub laboratory_id: Option<i32>, | |||
pub analysistypeid: Option<i32>, | |||
} | |||
impl HyInformation { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_information (id, hy_name, flag, laboratory_id, analysistypeid) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5)", | |||
&[&self.id, &self.hy_name, &self.flag, &self.laboratory_id, &self.analysistypeid], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyCyTask { | |||
pub id: i32, | |||
pub task_id: Option<i32>, | |||
pub task_name: Option<String>, | |||
pub task_status: Option<i32>, | |||
pub create_time: Option<NaiveDateTime>, | |||
pub create_user: Option<String>, | |||
pub remark: Option<String>, | |||
} | |||
impl HyCyTask { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_cytask (id, task_id, task_name, task_status, create_time, | |||
create_user, remark) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7)", | |||
&[&self.id, &self.task_id, &self.task_name, &self.task_status, | |||
&self.create_time, &self.create_user, &self.remark], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HyRecord { | |||
#[serde(skip_deserializing)] | |||
pub id: i32, | |||
pub hy_code: Option<String>, | |||
pub hy_type: Option<String>, | |||
pub hy_check: Option<i16>, | |||
pub hy_approve: Option<i16>, | |||
pub check_time: Option<NaiveDateTime>, | |||
pub approve_time: Option<NaiveDateTime>, | |||
pub approve_user: Option<String>, | |||
pub check_user: Option<String>, | |||
pub hy_time: Option<NaiveDateTime>, | |||
pub hy_values: Option<String>, | |||
pub accept_time: Option<NaiveDateTime>, | |||
pub accept_user: Option<String>, | |||
pub mt: Option<f64>, | |||
pub mad: Option<f64>, | |||
pub aad: Option<f64>, | |||
pub ad: Option<f64>, | |||
pub vad: Option<f64>, | |||
pub vd: Option<f64>, | |||
pub var_data: Option<f64>, | |||
pub vdaf: Option<f64>, | |||
pub fcad: Option<f64>, | |||
pub st_ar: Option<f64>, | |||
pub st_ad: Option<f64>, | |||
pub st_d: Option<f64>, | |||
pub had: Option<f64>, | |||
pub hd: Option<f64>, | |||
pub qb_ad: Option<f64>, | |||
pub qgr_ad: Option<f64>, | |||
pub qgr_d: Option<f64>, | |||
pub qnet_ar_mj_kg: Option<f64>, | |||
pub qnet_ar_j_cal: Option<i32>, | |||
pub v: Option<f64>, | |||
pub aar: Option<f64>, | |||
pub qnet_ar: Option<f64>, | |||
pub qnet_ar1: Option<f64>, | |||
pub crc: Option<i32>, | |||
pub st_daf: Option<f64>, | |||
pub cad: Option<f64>, | |||
pub cd: Option<f64>, | |||
pub isauto: Option<i16>, | |||
pub isnormal: Option<i32>, | |||
} | |||
impl HyRecord { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_record (hy_code, hy_type, hy_check, hy_approve, check_time, | |||
approve_time, approve_user, check_user, hy_time, hy_values, accept_time, accept_user, | |||
mt, mad, aad, ad, vad, vd, var, vdaf, fcad, st_ar, st_ad, st_d, had, hd, qb_ad, | |||
qgr_ad, qgr_d, qnet_ar_mj_kg, qnet_ar_j_cal, v, aar, qnet_ar, qnet_ar1, crc, | |||
st_daf, cad, cd, isauto, isnormal) | |||
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)", | |||
&[&self.hy_code, &self.hy_type, &self.hy_check, &self.hy_approve, &self.check_time, | |||
&self.approve_time, &self.approve_user, &self.check_user, &self.hy_time, | |||
&self.hy_values, &self.accept_time, &self.accept_user, &self.mt, &self.mad, | |||
&self.aad, &self.ad, &self.vad, &self.vd, &self.var_data, &self.vdaf, &self.fcad, | |||
&self.st_ar, &self.st_ad, &self.st_d, &self.had, &self.hd, &self.qb_ad, | |||
&self.qgr_ad, &self.qgr_d, &self.qnet_ar_mj_kg, &self.qnet_ar_j_cal, &self.v, | |||
&self.aar, &self.qnet_ar, &self.qnet_ar1, &self.crc, &self.st_daf, &self.cad, | |||
&self.cd, &self.isauto, &self.isnormal], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} | |||
#[derive(Debug, Serialize, Deserialize)] | |||
pub struct HySampleCollectionDetail { | |||
pub id: i32, | |||
pub num: i32, | |||
pub unit_num: i32, | |||
pub time: Option<NaiveDateTime>, | |||
pub type_: Option<i32>, | |||
pub sy_method: Option<i32>, | |||
pub sy_time: Option<NaiveDateTime>, | |||
pub one_num: Option<String>, | |||
pub two_num: Option<String>, | |||
pub three_num: Option<String>, | |||
pub sy_starttime: Option<NaiveDateTime>, | |||
pub sy_endtime: Option<NaiveDateTime>, | |||
pub cy_startnum: Option<String>, | |||
pub cy_endnum: Option<String>, | |||
pub sy_user: Option<String>, | |||
pub sy_car_count: Option<i32>, | |||
pub sy_dun_weight: Option<f64>, | |||
pub byz_bag_count: Option<i16>, | |||
pub y_liu: Option<i16>, | |||
pub zy_user: Option<String>, | |||
} | |||
impl HySampleCollectionDetail { | |||
pub async fn insert(&self, client: &tokio_postgres::Client) -> Result<(), PgError> { | |||
client | |||
.execute( | |||
"INSERT INTO public.hy_sample_collection_detail (id, num, unit_num, time, type, | |||
sy_method, sy_time, one_num, two_num, three_num, sy_starttime, sy_endtime, | |||
cy_startnum, cy_endnum, sy_user, sy_car_count, sy_dun_weight, byz_bag_count, | |||
y_liu, zy_user) | |||
OVERRIDING SYSTEM VALUE | |||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, | |||
$16, $17, $18, $19, $20)", | |||
&[&self.id, &self.num, &self.unit_num, &self.time, &self.type_, &self.sy_method, | |||
&self.sy_time, &self.one_num, &self.two_num, &self.three_num, &self.sy_starttime, | |||
&self.sy_endtime, &self.cy_startnum, &self.cy_endnum, &self.sy_user, | |||
&self.sy_car_count, &self.sy_dun_weight, &self.byz_bag_count, &self.y_liu, | |||
&self.zy_user], | |||
) | |||
.await?; | |||
Ok(()) | |||
} | |||
} |
@@ -1 +1 @@ | |||
0c18376461b43be3 | |||
5f92b3e22ca529e1 |
@@ -1 +1 @@ | |||
{"rustc":13800692020808712694,"features":"[]","declared_features":"[]","target":8765685456636761285,"profile":8731458305071235362,"path":4942398508502643691,"deps":[[4679662532519462650,"tokio_postgres",false,10165692077103750655],[5138218615291878843,"tokio",false,15265975105261538754],[6547980334806251551,"chrono",false,15080356830784337688],[9689903380558560274,"serde",false,9113250839399411242],[15367738274754116744,"serde_json",false,13898242479202773795],[18150860780478849731,"config",false,16692050494851569320]],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\tcp_server-d434eb7e44cc404e\\dep-bin-tcp_server","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0} | |||
{"rustc":13800692020808712694,"features":"[]","declared_features":"[]","target":8765685456636761285,"profile":8731458305071235362,"path":4942398508502643691,"deps":[[4679662532519462650,"tokio_postgres",false,17428534237561806687],[4903361426315736749,"log4rs",false,16408576812704843639],[5138218615291878843,"tokio",false,15265975105261538754],[6547980334806251551,"chrono",false,5514382626025845838],[9689903380558560274,"serde",false,9113250839399411242],[15367738274754116744,"serde_json",false,13898242479202773795],[18150860780478849731,"config",false,4613493946607459254]],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\tcp_server-d434eb7e44cc404e\\dep-bin-tcp_server","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0} |
@@ -1,5 +1,6 @@ | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\deps\tcp_server.exe: src\main.rs | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\deps\tcp_server.exe: src\main.rs src\models.rs | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\deps\tcp_server.d: src\main.rs | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\deps\tcp_server.d: src\main.rs src\models.rs | |||
src\main.rs: | |||
src\models.rs: |
@@ -1 +1 @@ | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\tcp_server.exe: C:\A_Code\auseft.Platform.DataSync\tcp_server\src\main.rs | |||
C:\A_Code\auseft.Platform.DataSync\tcp_server\target\debug\tcp_server.exe: C:\A_Code\auseft.Platform.DataSync\tcp_server\src\main.rs C:\A_Code\auseft.Platform.DataSync\tcp_server\src\models.rs |