From a05c425061dccbf735f849eb493c4f6815af91df Mon Sep 17 00:00:00 2001 From: wangshuai Date: Tue, 1 Sep 2020 09:52:24 +0800 Subject: [PATCH] 'commit' --- dsSupport/Utils/CacheUtil/DaoCache.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dsSupport/Utils/CacheUtil/DaoCache.go b/dsSupport/Utils/CacheUtil/DaoCache.go index b5b0dd60..982608f7 100644 --- a/dsSupport/Utils/CacheUtil/DaoCache.go +++ b/dsSupport/Utils/CacheUtil/DaoCache.go @@ -9,6 +9,7 @@ import ( "fmt" "github.com/go-redis/redis/v7" "reflect" + "regexp" "strconv" "strings" "time" @@ -143,8 +144,10 @@ func batchReadRedis(ids []string, prefix string) ([]map[string]interface{}, []st */ func count(baseSql string, pkField string, args []interface{}) (int32, error) { //替换掉分页代码,获取数据量总数 - countSql := strings.Replace(baseSql, "SELECT "+pkField+" ", "SELECT count(*) as count ", -1) - fmt.Println("countSql==", countSql) + reg := regexp.MustCompile(`SELECT ` + pkField + ` `) + //countSql := strings.Replace(baseSql, "SELECT "+pkField+" ", "SELECT count(*) as count ", -1) + countSql := reg.ReplaceAllString(baseSql, "SELECT count(*) as count ") + fmt.Println("countSql==", countSql) var count int32 //去掉最后的limit+offset args = args[0 : len(args)-2]