|
@@ -42,31 +42,35 @@ func (m *memberPush) PutTodayCache(userId string, pc_a *SubPush) {
|
|
|
func (m *memberPush) todayKey(userId string) string {
|
|
|
return fmt.Sprintf("memberpush_%s", userId)
|
|
|
}
|
|
|
-func (m *memberPush) Datas(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
|
|
|
+func (m *memberPush) Datas(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum int, selectTime, area string, pageSizePC int, startTime, endTime string) (hasNextPage bool, result []*SubPushList, count int64) {
|
|
|
if pageNum < 1 {
|
|
|
pageNum = 1
|
|
|
}
|
|
|
+ if pageSizePC == 0 || pageSizePC > 100 {
|
|
|
+ pageSizePC = pageSize
|
|
|
+ }
|
|
|
now := NowFormat(Date_Short_Layout)
|
|
|
- start := (pageNum - 1) * pageSize
|
|
|
- end := start + pageSize
|
|
|
+ start := (pageNum - 1) * pageSizePC
|
|
|
+ end := start + pageSizePC
|
|
|
if now == selectTime && area == "" {
|
|
|
subPush, err := m.GetTodayCache(userId)
|
|
|
if err != nil {
|
|
|
log.Println(userId, "GetTodayCache Error", err)
|
|
|
}
|
|
|
if err != nil || subPush == nil || subPush.Date != now || len(subPush.Datas) == 0 {
|
|
|
- list := m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSize, selectTime, area, false)
|
|
|
+ listSearch, countSearch := m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSizePC, selectTime, area, false, startTime, endTime)
|
|
|
subPush = &SubPush{
|
|
|
Date: now,
|
|
|
- Datas: list,
|
|
|
+ Datas: listSearch,
|
|
|
+ Count: countSearch,
|
|
|
}
|
|
|
m.PutTodayCache(userId, subPush)
|
|
|
}
|
|
|
- length := len(subPush.Datas)
|
|
|
- if end > length {
|
|
|
- end = length
|
|
|
+ count = subPush.Count
|
|
|
+ if end > int(count) {
|
|
|
+ end = int(count)
|
|
|
}
|
|
|
- if start < length {
|
|
|
+ if start < int(count) {
|
|
|
result = subPush.Datas[start:end]
|
|
|
}
|
|
|
} else if selectTime == "" && area == "" && pageNum <= 5 {
|
|
@@ -74,28 +78,33 @@ func (m *memberPush) Datas(Mgo_bidding mg.MongodbSim, bidding, bidding_back stri
|
|
|
if err != nil {
|
|
|
log.Println(userId, "GetAllCache Error", err)
|
|
|
}
|
|
|
- if err != nil || allCache == nil || len(allCache) == 0 {
|
|
|
- allCache = m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, 1, AllSubPushCacheSize, selectTime, area, true)
|
|
|
+ if err != nil || allCache == nil {
|
|
|
+ listSearch, countSearch := m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, 1, AllSubPushCacheSize, selectTime, area, true, startTime, endTime)
|
|
|
+ allCache = &SubPush{
|
|
|
+ Date: now,
|
|
|
+ Datas: listSearch,
|
|
|
+ Count: countSearch,
|
|
|
+ }
|
|
|
m.PutAllCache(userId, allCache)
|
|
|
}
|
|
|
- length := len(allCache)
|
|
|
- if end > length {
|
|
|
- end = length
|
|
|
+ count = allCache.Count
|
|
|
+ if end > int(count) {
|
|
|
+ end = int(count)
|
|
|
}
|
|
|
- if start < length {
|
|
|
- result = allCache[start:end]
|
|
|
+ if start < int(count) {
|
|
|
+ result = allCache.Datas[start:end]
|
|
|
}
|
|
|
} else {
|
|
|
- result = m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSize, selectTime, area, true)
|
|
|
+ result, count = m.getDatasFromMysql(Mgo_bidding, bidding, bidding_back, PushMysql, userId, pageNum, pageSizePC, selectTime, area, true, startTime, endTime)
|
|
|
}
|
|
|
if result == nil {
|
|
|
result = []*SubPushList{}
|
|
|
}
|
|
|
- hasNextPage = len(result) >= pageSize
|
|
|
+ hasNextPage = len(result) >= pageSizePC
|
|
|
return
|
|
|
}
|
|
|
-func (m *memberPush) getDatasFromMysql(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum, myPageSize int, selectTime, area string, isLimit bool) (result []*SubPushList) {
|
|
|
- findSQL := `select id,date,infoid,isvisit,matchkeys,type from pushmember where userid="` + userId + `"`
|
|
|
+func (m *memberPush) getDatasFromMysql(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, PushMysql *mysql.Mysql, userId string, pageNum, myPageSize int, selectTime, area string, isLimit bool, startTime, endTime string) (result []*SubPushList, count int64) {
|
|
|
+ findSQL := ` %s where userid="` + userId + `" `
|
|
|
findStr := ""
|
|
|
if selectTime != "" {
|
|
|
startTime := selectTime + " 00:00:00"
|
|
@@ -103,27 +112,51 @@ func (m *memberPush) getDatasFromMysql(Mgo_bidding mg.MongodbSim, bidding, biddi
|
|
|
st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
|
|
|
et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
|
|
|
findStr += " and date < " + fmt.Sprint(et.Unix()) + " and date >= " + fmt.Sprint(st.Unix())
|
|
|
+ } else if startTime != "" && endTime != "" {
|
|
|
+ startTime = startTime + " 00:00:00"
|
|
|
+ endTime = endTime + " 23:59:59"
|
|
|
+ st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
|
|
|
+ et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
|
|
|
+ findStr += " and date < " + fmt.Sprint(et.Unix()) + " and date >= " + fmt.Sprint(st.Unix())
|
|
|
}
|
|
|
if area != "" {
|
|
|
- findStr += " and area in ("
|
|
|
- var _area = ""
|
|
|
+ var _area, _city = "", ""
|
|
|
for _, v := range strings.Split(area, ",") {
|
|
|
if v == "全部" {
|
|
|
continue
|
|
|
}
|
|
|
- if _area != "" {
|
|
|
- _area += ","
|
|
|
+ //省份
|
|
|
+ if province, ok := PushMapping.Area[v]; ok {
|
|
|
+ if _area != "" {
|
|
|
+ _area += ","
|
|
|
+ }
|
|
|
+ _area += fmt.Sprint(province)
|
|
|
+ }
|
|
|
+ //城市
|
|
|
+ if city, ok := PushMapping.City[v]; ok {
|
|
|
+ if _city != "" {
|
|
|
+ _city += ","
|
|
|
+ }
|
|
|
+ _city += fmt.Sprint(city)
|
|
|
}
|
|
|
- _area += fmt.Sprint(PushMapping.Area[v])
|
|
|
}
|
|
|
- findStr += _area + ")"
|
|
|
+
|
|
|
+ if _area != "" && _city != "" {
|
|
|
+ findStr += fmt.Sprintf(" and ( area in ( %s ) or city in ( %s ) )", _area, _city)
|
|
|
+ } else if _area != "" && _city == "" { //仅查询省份
|
|
|
+ findStr += fmt.Sprintf(" and area in ( %s ) ", _area)
|
|
|
+ } else if _area == "" && _city != "" { //仅查询城市
|
|
|
+ findStr += fmt.Sprintf(" and city in ( %s ) ", _city)
|
|
|
+ }
|
|
|
}
|
|
|
start := (pageNum - 1) * myPageSize
|
|
|
+ count = PushMysql.CountBySql(fmt.Sprintf(findSQL+findStr, "select count(id) from pushmember"))
|
|
|
+
|
|
|
findStr += " order by id desc"
|
|
|
if isLimit {
|
|
|
findStr += " limit " + fmt.Sprint(start) + "," + fmt.Sprint(myPageSize)
|
|
|
}
|
|
|
- findSQL = findSQL + findStr
|
|
|
+ findSQL = fmt.Sprintf(findSQL+findStr, `select id,date,infoid,isvisit,matchkeys,type from pushmember`)
|
|
|
log.Println("findsql:", findSQL)
|
|
|
list := PushMysql.SelectBySql(findSQL)
|
|
|
if len(*list) > 0 {
|
|
@@ -173,7 +206,7 @@ func (m *memberPush) Visit(PushMysql *mysql.Mysql, userId string, id int) {
|
|
|
//
|
|
|
allSubPush, err := m.GetAllCache(userId)
|
|
|
if err == nil && allSubPush != nil {
|
|
|
- for _, v := range allSubPush {
|
|
|
+ for _, v := range allSubPush.Datas {
|
|
|
if v.Ca_index == Int64All(id) {
|
|
|
v.Ca_isvisit = 1
|
|
|
break
|
|
@@ -185,26 +218,22 @@ func (m *memberPush) Visit(PushMysql *mysql.Mysql, userId string, id int) {
|
|
|
|
|
|
//查看全部列表缓存
|
|
|
func (m *memberPush) allKey(userId string) string {
|
|
|
- return fmt.Sprintf("all_memberpush_%s", userId)
|
|
|
+ return fmt.Sprintf("all_memberpush_new_%s", userId)
|
|
|
}
|
|
|
|
|
|
-func (m *memberPush) PutAllCache(userId string, datas []*SubPushList) {
|
|
|
+func (m *memberPush) PutAllCache(userId string, datas *SubPush) {
|
|
|
redis.Put("pushcache_2_a", m.allKey(userId), datas, threeDay)
|
|
|
}
|
|
|
|
|
|
-func (m *memberPush) GetAllCache(userId string) ([]*SubPushList, error) {
|
|
|
- return m.GetCache("pushcache_2_a", m.allKey(userId))
|
|
|
-}
|
|
|
-
|
|
|
-func (m *memberPush) GetCache(code, key string) ([]*SubPushList, error) {
|
|
|
- pc_a, err := redis.GetNewBytes(code, key)
|
|
|
+func (m *memberPush) GetAllCache(userId string) (*SubPush, error) {
|
|
|
+ pc_a, err := redis.GetNewBytes("pushcache_2_b", m.allKey(userId))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if pc_a == nil {
|
|
|
return nil, nil
|
|
|
}
|
|
|
- var p []*SubPushList
|
|
|
+ var p *SubPush
|
|
|
if err := json.Unmarshal(*pc_a, &p); err != nil {
|
|
|
return nil, err
|
|
|
}
|