소스 검색

新增语音播报详情、拆分消息推送

hsun 2 년 전
부모
커밋
c63ce3e3ff

+ 82 - 15
controller/voice_broadcast/voice_broadcast.go

@@ -12,7 +12,6 @@ import (
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
-	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
 	"os"
@@ -46,7 +45,7 @@ func BroadcastList(c *gin.Context) {
 	userinfo := user.GetInfoByClaims(c)
 	ok, checkInfo, _, err := company.CheckBaseFiccPermission(userinfo.CompanyID, int(userinfo.UserID))
 	if err != nil {
-		response.FailMsg("用户权限验证失败", "CheckBaseAuth-用户权限验证失败" + err.Error(), c)
+		response.FailMsg("用户权限验证失败", "CheckBaseAuth-用户权限验证失败"+err.Error(), c)
 		c.Abort()
 		return
 	}
@@ -81,7 +80,7 @@ func BroadcastList(c *gin.Context) {
 // @Router /add [post]
 func AddBroadcast(c *gin.Context) {
 	broadcastName := c.PostForm("broadcast_name")
-	fmt.Println("broadcastName:",broadcastName)
+	fmt.Println("broadcastName:", broadcastName)
 	nsectionId := c.PostForm("section_id")
 	sectionId, _ := strconv.Atoi(nsectionId)
 	sectionName := c.PostForm("section_name")
@@ -168,12 +167,6 @@ func AddBroadcast(c *gin.Context) {
 	if err != nil {
 		fmt.Println("AddUserViewHistory err", err.Error())
 	}
-
-	// 推送回复消息给用户
-	go wechat.SendVoiceBroadcastWxMsg(voiceBroadcast.BroadcastId, voiceBroadcast.SectionName, voiceBroadcast.BroadcastName)
-
-	//同花顺客群
-	go services.SendVoiceBroadcastToThs(voiceBroadcast)
 	response.Ok("发布成功", c)
 }
 
@@ -219,7 +212,7 @@ func SectionList(c *gin.Context) {
 
 	//如果有被禁用的板块,去语音列表查找被禁用板块有没有语音
 	var lists []*voice_broadcast.VoiceBroadcast
-	if len(bannedIds) > 0{
+	if len(bannedIds) > 0 {
 		lists, err = voice_section.GetVoiceSectionFromBroadcast(bannedIds)
 		if err != nil {
 			response.FailMsg("查询语音播报禁用板块失败", "GetVoiceSectionFromBroadcast, Err:"+err.Error(), c)
@@ -235,7 +228,7 @@ func SectionList(c *gin.Context) {
 			bannedMap[broadcast.SectionId] = broadcast.SectionId
 		}
 		for _, section := range sList {
-			_,ok := bannedMap[section.SectionId]
+			_, ok := bannedMap[section.SectionId]
 			if section.Status != 0 || ok {
 				newsList = append(newsList, section)
 			}
@@ -262,7 +255,7 @@ func SectionList(c *gin.Context) {
 				sectionList = append(sectionList, section)
 			}
 		}
-		if len(sectionList) == 0{
+		if len(sectionList) == 0 {
 			continue
 		}
 		v.Children = sectionList
@@ -285,7 +278,7 @@ func DelBroadcast(c *gin.Context) {
 		response.FailMsg("转换id失败,请输入正确的id", "strconv.Atoi, Err:"+err.Error(), c)
 	}
 	if broadcastId <= 0 {
-		response.FailMsg("参数错误","参数有误", c)
+		response.FailMsg("参数错误", "参数有误", c)
 		return
 	}
 	var item voice_broadcast.VoiceBroadcast
@@ -310,12 +303,86 @@ func AddStatistics(c *gin.Context) {
 		return
 	}
 
-	if req.BroadcastId <= 0{
+	if req.BroadcastId <= 0 {
 		response.Fail("参数有误", c)
 	}
 	userinfo := user.GetInfoByClaims(c)
-	
+
 	go services.AddBroadcastRecord(userinfo, req.Source, req.BroadcastId)
 
 	response.Ok("新增记录成功", c)
 }
+
+// BroadcastDetail 获取语音播报详情
+// @Tags 语音播报模块
+// @Description 获取语音播报详情
+// @Param variety_tag_id  query  int  true  "标签ID"
+// @Success 200 {object} response.PriceDrivenItem
+// @failure 400 {string} string "获取失败"
+// @Router /detail [get]
+func BroadcastDetail(c *gin.Context) {
+	var req request.BroadcastDetailReq
+	if err := c.Bind(&req); err != nil {
+		response.Fail("参数有误", c)
+		return
+	}
+	if req.BroadcastId <= 0 {
+		response.Fail("参数有误", c)
+		return
+	}
+	userInfo := user.GetInfoByClaims(c)
+	item, e := voice_broadcast.GetBroadcastById(req.BroadcastId)
+	if e != nil {
+		response.FailMsg("获取失败", "BroadcastDetail ErrMsg:"+e.Error(), c)
+		return
+	}
+	resp := &voiceResp.Broadcast{
+		BroadcastId:      item.BroadcastId,
+		BroadcastName:    item.BroadcastName,
+		SectionId:        item.SectionId,
+		SectionName:      item.SectionName,
+		VarietyId:        item.VarietyId,
+		VarietyName:      item.VarietyName,
+		AuthorId:         item.AuthorId,
+		Author:           item.Author,
+		ImgUrl:           item.ImgUrl,
+		VoiceUrl:         item.VoiceUrl,
+		VoicePlaySeconds: item.VoicePlaySeconds,
+		VoiceSize:        item.VoiceSize,
+		CreateTime:       item.CreateTime,
+	}
+	// 是否为作者、是否可以推送消息
+	if int(userInfo.UserID) == item.AuthorId {
+		resp.IsAuthor = true
+		if item.MsgState == 0 {
+			resp.CouldSendMsg = true
+		}
+	}
+	response.OkData("获取成功", resp, c)
+}
+
+// MsgSend 语音播报消息推送
+// @Tags 语音播报模块
+// @Description 语音播报消息推送
+// @Param broadcast_id	query  int  true  "语音播报ID"
+// @Success 200 {string} string "操作成功"
+// @failure 400 {string} string "操作失败"
+// @Router /msg_send [post]
+func MsgSend(c *gin.Context) {
+	var req request.BroadcastMsgSendReq
+	if err := c.Bind(&req); err != nil {
+		response.Fail("参数有误", c)
+		return
+	}
+	if req.BroadcastId <= 0 {
+		response.Fail("参数有误", c)
+		return
+	}
+	userInfo := user.GetInfoByClaims(c)
+	errMsg, err := services.SendBroadcastMsg(req.BroadcastId, int(userInfo.UserID))
+	if err != nil {
+		response.FailMsg(errMsg, "MsgSend ErrMsg:"+err.Error(), c)
+		return
+	}
+	response.Ok("操作成功", c)
+}

+ 9 - 1
models/request/voice_broadcast.go

@@ -35,6 +35,14 @@ type AddBroadcastReq struct {
 //}
 
 type AddBroadcastStatisticsReq struct {
-	Source      int    `json:"source" description:"点击来源,1手机小程序,2pc小程序,3web端"`
+	Source      int `json:"source" description:"点击来源,1手机小程序,2pc小程序,3web端"`
 	BroadcastId int `json:"broadcast_id" `
 }
+
+type BroadcastDetailReq struct {
+	BroadcastId int `json:"broadcast_id" form:"broadcast_id" description:"语音播报ID"`
+}
+
+type BroadcastMsgSendReq struct {
+	BroadcastId int `json:"broadcast_id" description:"语音播报ID"`
+}

+ 1 - 0
models/response/voice_broadcast.go

@@ -21,6 +21,7 @@ type Broadcast struct {
 	VoiceSize        string `description:"音频大小"`
 	CreateTime       string `description:"创建时间"`
 	IsAuthor         bool   `description:"是否为作者"`
+	CouldSendMsg     bool   `description:"是否可推送消息"`
 }
 
 //type SectionListResp struct {

+ 5 - 0
models/tables/voice_broadcast/query.go

@@ -23,4 +23,9 @@ func GetBroadcast(pageIndex, pageSize int) (list []*VoiceBroadcast, err error) {
 func GetBroadcastById(broadcastId int) (list *VoiceBroadcast, err error) {
 	err = global.DEFAULT_MYSQL.Model(VoiceBroadcast{}).Where("broadcast_id=?", broadcastId).First(&list).Error
 	return
+}
+
+func (item *VoiceBroadcast) Update(updateCols []string) (err error) {
+	err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).Error
+	return
 }

+ 2 - 0
models/tables/voice_broadcast/voice_broadcast.go

@@ -14,6 +14,8 @@ type VoiceBroadcast struct {
 	VoicePlaySeconds string `description:"音频时长"`
 	VoiceSize        string `description:"音频大小"`
 	CreateTime       string `description:"创建时间"`
+	MsgState         int    `description:"消息推送状态:0-待推送 1-已推送"`
+	MsgTime          string `description:"消息推送时间"`
 }
 
 // TableName get sql table name.获取数据库表名

+ 4 - 0
routers/voice_broadcast.go

@@ -13,5 +13,9 @@ func InitVoiceBroadcast(r *gin.Engine)  {
 	rGroup.GET("/section/list", voice_broadcast.SectionList)
 	rGroup.GET("/delete", voice_broadcast.DelBroadcast)
 	rGroup.POST("/statistics/add", voice_broadcast.AddStatistics)
+	// 权限校验
+	rGroup2 := r.Group("api/voice/broadcast").Use(middleware.Token(), middleware.CheckBaseAuth())
+	rGroup2.GET("/detail", voice_broadcast.BroadcastDetail)
+	rGroup2.POST("/msg_send", voice_broadcast.MsgSend)
 }
 

+ 2 - 2
services/report_push.go

@@ -159,7 +159,7 @@ func SendThs(title, labelStr, abstract, jumpBaseUrl, logoUrl, dataType string) (
 }
 
 // SendVoiceBroadcastToThs 发送语音播报到同花顺
-func SendVoiceBroadcastToThs(voice voice_broadcast.VoiceBroadcast) (err error) {
+func SendVoiceBroadcastToThs(voice *voice_broadcast.VoiceBroadcast) (err error) {
 	defer func() {
 		if err != nil {
 			go alarm_msg.SendAlarmMsg("发送语音播报至同花顺失败 ErrMsg:"+err.Error(), 3)
@@ -168,7 +168,7 @@ func SendVoiceBroadcastToThs(voice voice_broadcast.VoiceBroadcast) (err error) {
 	}()
 	permissionName := "宏观" //写死宏观,默认所有群都推
 	//小程序跳转地址
-	jumpBaseUrl := wechat.WxYbAppId + `/pages/voice/voice?voiceId=`
+	jumpBaseUrl := wechat.WxYbAppId + `/pages-voice/voiceDetail?voiceId=`
 
 	logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
 

+ 47 - 0
services/voice_broadcast.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_yb/models/tables/voice_broadcast"
 	"hongze/hongze_yb/models/tables/voice_broadcast_statistics"
 	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/services/wechat"
 	"hongze/hongze_yb/utils"
 	"time"
 )
@@ -42,6 +43,10 @@ func GetVoiceBroadcastList(pageindex, pagesize, sectionId, broadcastId int, user
 				}
 				if int(userInfo.UserID) == item.AuthorId{
 					respItem.IsAuthor = true
+					// 是否可以推送消息
+					if item.MsgState == 0 {
+						respItem.CouldSendMsg = true
+					}
 				}
 				list = append(list, respItem)
 
@@ -73,6 +78,10 @@ func GetVoiceBroadcastList(pageindex, pagesize, sectionId, broadcastId int, user
 			}
 			if int(userInfo.UserID) == item.AuthorId{
 				respItem.IsAuthor = true
+				// 是否可以推送消息
+				if item.MsgState == 0 {
+					respItem.CouldSendMsg = true
+				}
 			}
 			list = append(list, respItem)
 
@@ -206,4 +215,42 @@ func AddBroadcastRecord(userinfo user.UserInfo, source, broadcastId int) {
 		return
 	}
 	return
+}
+
+// SendBroadcastMsg 推送语音播报消息
+func SendBroadcastMsg(broadcastId, userId int) (errMsg string, err error) {
+	broadcast, e := voice_broadcast.GetBroadcastById(broadcastId)
+	if e != nil {
+		errMsg = "推送失败, 语音播报信息有误"
+		err = errors.New("获取语音播报信息失败, Err: " + e.Error())
+		return
+	}
+	if broadcast.AuthorId != userId {
+		errMsg = "仅语音播报创建人可推送"
+		err = errors.New("仅语音播报创建人可推送")
+		return
+	}
+	if broadcast.MsgState != 0 {
+		errMsg = "请勿重复推送"
+		err = errors.New("请勿重复推送")
+		return
+	}
+	// 更新语音播报信息
+	updateCols := []string{"MsgState", "MsgTime"}
+	broadcast.MsgState = 1
+	broadcast.MsgTime = time.Now().Format(utils.FormatDateTime)
+	if e = broadcast.Update(updateCols); e != nil {
+		errMsg = "更新语音播报失败"
+		err = errors.New("更新语音播报失败")
+		return
+	}
+	// 推送模板消息
+	go func() {
+		_ = wechat.SendVoiceBroadcastWxMsg(broadcast.BroadcastId, broadcast.SectionName, broadcast.BroadcastName)
+	}()
+	// 推送客群消息
+	go func() {
+		_ = SendVoiceBroadcastToThs(broadcast)
+	}()
+	return
 }

+ 1 - 1
services/wechat/template_msg.go

@@ -277,7 +277,7 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
 	sendMap["template_id"] = TemplateIdWithCommunityQuestion
 	sendMap["data"] = sendData
 
-	wxAppPath := fmt.Sprintf("pages/voice/voice?voiceId=%d", broadcastId)
+	wxAppPath := fmt.Sprintf("pages-voice/voiceDetail?voiceId=%d", broadcastId)
 	if global.CONFIG.Serve.RunMode == "debug" {
 		// 仅测试环境测试用
 		wxAppPath = "pages-report/reportDetail?reportId=3800"