article_red.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "time"
  9. )
  10. //处理文章小红点
  11. func GetShowTimeLineIsRed(user *models.WxUserItem, industrialManagementId int) (isRed bool, err error) {
  12. //时间线
  13. timeLineItem := models.IndustrialToArticleCategoryRep{
  14. CategoryId: 99999,
  15. MatchTypeName: "时间线",
  16. }
  17. timeLineList, e := models.GetTimeLineReportIndustrialListRed(user.UserId, industrialManagementId, 0, 30)
  18. if e != nil {
  19. err = errors.New("GetTimeLineReportIndustrialListRed, Err: " + e.Error())
  20. return
  21. }
  22. //查询用户今天是否看过时间线
  23. //haveMorningMeeting := false
  24. //var morningMeetingTime string
  25. //count, e := models.GetTimeLineRecordCount(user.UserId, industrialManagementId)
  26. //if e != nil {
  27. // err = errors.New("GetTimeLineRecordCount, Err: " + e.Error())
  28. // return
  29. //}
  30. //var recordItem *models.CygxPageHistoryRecord
  31. //if count > 1 {
  32. // recordItem, e = models.GetTimeLineRecordItem(user.UserId, industrialManagementId)
  33. // if e != nil {
  34. // err = errors.New("GetTimeLineRecordCount, Err: " + e.Error())
  35. // return
  36. // }
  37. //}
  38. for _, v := range timeLineList {
  39. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  40. if v.SubCategoryName == "时间线" {
  41. //haveMorningMeeting = true
  42. //morningMeetingTime = v.PublishDate
  43. continue
  44. }
  45. timeLineItem.IsRed = true
  46. }
  47. }
  48. //因为无法记录用户是否看过晨会点评,所以用用户今天是否看过时间线来判断是否显示小红点,这里是判断分类的小红点
  49. //timeLineRed := false
  50. //if count < 2 {
  51. // timeLineRed = true
  52. //} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(morningMeetingTime)) {
  53. // timeLineRed = true
  54. //}
  55. //if !timeLineItem.IsRed && timeLineRed && haveMorningMeeting {
  56. // timeLineItem.IsRed = true
  57. //}
  58. isRed = timeLineItem.IsRed
  59. return
  60. }
  61. //// UserViewRedisData 阅读数据
  62. //type UserViewRedisData struct {
  63. // Mobile string `json:"mobile"`
  64. // Email string `json:"email"`
  65. // RealName string `json:"real_name"`
  66. // CompanyName string `json:"company_name"`
  67. // ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  68. // ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  69. // CompanyId int `json:"company_id" description:"客户id"`
  70. //}
  71. type UserViewRedisData struct {
  72. Mobile string `json:"mobile"`
  73. Email string `json:"email"`
  74. RealName string `json:"real_name"`
  75. CompanyName string `json:"company_name"`
  76. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  77. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  78. CompanyId int `json:"company_id" description:"客户id"`
  79. UserId int `json:"user_id" description:"用户id"`
  80. ReportId int `json:"report_id" description:"报告id"`
  81. StopTime int `json:"stop_time" description:"停留时间"`
  82. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  83. OutId int `json:"out_id" description:"记录ID"`
  84. }
  85. type ReportViewRecord struct {
  86. Id int `orm:"column(id);pk"`
  87. UserId int `description:"用户id"`
  88. ReportId int `description:"报告id"`
  89. Mobile string `description:"手机号"`
  90. Email string `description:"邮箱"`
  91. RealName string `description:"用户实际姓名"`
  92. CompanyName string `description:"公司名称"`
  93. CreateTime time.Time `description:"创建时间"`
  94. StopTime int `json:"stop_time" description:"停留时间"`
  95. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  96. OutId int `json:"out_id" description:"记录ID"`
  97. }
  98. // PushViewRecordNewRedisData 阅读数据加入到redis
  99. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  100. data := &UserViewRedisData{
  101. Mobile: reportViewRecord.Mobile,
  102. Email: reportViewRecord.Email,
  103. RealName: reportViewRecord.RealName,
  104. CompanyName: reportViewRecord.CompanyName,
  105. ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
  106. ProductId: 2,
  107. CompanyId: companyId,
  108. UserId: reportViewRecord.UserId,
  109. ReportId: reportViewRecord.ReportId,
  110. StopTime: reportViewRecord.StopTime,
  111. ReportChapterId: reportViewRecord.ReportChapterId,
  112. OutId: reportViewRecord.OutId,
  113. }
  114. if utils.Re == nil {
  115. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  116. if err != nil {
  117. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  118. }
  119. return true
  120. }
  121. return false
  122. }
  123. // GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
  124. func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
  125. var condition string
  126. var pars []interface{}
  127. condition = " AND user_id = ? "
  128. pars = append(pars, user.UserId)
  129. articleIdMap = make(map[int]bool, 0)
  130. list, err := models.GetArticleHistoryRecord(condition, pars)
  131. if err != nil && err.Error() != utils.ErrNoRow() {
  132. return
  133. }
  134. for _, v := range list {
  135. articleIdMap[v.ArticleId] = true
  136. }
  137. return
  138. }
  139. // GetUserArticleHistoryIndustrialNewPublishDate 获取产业关联的的文章用户是否阅读
  140. func GetUserArticleHistoryIndustrialNewPublishDate(user *models.WxUserItem, industrialIdArr []int, articleTypeIds, resource string) (mapIndustrialArticleHistory map[int]bool, err error) {
  141. if len(industrialIdArr) == 0 {
  142. return
  143. }
  144. var condition string
  145. var pars []interface{}
  146. articleIdMap, err := GetUserArticleHistoryRecord(user)
  147. if err != nil {
  148. return
  149. }
  150. if resource == utils.REOURCE_YX {
  151. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  152. } else {
  153. condition = ` AND a.article_type_id = 0 AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId)
  154. }
  155. var startTime time.Time
  156. if utils.StrTimeToTime(utils.OnlineTime).After(user.CreatedTime) {
  157. startTime = utils.StrTimeToTime(utils.OnlineTime)
  158. } else {
  159. startTime = user.CreatedTime
  160. }
  161. condition += ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) AND a.publish_date > ? `
  162. pars = append(pars, industrialIdArr, startTime)
  163. list, err := models.GetCygxIndustrialArticleGroupManagement(condition, pars)
  164. if err != nil {
  165. return
  166. }
  167. mapIndustrialArticle := make(map[int][]*models.CygxIndustrialArticleGroupManagementResp)
  168. //mapIndustrialArticleMax := make(map[int]int, 0)
  169. mapIndustrialArticleHistory = make(map[int]bool, 0)
  170. //mapIndustrialArticleMaxTime := make(map[int]time.Time)
  171. for _, v := range list {
  172. item := new(models.CygxIndustrialArticleGroupManagementResp)
  173. item.IndustrialManagementId = v.IndustrialManagementId
  174. item.ArticleId = v.ArticleId
  175. item.PublishDate = v.PublishDate
  176. mapIndustrialArticle[v.IndustrialManagementId] = append(mapIndustrialArticle[v.IndustrialManagementId], item)
  177. }
  178. for k, v := range mapIndustrialArticle {
  179. for _, item := range v {
  180. if !articleIdMap[item.ArticleId] {
  181. mapIndustrialArticleHistory[k] = true
  182. }
  183. }
  184. }
  185. return
  186. }