浏览代码

列表展示方式修改

ziwen 2 年之前
父节点
当前提交
d9a2142da6
共有 2 个文件被更改,包括 52 次插入2 次删除
  1. 42 1
      controller/voice_broadcast/voice_broadcast.go
  2. 10 1
      models/tables/voice_section/query.go

+ 42 - 1
controller/voice_broadcast/voice_broadcast.go

@@ -203,6 +203,44 @@ func SectionList(c *gin.Context) {
 	//	}
 	//	sectionList = append(sectionList, section)
 	//}
+	var newsList []*voice_section.VoiceSection
+	//var bannedSectionList []*voice_section.VoiceSection
+
+	//查找被禁用的板块ids
+	var bannedIds []int
+	for _, section := range sList {
+		if section.Status == 0 {
+			//bannedSectionList = append(bannedSectionList, section)
+			bannedIds = append(bannedIds, section.SectionId)
+		} else {
+			newsList = append(newsList, section)
+		}
+	}
+
+	//如果有被禁用的板块,去语音列表查找被禁用板块有没有语音
+	var lists []*voice_broadcast.VoiceBroadcast
+	if len(bannedIds) > 0{
+		lists, err = voice_section.GetVoiceSectionFromBroadcast(bannedIds)
+		if err != nil {
+			response.FailMsg("查询语音播报禁用板块失败", "GetVoiceSectionFromBroadcast, Err:"+err.Error(), c)
+		}
+	}
+
+	//被禁用板块有语音,依然显示该板块
+	if len(lists) > 0 {
+		//清空切片,用新的
+		newsList = newsList[0:0]
+		bannedMap := make(map[int]int)
+		for _, broadcast := range lists {
+			bannedMap[broadcast.SectionId] = broadcast.SectionId
+		}
+		for _, section := range sList {
+			_,ok := bannedMap[section.SectionId]
+			if section.Status != 0 && ok {
+				newsList = append(newsList, section)
+			}
+		}
+	}
 
 	for _, v := range vList {
 		variety := voiceResp.VarietyList{
@@ -213,7 +251,7 @@ func SectionList(c *gin.Context) {
 	}
 
 	for _, v := range varietyList {
-		for _, s := range sList {
+		for _, s := range newsList {
 			if v.VarietyId == s.VarietyId {
 				section := voiceResp.SectionList{
 					ImgUrl:      s.ImgUrl,
@@ -224,6 +262,9 @@ func SectionList(c *gin.Context) {
 				sectionList = append(sectionList, section)
 			}
 		}
+		if len(sectionList) == 0{
+			continue
+		}
 		v.Children = sectionList
 		resp = append(resp, v)
 		sectionList = []voiceResp.SectionList{}

+ 10 - 1
models/tables/voice_section/query.go

@@ -1,6 +1,9 @@
 package voice_section
 
-import "hongze/hongze_yb/global"
+import (
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/tables/voice_broadcast"
+)
 
 // GetVoiceSection 查询所有语音播报章节
 func GetVoiceSection() (list []*VoiceSection, err error) {
@@ -12,4 +15,10 @@ func GetVoiceSection() (list []*VoiceSection, err error) {
 func GetVoiceVariety() (list []*VoiceSection, err error) {
 	err = global.DEFAULT_MYSQL.Group("variety_id").Find(&list).Error
 	return
+}
+
+// GetVoiceSectionFromBroadcast 查询所有语音播报章节
+func GetVoiceSectionFromBroadcast(bannedIds []int) (list []*voice_broadcast.VoiceBroadcast, err error) {
+	err = global.DEFAULT_MYSQL.Where("section_id IN (?)", bannedIds).Group("section_id").Find(&list).Error
+	return
 }