xingzai 2 роки тому
батько
коміт
4c209b4d37
3 змінених файлів з 136 додано та 1 видалено
  1. 16 1
      models/page_history_record.go
  2. 58 0
      models/report.go
  3. 62 0
      services/article_red.go

+ 16 - 1
models/page_history_record.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"strconv"
 	"time"
 )
 
@@ -36,9 +37,23 @@ type CygxPageHistoryRecordHtgjRep struct {
 	Sign                   string `description:"签名"`
 }
 
-//添加
+// 添加
 func AddCygxPageHistoryRecord(item *CygxPageHistoryRecord) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
 }
+
+func GetTimeLineRecordCount(userId, industrialManagementId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=` + strconv.Itoa(industrialManagementId) + `'`
+	err = o.Raw(sql, userId).QueryRow(&count)
+	return
+}
+
+func GetTimeLineRecordItem(userId, industrialManagementId int) (item *CygxPageHistoryRecord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=` + strconv.Itoa(industrialManagementId) + `' ORDER BY create_time DESC LIMIT 1,1 `
+	err = o.Raw(sql, userId).QueryRow(&item)
+	return
+}

+ 58 - 0
models/report.go

@@ -403,6 +403,64 @@ func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize
 	return
 }
 
+type TimeLineReportItem struct {
+	Id              int    `description:"文章或晨报点评id"`
+	Title           string `description:"标题"`
+	PublishTime     string `description:"发布时间"`
+	Content         string `description:"内容"`
+	VideoUrl        string `description:"视频链接"`
+	IsHaveVideo     bool   `description:"是否包含视频"`
+	ImgUrlPc        string `description:"pc图片"`
+	SubCategoryName string `description:"二级分类"`
+	IsRed           bool   `description:"是否标红"`
+	Readnum         int    `description:"阅读数量"`
+}
+
+// 获取产业报告+晨会点评列表
+func GetTimeLineReportIndustrialListRed(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	* 
+FROM
+	(
+		SELECT
+		a.article_id AS id,
+		a.title,
+		a.publish_date AS publish_time,
+		a.video_url,
+		a.sub_category_name,
+		'' AS content,
+		( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = a.article_id ) AS readnum 
+	FROM
+		cygx_article AS a
+		INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id 
+	WHERE
+		a.publish_status = 1 
+		AND a.is_class = 1 
+		AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
+	SELECT
+		mmc.id,
+		'' AS title,
+		mm.publish_time AS publish_time,
+		'' AS video_url,
+		'时间线' AS sub_category_name,
+		mmc.content,
+		0  AS readnum 
+	FROM
+		cygx_morning_meeting_review_chapter AS mmc
+		INNER JOIN cygx_morning_meeting_reviews AS mm 
+	WHERE
+		mm.id = mmc.meeting_id 
+		AND mm.STATUS = 1 
+		AND mmc.industry_id = ? 
+	) AS t 
+`
+	sql += ` ORDER BY 
+	t.publish_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 type IndustrialPublishdate struct {
 	PublishDate            string `description:"发布时间"`
 	IndustrialManagementId int    `description:"产业D"`

+ 62 - 0
services/article_red.go

@@ -0,0 +1,62 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+)
+
+//处理文章小红点
+
+func ShowTimeLine(user *models.WxUserItem, industrialManagementId int) (err error, isRed bool) {
+	//时间线
+	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.PublishTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishTime)) {
+			if v.SubCategoryName == "时间线" {
+				haveMorningMeeting = true
+				morningMeetingTime = v.PublishTime
+				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
+	}
+
+	return
+
+}