voice_section.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package yb
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/yb"
  8. "hongze/hz_crm_api/models/yb/request"
  9. "hongze/hz_crm_api/models/yb/response"
  10. "hongze/hz_crm_api/utils"
  11. "time"
  12. )
  13. // 音频播报板块
  14. type VoiceSectionController struct {
  15. controllers.BaseAuthController
  16. }
  17. // VoiceSectionList
  18. // @Title 语音播报板块配置列表
  19. // @Description 语音播报板块配置列表接口
  20. // @Success 200 {object} response.VoiceSectionResp
  21. // @router /voice/section/list [get]
  22. func (this *VoiceSectionController) VoiceSectionList() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. sysUser := this.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. pageSize, _ := this.GetInt("PageSize")
  36. currentIndex, _ := this.GetInt("CurrentIndex")
  37. var startSize int
  38. if pageSize <= 0 {
  39. pageSize = utils.PageSize20
  40. }
  41. if currentIndex <= 0 {
  42. currentIndex = 1
  43. }
  44. startSize = paging.StartIndex(currentIndex, pageSize)
  45. list, err := yb.GetVoiceSectionList(startSize, pageSize)
  46. if err != nil && err.Error() != utils.ErrNoRow() {
  47. br.Msg = "获取语音播报板块信息失败"
  48. br.ErrMsg = "获取语音播报板块信息失败,Err:" + err.Error()
  49. return
  50. }
  51. total, err := yb.GetVoiceSectionTotal()
  52. if err != nil {
  53. br.Msg = "获取留言列表总数失败!"
  54. br.ErrMsg = "获取留言列表总数失败,Err:" + err.Error()
  55. return
  56. }
  57. page := paging.GetPaging(currentIndex, pageSize, total)
  58. br.Ret = 200
  59. br.Success = true
  60. br.Msg = "获取成功"
  61. br.Data = response.VoiceSectionResp{
  62. List: list,
  63. Paging: page,
  64. }
  65. return
  66. }
  67. // AddVoiceSection
  68. // @Title 新增语音播报板块
  69. // @Description 新增语音播报板块接口
  70. // @Param request body request.VoiceSectionReq true "type json string"
  71. // @Success Ret=200 操作成功
  72. // @router /voice/section/add [post]
  73. func (this *VoiceSectionController) AddVoiceSection() {
  74. br := new(models.BaseResponse).Init()
  75. defer func() {
  76. this.Data["json"] = br
  77. this.ServeJSON()
  78. }()
  79. sysUser := this.SysUser
  80. if sysUser == nil {
  81. br.Msg = "请登录"
  82. br.ErrMsg = "请登录,SysUser Is Empty"
  83. br.Ret = 408
  84. return
  85. }
  86. var req request.VoiceSectionReq
  87. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  88. if err != nil {
  89. br.Msg = "参数解析异常!"
  90. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  91. return
  92. }
  93. // 校验参数
  94. if req.VarietyName == "" || req.SectionName == "" || req.VarietyId == 0 {
  95. br.Msg = "参数有误,请重新填写"
  96. br.ErrMsg = "参数有误,请重新填写"
  97. return
  98. }
  99. item := yb.VoiceSection{
  100. SectionName: req.SectionName,
  101. ImgUrl: req.ImgUrl,
  102. VarietyId: req.VarietyId,
  103. VarietyName: req.VarietyName,
  104. Status: 1,
  105. CreateTime: time.Now().Format(utils.FormatDateTime),
  106. }
  107. err = yb.AddVoiceSection(item)
  108. if err != nil {
  109. br.Msg = "新增失败"
  110. br.ErrMsg = "AddVoiceSection error" + err.Error()
  111. return
  112. }
  113. br.Ret = 200
  114. br.Success = true
  115. br.Msg = "操作成功"
  116. return
  117. }
  118. // EditVoiceSection
  119. // @Title 禁用语音播报板块
  120. // @Description 禁用语音播报板块接口
  121. // @Param SectionId query int false "板块id"
  122. // @Param SectionName query string false "板块名称"
  123. // @Param ImgUrl query string false "背景图url"
  124. // @Param Enable query int false "0禁用,1启用"
  125. // @Success Ret=200 操作成功
  126. // @router /voice/section/edit [get]
  127. func (this *VoiceSectionController) EditVoiceSection() {
  128. br := new(models.BaseResponse).Init()
  129. defer func() {
  130. this.Data["json"] = br
  131. this.ServeJSON()
  132. }()
  133. sysUser := this.SysUser
  134. if sysUser == nil {
  135. br.Msg = "请登录"
  136. br.ErrMsg = "请登录,SysUser Is Empty"
  137. br.Ret = 408
  138. return
  139. }
  140. var item yb.VoiceSection
  141. cols := make([]string, 0)
  142. sectionId, _ := this.GetInt("SectionId", 0)
  143. if sectionId == 0 {
  144. br.Msg = "板块id错误"
  145. br.ErrMsg = "板块id错误"
  146. return
  147. }
  148. item.SectionId = sectionId
  149. enable, _ := this.GetInt("Enable", -1)
  150. if enable != -1 {
  151. item.Status = enable
  152. cols = append(cols, "status")
  153. }
  154. sectionName := this.GetString("SectionName", "")
  155. if sectionName != "" {
  156. item.SectionName = sectionName
  157. cols = append(cols, "section_name")
  158. //更新统计表中的sectionName
  159. err := yb.UpdateVoiceBroadcastName(sectionId, sectionName)
  160. if err != nil {
  161. br.Msg = "修改失败"
  162. br.ErrMsg = "修改失败" + err.Error()
  163. return
  164. }
  165. }
  166. imgUrl := this.GetString("ImgUrl", "")
  167. if imgUrl != "" {
  168. item.ImgUrl = imgUrl
  169. cols = append(cols, "img_url")
  170. }
  171. total, err := yb.GetVoiceSectionEnableTotal()
  172. if err != nil {
  173. br.Msg = "查询失败"
  174. br.ErrMsg = "查询失败" + err.Error()
  175. return
  176. }
  177. if enable == 0 && total < 2 {
  178. br.Ret = 403
  179. br.Success = true
  180. br.Msg = "禁用失败,请至少启用一个版块!"
  181. return
  182. } else {
  183. err = item.Update(cols)
  184. if err != nil {
  185. br.Msg = "修改失败"
  186. br.ErrMsg = "修改失败" + err.Error()
  187. return
  188. }
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = "操作成功"
  192. //if imgUrl != "" {
  193. // go yb.UpdateVoiceBroadcast(sectionId, imgUrl)
  194. //}
  195. return
  196. }
  197. }