From 29d3d3b9f32f9ed1a9eedcfcbe19424477656635 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期二, 14 十一月 2023 14:01:07 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
---
controllers/product_controller.go | 40 ++++++++++++++++++++
models/material.go | 13 ++++--
request/product_request.go | 10 +++++
3 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 26b5918..f84d50e 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -109,6 +109,46 @@
product.CategoryName = category.Name
}
}
+ var reorderAmount request.ProductStatisticsAmount
+ if err := models.NewOperationSearch().Orm.
+ Table("wms_operation_details").
+ InnerJoins("INNER JOIN wms_operation on wms_operation_details.operation_id=wms_operation.id").
+ Select("wms_operation_details.product_id,SUM(wms_operation_details.amount) as total_count").
+ Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Ready, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}).
+ Group("wms_operation_details.product_id").
+ //Order("wms_operation_details.product_id").
+ First(&reorderAmount).Error; err != nil {
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧鏁版嵁缁熻澶辫触")
+ return
+ } else {
+ reorderAmount.TotalAmount = decimal.NewFromInt(0)
+ }
+ }
+ product.PredictionAmount = product.Amount.Add(reorderAmount.TotalAmount)
+
+ var statisticsList []*request.ProductStatistics
+ if err := models.NewOperationSearch().Orm.
+ Table("wms_operation").
+ InnerJoins("INNER JOIN wms_operation_details on wms_operation_details.operation_id=wms_operation.id").
+ Select("SUM(wms_operation_details.amount) as total_amount,wms_operation.base_operation_type").
+ Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Finish, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}).
+ Group("wms_operation.base_operation_type").
+ Find(&statisticsList).Error; err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "浜у搧鏁版嵁缁熻澶辫触")
+ return
+ }
+ for _, v := range statisticsList {
+ if v.BaseOperationType == constvar.BaseOperationTypeIncoming {
+ product.InputAmount = v.TotalAmount
+ }
+ if v.BaseOperationType == constvar.BaseOperationTypeOutgoing {
+ product.OutputAmount = product.OutputAmount.Add(v.TotalAmount)
+ }
+ if v.BaseOperationType == constvar.BaseOperationTypeAdjust {
+ product.OutputAmount = product.OutputAmount.Add(v.TotalAmount)
+ }
+ }
}
util.ResponseFormatList(c, code.Success, products, int(total))
}
diff --git a/models/material.go b/models/material.go
index fd2e51b..c77b4b9 100644
--- a/models/material.go
+++ b/models/material.go
@@ -67,11 +67,14 @@
//HSCode string `gorm:"type:varchar(255);comment:HS缂栫爜" json:"HSCode"` //HS缂栫爜
//OriginCountryId int `gorm:"type:int(11);comment:鍘熶骇鍦癷d" json:"originCountryId"` //鍘熶骇鍦癷d
//OriginCountryName string `gorm:"type:varchar(255);comment:鍘熶骇鍦板悕绉�" json:"originCountryName"` //鍘熶骇鍦板悕绉�
- InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑
- OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑
- InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
- AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"`
- AttachmentIDs []uint `json:"attachmentIDs" gorm:"-"`
+ InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑
+ OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑
+ InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
+ AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"`
+ AttachmentIDs []uint `json:"attachmentIDs" gorm:"-"`
+ PredictionAmount decimal.Decimal `json:"predictionAmount" gorm:"-"`
+ InputAmount decimal.Decimal `json:"inputAmount" gorm:"-"`
+ OutputAmount decimal.Decimal `json:"outputAmount" gorm:"-"`
}
MaterialSearch struct {
diff --git a/request/product_request.go b/request/product_request.go
index c48f3c0..b484263 100644
--- a/request/product_request.go
+++ b/request/product_request.go
@@ -49,3 +49,13 @@
ProductId string `json:"productId"`
LocationId int `json:"locationId"`
}
+
+type ProductStatistics struct {
+ TotalAmount decimal.Decimal `gorm:"column:total_amount"`
+ BaseOperationType constvar.BaseOperationType `gorm:"column:base_operation_type"` //鍩虹浣滀笟绫诲瀷
+}
+
+type ProductStatisticsAmount struct {
+ ProductId string `gorm:"column:product_id"`
+ TotalAmount decimal.Decimal `gorm:"column:total_amount"`
+}
--
Gitblit v1.8.0