From 80c8e74c7428329f06d1aa3b70b95b46da732b0a Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 27 六月 2024 20:09:03 +0800 Subject: [PATCH] 保存库存结算时间点重启定时任务 --- models/location_product_amount.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 0d27a70..d4990b1 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -47,13 +47,15 @@ ProductId string `json:"productId" gorm:"column:product_id"` ProductName string `json:"productName" gorm:"column:product_name"` Amount decimal.Decimal `json:"amount" gorm:"column:amount"` + AmountMoreUnits []UnitItems `json:"amountMoreUnits" gorm:"-"` //鍦ㄥ簱鏁伴噺澶氬崟浣� Unit string `json:"unit" gorm:"column:unit"` CreateDate string `json:"createDate" gorm:"column:create_date"` - AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` - DifferenceAmount decimal.Decimal `json:"differenceAmount" gorm:"-"` + AdjustAmount decimal.Decimal `json:"adjustAmount" gorm:"column:adjust_amount"` //宸�� + DifferenceAmount decimal.Decimal `json:"differenceAmount" gorm:"-"` //璁℃暟鏁伴噺 OperationId int `json:"operationId" gorm:"column:operation_id"` Status constvar.OperationStatus `json:"status" gorm:"status"` BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"base_operation_type"` + Weight decimal.Decimal `gorm:"type:decimal(20,3);comment:閲嶉噺" json:"weight"` //閲嶉噺 } ) @@ -252,6 +254,9 @@ db = slf.build() ) + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } if err := db.Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } @@ -288,3 +293,35 @@ return nil } + +func (slf *LocationProductAmountSearch) GroupCount(field string) ([]*GroupCount, error) { + var ( + db = slf.build() + result = make([]*GroupCount, 0) + ) + if err := db.Select("count(*) as total, " + field + " as class").Group(field).Scan(&result).Error; err != nil { + return nil, fmt.Errorf("select group err: %v", err) + } + return result, nil +} + +func (slf *LocationProductAmountSearch) GroupSum(groupField string, sumField string) ([]*GroupSum, error) { + var ( + db = slf.build() + result = make([]*GroupSum, 0) + ) + if err := db.Select("sum(" + sumField + ") as sum, " + groupField + " as class").Group(groupField).Scan(&result).Error; err != nil { + return nil, fmt.Errorf("select group err: %v", err) + } + return result, nil +} + +func (slf *LocationProductAmountSearch) Save(record *LocationProductAmount) error { + var db = slf.build() + + if err := db.Omit("CreatedAt").Save(record).Error; err != nil { + return fmt.Errorf("save err: %v, record: %+v", err, record) + } + + return nil +} -- Gitblit v1.8.0