浏览代码

服务端可以接收时间调整

晋江
OCEAN 2 个月前
父节点
当前提交
6d42943b79
共有 4 个文件被更改,包括 44 次插入36 次删除
  1. +3
    -2
      tcp_client/config.toml
  2. +41
    -34
      tcp_server/src/main.rs
  3. 二进制
      tcp_server/target/debug/tcp_server.exe
  4. 二进制
      tcp_server/target/debug/tcp_server.pdb

+ 3
- 2
tcp_client/config.toml 查看文件

@@ -1,6 +1,7 @@
[server]
host = "10.180.4.88"
#host = "127.0.0.1"
#host = "10.180.4.88"
host = "127.0.0.1"

port = 9090

[client]


+ 41
- 34
tcp_server/src/main.rs 查看文件

@@ -33,19 +33,15 @@ struct RecordInfo {
id: i32,
hy_code: Option<String>,
r#type: Option<String>,
hy_check: Option<i16>,
hy_approve: Option<i16>,
#[serde(default)]
check_time: Option<NaiveDateTime>,
#[serde(default)]
approve_time: Option<NaiveDateTime>,
hy_check: i32,
hy_approve: i32,
check_time: Option<String>,
approve_time: Option<String>,
approve_user: Option<String>,
check_user: Option<String>,
#[serde(default)]
hy_time: Option<NaiveDateTime>,
hy_time: Option<String>,
hy_values: Option<String>,
#[serde(default)]
accept_time: Option<NaiveDateTime>,
accept_time: Option<String>,
accept_user: Option<String>,
mt: Option<Decimal>,
mad: Option<Decimal>,
@@ -74,9 +70,9 @@ struct RecordInfo {
st_daf: Option<Decimal>,
cad: Option<Decimal>,
cd: Option<Decimal>,
isauto: Option<i16>,
isauto: Option<i32>,
hy_type: Option<String>,
isnormal: Option<i32>,
isnormal: i32,
}

#[derive(Debug, Deserialize)]
@@ -602,6 +598,16 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re
.await?
.get::<_, bool>(0);

// 解析时间字段
let check_time = info.check_time.as_deref()
.and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok());
let approve_time = info.approve_time.as_deref()
.and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok());
let hy_time = info.hy_time.as_deref()
.and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok());
let accept_time = info.accept_time.as_deref()
.and_then(|s| NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").ok());

if exists {
// 如果记录存在,执行更新操作
client.execute(
@@ -617,15 +623,15 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re
cd = $40, isauto = $41, hy_type = $42, isnormal = $43
WHERE id = $1",
&[
&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
&info.id, &info.hy_code, &info.r#type, &(info.hy_check as i16), &(info.hy_approve as i16),
&check_time, &approve_time, &info.approve_user, &info.check_user,
&hy_time, &info.hy_values, &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.map(|x| x as i16), &info.hy_type, &(info.isnormal as i32)
],
).await?;
println!("成功更新记录信息: ID {}", info.id);
@@ -645,21 +651,22 @@ async fn insert_record(client: &tokio_postgres::Client, info: &RecordInfo) -> Re
qnet_ar, qnet_ar1, crc, st_daf, cad,
cd, isauto, hy_type, isnormal
) 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
$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
&info.id, &info.hy_code, &info.r#type, &(info.hy_check as i16), &(info.hy_approve as i16),
&check_time, &approve_time, &info.approve_user, &info.check_user,
&hy_time, &info.hy_values, &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.map(|x| x as i16), &info.hy_type, &(info.isnormal as i32)
],
).await?;



二进制
tcp_server/target/debug/tcp_server.exe 查看文件


二进制
tcp_server/target/debug/tcp_server.pdb 查看文件


正在加载...
取消
保存