Browse Source

Merge branch 'view_total_redis'

Roc 3 years ago
parent
commit
595fea42b1
2 changed files with 50 additions and 1 deletions
  1. 44 0
      logic/report/research_report.go
  2. 6 1
      utils/constants.go

+ 44 - 0
logic/report/research_report.go

@@ -1,8 +1,11 @@
 package report
 
 import (
+	"context"
+	"encoding/json"
 	"errors"
 	"fmt"
+	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
@@ -116,6 +119,9 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 		fmt.Println("AddUserViewHistory err", err.Error())
 	}
 
+	//添加阅读日志的数据加入到redis
+	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
+
 	result = ResearchReportInfo{
 		ResearchReportInfo:     reportInfo,
 		ResearchReportTypeList: researchReportTypeList,
@@ -237,6 +243,10 @@ func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (resu
 	if err != nil {
 		fmt.Println("AddUserViewHistory err", err.Error())
 	}
+
+	//添加阅读日志的数据加入到redis
+	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
+
 	result = ResearchReportTypeContentInfo{
 		ResearchReportTypeContentList: researchReportTypeContentList,
 		ResearchReportTypeInfo:        researchReportTypeInfo,
@@ -244,3 +254,37 @@ func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (resu
 	}
 	return
 }
+
+// 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"`
+	CompanyId   int    `json:"company_id" description:"客户id"`
+}
+
+// PushViewRecordNewRedisData 阅读数据加入到redis
+func PushViewRecordNewRedisData(userViewHistory *user_view_history.UserViewHistory, companyId int) bool {
+	data := &UserViewRedisData{
+		Mobile:      userViewHistory.Mobile,
+		Email:       userViewHistory.Email,
+		RealName:    userViewHistory.RealName,
+		CompanyName: userViewHistory.CompanyName,
+		ViewTime:    userViewHistory.CreatedTime.Format(utils.FormatDateTime),
+		ProductId:   1,
+		CompanyId:   companyId,
+	}
+
+	if global.Redis != nil {
+		dataStr, _ := json.Marshal(data)
+		_, err := global.Redis.LPush(context.TODO(), utils.CACHE_KEY_USER_VIEW, dataStr).Result()
+		if err != nil {
+			fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
+		}
+		return true
+	}
+	return false
+}

+ 6 - 1
utils/constants.go

@@ -95,4 +95,9 @@ const (
 	Hz_Data_PB_Url = "http://datapb.hzinsights.com:8040/"   //彭博接口地址
 	Hz_Data_LT_Url = "http://dataek.hzinsights.com:8040/"   //路透社接口地址
 	EDB_DATA_LIMIT = 10
-)
+)
+
+//缓存key
+const (
+	CACHE_KEY_USER_VIEW = "user_view_record" //用户阅读数据
+)