2 Commits 70ffeca855 ... 633fbac34b

Author SHA1 Message Date
  陈雪 633fbac34b ✨ feat(table): 新增获取区域及其桌子信息的接口 23 hours ago
  陈雪 9da53cbfb5 ✨ feat(table): 新增区域和桌子接口,创建桌子服务以获取区域桌子信息 23 hours ago

+ 7 - 8
src-tauri/src/commands/table.rs

@@ -1,15 +1,14 @@
 use crate::{
     CmdResult, CmdState,
-    service::category::{Category, CategoryWithSpu},
+    service::table::{AreaWithTable, Table},
 };
 
 #[tauri::command]
-pub async fn get_table(app_state: CmdState<'_>) -> CmdResult<Vec<CategoryWithSpu>> {
-    let category = Category::new(app_state.conn.clone());
-    let categories = category.get_category_commodity().await;
-    match categories {
-        Ok(categories) => Ok(categories),
-        Err(e) => Err(format!("请求分类失败{:?}", e)),
+pub async fn get_table_area(app_state: CmdState<'_>) -> CmdResult<Vec<AreaWithTable>> {
+    let table_service = Table::new(app_state.conn.clone());
+    let area_table = table_service.get_table_area().await;
+    match area_table {
+        Ok(areas) => Ok(areas),
+        Err(e) => Err(format!("获取区域错误{:?}", e)),
     }
-    // Ok("111".into())
 }

+ 1 - 1
src-tauri/src/lib.rs

@@ -44,7 +44,7 @@ pub fn run() {
             })
         })
         .invoke_handler(tauri::generate_handler![
-            table::get_table,
+            table::get_table_area,
             category::get_category,
             commodity::get_commodity
         ])

+ 5 - 5
src-tauri/src/models/prelude.rs

@@ -2,10 +2,10 @@
 
 pub use super::menu_cate::Entity as MenuCate;
 pub use super::menu_commodity::Entity as MenuCommodity;
-pub use super::menu_sku::Entity as MenuSku;
-pub use super::menu_sku_spec::Entity as MenuSkuSpec;
-pub use super::menu_spec::Entity as MenuSpec;
+// pub use super::menu_sku::Entity as MenuSku;
+// pub use super::menu_sku_spec::Entity as MenuSkuSpec;
+// pub use super::menu_spec::Entity as MenuSpec;
 pub use super::store_area::Entity as StoreArea;
-pub use super::store_material::Entity as StoreMaterial;
-pub use super::store_order::Entity as StoreOrder;
+// pub use super::store_material::Entity as StoreMaterial;
+// pub use super::store_order::Entity as StoreOrder;
 pub use super::store_table::Entity as StoreTable;

+ 2 - 1
src-tauri/src/service/mod.rs

@@ -1 +1,2 @@
-pub(crate) mod category;
+pub mod category;
+pub mod table;

+ 63 - 0
src-tauri/src/service/table.rs

@@ -0,0 +1,63 @@
+use std::sync::Arc;
+
+use anyhow::Ok;
+use sea_orm::{DatabaseConnection, EntityTrait, QuerySelect};
+use serde::{Deserialize, Serialize};
+
+use crate::models::{
+    prelude::{StoreArea, StoreTable},
+    store_area, store_table,
+};
+
+pub struct Table {
+    conn: Arc<DatabaseConnection>,
+}
+
+#[derive(Deserialize, Serialize)]
+struct QueryTable {
+    id: i32,
+    table_no: String,
+    capacity: Option<i32>,
+}
+
+#[derive(Deserialize, Serialize)]
+pub struct AreaWithTable {
+    id: i32,
+    name: String,
+    description: Option<String>,
+    tables: Vec<QueryTable>,
+}
+
+impl Table {
+    pub fn new(conn: Arc<DatabaseConnection>) -> Self {
+        return Self { conn };
+    }
+    pub async fn get_table_area(&self) -> anyhow::Result<Vec<AreaWithTable>> {
+        let area_with_table = StoreArea::find()
+            .find_with_related(StoreTable)
+            .column(store_area::Column::Id)
+            .column(store_area::Column::Name)
+            .column(store_area::Column::Description)
+            .column(store_table::Column::Id)
+            .column(store_table::Column::TableNo)
+            .column(store_table::Column::Capacity)
+            .all(&*self.conn)
+            .await?;
+        Ok(area_with_table
+            .into_iter()
+            .map(|(area, tables)| AreaWithTable {
+                id: area.id,
+                name: area.name,
+                description: area.description,
+                tables: tables
+                    .iter()
+                    .map(|table| QueryTable {
+                        id: table.id,
+                        table_no: table.table_no.clone(),
+                        capacity: table.capacity,
+                    })
+                    .collect(),
+            })
+            .collect())
+    }
+}

+ 12 - 0
src/interface/StoreTable.ts

@@ -0,0 +1,12 @@
+export interface Area {
+  id: number
+  name: string
+  description: string
+  tables: Table[]
+}
+
+export interface Table {
+  id: number
+  tableNo: string
+  capacity: number
+}

+ 8 - 0
src/service/TableService.ts

@@ -0,0 +1,8 @@
+import { Area } from '@/interface/StoreTable'
+import { invoke } from '@tauri-apps/api/core'
+
+export class TableService {
+  static getAreaTables() {
+    return invoke<Area>('get_table_area')
+  }
+}