- GetStores不用SQL分页

This commit is contained in:
gazebo
2019-06-28 15:26:56 +08:00
parent b0a2a672f9
commit e55b49b1c3

View File

@@ -305,29 +305,29 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
sql += sqlWhere + ` sql += sqlWhere + `
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53 GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53
ORDER BY t1.id DESC ORDER BY t1.id DESC
LIMIT ? OFFSET ?` /*LIMIT ? OFFSET ?*/`
pageSize = jxutils.FormalizePageSize(pageSize) pageSize = jxutils.FormalizePageSize(pageSize)
if offset < 0 { if offset < 0 {
offset = 0 offset = 0
} }
sqlParams = append(sqlParams, sqlWhereParams...) sqlParams = append(sqlParams, sqlWhereParams...)
sqlParams = append(sqlParams, pageSize, offset) // sqlParams = append(sqlParams, pageSize, offset)
retVal = &StoresInfo{} retVal = &StoresInfo{}
db := dao.GetDB() db := dao.GetDB()
dao.Begin(db) // dao.Begin(db)
defer func() { // defer func() {
if r := recover(); r != nil { // if r := recover(); r != nil {
dao.Rollback(db) // dao.Rollback(db)
panic(r) // panic(r)
} // }
}() // }()
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false)) // globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
// globals.SugarLogger.Debug(sql) // globals.SugarLogger.Debug(sql)
var storeList []*StoreExt var storeList []*StoreExt
mapLimit := false mapLimit := false
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil { if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
retVal.TotalCount = dao.GetLastTotalRowCount(db) // retVal.TotalCount = dao.GetLastTotalRowCount(db)
dao.Commit(db) // dao.Commit(db)
// globals.SugarLogger.Debugf("GetStores, len(storeList):%d", len(storeList)) // globals.SugarLogger.Debugf("GetStores, len(storeList):%d", len(storeList))
var ( var (
mapLatitude, mapLongitude float64 mapLatitude, mapLongitude float64
@@ -359,11 +359,20 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
} }
} }
retVal.Stores, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo) retVal.Stores, err = filterStoreByOrderInfo(db, retVal.Stores, orderTimeFrom, orderTimeTo, orderCountFrom, orderCountTo)
if mapLimit {
retVal.TotalCount = len(retVal.Stores) retVal.TotalCount = len(retVal.Stores)
} if offset >= retVal.TotalCount {
retVal.Stores = nil
} else { } else {
dao.Rollback(db) if offset+pageSize > retVal.TotalCount {
pageSize = retVal.TotalCount - offset
}
retVal.Stores = retVal.Stores[offset : offset+pageSize]
}
// if mapLimit {
// retVal.TotalCount = len(retVal.Stores)
// }
} else {
// dao.Rollback(db)
} }
if mapLimit && len(retVal.Stores) > 0 { if mapLimit && len(retVal.Stores) > 0 {
retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores) retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores)