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/move_history.go | 80 ++++++++++++++++++++++++++++------------
1 files changed, 56 insertions(+), 24 deletions(-)
diff --git a/models/move_history.go b/models/move_history.go
index f4c8b7d..4d7b10d 100644
--- a/models/move_history.go
+++ b/models/move_history.go
@@ -2,7 +2,7 @@
import (
"fmt"
- "google.golang.org/genproto/googleapis/type/decimal"
+ "github.com/shopspring/decimal"
"gorm.io/gorm"
"wms/constvar"
"wms/pkg/mysqlx"
@@ -13,19 +13,22 @@
MoveHistory struct {
WmsModel
Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿
- BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
- OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
- OperationId int `json:"operationRecordId" gorm:"type:int;not null;comment:鎿嶄綔id"` //鎿嶄綔id
-
- ProductId int `json:"productId" gorm:"type:int;not null;comment:浜у搧id"` //浜у搧id
- ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
- Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
-
- FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
- FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationId"` //婧愪綅缃�
- ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
- ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //鐩爣浣嶇疆
+ Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿
+ BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
+ OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
+ OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);not null;comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О
+ OperationId int `json:"operationId" gorm:"type:int;not null;comment:鎿嶄綔id"` //鎿嶄綔id
+ ProductId string `json:"productId" gorm:"type:varchar(255);not null;comment:浜у搧id"` //浜у搧id
+ Product Material `json:"-" gorm:"foreignKey:ProductId"` //浜у搧
+ 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:char(10);not null;comment:鍗曚綅"` //鍗曚綅
+ Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);not null;comment:閲嶉噺"` //閲嶉噺
+ FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
+ FromLocation string `json:"fromLocation" gorm:"type:varchar(255);not null;comment:婧愪綅缃�"` //婧愪綅缃�
+ ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
+ ToLocation string `json:"toLocation" gorm:"type:varchar(255);not null;comment:鐩爣浣嶇疆"` //鐩爣浣嶇疆
+ Operator string `json:"operator" gorm:"type:varchar(255);not null;comment:鎿嶄綔鑰�"` //鎿嶄綔鑰�
}
MoveHistorySearch struct {
@@ -40,7 +43,7 @@
)
func (slf *MoveHistory) TableName() string {
- return "move_history"
+ return "wms_move_history"
}
func NewMoveHistorySearch() *MoveHistorySearch {
@@ -77,7 +80,7 @@
return slf
}
-func (slf *MoveHistorySearch) build() *gorm.DB {
+func (slf *MoveHistorySearch) Build() *gorm.DB {
var db = slf.Orm.Model(&MoveHistory{})
if slf.ID != 0 {
@@ -92,12 +95,16 @@
db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
}
+ if slf.Preload {
+ db = db.Model(&MoveHistory{}).Preload("Product")
+ }
+
return db
}
// Create 鍗曟潯鎻掑叆
func (slf *MoveHistorySearch) Create(record *MoveHistory) error {
- var db = slf.build()
+ var db = slf.Build()
if err := db.Create(record).Error; err != nil {
return err
@@ -108,7 +115,7 @@
// CreateBatch 鎵归噺鎻掑叆
func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error {
- var db = slf.build()
+ var db = slf.Build()
if err := db.Create(&records).Error; err != nil {
return fmt.Errorf("create batch err: %v, records: %+v", err, records)
@@ -118,7 +125,7 @@
}
func (slf *MoveHistorySearch) Update(record *MoveHistory) error {
- var db = slf.build()
+ var db = slf.Build()
if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
return fmt.Errorf("save err: %v, record: %+v", err, record)
@@ -129,7 +136,7 @@
func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error {
var (
- db = slf.build()
+ db = slf.Build()
)
if err := db.Updates(upMap).Error; err != nil {
@@ -152,14 +159,14 @@
}
func (slf *MoveHistorySearch) Delete() error {
- var db = slf.build()
+ var db = slf.Build()
return db.Delete(&MoveHistory{}).Error
}
func (slf *MoveHistorySearch) First() (*MoveHistory, error) {
var (
record = new(MoveHistory)
- db = slf.build()
+ db = slf.Build()
)
if err := db.First(record).Error; err != nil {
@@ -173,7 +180,7 @@
var (
records = make([]*MoveHistory, 0)
total int64
- db = slf.build()
+ db = slf.Build()
)
if err := db.Count(&total).Error; err != nil {
@@ -189,10 +196,25 @@
return records, total, nil
}
+// FindAs 鎸夋寚瀹氬舰寮�
+func (slf *MoveHistorySearch) FindAs(obj interface{}) (err error) {
+ var (
+ db = slf.Build()
+ )
+ if slf.PageNum*slf.PageSize > 0 {
+ db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+ }
+ if err := db.Find(obj).Error; err != nil {
+ return fmt.Errorf("find records err: %v", err)
+ }
+
+ return nil
+}
+
func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) {
var (
records = make([]*MoveHistory, 0)
- db = slf.build()
+ db = slf.Build()
)
if slf.PageNum*slf.PageSize > 0 {
@@ -242,3 +264,13 @@
return records, nil
}
+
+func (slf *MoveHistorySearch) Count() (int64, error) {
+ var (
+ total int64
+ db = slf.Build()
+ )
+
+ err := db.Count(&total).Error
+ return total, err
+}
--
Gitblit v1.8.0