Explorar el Código

feat:p510 bxbuyer rpc 采购单位搜索保存历史搜索记录

fuwencai hace 1 año
padre
commit
861c6b4445
Se han modificado 2 ficheros con 31 adiciones y 1 borrados
  1. 4 1
      jyBXBuyer/rpc/internal/logic/buyerlistlogic.go
  2. 27 0
      jyBXBuyer/rpc/model/util.go

+ 4 - 1
jyBXBuyer/rpc/internal/logic/buyerlistlogic.go

@@ -56,7 +56,10 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 	if in.PageNum*in.PageSize > IC.C.BuyerSearchLimit && (in.PageNum-1)*in.PageSize >= IC.C.BuyerSearchLimit {
 		in.PageNum = IC.C.BuyerSearchLimit / in.PageSize
 	}
-
+	if in.BuyerName != "" && in.UserId != "" {
+		// 保存搜索记录
+		model.SaveHistory(in.BuyerName, in.UserId, "history_buyer_s_%s")
+	}
 	query, CountQuery := "", ""
 	buyerNames := []string{}
 	if model.CheckEmpty(in) {

+ 27 - 0
jyBXBuyer/rpc/model/util.go

@@ -1,7 +1,10 @@
 package model
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
+	"fmt"
 	"math/rand"
+	"strings"
 	"time"
 )
 
@@ -10,3 +13,27 @@ func GetRand(n int) int {
 	// 获取一个范围在 [0, ) 的随机整数
 	return randGen.Intn(n)
 }
+
+// SaveHistory 保存历史记录
+func SaveHistory(matchKey string, userId string, redisKey string) bool {
+	redisKey = fmt.Sprintf(redisKey, userId)
+	history := redis.GetStr("other", 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("other", redisKey, strings.Join(arrS, ","), -1)
+}