From f45e4cb8045fe60f96f467dc4ea1e2ae57445712 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 03 七月 2024 23:13:40 +0800
Subject: [PATCH] 默认位置parent_id为视图位置id

---
 models/product_category.go |   41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/models/product_category.go b/models/product_category.go
index 1658605..af90da8 100644
--- a/models/product_category.go
+++ b/models/product_category.go
@@ -10,14 +10,15 @@
 type (
 	// ProductCategory 浜у搧鍒嗙被
 	ProductCategory struct {
-		BaseModelInt
-		Name                 string                        `json:"name" gorm:"index;type:varchar(255);not null;comment:鍒嗙被鍚嶇О"` //浣嶇疆鍚嶇О
+		WmsModel
+		Id                   int                           `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Name                 string                        `json:"name" gorm:"index;type:varchar(255);not null;comment:鍒嗙被鍚嶇О"` //鍒嗙被鍚嶇О
 		ParentId             int                           `json:"parentId" gorm:"type:int;comment:涓婄骇鍒嗙被id"`                   //涓婄骇id
-		RouteId              int                           `json:"routeId" gorm:"type:int;comment:璺嚎id"`
-		RouteName            string                        `json:"routeName" gorm:"type:varchar(512);comment:璺嚎鍚嶇О"`         //鍏徃
-		ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:寮哄埗涓嬫灦绛栫暐"` //寮哄埗涓嬫灦绛栫暐
-		CostingMethod        constvar.CostingMethod        `json:"costingMethod" gorm:"type:tinyint;comment:鎴愭湰鏂规硶"`          //鎴愭湰鏂规硶
-		InventoryValuation   constvar.InventoryValuation   `json:"inventoryValuation" gorm:"type:tinyint;comment:搴撳瓨璁′环"`     //搴撳瓨璁′环
+		RouteId              int                           `json:"routeId" gorm:"type:int;comment:璺嚎id"`                      //璺嚎id
+		RouteName            string                        `json:"routeName" gorm:"type:varchar(512);comment:璺嚎鍚嶇О"`           //鍏徃
+		ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:寮哄埗涓嬫灦绛栫暐"`   //寮哄埗涓嬫灦绛栫暐
+		CostingMethod        constvar.CostingMethod        `json:"costingMethod" gorm:"type:tinyint;comment:鎴愭湰鏂规硶"`            //鎴愭湰鏂规硶
+		InventoryValuation   constvar.InventoryValuation   `json:"inventoryValuation" gorm:"type:tinyint;comment:搴撳瓨璁′环"`       //搴撳瓨璁′环
 	}
 
 	ProductCategorySearch struct {
@@ -28,6 +29,7 @@
 		Keyword  string
 		Orm      *gorm.DB
 		Preload  bool
+		Ids      []int
 	}
 )
 
@@ -54,8 +56,8 @@
 	return slf
 }
 
-func (slf *ProductCategorySearch) SetID(id uint) *ProductCategorySearch {
-	slf.ID = id
+func (slf *ProductCategorySearch) SetID(id int) *ProductCategorySearch {
+	slf.Id = id
 	return slf
 }
 
@@ -73,12 +75,16 @@
 	slf.Preload = preload
 	return slf
 }
+func (slf *ProductCategorySearch) SetIds(ids []int) *ProductCategorySearch {
+	slf.Ids = ids
+	return slf
+}
 
 func (slf *ProductCategorySearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&ProductCategory{})
 
-	if slf.ID != 0 {
-		db = db.Where("id = ?", slf.ID)
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
 	}
 
 	if slf.Order != "" {
@@ -91,6 +97,9 @@
 
 	if slf.Name != "" {
 		db = db.Where("name = ?", slf.Name)
+	}
+	if len(slf.Ids) > 0 {
+		db = db.Where("id in (?)", slf.Ids)
 	}
 
 	return db
@@ -243,3 +252,13 @@
 
 	return records, nil
 }
+
+func (slf *ProductCategorySearch) Save(record *ProductCategory) error {
+	var db = slf.build()
+
+	if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}

--
Gitblit v1.8.0