瀏覽代碼

✨ feat(commands): 重命名命令函数并新增材料和订单服务

陈雪 21 小時之前
父節點
當前提交
7824726f14

+ 1 - 1
src-tauri/src/commands/category.rs

@@ -4,7 +4,7 @@ use crate::{
 };
 
 #[tauri::command]
-pub async fn get_category(app_state: CmdState<'_>) -> CmdResult<Vec<CategoryWithSpu>> {
+pub async fn category(app_state: CmdState<'_>) -> CmdResult<Vec<CategoryWithSpu>> {
     let category = Category::new(app_state.conn.clone());
     let categories = category.get_category_commodity().await;
     match categories {

+ 7 - 10
src-tauri/src/commands/commodity.rs

@@ -1,15 +1,12 @@
-use crate::{
-    CmdResult, CmdState,
-    service::category::{Category, CategoryWithSpu},
-};
+use crate::{CmdResult, CmdState, service::commodity::Commodity};
 
 #[tauri::command]
-pub async fn get_commodity(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 commodity(app_state: CmdState<'_>) -> CmdResult<()> {
+    let commodity_service = Commodity::new(app_state.conn.clone());
+    let goods = commodity_service.get_spu_list().await;
+    match goods {
+        Ok(_) => Ok(()),
+        Err(e) => Err(format!("请求商品信息失败{:?}", e)),
     }
     // Ok("111".into())
 }

+ 11 - 0
src-tauri/src/commands/material.rs

@@ -0,0 +1,11 @@
+use crate::{CmdResult, CmdState, service::material::Material};
+
+#[tauri::command]
+pub async fn material(app_state: CmdState<'_>) -> CmdResult<()> {
+    let material_service = Material::new(app_state.conn.clone());
+    let material = material_service.get_material_list().await;
+    match material {
+        Ok(_) => Ok(()),
+        Err(e) => Err(format!("请求材料信息失败{:?}", e)),
+    }
+}

+ 2 - 0
src-tauri/src/commands/mod.rs

@@ -1,3 +1,5 @@
 pub mod category;
 pub mod commodity;
+pub mod material;
+pub mod order;
 pub mod table;

+ 11 - 0
src-tauri/src/commands/order.rs

@@ -0,0 +1,11 @@
+use crate::{CmdResult, CmdState, service::order::Order};
+
+#[tauri::command]
+pub async fn order(app_state: CmdState<'_>) -> CmdResult<()> {
+    let order_service = Order::new(app_state.conn.clone());
+    let orders = order_service.get_order_list().await;
+    match orders {
+        Ok(_) => todo!(),
+        Err(_) => todo!(),
+    }
+}

+ 1 - 1
src-tauri/src/commands/table.rs

@@ -4,7 +4,7 @@ use crate::{
 };
 
 #[tauri::command]
-pub async fn get_table_area(app_state: CmdState<'_>) -> CmdResult<Vec<AreaWithTable>> {
+pub async fn 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 {

+ 6 - 4
src-tauri/src/lib.rs

@@ -3,7 +3,7 @@ mod models;
 mod service;
 mod utils;
 
-use commands::{category, commodity, table};
+use commands::{category, commodity, material, order, table};
 use sea_orm::{ConnectionTrait, DatabaseConnection};
 use std::fs::File;
 use std::sync::Arc;
@@ -44,9 +44,11 @@ pub fn run() {
             })
         })
         .invoke_handler(tauri::generate_handler![
-            table::get_table_area,
-            category::get_category,
-            commodity::get_commodity
+            table::area,
+            category::category,
+            commodity::commodity,
+            order::order,
+            material::material
         ])
         .plugin(tauri_plugin_os::init())
         .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {

+ 0 - 1
src-tauri/src/models/prelude.rs

@@ -3,7 +3,6 @@
 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::store_area::Entity as StoreArea;
 pub use super::store_material::Entity as StoreMaterial;

+ 10 - 1
src-tauri/src/models/store_order.rs

@@ -35,6 +35,15 @@ pub struct Model {
 }
 
 #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
-pub enum Relation {}
+pub enum Relation {
+    #[sea_orm(has_many = "super::store_order_refund::Entity")]
+    StoreOrderRefund,
+}
+
+impl Related<super::store_order_refund::Entity> for Entity {
+    fn to() -> RelationDef {
+        Relation::StoreOrderRefund.def()
+    }
+}
 
 impl ActiveModelBehavior for ActiveModel {}

+ 25 - 0
src-tauri/src/service/commodity.rs

@@ -0,0 +1,25 @@
+use std::sync::Arc;
+
+use sea_orm::{DatabaseConnection, EntityTrait};
+
+use crate::models::prelude::{MenuCommodity, MenuSku, MenuSpec};
+
+pub struct Commodity {
+    conn: Arc<DatabaseConnection>,
+}
+
+impl Commodity {
+    pub fn new(conn: Arc<DatabaseConnection>) -> Self {
+        return Self { conn };
+    }
+
+    pub async fn get_spu_list(&self) -> anyhow::Result<()> {
+        let goods = MenuCommodity::find()
+            .find_also_related(MenuSku)
+            .find_also_related(MenuSpec)
+            .all(&*self.conn)
+            .await?;
+        println!("{:?}", goods);
+        Ok(())
+    }
+}

+ 21 - 0
src-tauri/src/service/material.rs

@@ -0,0 +1,21 @@
+use std::sync::Arc;
+
+use sea_orm::{DatabaseConnection, EntityTrait};
+
+use crate::models::prelude::StoreMaterial;
+
+pub struct Material {
+    conn: Arc<DatabaseConnection>,
+}
+
+impl Material {
+    pub fn new(conn: Arc<DatabaseConnection>) -> Self {
+        return Self { conn };
+    }
+
+    pub async fn get_material_list(&self) -> anyhow::Result<()> {
+        let materials = StoreMaterial::find().all(&*self.conn).await?;
+        println!("{:?}", materials);
+        Ok(())
+    }
+}

+ 3 - 0
src-tauri/src/service/mod.rs

@@ -1,2 +1,5 @@
 pub mod category;
+pub mod commodity;
+pub mod material;
+pub mod order;
 pub mod table;

+ 24 - 0
src-tauri/src/service/order.rs

@@ -0,0 +1,24 @@
+use std::sync::Arc;
+
+use sea_orm::{DatabaseConnection, EntityTrait};
+
+use crate::models::prelude::{StoreOrder, StoreOrderRefund};
+
+pub struct Order {
+    conn: Arc<DatabaseConnection>,
+}
+
+impl Order {
+    pub fn new(conn: Arc<DatabaseConnection>) -> Self {
+        return Self { conn };
+    }
+
+    pub async fn get_order_list(&self) -> anyhow::Result<()> {
+        let orders = StoreOrder::find()
+            .find_also_related(StoreOrderRefund)
+            .all(&*self.conn)
+            .await?;
+        println!("{:?}", orders);
+        Ok(())
+    }
+}