From 6c4567aadbf6b35569e1ab2b1d726aba90eff4ab Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期三, 03 七月 2024 10:37:06 +0800
Subject: [PATCH] 用户显示账户转为显示名称

---
 models/warehouse_month_stats.go |   41 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/models/warehouse_month_stats.go b/models/warehouse_month_stats.go
index 72f494c..d0c43d0 100644
--- a/models/warehouse_month_stats.go
+++ b/models/warehouse_month_stats.go
@@ -22,10 +22,10 @@
 		EndAmount   decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"`      //鏈熸湯缁撲綑鏁伴噺
 
 		InputAmount decimal.Decimal        `json:"inputAmount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鍏ュ簱鏁伴噺
-		InputItems  []*WarehouseStatsItems `json:"inputMoreUnitsArr"`                                          //鍏ュ簱鏄庣粏
+		InputItems  []*WarehouseStatsItems `json:"inputItems"`                                                 //鍏ュ簱鏄庣粏
 
 		OutputAmount decimal.Decimal        `json:"outputAmount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鍑哄簱鏁伴噺
-		OutputItems  []*WarehouseStatsItems `json:"outputMoreUnitsArr"`                                          //鍑哄簱鏄庣粏
+		OutputItems  []*WarehouseStatsItems `json:"outputItems"`                                                 //鍑哄簱鏄庣粏
 
 		Date string `json:"date" gorm:"index;type:varchar(255); not null;default ''"` //鏃ユ湡 2024-04
 	}
@@ -48,8 +48,12 @@
 	}
 )
 
+func (slf *WarehouseStatsItems) TableName() string {
+	return "wms_warehouse_month_stats_items"
+}
+
 func (slf *WarehouseMonthStats) TableName() string {
-	return "wms_month_stats"
+	return "wms_warehouse_month_stats"
 }
 
 func NewWarehouseMonthStatsSearch() *WarehouseMonthStatsSearch {
@@ -96,6 +100,21 @@
 	return slf
 }
 
+func (slf *WarehouseMonthStatsSearch) SetWarehouseId(id int) *WarehouseMonthStatsSearch {
+	slf.WarehouseId = id
+	return slf
+}
+
+func (slf *WarehouseMonthStatsSearch) Save(record *WarehouseMonthStats) 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
+}
+
 func (slf *WarehouseMonthStatsSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&WarehouseMonthStats{})
 
@@ -118,6 +137,14 @@
 
 	if slf.Fields != "" {
 		db = db.Select(slf.Fields)
+	}
+
+	if slf.WarehouseId != 0 {
+		db = db.Where("warehouse_id = ?", slf.WarehouseId)
+	}
+
+	if slf.Preload {
+		db = db.Preload("InputItems").Preload("OutputItems")
 	}
 
 	return db
@@ -279,6 +306,14 @@
 	return m
 }
 
+func WarehouseStatsItemMap(records []*WarehouseStatsItems) (m map[string]*WarehouseStatsItems) {
+	m = make(map[string]*WarehouseStatsItems, len(records))
+	for _, record := range records {
+		m[record.Name] = record
+	}
+	return m
+}
+
 func (slf *WarehouseMonthStatsSearch) Count() (int64, error) {
 	var (
 		total int64

--
Gitblit v1.8.0