From 71288e85afbfc7ac12d5060feb1d29aa139513d6 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 16 四月 2024 20:47:10 +0800 Subject: [PATCH] 增加月度统计库存定时任务,统计期初数量,出入库数量,期末数量 --- models/location_product_amount.go | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/models/location_product_amount.go b/models/location_product_amount.go index c102c5b..447b469 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -289,3 +289,25 @@ 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 +} -- Gitblit v1.8.0