From a4b0a956673b76ba15cc8fca49fe8b8f9eee3816 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 21 Dec 2018 10:41:28 +0800 Subject: [PATCH] - change return type to PagedInfo for GetStoreOpRequests --- business/jxstore/cms/store_sku.go | 20 ++++++++++++++------ business/model/dao/dao.go | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index e0ece3dd6..e22f4ae72 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -349,10 +349,11 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str for k, skuName := range skuNamesInfo.SkuNames { nameIDs[k] = skuName.ID } - requestList, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", []int{storeID}, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1) + pagedInfo, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", []int{storeID}, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1) if err = err2; err != nil { return nil, err } + requestList := pagedInfo.Data.([]*StoreOpRequestInfo) requestMap := make(map[int]*StoreOpRequestInfo) for _, requestOp := range requestList { requestMap[requestOp.ItemID] = requestOp @@ -1000,10 +1001,11 @@ func RejectStoreOpRequests(ctx *jxcontext.Context, reqIDs []int, rejectReason st } // 当前些函数只针对type为: RequestTypeChangePrice与RequestTypeFocusSkuName的查询才有效 -func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyword string, storeIDs, itemIDs, typeList, statusList []int, offset, pageSize int) (requestList []*StoreOpRequestInfo, err error) { +func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyword string, storeIDs, itemIDs, typeList, statusList []int, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { if globals.EnablePendingChange { sql := ` - SELECT t1.id, t1.created_at, t1.updated_at, t1.last_operator, t1.deleted_at, + SELECT SQL_CALC_FOUND_ROWS + t1.id, t1.created_at, t1.updated_at, t1.last_operator, t1.deleted_at, t1.type, t1.store_id, t1.item_id, t1.status, t1.user_id, t1.int_param1, t1.int_param2, t2.name store_name, t3.prefix sku_name_prefix, t3.name sku_name_name, AVG(t5.unit_price) unit_price FROM store_op_request t1 @@ -1051,8 +1053,8 @@ func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyw } sql += ` - GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 - LIMIT ? OFFSET ?` + GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + LIMIT ? OFFSET ?` pageSize = jxutils.FormalizePageSize(pageSize) sqlOffset := offset sqlPageSize := pageSize @@ -1060,8 +1062,14 @@ func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyw db := dao.GetDB() // globals.SugarLogger.Debug(sql) // globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false)) + var requestList []*StoreOpRequestInfo + dao.Begin(db) + defer dao.Commit(db) if err = dao.GetRows(db, &requestList, sql, sqlParams...); err == nil { - return requestList, nil + return &model.PagedInfo{ + TotalCount: dao.GetLastTotalRowCount(db), + Data: requestList, + }, nil } } return nil, err diff --git a/business/model/dao/dao.go b/business/model/dao/dao.go index b1a34bf43..53bcd0698 100644 --- a/business/model/dao/dao.go +++ b/business/model/dao/dao.go @@ -169,3 +169,11 @@ func ExecuteSQL(db *DaoDB, sql string, params ...interface{}) (num int64, err er }, sql) return num, err } + +func GetLastTotalRowCount(db *DaoDB) int { + countInfo := &struct{ Ct int }{} + if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil { + return countInfo.Ct + } + return 0 +}