- change return type to PagedInfo for GetStoreOpRequests

This commit is contained in:
gazebo
2018-12-21 10:41:28 +08:00
parent bf3463aee8
commit a4b0a95667
2 changed files with 22 additions and 6 deletions

View File

@@ -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

View File

@@ -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
}