瀏覽代碼

研报视频社区客群消息

hsun 2 年之前
父節點
當前提交
7f9965a76a
共有 3 個文件被更改,包括 113 次插入0 次删除
  1. 1 0
      models/db.go
  2. 77 0
      models/yb/community_video.go
  3. 35 0
      services/report_push.go

+ 1 - 0
models/db.go

@@ -133,5 +133,6 @@ func initYbTable() {
 		new(yb.Speaker),          //研报主持人表
 		new(yb.ComeinEvent),      //进门会议表
 		new(yb.ComeinEventUser),  //进门会议用户表
+		new(yb.CommunityVideo),	  //研报视频社区
 	)
 }

+ 77 - 0
models/yb/community_video.go

@@ -0,0 +1,77 @@
+package yb
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// CommunityVideo 视频社区
+type CommunityVideo struct {
+	CommunityVideoId    int       `orm:"column(community_video_id);pk" description:"问题ID"`
+	Title               string    `description:"视频标题"`
+	ChartPermissionId   int       `description:"品种权限ID"`
+	ChartPermissionName string    `description:"品种权限名称"`
+	CoverImgUrl         string    `description:"封面图地址"`
+	VideoUrl            string    `description:"视频地址"`
+	VideoSeconds        string    `description:"视频时长,单位秒"`
+	PublishState        int       `description:"发布状态:0-待发布 1-已发布"`
+	SendThsState        int       `description:"客群消息推送状态:0-待推送 1-已推送"`
+	IsDeleted           int       `description:"是否已删除 0-否 1-是"`
+	PublishTime         time.Time `description:"发布时间"`
+	SendThsTime         time.Time `description:"推送客群时间"`
+	CreateTime          time.Time `description:"提问时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+	DeleteTime          time.Time `description:"删除时间"`
+}
+
+func (item *CommunityVideo) TableName() string {
+	return "yb_community_video"
+}
+
+func (item *CommunityVideo) Add() (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	item.CommunityVideoId = int(lastId)
+	return
+}
+
+func (item *CommunityVideo) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(item, cols...)
+	return
+}
+
+// GetVideoById 主键获取视频
+func GetVideoById(videoId int) (item *CommunityVideo, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM yb_community_video WHERE community_video_id = ? AND is_deleted = 0 LIMIT 1`
+	err = o.Raw(sql, videoId).QueryRow(&item)
+	return
+}
+
+// GetCommunityVideoList 获取视频列表
+func GetCommunityVideoList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CommunityVideo, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM yb_community_video WHERE is_deleted = 0 `
+	sql += condition
+	sql += ` ORDER BY create_time DESC`
+
+	totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
+	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
+		return
+	}
+	sql += ` LIMIT ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	return
+}
+
+// DeleteVideo 删除视频
+func DeleteVideo(videoId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE yb_community_video SET is_deleted = 1, delete_time = NOW() WHERE community_video_id = ? LIMIT 1`
+	_, err = o.Raw(sql, videoId).Exec()
+	return
+}

+ 35 - 0
services/report_push.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"github.com/wenzhenxi/gorsa"
 	"hongze/hongze_task/models"
+	"hongze/hongze_task/models/yb"
 	"hongze/hongze_task/services/alarm_msg"
 	"hongze/hongze_task/utils"
 	"io/ioutil"
@@ -165,6 +166,11 @@ func SendToThs(sendDetailId, reportId int, reportType string) (err error) {
 		if tmpErr != nil {
 			err = tmpErr
 		}
+	case "研报视频社区":
+		tmpErr := SendYbCommunityVideoToThs(reportId)
+		if tmpErr != nil {
+			err = tmpErr
+		}
 	default:
 		err = errors.New("异常类型")
 	}
@@ -460,3 +466,32 @@ func SendReportMiniToThs(reportId int) (err error) {
 
 	return
 }
+
+// SendYbCommunityVideoToThs 推送研报小程序视频社区客群消息
+func SendYbCommunityVideoToThs(videoId int) (err error) {
+	defer func() {
+		if err != nil {
+			go alarm_msg.SendAlarmMsg("SendYbCommunityVideoToThs-延时任务发送报告至同花顺失败, CommunityVideoId:"+strconv.Itoa(videoId)+", ErrMsg:"+err.Error(), 3)
+		}
+	}()
+	video, e := yb.GetVideoById(videoId)
+	if e != nil {
+		err = errors.New("获取视频信息失败, Err:" + e.Error())
+		return
+	}
+	permissionName := video.ChartPermissionName
+	title := video.Title
+	if permissionName == "" {
+		err = errors.New("客群标签为空, 不可推送")
+		return
+	}
+	if permissionName == "宏观经济" {
+		permissionName = "宏观"
+	}
+	jumpUrl := fmt.Sprint(utils.WxYbAppId + `/pages/video/videoList?videoId=`, videoId)
+	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
+	// 推送至同花顺
+	dataType := "2"
+	err = SendThs(title, permissionName, title, jumpUrl, logoUrl, dataType)
+	return
+}