|
@@ -1,10 +1,20 @@
|
|
|
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"
|
|
|
"hongze/hongze_yb/models/tables/research_report_type"
|
|
|
+ "hongze/hongze_yb/models/tables/user_view_history"
|
|
|
+ "hongze/hongze_yb/models/tables/wx_user"
|
|
|
"hongze/hongze_yb/utils"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type ResearchReportInfo struct {
|
|
@@ -60,11 +70,64 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 联系人信息
|
|
|
+ strInt64 := strconv.FormatUint(userId, 10)
|
|
|
+ id, _ := strconv.Atoi(strInt64)
|
|
|
+ wxUserInfo, err := wx_user.GetByUserId(id)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetByUserId:", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ if tmpErr == utils.ErrNoRow {
|
|
|
+ err = errors.New("找不到该客户")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询是否读过这篇报告,如果未读过则阅读人数+1
|
|
|
+ _, err = user_view_history.GetReportByUserId(userId, reportInfo.ResearchReportID)
|
|
|
+ if err != nil {
|
|
|
+ err = reportInfo.UpdateViewers()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("UpdateViewers err:", err.Error())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增userViewHistory记录
|
|
|
+ userViewHistory := &user_view_history.UserViewHistory{
|
|
|
+ ViewHistoryID: 0,
|
|
|
+ UserID: userId,
|
|
|
+ Mobile: wxUserInfo.Mobile,
|
|
|
+ Email: wxUserInfo.Email,
|
|
|
+ RealName: wxUserInfo.RealName,
|
|
|
+ CompanyName: companyInfo.CompanyName,
|
|
|
+ ViewTitle: "",
|
|
|
+ ViewPage: "",
|
|
|
+ ReportChapterModule: "",
|
|
|
+ CreatedTime: time.Now(),
|
|
|
+ LastUpdatedTime: time.Now(),
|
|
|
+ Type: "weekly_report",
|
|
|
+ ResearchReportID: reportInfo.ResearchReportID,
|
|
|
+ ResearchReportTypeID: 0,
|
|
|
+ }
|
|
|
+ err = userViewHistory.AddUserViewHistory()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddUserViewHistory err", err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加阅读日志的数据加入到redis
|
|
|
+ go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
|
|
|
+
|
|
|
result = ResearchReportInfo{
|
|
|
ResearchReportInfo: reportInfo,
|
|
|
ResearchReportTypeList: researchReportTypeList,
|
|
|
HasMenu: 1,
|
|
|
}
|
|
|
+
|
|
|
if len(researchReportTypeList) <= 0 {
|
|
|
|
|
|
} else if len(researchReportTypeList) == 1 {
|
|
@@ -141,6 +204,48 @@ func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (resu
|
|
|
if len(researchReportTypeContentList) > 0 {
|
|
|
add = 0
|
|
|
}
|
|
|
+ // 联系人信息
|
|
|
+ strInt64 := strconv.FormatUint(userId, 10)
|
|
|
+ id, _ := strconv.Atoi(strInt64)
|
|
|
+ wxUserInfo, err := wx_user.GetByUserId(id)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("GetByUserId:", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ if tmpErr == utils.ErrNoRow {
|
|
|
+ err = errors.New("找不到该客户")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增userViewHistory记录
|
|
|
+ userViewHistory := &user_view_history.UserViewHistory{
|
|
|
+ ViewHistoryID: 0,
|
|
|
+ UserID: userId,
|
|
|
+ Mobile: wxUserInfo.Mobile,
|
|
|
+ Email: wxUserInfo.Email,
|
|
|
+ RealName: wxUserInfo.RealName,
|
|
|
+ CompanyName: companyInfo.CompanyName,
|
|
|
+ ViewTitle: "",
|
|
|
+ ViewPage: "",
|
|
|
+ ReportChapterModule: "",
|
|
|
+ CreatedTime: time.Now(),
|
|
|
+ LastUpdatedTime: time.Now(),
|
|
|
+ Type: "weekly_report",
|
|
|
+ ResearchReportID: reportInfo.ResearchReportID,
|
|
|
+ ResearchReportTypeID: researchReportTypeId,
|
|
|
+ }
|
|
|
+ err = userViewHistory.AddUserViewHistory()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddUserViewHistory err", err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加阅读日志的数据加入到redis
|
|
|
+ go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
|
|
|
|
|
|
result = ResearchReportTypeContentInfo{
|
|
|
ResearchReportTypeContentList: researchReportTypeContentList,
|
|
@@ -149,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
|
|
|
+}
|