From 137441e2396cf231f9d41e5c399038dbfe01433f Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期二, 16 七月 2024 20:24:55 +0800
Subject: [PATCH] 添加字段,库存报表统计返回结果添加productType(产品类别)、productSpecs(产品规格),产品类别由原来的productType改为productCategory
---
models/warehouse_month_stats.go | 69 ++++++++++++++++++++++++++++++----
1 files changed, 61 insertions(+), 8 deletions(-)
diff --git a/models/warehouse_month_stats.go b/models/warehouse_month_stats.go
index ae73de2..4a829e9 100644
--- a/models/warehouse_month_stats.go
+++ b/models/warehouse_month_stats.go
@@ -21,19 +21,20 @@
BeginAmount decimal.Decimal `json:"beginAmount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鏈熷垵鏁伴噺
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"` //鍏ュ簱鏄庣粏
-
+ InputAmount decimal.Decimal `json:"inputAmount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鍏ュ簱鏁伴噺
+ InputItems []*WarehouseStatsItems `json:"inputItems" gorm:"-"` //鍏ュ簱鏄庣粏
+ Items []*WarehouseStatsItems `json:"-"`
OutputAmount decimal.Decimal `json:"outputAmount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鍑哄簱鏁伴噺
- OutputItems []*WarehouseStatsItems `json:"outputMoreUnitsArr"` //鍑哄簱鏄庣粏
+ OutputItems []*WarehouseStatsItems `json:"outputItems" gorm:"-"` //鍑哄簱鏄庣粏
Date string `json:"date" gorm:"index;type:varchar(255); not null;default ''"` //鏃ユ湡 2024-04
}
WarehouseStatsItems struct {
- WarehouseMonthStatsId int `json:"warehouseMonthStatsId"`
- Name string `json:"name" gorm:"type:varchar(255);not null;default:''"` //鍏ュ簱鏉ユ簮锛屽嚭搴撳幓澶�
- Amount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;"` //鏁伴噺
+ WarehouseMonthStatsId int `json:"warehouseMonthStatsId"`
+ Type MonthStatsItemsType `json:"type" gorm:"type:tinyint;not null;default:1"`
+ Name string `json:"name" gorm:"type:varchar(255);not null;default:''"` //鍏ュ簱鏉ユ簮锛屽嚭搴撳幓澶�
+ Amount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;"` //鏁伴噺
}
WarehouseMonthStatsSearch struct {
@@ -48,12 +49,64 @@
}
)
+type MonthStatsItemsType int
+
+const (
+ MonthStatsItemsTypeInput MonthStatsItemsType = 1 //鍏ュ簱
+ MonthStatsItemsTypeOutput MonthStatsItemsType = 2 //鍑哄簱
+)
+
func (slf *WarehouseStatsItems) TableName() string {
return "wms_warehouse_month_stats_items"
}
func (slf *WarehouseMonthStats) TableName() string {
return "wms_warehouse_month_stats"
+}
+
+func (slf *WarehouseMonthStats) BeforeCreate(tx *gorm.DB) error {
+ if len(slf.InputItems) != 0 || len(slf.OutputItems) != 0 {
+ items := make([]*WarehouseStatsItems, 0, len(slf.InputItems)+len(slf.OutputItems))
+ for _, item := range slf.InputItems {
+ items = append(items, &WarehouseStatsItems{
+ Type: MonthStatsItemsTypeInput,
+ Name: item.Name,
+ Amount: item.Amount,
+ })
+ }
+
+ for _, item := range slf.OutputItems {
+ items = append(items, &WarehouseStatsItems{
+ Type: MonthStatsItemsTypeOutput,
+ Name: item.Name,
+ Amount: item.Amount,
+ })
+ }
+
+ slf.Items = items
+ }
+
+ return nil
+}
+
+func (slf *WarehouseMonthStats) AfterFind(tx *gorm.DB) error {
+ if len(slf.Items) != 0 {
+ inputItems := make([]*WarehouseStatsItems, 0)
+ outputItems := make([]*WarehouseStatsItems, 0)
+ for _, v := range slf.Items {
+ item := WarehouseStatsItems{
+ Type: v.Type,
+ Name: v.Name,
+ Amount: v.Amount,
+ }
+ if v.Type == MonthStatsItemsTypeInput {
+ inputItems = append(inputItems, &item)
+ } else {
+ outputItems = append(outputItems, &item)
+ }
+ }
+ }
+ return nil
}
func NewWarehouseMonthStatsSearch() *WarehouseMonthStatsSearch {
@@ -144,7 +197,7 @@
}
if slf.Preload {
- db = db.Preload("InputItems").Preload("OutputItems")
+ db = db.Preload("Items")
}
return db
--
Gitblit v1.8.0