|
@@ -12,7 +12,6 @@ import (
|
|
|
"hongze/hongze_yb/models/tables/voice_broadcast"
|
|
|
"hongze/hongze_yb/models/tables/voice_broadcast_img"
|
|
|
"hongze/hongze_yb/models/tables/voice_broadcast_statistics"
|
|
|
- "hongze/hongze_yb/models/tables/voice_section"
|
|
|
"hongze/hongze_yb/services/user"
|
|
|
"hongze/hongze_yb/services/wechat"
|
|
|
"hongze/hongze_yb/utils"
|
|
@@ -24,110 +23,62 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-func GetVoiceBroadcastList(pageindex, pagesize, sectionId, broadcastId int, userInfo user.UserInfo) (list []response.Broadcast, err error) {
|
|
|
- if broadcastId == 0 {
|
|
|
- if sectionId == 0 {
|
|
|
- broadList, e := voice_broadcast.GetBroadcast(pageindex, pagesize)
|
|
|
- if e != nil {
|
|
|
- e = errors.New("获取语音播报列表失败 Err:" + e.Error())
|
|
|
- }
|
|
|
- for _, item := range broadList {
|
|
|
- var respItem response.Broadcast
|
|
|
- respItem = response.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,
|
|
|
- IsAuthor: false,
|
|
|
- }
|
|
|
- if int(userInfo.UserID) == item.AuthorId {
|
|
|
- respItem.IsAuthor = true
|
|
|
- // 是否可以推送消息
|
|
|
- if item.MsgState == 0 {
|
|
|
- respItem.CouldSendMsg = true
|
|
|
- }
|
|
|
- }
|
|
|
- list = append(list, respItem)
|
|
|
-
|
|
|
- }
|
|
|
- err = e
|
|
|
- return
|
|
|
- }
|
|
|
- broadList, e := voice_broadcast.GetBroadcastByCondition(pageindex, pagesize, sectionId)
|
|
|
- if e != nil {
|
|
|
- e = errors.New("获取语音播报列表失败 Err:" + e.Error())
|
|
|
- }
|
|
|
- for _, item := range broadList {
|
|
|
- var respItem response.Broadcast
|
|
|
- respItem = response.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,
|
|
|
- IsAuthor: false,
|
|
|
- }
|
|
|
- if int(userInfo.UserID) == item.AuthorId {
|
|
|
- respItem.IsAuthor = true
|
|
|
- // 是否可以推送消息
|
|
|
- if item.MsgState == 0 {
|
|
|
- respItem.CouldSendMsg = true
|
|
|
- }
|
|
|
- }
|
|
|
- list = append(list, respItem)
|
|
|
-
|
|
|
- }
|
|
|
- err = e
|
|
|
- return
|
|
|
+// GetVoiceBroadcastList 获取语音播报列表
|
|
|
+func GetVoiceBroadcastList(pageIndex, pageSize, sectionId, broadcastId, authorId, mineStatus int, userInfo user.UserInfo) (resp []response.Broadcast, err error) {
|
|
|
+ condition := ` 1=1`
|
|
|
+ var pars []interface{}
|
|
|
+ // 分享进来的指定语音播报
|
|
|
+ if broadcastId > 0 {
|
|
|
+ condition += ` AND broadcast_id = ?`
|
|
|
+ pars = append(pars, broadcastId)
|
|
|
} else {
|
|
|
- broadList, e := voice_broadcast.GetBroadcastByIdAndPage(pageindex, pagesize, broadcastId)
|
|
|
- if e != nil {
|
|
|
- e = errors.New("获取语音播报列表失败 Err:" + e.Error())
|
|
|
+ // 板块
|
|
|
+ if sectionId > 0 {
|
|
|
+ condition += ` AND section_id = ?`
|
|
|
+ pars = append(pars, sectionId)
|
|
|
}
|
|
|
- for _, item := range broadList {
|
|
|
- var respItem response.Broadcast
|
|
|
- respItem = response.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,
|
|
|
- IsAuthor: false,
|
|
|
+ // 我的
|
|
|
+ if authorId > 0 {
|
|
|
+ condition += ` AND author_id = ?`
|
|
|
+ pars = append(pars, authorId)
|
|
|
+ // 我的语音播报状态: 0-未发布 1-已发布 2-全部
|
|
|
+ if mineStatus != 2 {
|
|
|
+ condition += ` AND publish_state = ?`
|
|
|
+ pars = append(pars, mineStatus)
|
|
|
}
|
|
|
- if int(userInfo.UserID) == item.AuthorId {
|
|
|
- respItem.IsAuthor = true
|
|
|
- }
|
|
|
- list = append(list, respItem)
|
|
|
-
|
|
|
}
|
|
|
- err = e
|
|
|
+ }
|
|
|
+ voiceList, e := voice_broadcast.GetPageListByCondition(condition, pars, pageIndex, pageSize)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取语音播报列表失败, Err: " + e.Error())
|
|
|
return
|
|
|
}
|
|
|
+ listLen := len(voiceList)
|
|
|
+ if listLen == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 图片
|
|
|
+ voiceIds := make([]int, 0)
|
|
|
+ for i := 0; i < listLen; i++ {
|
|
|
+ voiceIds = append(voiceIds, voiceList[i].BroadcastId)
|
|
|
+ }
|
|
|
+ imgList, e := voice_broadcast_img.GetVoiceImgListByVoiceIds(voiceIds)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取语音播报列表图片失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgMap := make(map[int][]*voice_broadcast_img.YbVoiceBroadcastImg, 0)
|
|
|
+ imgListLen := len(imgList)
|
|
|
+ for i := 0; i < imgListLen; i++ {
|
|
|
+ imgMap[imgList[i].BroadcastId] = append(imgMap[imgList[i].BroadcastId], imgList[i])
|
|
|
+ }
|
|
|
+ // 响应数据
|
|
|
+ userId := int(userInfo.UserID)
|
|
|
+ for i := 0; i < listLen; i++ {
|
|
|
+ r := handleBroadcastItem(userId, voiceList[i], imgMap[voiceList[i].BroadcastId])
|
|
|
+ resp = append(resp, r)
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// GetVoiceAdminByUserInfo 判断当前用户是否为语音管理员
|
|
@@ -262,78 +213,6 @@ func SendBroadcastMsg(broadcastId, userId int) (errMsg string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// VoiceBroadcastShareImgPars 语音播报分享图参数
|
|
|
-type VoiceBroadcastShareImgPars struct {
|
|
|
- BackgroundImg string `json:"background_img"`
|
|
|
- Title string `json:"title"`
|
|
|
- CreateTime string `json:"create_time"`
|
|
|
-}
|
|
|
-
|
|
|
-// UpdateVoiceBroadcastImgUrl 更新历史语音播报分享图
|
|
|
-func UpdateVoiceBroadcastImgUrl() (err error) {
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err.Error())
|
|
|
- }
|
|
|
- }()
|
|
|
- // 获取语音播报列表
|
|
|
- list, e := voice_broadcast.GetBroadcastList()
|
|
|
- if e != nil {
|
|
|
- err = errors.New("获取语音播报列表失败")
|
|
|
- return
|
|
|
- }
|
|
|
- // 获取语音播报板块分享图
|
|
|
- sectionList, e := voice_section.GetVoiceSection()
|
|
|
- if e != nil {
|
|
|
- err = errors.New("获取语音播报列表失败")
|
|
|
- return
|
|
|
- }
|
|
|
- sectionMap := make(map[int]string, 0)
|
|
|
- sectionNameMap := make(map[int]string, 0)
|
|
|
- for _, s := range sectionList {
|
|
|
- sectionMap[s.SectionId] = s.ImgUrl
|
|
|
- sectionNameMap[s.SectionId] = s.SectionName
|
|
|
- }
|
|
|
- // 生成语音分享图并更新
|
|
|
- listLen := len(list)
|
|
|
- fmt.Println("待更新数:", listLen)
|
|
|
- updateCols := []string{"ImgUrl"}
|
|
|
- for i := 0; i < listLen; i++ {
|
|
|
- item := list[i]
|
|
|
- fmt.Println("正在更新-Id:", item.BroadcastId)
|
|
|
- imgUrl := sectionMap[item.SectionId]
|
|
|
- if imgUrl == "" {
|
|
|
- fmt.Println("背景图为空-Id:", item.BroadcastId)
|
|
|
- continue
|
|
|
- }
|
|
|
- sectionName := sectionNameMap[item.SectionId]
|
|
|
- timeDate := item.CreateTime[0:10]
|
|
|
- pars := VoiceBroadcastShareImgPars{
|
|
|
- BackgroundImg: imgUrl,
|
|
|
- Title: sectionName,
|
|
|
- CreateTime: timeDate,
|
|
|
- }
|
|
|
- parsByte, e := json.Marshal(pars)
|
|
|
- if e != nil {
|
|
|
- err = errors.New("分享图参数有误")
|
|
|
- return
|
|
|
- }
|
|
|
- shareImg, e := GetDynamicShareImg(VoiceBroadcastShareImgSource, string(parsByte))
|
|
|
- //fmt.Println(shareImg)
|
|
|
- if e != nil {
|
|
|
- err = errors.New("生成分享图失败")
|
|
|
- return
|
|
|
- }
|
|
|
- item.ImgUrl = shareImg
|
|
|
- if e = item.Update(updateCols); e != nil {
|
|
|
- err = errors.New("更新语音播报失败")
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("更新成功-Id:", item.BroadcastId)
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
// PublishVoiceBroadcast 发布语音播报
|
|
|
func PublishVoiceBroadcast(broadcastId, sectionId, varietyId, authorId, publishType int, broadcastName, sectionName, varietyName, author,
|
|
|
imgUrl, prePublishTime, imgs string, voiceFile *multipart.FileHeader) (errMsg string, err error) {
|
|
@@ -453,6 +332,13 @@ func PublishVoiceBroadcast(broadcastId, sectionId, varietyId, authorId, publishT
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// VoiceBroadcastShareImgPars 语音播报分享图参数
|
|
|
+type VoiceBroadcastShareImgPars struct {
|
|
|
+ BackgroundImg string `json:"background_img"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ CreateTime string `json:"create_time"`
|
|
|
+}
|
|
|
+
|
|
|
// createVoiceBroadcastShareImg 生成动态分享图
|
|
|
func createVoiceBroadcastShareImg(baseImg, sectionName, createTime string) (shareImg string, err error) {
|
|
|
pars := VoiceBroadcastShareImgPars{
|
|
@@ -528,3 +414,56 @@ func handleVoiceBroadcastFile(voiceFile *multipart.FileHeader) (fileSeconds int,
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetVoiceBroadcastDetail 获取语音播报详情
|
|
|
+func GetVoiceBroadcastDetail(broadcastId, userId int) (detail response.Broadcast, err error) {
|
|
|
+ item, e := voice_broadcast.GetBroadcastById(broadcastId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取语音播报详情失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 语音播报图片
|
|
|
+ imgList, e := voice_broadcast_img.GetVoiceImgListByVoiceId(broadcastId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("获取语音播报图片失败, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ detail = handleBroadcastItem(userId, item, imgList)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handleBroadcastItem 语音播报响应数据处理
|
|
|
+func handleBroadcastItem(userId int, item *voice_broadcast.VoiceBroadcast, imgs []*voice_broadcast_img.YbVoiceBroadcastImg) (resp response.Broadcast) {
|
|
|
+ if item == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.BroadcastId = item.BroadcastId
|
|
|
+ resp.BroadcastName = item.BroadcastName
|
|
|
+ resp.SectionId = item.SectionId
|
|
|
+ resp.SectionName = item.SectionName
|
|
|
+ resp.VarietyId = item.VarietyId
|
|
|
+ resp.VarietyName = item.VarietyName
|
|
|
+ resp.AuthorId = item.AuthorId
|
|
|
+ resp.Author = item.Author
|
|
|
+ resp.ImgUrl = item.ImgUrl
|
|
|
+ resp.VoiceUrl = item.VoiceUrl
|
|
|
+ resp.VoicePlaySeconds = item.VoicePlaySeconds
|
|
|
+ resp.VoiceSize = item.VoiceSize
|
|
|
+ resp.CreateTime = item.CreateTime
|
|
|
+ resp.PublishState = item.PublishState
|
|
|
+ resp.PrePublishTime = item.PrePublishTime
|
|
|
+ // 是否为作者、是否可推送消息
|
|
|
+ if userId == item.AuthorId {
|
|
|
+ resp.IsAuthor = true
|
|
|
+ if item.MsgState == 0 {
|
|
|
+ resp.CouldSendMsg = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ imgLen := len(imgs)
|
|
|
+ imgArr := make([]string, 0)
|
|
|
+ for i := 0; i < imgLen; i++ {
|
|
|
+ imgArr = append(imgArr, imgs[i].ImgUrl)
|
|
|
+ }
|
|
|
+ resp.Imgs = imgArr
|
|
|
+ return
|
|
|
+}
|