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/operation_details.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/models/operation_details.go b/models/operation_details.go
index ea37b72..a00b670 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -4,30 +4,41 @@
"fmt"
"github.com/shopspring/decimal"
"gorm.io/gorm"
+ "wms/constvar"
"wms/pkg/mysqlx"
)
type (
- // OperationDetails 鎿嶄綔鏄庣粏琛�
+ // OperationDetails 搴撳瓨鎿嶄綔鏄庣粏琛�
OperationDetails struct {
WmsModel
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- OperationID int `json:"operationId" gorm:"index;type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔id
- ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ OperationID int `json:"operationId" gorm:"index;type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔璁板綍id
+ BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
+ ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
//ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
- Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
+ Amount decimal.Decimal `json:"amount" gorm:"type:decimal(30,10);not null;comment:鏁伴噺"` //鏁伴噺
+ StockAmount decimal.Decimal `json:"stockAmount" gorm:"type:decimal(30,10);comment:搴撳瓨鏁伴噺"` //搴撳瓨鏁伴噺锛岀洏鐐规椂鐢�
//Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` //鍗曚綅
- Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"`
+ Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` // 鐗╂枡淇℃伅
FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃�
ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆
- TotalGrossWeight decimal.Decimal `json:"totalGrossWeight" gorm:"type:decimal(20,3);comment:鎬绘瘺閲�"`
- TotalNetWeight decimal.Decimal `json:"totalNetWeight" gorm:"type:decimal(20,3);comment:鎬诲噣閲�"`
- AuxiliaryAmount decimal.Decimal `json:"auxiliaryAmount" gorm:"type:decimal(20,3);comment:杈呭姪鏁伴噺"`
- AuxiliaryUnit string `json:"auxiliaryUnit" gorm:"type:varchar(191);comment:杈呭姪鍗曚綅"`
- Note string `gorm:"type:varchar(1024);comment:澶囨敞" json:"note"`
+ TotalGrossWeight decimal.Decimal `json:"totalGrossWeight" gorm:"type:decimal(20,3);comment:鎬绘瘺閲�"` // 鎬绘瘺閲�
+ TotalNetWeight decimal.Decimal `json:"totalNetWeight" gorm:"type:decimal(20,3);comment:鎬诲噣閲�"` // 鎬诲噣閲�
+ AuxiliaryAmount decimal.Decimal `json:"auxiliaryAmount" gorm:"type:decimal(20,3);comment:杈呭姪鏁伴噺"` // 杈呭姪鏁伴噺
+ AuxiliaryUnit string `json:"auxiliaryUnit" gorm:"type:varchar(191);comment:杈呭姪鍗曚綅"` // 杈呭姪鍗曚綅
+ Remark string `json:"remark" gorm:"type:varchar(1024);comment:澶囨敞"` // 澶囨敞
+ IsInternalOutput bool `json:"isInternalOutput" gorm:"type:tinyint(1);comment:鏄惁璋冩嫧浜х敓鐨勫嚭搴�"` //鏄惁璋冩嫧浜х敓鐨勫嚭搴�
+ DealerType string `json:"dealerType" gorm:"type:varchar(255);comment:鍑哄叆搴撶被鍨�"` //鍑哄叆搴撶被鍨�
+
+ Cost decimal.Decimal `json:"cost" gorm:"type:decimal(20,4);comment:鎴愭湰鍗曚环"` //鎴愭湰鍗曚环
+ SalePrice decimal.Decimal `json:"salePrice" gorm:"type:decimal(20,4);comment:閿�鍞崟浠�"` //閿�鍞崟浠�
+ // 鍢夎仈浠撳偍娣诲姞 SilkMarket銆丼ilkMarketClose
+ SilkMarket string `json:"silkMarket" gorm:"type:varchar(255);comment:搴勫彛"` // 搴勫彛
+ SilkMarketClose string `json:"silkMarketClose" gorm:"type:varchar(10);comment:搴勫彛鍏抽棴"` // 搴勫彛鍏抽棴
}
OperationDetailsSearch struct {
@@ -101,6 +112,11 @@
return slf
}
+func (slf *OperationDetailsSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationDetailsSearch {
+ slf.BaseOperationType = baseOperationType
+ return slf
+}
+
func (slf *OperationDetailsSearch) build() *gorm.DB {
var db = slf.Orm.Model(&OperationDetails{})
@@ -132,6 +148,10 @@
if slf.Fields != "" {
db = db.Select(slf.Fields)
+ }
+
+ if slf.BaseOperationType != 0 {
+ db = db.Where("base_operation_type = ?", slf.BaseOperationType)
}
return db
@@ -308,3 +328,20 @@
}
return result, nil
}
+
+type GroupByDealerTypeWarehouse struct {
+ DealerType string
+ ProductID string
+ Sum decimal.Decimal
+}
+
+func (slf *OperationDetailsSearch) GroupMultiSumAmount() ([]*GroupByDealerTypeWarehouse, error) {
+ var (
+ db = slf.build()
+ result = make([]*GroupByDealerTypeWarehouse, 0)
+ )
+ if err := db.Select("sum(amount) as sum, dealer_type, product_id").Group("product_id, dealer_type").Scan(&result).Error; err != nil {
+ return nil, fmt.Errorf("select group err: %v", err)
+ }
+ return result, nil
+}
--
Gitblit v1.8.0