ソースを参照

fix:新增阅读记录加入redis

Roc 3 年 前
コミット
923b0afc23
3 ファイル変更51 行追加0 行削除
  1. 37 0
      cache/report_cache.go
  2. 9 0
      controllers/report.go
  3. 5 0
      utils/constants.go

+ 37 - 0
cache/report_cache.go

@@ -0,0 +1,37 @@
+package cache
+
+import (
+	"fmt"
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/utils"
+)
+
+// UserViewRedisData 阅读数据
+type UserViewRedisData struct {
+	Mobile      string `json:"mobile"`
+	Email       string `json:"email"`
+	RealName    string `json:"real_name"`
+	CompanyName string `json:"company_name"`
+	ViewTime    string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
+	ProductId   int    `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
+}
+
+// PushViewRecordNewRedisData 阅读数据加入到redis
+func PushViewRecordNewRedisData(reportViewRecord *models.ReportViewRecord) bool {
+	data := &UserViewRedisData{
+		Mobile:      reportViewRecord.Mobile,
+		Email:       reportViewRecord.Email,
+		RealName:    reportViewRecord.RealName,
+		CompanyName: reportViewRecord.CompanyName,
+		ViewTime:    reportViewRecord.CreateTime.Format(utils.FormatDateTime),
+		ProductId:   1,
+	}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
+		if err != nil {
+			fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
+		}
+		return true
+	}
+	return false
+}

+ 9 - 0
controllers/report.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"hongze/hongze_api/cache"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
 	"hongze/hongze_api/utils"
@@ -210,6 +211,10 @@ func (this *ReportController) Detail() {
 		if err != nil {
 			go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
 		}
+
+		// 添加阅读日志的数据加入到redis
+		go cache.PushViewRecordNewRedisData(record)
+
 		//修改联系人最后一次阅读报告时间
 		go models.SetWxUserReportLastViewTime(user.UserId)
 	}
@@ -517,6 +522,10 @@ func (this *ReportController) AddViewRecordReport() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+
+	// 添加阅读日志的数据加入到redis
+	go cache.PushViewRecordNewRedisData(record)
+
 	//修改联系人最后一次阅读报告时间
 	go models.SetWxUserReportLastViewTime(user.UserId)
 

+ 5 - 0
utils/constants.go

@@ -79,3 +79,8 @@ const (
 	COMPANY_STATUS_FORMAL    = "正式"
 	COMPANY_STATUS_POTENTIAL = "潜在"
 )
+
+//缓存key
+const (
+	CACHE_KEY_USER_VIEW = "user_view_record" //用户阅读数据
+)