Browse Source

no message

xingzai 1 year ago
parent
commit
87e6d7e02a
4 changed files with 131 additions and 11 deletions
  1. 1 1
      controllers/report.go
  2. 60 0
      models/timeline_log.go
  3. 12 10
      services/industrial_management.go
  4. 58 0
      services/timeline_log.go

+ 1 - 1
controllers/report.go

@@ -749,7 +749,7 @@ func (this *ReportController) List() {
 
 		resp := new(models.TimeLineReportListResp)
 		//resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
-
+		go services.AddCygxTimelineLog(user, industrialManagementId)
 		resp.List = list
 		resp.Paging = page
 		br.Ret = 200

+ 60 - 0
models/timeline_log.go

@@ -0,0 +1,60 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+type CygxTimelineLog struct {
+	Id                     int       `orm:"column(id);pk"`
+	IndustrialManagementId int       `description:"产业D"`
+	UserId                 int       `description:"用户ID"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	CompanyId              int       `description:"公司id"`
+	CompanyName            string    `description:"公司名称"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+	RealName               string    `description:"用户实际名称"`
+}
+
+// 判断用户是否阅读过该产业下的时间线
+func GetCygxTimelineLogCountByUser(userId, industrialManagementId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_timeline_log as a  WHERE user_id= ?    AND industrial_management_id  = ? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, userId, industrialManagementId).QueryRow(&count)
+	return
+}
+
+// 新增
+func AddCygxTimelineLog(item *CygxTimelineLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// UpdateCygxTimelineLogModifyTime 更新用户阅读过该产业下的时间线的时间
+func UpdateCygxTimelineLogModifyTime(userId, industrialManagementId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_timeline_log SET modify_time = ?  WHERE user_id= ?    AND industrial_management_id  = ? `
+	_, err = o.Raw(sql, time.Now(), userId, industrialManagementId).Exec()
+	return
+}
+
+//func GetCygxTimelineLogCount(userId int, date string) (items []*CygxPageHistoryRecord, err error) {
+//	o := orm.NewOrm()
+//	sql := `SELECT * FROM cygx_timeline_log WHERE user_id=?  `
+//	_, err = o.Raw(sql, userId, date).QueryRows(&items)
+//	return
+//}
+
+func GetCygxTimelineLogCount(userId int, industrialIdArr []int) (items []*CygxTimelineLog, err error) {
+	if len(industrialIdArr) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_timeline_log WHERE user_id=? AND 	 industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)`
+	_, err = o.Raw(sql, userId, industrialIdArr).QueryRows(&items)
+	return
+}

+ 12 - 10
services/industrial_management.go

@@ -523,21 +523,23 @@ func HandleIndustryList(list []*models.IndustrialManagement, user *models.WxUser
 	//查询用户今天是否看过时间线
 	//haveMorningMeeting := false
 	//var morningMeetingTime string
-	recrodList, err := models.GetTimeLineRecordAllCount(user.UserId, time.Now().Format(utils.FormatDate))
-	if err != nil {
+	recrodList, err := models.GetCygxTimelineLogCount(user.UserId, industrialIdArr)
+	if err != nil && err.Error() != utils.ErrNoRow() {
 		return
 	}
 	var industrialManagementIdstr string
 	industrialIdMap := make(map[string]time.Time)
 	for _, v := range recrodList {
-		industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
-		if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
-			if createTime.Before(v.CreateTime) {
-				industrialIdMap[industrialManagementIdstr] = v.CreateTime
-			}
-		} else {
-			industrialIdMap[industrialManagementIdstr] = v.CreateTime
-		}
+		industrialManagementIdstr = strconv.Itoa(v.IndustrialManagementId)
+		industrialIdMap[industrialManagementIdstr] = v.ModifyTime
+		//industrialManagementIdstr = strings.TrimLeft(v.Parameter, "PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=")
+		//if createTime, ok := industrialIdMap[industrialManagementIdstr]; ok {
+		//	if createTime.Before(v.CreateTime) {
+		//		industrialIdMap[industrialManagementIdstr] = v.CreateTime
+		//	}
+		//} else {
+		//	industrialIdMap[industrialManagementIdstr] = v.CreateTime
+		//}
 	}
 
 	mmList, err := models.GetCygxMorningMeetingReviewsListByIndustrialIds(industrialIds)

+ 58 - 0
services/timeline_log.go

@@ -0,0 +1,58 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+// 记录产业时间线的点击记录
+func AddCygxTimelineLog(user *models.WxUserItem, industrialManagementId int) (err error) {
+	if user.UserId == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("记录产业时间线的点击记录 失败 AddCygxTimelineLog Err:"+err.Error(), "userId:", user.UserId, "industrialManagementId:", industrialManagementId), 2)
+		}
+	}()
+	//获取销售信息
+	sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
+		return
+	}
+	if sellerItem == nil {
+		return
+	}
+
+	//判断一个用户是否阅读过 某一篇研选专栏
+	totalRecord, e := models.GetCygxTimelineLogCountByUser(user.UserId, industrialManagementId)
+	if e != nil {
+		err = errors.New("GetCygxTimelineLogCountByUser, Err: " + e.Error())
+		return
+	}
+	if totalRecord == 0 {
+		item := new(models.CygxTimelineLog)
+		item.UserId = user.UserId
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.RealName = user.RealName
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.IndustrialManagementId = industrialManagementId
+		_, e = models.AddCygxTimelineLog(item) // 添加历史记录
+	} else {
+		//更新时间线下对应产业的阅读时间
+		e = models.UpdateCygxTimelineLogModifyTime(user.UserId, industrialManagementId)
+		if e != nil {
+			err = errors.New("UpdateCygxTimelineLogModifyTime, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}