ziwen 2 سال پیش
والد
کامیت
8bacdd6c9a

+ 46 - 6
controller/voice_broadcast/voice_broadcast.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hongze_yb/models/request"
 	"hongze/hongze_yb/models/request"
 	voiceResp "hongze/hongze_yb/models/response"
 	voiceResp "hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/voice_broadcast"
 	"hongze/hongze_yb/models/tables/voice_broadcast"
+	"hongze/hongze_yb/models/tables/voice_section"
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
@@ -66,7 +67,6 @@ func BroadcastList(c *gin.Context) {
 // @failure 400 {string} string "发布失败"
 // @failure 400 {string} string "发布失败"
 // @Router /add [post]
 // @Router /add [post]
 func AddBroadcast(c *gin.Context) {
 func AddBroadcast(c *gin.Context) {
-	//var req request.AddBroadcastReq
 	broadcastName := c.PostForm("broadcast_name")
 	broadcastName := c.PostForm("broadcast_name")
 	fmt.Println("broadcastName:",broadcastName)
 	fmt.Println("broadcastName:",broadcastName)
 	nsectionId := c.PostForm("section_id")
 	nsectionId := c.PostForm("section_id")
@@ -158,13 +158,53 @@ func AddBroadcast(c *gin.Context) {
 
 
 // BroadcastList
 // BroadcastList
 // @Description 语音播报列表
 // @Description 语音播报列表
-// @Param page_index			query int false "页码"
-// @Param page_size				query int false "每页数量"
-// @Param broadcast_id			query int false "语音播报id"
-// @Param section_id			query int false "板块id"
 // @Success 200 {object} []voiceResp.BroadcastListResp
 // @Success 200 {object} []voiceResp.BroadcastListResp
 // @failure 400 {string} string "获取失败"
 // @failure 400 {string} string "获取失败"
 // @Router /section/list [get]
 // @Router /section/list [get]
 func SectionList(c *gin.Context) {
 func SectionList(c *gin.Context) {
-	
+	sList, err := voice_section.GetVoiceSection()
+	if err != nil {
+		response.FailMsg("查询语音播报板块失败", "GetVoiceSection, Err:"+err.Error(), c)
+	}
+	vList, err := voice_section.GetVoiceVariety()
+	if err != nil {
+		response.FailMsg("查询语音播报板块失败", "GetVoiceSection, Err:"+err.Error(), c)
+	}
+	var sectionList []voiceResp.SectionList
+	var varietyList []voiceResp.VarietyList
+	var resp []voiceResp.VarietyList
+	//var resp voiceResp.SectionListResp
+	//for _, s := range sList {
+	//	section := voiceResp.SectionList{
+	//		SectionId:   s.SectionId,
+	//		SectionName: s.SectionName,
+	//		Status:      s.Status,
+	//	}
+	//	sectionList = append(sectionList, section)
+	//}
+
+	for _, v := range vList {
+		variety := voiceResp.VarietyList{
+			VarietyId:   v.VarietyId,
+			VarietyName: v.VarietyName,
+		}
+		varietyList = append(varietyList, variety)
+	}
+
+	for _, v := range varietyList {
+		for _, s := range sList {
+			if v.VarietyId == s.VarietyId {
+				section := voiceResp.SectionList{
+							SectionId:   s.SectionId,
+							SectionName: s.SectionName,
+							Status:      s.Status,
+						}
+				sectionList = append(sectionList, section)
+			}
+		}
+		v.Children = sectionList
+		resp = append(resp, v)
+		sectionList = []voiceResp.SectionList{}
+	}
+	response.OkData("上传成功", resp, c)
 }
 }

+ 14 - 0
models/response/voice_broadcast.go

@@ -21,3 +21,17 @@ type Broadcast struct {
 	CreateTime       string `description:"创建时间"`
 	CreateTime       string `description:"创建时间"`
 	IsAuthor         bool   `description:"是否为作者"`
 	IsAuthor         bool   `description:"是否为作者"`
 }
 }
+
+//type SectionListResp struct {
+//	List []VarietyList
+//}
+type VarietyList struct {
+	VarietyId   int
+	VarietyName string
+	Children    []SectionList
+}
+type SectionList struct {
+	SectionId   int
+	SectionName string
+	Status      int
+}

+ 15 - 0
models/tables/voice_section/query.go

@@ -0,0 +1,15 @@
+package voice_section
+
+import "hongze/hongze_yb/global"
+
+// GetVoiceSection 查询所有语音播报章节
+func GetVoiceSection() (list []*VoiceSection, err error) {
+	err = global.DEFAULT_MYSQL.Find(&list).Error
+	return
+}
+
+// GetVoiceSection 查询所有语音播报章节
+func GetVoiceVariety() (list []*VoiceSection, err error) {
+	err = global.DEFAULT_MYSQL.Group("variety_id").Find(&list).Error
+	return
+}

+ 15 - 0
models/tables/voice_section/voice_section.go

@@ -0,0 +1,15 @@
+package voice_section
+
+type VoiceSection struct {
+	SectionId   int       `orm:"column(section_id);pk" description:"板块id"`
+	SectionName string    `description:"板块名称"`
+	VarietyId   int       `description:"品种id"`
+	VarietyName string    `description:"品种名称"`
+	Status      int       `description:"角色状态"`
+	CreateTime  string `description:"创建时间"`
+}
+
+// TableName 表名变更
+func (voiceSection *VoiceSection) TableName() string {
+	return "yb_voice_section"
+}