123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/utils"
- "strconv"
- "time"
- )
- //处理文章小红点
- func GetShowTimeLineIsRed(user *models.WxUserItem, industrialManagementId int) (isRed bool, err error) {
- //时间线
- timeLineItem := models.IndustrialToArticleCategoryRep{
- CategoryId: 99999,
- MatchTypeName: "时间线",
- }
- timeLineList, e := models.GetTimeLineReportIndustrialListRed(user.UserId, industrialManagementId, 0, 30)
- if e != nil {
- err = errors.New("GetTimeLineReportIndustrialListRed, Err: " + e.Error())
- return
- }
- //查询用户今天是否看过时间线
- //haveMorningMeeting := false
- //var morningMeetingTime string
- //count, e := models.GetTimeLineRecordCount(user.UserId, industrialManagementId)
- //if e != nil {
- // err = errors.New("GetTimeLineRecordCount, Err: " + e.Error())
- // return
- //}
- //var recordItem *models.CygxPageHistoryRecord
- //if count > 1 {
- // recordItem, e = models.GetTimeLineRecordItem(user.UserId, industrialManagementId)
- // if e != nil {
- // err = errors.New("GetTimeLineRecordCount, Err: " + e.Error())
- // return
- // }
- //}
- for _, v := range timeLineList {
- if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
- if v.SubCategoryName == "时间线" {
- //haveMorningMeeting = true
- //morningMeetingTime = v.PublishDate
- continue
- }
- timeLineItem.IsRed = true
- }
- }
- //因为无法记录用户是否看过晨会点评,所以用用户今天是否看过时间线来判断是否显示小红点,这里是判断分类的小红点
- //timeLineRed := false
- //if count < 2 {
- // timeLineRed = true
- //} else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(morningMeetingTime)) {
- // timeLineRed = true
- //}
- //if !timeLineItem.IsRed && timeLineRed && haveMorningMeeting {
- // timeLineItem.IsRed = true
- //}
- isRed = timeLineItem.IsRed
- 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"`
- //}
- 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"`
- UserId int `json:"user_id" description:"用户id"`
- ReportId int `json:"report_id" description:"报告id"`
- StopTime int `json:"stop_time" description:"停留时间"`
- ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
- OutId int `json:"out_id" description:"记录ID"`
- }
- type ReportViewRecord struct {
- Id int `orm:"column(id);pk"`
- UserId int `description:"用户id"`
- ReportId int `description:"报告id"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- RealName string `description:"用户实际姓名"`
- CompanyName string `description:"公司名称"`
- CreateTime time.Time `description:"创建时间"`
- StopTime int `json:"stop_time" description:"停留时间"`
- ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
- OutId int `json:"out_id" description:"记录ID"`
- }
- // PushViewRecordNewRedisData 阅读数据加入到redis
- func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
- data := &UserViewRedisData{
- Mobile: reportViewRecord.Mobile,
- Email: reportViewRecord.Email,
- RealName: reportViewRecord.RealName,
- CompanyName: reportViewRecord.CompanyName,
- ViewTime: reportViewRecord.CreateTime.Format(utils.FormatDateTime),
- ProductId: 2,
- CompanyId: companyId,
- UserId: reportViewRecord.UserId,
- ReportId: reportViewRecord.ReportId,
- StopTime: reportViewRecord.StopTime,
- ReportChapterId: reportViewRecord.ReportChapterId,
- OutId: reportViewRecord.OutId,
- }
- 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
- }
- // GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
- func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
- var condition string
- var pars []interface{}
- condition = " AND user_id = ? "
- pars = append(pars, user.UserId)
- articleIdMap = make(map[int]bool, 0)
- list, err := models.GetArticleHistoryRecord(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return
- }
- for _, v := range list {
- articleIdMap[v.ArticleId] = true
- }
- return
- }
- // GetUserArticleHistoryIndustrialNewPublishDate 获取产业关联的的文章用户是否阅读
- func GetUserArticleHistoryIndustrialNewPublishDate(user *models.WxUserItem, industrialIdArr []int, articleTypeIds, resource string) (mapIndustrialArticleHistory map[int]bool, err error) {
- if len(industrialIdArr) == 0 {
- return
- }
- var condition string
- var pars []interface{}
- articleIdMap, err := GetUserArticleHistoryRecord(user)
- if err != nil {
- return
- }
- if resource == utils.REOURCE_YX {
- condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
- } else {
- condition = ` AND a.article_type_id = 0 AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId)
- }
- var startTime time.Time
- if utils.StrTimeToTime(utils.OnlineTime).After(user.CreatedTime) {
- startTime = utils.StrTimeToTime(utils.OnlineTime)
- } else {
- startTime = user.CreatedTime
- }
- condition += ` AND mg.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) AND a.publish_date > ? `
- pars = append(pars, industrialIdArr, startTime)
- list, err := models.GetCygxIndustrialArticleGroupManagement(condition, pars)
- if err != nil {
- return
- }
- mapIndustrialArticle := make(map[int][]*models.CygxIndustrialArticleGroupManagementResp)
- //mapIndustrialArticleMax := make(map[int]int, 0)
- mapIndustrialArticleHistory = make(map[int]bool, 0)
- //mapIndustrialArticleMaxTime := make(map[int]time.Time)
- for _, v := range list {
- item := new(models.CygxIndustrialArticleGroupManagementResp)
- item.IndustrialManagementId = v.IndustrialManagementId
- item.ArticleId = v.ArticleId
- item.PublishDate = v.PublishDate
- mapIndustrialArticle[v.IndustrialManagementId] = append(mapIndustrialArticle[v.IndustrialManagementId], item)
- }
- for k, v := range mapIndustrialArticle {
- for _, item := range v {
- if !articleIdMap[item.ArticleId] {
- mapIndustrialArticleHistory[k] = true
- }
- }
- }
- return
- }
|