From c950586b718ae6fc198bedf424609a4ac94cb5d1 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 04 七月 2024 18:16:07 +0800
Subject: [PATCH] 增加根据位置或仓库查询产品及库存列表

---
 models/operation_details.go |   41 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/models/operation_details.go b/models/operation_details.go
index ea37b72..c596a44 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -4,6 +4,7 @@
 	"fmt"
 	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
+	"wms/constvar"
 	"wms/pkg/mysqlx"
 )
 
@@ -11,9 +12,10 @@
 	// 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:鏁伴噺"` //鏁伴噺
 		//Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`                    //鍗曚綅
@@ -27,7 +29,12 @@
 		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"`
+		Remark           string          `gorm:"type:varchar(1024);comment:澶囨敞" json:"remark"`
+		IsInternalOutput bool            `json:"isInternalOutput"` //鏄惁璋冩嫧浜х敓鐨勫嚭搴�
+		DealerType       string          `json:"dealerType"`       //鍑哄叆搴撶被鍨�
+
+		Cost      decimal.Decimal `json:"cost" `      //鎴愭湰鍗曚环
+		SalePrice decimal.Decimal `json:"salePrice" ` //閿�鍞崟浠�
 	}
 
 	OperationDetailsSearch struct {
@@ -101,6 +108,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 +144,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 +324,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