|
@@ -0,0 +1,51 @@
|
|
|
|
+package util
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
|
+ "fmt"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ TypeSearch = "1" // 标讯搜索历史记录
|
|
|
|
+ TypeEntSearch = "2" // 企业历史搜索
|
|
|
|
+ TypeEntView = "3" // 企业历史浏览
|
|
|
|
+ TypeBuyerSearch = "4" // 采购单位历史搜索
|
|
|
|
+ TypeBuyerView = "5" // 采购单位历史浏览
|
|
|
|
+ RedisName = "other"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var (
|
|
|
|
+ // HistoryRedisKeyMap 历史记录对应的Rediskey
|
|
|
|
+ HistoryRedisKeyMap = map[string]string{
|
|
|
|
+ TypeSearch: "s_%s",
|
|
|
|
+ TypeEntSearch: "history_ent_s_%s",
|
|
|
|
+ TypeEntView: "history_ent_v_%s",
|
|
|
|
+ TypeBuyerSearch: "history_buyer_s_%s",
|
|
|
|
+ TypeBuyerView: "history_buyer_v_%s",
|
|
|
|
+ }
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// SaveHistory 保存历史记录
|
|
|
|
+func SaveHistory(matchKey string, userId string, redisKey string) bool {
|
|
|
|
+ redisKey = fmt.Sprintf(redisKey, userId)
|
|
|
|
+ history := redis.GetStr(RedisName, redisKey)
|
|
|
|
+ arrS := []string{}
|
|
|
|
+ arrS = strings.Split(history, ",")
|
|
|
|
+ //新增历史记录
|
|
|
|
+ if history == "" {
|
|
|
|
+ arrS = make([]string, 0)
|
|
|
|
+ }
|
|
|
|
+ for k, v := range arrS {
|
|
|
|
+ if v == strings.TrimSpace(matchKey) {
|
|
|
|
+ arrS = append(arrS[:k], arrS[k+1:]...)
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ arrS = append(arrS, strings.TrimSpace(matchKey))
|
|
|
|
+ if len(arrS) > 10 {
|
|
|
|
+ arrS = arrS[len(arrS)-10:]
|
|
|
|
+ }
|
|
|
|
+ return redis.Put(RedisName, redisKey, strings.Join(arrS, ","), -1)
|
|
|
|
+}
|