wcj há 5 anos atrás
pai
commit
ba5fdadf08
1 ficheiros alterados com 21 adições e 21 exclusões
  1. 21 21
      common/src/qfw/util/jy/entnichepush.go

+ 21 - 21
common/src/qfw/util/jy/entnichepush.go

@@ -21,8 +21,8 @@ type entnichePush struct {
 }
 
 //从pushcache_2_a中取
-func (e *entnichePush) GetTodayCache(userId int) (*SubPush, error) {
-	pc_a, err := redis.GetNewBytes("pushcache_2_b", e.todayKey(userId))
+func (e *entnichePush) GetTodayCache(entId, userId int) (*SubPush, error) {
+	pc_a, err := redis.GetNewBytes("pushcache_2_b", e.todayKey(entId, userId))
 	if err != nil {
 		return nil, err
 	}
@@ -37,13 +37,13 @@ func (e *entnichePush) GetTodayCache(userId int) (*SubPush, error) {
 }
 
 //往pushcache_2_a中放
-func (e *entnichePush) PutTodayCache(userId int, pc_a *SubPush) {
-	redis.Put("pushcache_2_b", e.todayKey(userId), pc_a, threeDay)
+func (e *entnichePush) PutTodayCache(entId, userId int, pc_a *SubPush) {
+	redis.Put("pushcache_2_b", e.todayKey(entId, userId), pc_a, threeDay)
 }
 
 //获取redis key
-func (e *entnichePush) todayKey(userId int) string {
-	return fmt.Sprintf("entnichepush_%d", userId)
+func (e *entnichePush) todayKey(entId, userId int) string {
+	return fmt.Sprintf("entnichepush_%d_%d", userId)
 }
 
 func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId, userId int, pageNum int, selectTime, area string) (hasNextPage bool, result []*SubPushList) {
@@ -54,7 +54,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 	start := (pageNum - 1) * pageSize
 	end := start + pageSize
 	if now == selectTime && area == "" {
-		subPush, err := e.GetTodayCache(userId)
+		subPush, err := e.GetTodayCache(entId, userId)
 		if err != nil {
 			log.Println(userId, "GetTodayCache Error", err)
 		}
@@ -64,7 +64,7 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 				Date:  now,
 				Datas: list,
 			}
-			e.PutTodayCache(userId, subPush)
+			e.PutTodayCache(entId, userId, subPush)
 		}
 		length := len(subPush.Datas)
 		if end > length {
@@ -74,13 +74,13 @@ func (e *entnichePush) Datas(MQFW mg.MongodbSim, PushMysql *mysql.Mysql, entId,
 			result = subPush.Datas[start:end]
 		}
 	} else if selectTime == "" && area == "" && pageNum <= 5 {
-		allCache, err := e.GetAllCache(userId)
+		allCache, err := e.GetAllCache(entId, userId)
 		if err != nil {
 			log.Println(userId, "GetAllCache Error", err)
 		}
 		if err != nil || allCache == nil || len(allCache) == 0 {
 			allCache = e.getDatasFromMysql(MQFW, PushMysql, entId, userId, 1, AllSubPushCacheSize, selectTime, area, true)
-			e.PutAllCache(userId, allCache)
+			e.PutAllCache(entId, userId, allCache)
 		}
 		length := len(allCache)
 		if end > length {
@@ -241,12 +241,12 @@ func (e *entnichePush) GetInfoByIds(MQFW mg.MongodbSim, pushCas []*PushCa) []*Su
 	return array
 }
 
-func (e *entnichePush) Visit(PushMysql *mysql.Mysql, userId, id int) {
+func (e *entnichePush) Visit(PushMysql *mysql.Mysql, entId, userId, id int) {
 	if id <= 0 {
 		return
 	}
 	PushMysql.UpdateOrDeleteBySql("update pushsubscribe set isvisit=1 where userid=? and id=?", userId, id)
-	todaySubPush, err := e.GetTodayCache(userId)
+	todaySubPush, err := e.GetTodayCache(entId, userId)
 	if err == nil && todaySubPush != nil {
 		for _, v := range todaySubPush.Datas {
 			if v.Ca_index == Int64All(id) {
@@ -254,10 +254,10 @@ func (e *entnichePush) Visit(PushMysql *mysql.Mysql, userId, id int) {
 				break
 			}
 		}
-		e.PutTodayCache(userId, todaySubPush)
+		e.PutTodayCache(entId, userId, todaySubPush)
 	}
 	//
-	allSubPush, err := e.GetAllCache(userId)
+	allSubPush, err := e.GetAllCache(entId, userId)
 	if err == nil && allSubPush != nil {
 		for _, v := range allSubPush {
 			if v.Ca_index == Int64All(id) {
@@ -265,21 +265,21 @@ func (e *entnichePush) Visit(PushMysql *mysql.Mysql, userId, id int) {
 				break
 			}
 		}
-		e.PutAllCache(userId, allSubPush)
+		e.PutAllCache(entId, userId, allSubPush)
 	}
 }
 
 //查看全部列表缓存
-func (e *entnichePush) allKey(userId int) string {
-	return fmt.Sprintf("all_entnichepush_%d", userId)
+func (e *entnichePush) allKey(entId, userId int) string {
+	return fmt.Sprintf("all_entnichepush_%d_%d", userId)
 }
 
-func (e *entnichePush) PutAllCache(userId int, datas []*SubPushList) {
-	redis.Put("pushcache_2_a", e.allKey(userId), datas, threeDay)
+func (e *entnichePush) PutAllCache(entId, userId int, datas []*SubPushList) {
+	redis.Put("pushcache_2_a", e.allKey(entId, userId), datas, threeDay)
 }
 
-func (e *entnichePush) GetAllCache(userId int) ([]*SubPushList, error) {
-	return e.GetCache("pushcache_2_a", e.allKey(userId))
+func (e *entnichePush) GetAllCache(entId, userId int) ([]*SubPushList, error) {
+	return e.GetCache("pushcache_2_a", e.allKey(entId, userId))
 }
 
 func (e *entnichePush) GetCache(code, key string) ([]*SubPushList, error) {