Forráskód Böngészése

调整设备删除与绑定时的行为,现在绑定成功时会将设备别名重置为sn,删除设备时也会尝试重置设备别名

zii 2 hete
szülő
commit
b13e6ced9e
3 módosított fájl, 5 hozzáadás és 5 törlés
  1. 2 2
      src/api/ability.rs
  2. 2 2
      src/api/auth.rs
  3. 1 1
      src/api/device.rs

+ 2 - 2
src/api/ability.rs

@@ -208,7 +208,7 @@ pub async fn drop_device(
         }else{
             return Json(JsonBack{errcode: 3000, errmsg: Some("数据库异常: 获取设备sn失败".to_string())});
         };
-    if let Err(e) = state.db_lite.execute("update device set belongto=0 where sn=?", [sn.clone()]).await{
+    if let Err(e) = state.db_lite.execute("update device set belongto=0,name=sn where sn=?", [sn.clone()]).await{
         return Json(JsonBack{errcode: 3000, errmsg: Some(format!("数据库异常: 移除设备从属失败{e}"))});
     }
     let mut sqls=Vec::new();
@@ -223,7 +223,7 @@ pub async fn drop_device(
     
     if let Err(e) = state.db_lite.execute("delete from map_user_device where did=?", [did]).await{log(Warning, format!("error: {e}"))}
 
-    if let Err(e) = state.db_lite.execute("update device set belongto=0 where did=?", [did]).await{log(Warning, format!("error: {e}"))}
+    if let Err(e) = state.db_lite.execute("update device set belongto=0,name=sn where did=?", [did]).await{log(Warning, format!("error: {e}"))}
 
     match state.mq_detail{
         Some(s) => {

+ 2 - 2
src/api/auth.rs

@@ -109,7 +109,7 @@ pub async fn auth(
         // 已注册时绑定设备
         if let Some(sn)= q.state.strip_prefix("did="){
             log(Debuging, format!("got did:  {}",sn));
-            match state.db_lite.execute("update device set belongto=? where sn=? and belongto=0", (id,sn)).await{
+            match state.db_lite.execute("update device set belongto=?,name=sn where sn=? and belongto=0", (id,sn)).await{
                 Err(e) => {println!("{e}");bindfail=Some("&bindfail=true");}
                 Ok(n)=>{
                     if n!=0{
@@ -186,7 +186,7 @@ pub async fn auth(
         // 未注册时绑定设备
         if let Some(sn)= q.state.strip_prefix("did="){
             log(Debuging, format!("got did:  {}",sn));
-            match state.db_lite.execute("update device set belongto=? where sn=? and belongto=0", (uid,sn)).await{
+            match state.db_lite.execute("update device set belongto=?,name=sn where sn=? and belongto=0", (uid,sn)).await{
                 Err(e)=>{println!("{e}");bindfail=Some("&bindfail=true");},
                 Ok(n ) => {
                     if n!=0{  // 设备绑定成功,update至少一条则记录并订阅

+ 1 - 1
src/api/device.rs

@@ -212,7 +212,7 @@ pub async fn d_del(
         return Json(JsonBack{errcode: 3000, errmsg: Some(format!("删除设备失败: 设备不存在"))});
     };
     if let Err(e) = state.db_lite.execute(
-        "update device set belongto=0 where id=?",
+        "update device set belongto=0,name=sn where id=?",
         [d.id]).await {
         return Json(JsonBack{errcode: 3000, errmsg: Some(format!("删除设备失败: {e}"))});
     }