meetme.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. package asterisk
  2. import (
  3. "fmt"
  4. "net/http"
  5. "pbx-api-gin/api/model"
  6. "pbx-api-gin/internal/app/ami/action"
  7. "pbx-api-gin/pkg/lfshook"
  8. "strings"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // @tags Asterisk-MeetMe
  12. // @Summary 查看所有会议室
  13. // @Description 会议室列表
  14. // @Security ApiKeyAuth
  15. // @Accept json
  16. // @Produce json
  17. // @Success 200 {object} model.APIOK "请求成功"
  18. // @Router /ginapi/plugin-asterisk/meetme/list [get]
  19. /*func listMeetMe(ctx *gin.Context) {
  20. amiRooms, _ := action.ListRoomMeetMe(make(map[string]string))
  21. var meets []model.MeetMe
  22. if err := mysql.DBOrmInstance.Find(&meets); err != nil {
  23. lfshook.NewLogger().Errorf("db index error %+v", err)
  24. ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "db error"})
  25. return
  26. }
  27. numRoomMap := make(map[string]*amiModel.MeetMeListRooms)
  28. for _, room := range amiRooms {
  29. numRoomMap[room.Conference] = room
  30. }
  31. rooms := make([]*model.MeetMeRoom, 0)
  32. for _, meet := range meets {
  33. room := &model.MeetMeRoom{
  34. MeetMe: meet,
  35. }
  36. if data, has := numRoomMap[meet.Conference]; has {
  37. mapstructure.Decode(data, room)
  38. }
  39. rooms = append(rooms, room)
  40. }
  41. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: rooms})
  42. }
  43. */
  44. // @tags Asterisk-MeetMe
  45. // @Summary 查看指定会议室
  46. // @Description 会议室信息
  47. // @Security ApiKeyAuth
  48. // @Accept json
  49. // @Produce json
  50. // @Param conference query string true "会议室号"
  51. // @Success 200 {object} model.APIOK "请求成功"
  52. // @Router /ginapi/plugin-asterisk/meetme/room [get]
  53. /*func room(ctx *gin.Context) {
  54. conference := ctx.Query("conference")
  55. if conference == "" {
  56. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: errors.New("conference is empty").Error()})
  57. return
  58. }
  59. items, err := action.ListMeetMe(conference)
  60. if err != nil {
  61. lfshook.NewLogger().Warn(err)
  62. }
  63. // 查询 room 信息
  64. var roomInfo *amiModel.MeetMeListRooms
  65. amiRooms, _ := action.ListRoomMeetMe(make(map[string]string))
  66. for _, room := range amiRooms {
  67. if room.Conference == conference {
  68. roomInfo = room
  69. break
  70. }
  71. }
  72. meet := model.MeetMe{Conference: conference}
  73. if _, err := mysql.DBOrmInstance.Get(&meet); err != nil {
  74. lfshook.NewLogger().Errorf("db get error %+v", err)
  75. ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "db error"})
  76. return
  77. }
  78. room := &model.MeetMeRoom{
  79. MeetMe: meet,
  80. }
  81. mapstructure.Decode(roomInfo, room)
  82. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: gin.H{"items": items, "room": room}})
  83. }
  84. */
  85. // @tags Asterisk-MeetMe
  86. // @Summary 邀请会议
  87. // @Description 邀请会议
  88. // @Security ApiKeyAuth
  89. // @Accept json
  90. // @Produce json
  91. // @Param data body model.MeetMeInviteVO true "加入会议参数"
  92. // @Success 200 {object} model.APIOK "请求成功"
  93. // @Router /ginapi/plugin-asterisk/meetme/invite [post]
  94. func inviteMeetMe(ctx *gin.Context) {
  95. var data model.MeetMeInviteVO
  96. if err := ctx.ShouldBindJSON(&data); err != nil {
  97. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  98. return
  99. }
  100. // 根据参数确定主叫, 再考虑用户登录的分机信息
  101. myExtension := ""
  102. if myExtension == "" {
  103. ID, _ := ctx.Get("ID")
  104. myExtension = "=================="
  105. if myExtension == "" {
  106. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: fmt.Sprintf("not found user extension by ID %d", ID)})
  107. return
  108. }
  109. }
  110. dialplan := "default"
  111. action.IviteMeetMe(data.Meetme, strings.Join(data.Extensions, ","), dialplan, myExtension)
  112. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data})
  113. }
  114. // @tags Asterisk-MeetMe
  115. // @Summary 踢出会议
  116. // @Description 踢出会议
  117. // @Security ApiKeyAuth
  118. // @Accept json
  119. // @Produce json
  120. // @Param data body model.MeetMeVO true "参数"
  121. // @Success 200 {object} model.APIOK "请求成功"
  122. // @Router /ginapi/plugin-asterisk/meetme/kick [post]
  123. func kickMeetMe(ctx *gin.Context) {
  124. var data model.MeetMeVO
  125. if err := ctx.ShouldBindJSON(&data); err != nil {
  126. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  127. return
  128. }
  129. err := action.KickMeetMe(data.Meetme, strings.Join(data.UserNum, ","))
  130. if err != nil {
  131. ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: err.Error()})
  132. return
  133. }
  134. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data})
  135. }
  136. // @tags Asterisk-MeetMe
  137. // @Summary 禁言
  138. // @Description 禁言
  139. // @Security ApiKeyAuth
  140. // @Accept json
  141. // @Produce json
  142. // @Param data body model.MeetMeVO true "参数"
  143. // @Success 200 {object} model.APIOK "请求成功"
  144. // @Router /ginapi/plugin-asterisk/meetme/mute [post]
  145. func muteMeetMe(ctx *gin.Context) {
  146. var data model.MeetMeVO
  147. if err := ctx.ShouldBindJSON(&data); err != nil {
  148. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  149. return
  150. }
  151. var hasError bool
  152. for _, number := range data.UserNum {
  153. _, err := action.MuteMeetMe(data.Meetme, number)
  154. if err != nil {
  155. lfshook.NewLogger().Error(err)
  156. hasError = true
  157. }
  158. }
  159. if hasError {
  160. ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "check error.log"})
  161. return
  162. }
  163. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: ""})
  164. }
  165. // @tags Asterisk-MeetMe
  166. // @Summary 取消禁言
  167. // @Description 取消禁言
  168. // @Security ApiKeyAuth
  169. // @Accept json
  170. // @Produce json
  171. // @Param data body model.MeetMeVO true "参数"
  172. // @Success 200 {object} model.APIOK "请求成功"
  173. // @Router /ginapi/plugin-asterisk/meetme/unmute [post]
  174. func unMuteMeetMe(ctx *gin.Context) {
  175. var data model.MeetMeVO
  176. if err := ctx.ShouldBindJSON(&data); err != nil {
  177. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  178. return
  179. }
  180. var hasError bool
  181. for _, number := range data.UserNum {
  182. _, err := action.UnMuteMeetMe(data.Meetme, number)
  183. if err != nil {
  184. lfshook.NewLogger().Error(err)
  185. hasError = true
  186. }
  187. }
  188. if hasError {
  189. ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "check error.log"})
  190. return
  191. }
  192. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: "mute ok"})
  193. }
  194. // @tags Asterisk-MeetMe
  195. // @Summary 开启锁定
  196. // @Description 开启锁定
  197. // @Security ApiKeyAuth
  198. // @Accept json
  199. // @Produce json
  200. // @Param data body model.MeetMeCommonVO true "参数"
  201. // @Success 200 {object} model.APIOK "请求成功"
  202. // @Router /ginapi/plugin-asterisk/meetme/lock [post]
  203. func lockMeetMe(ctx *gin.Context) {
  204. var data model.MeetMeCommonVO
  205. if err := ctx.ShouldBindJSON(&data); err != nil {
  206. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  207. return
  208. }
  209. action.LockMeetMe(data.Meetme)
  210. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data})
  211. }
  212. // @tags Asterisk-MeetMe
  213. // @Summary 关闭锁定
  214. // @Description 关闭锁定
  215. // @Security ApiKeyAuth
  216. // @Accept json
  217. // @Produce json
  218. // @Param data body model.MeetMeCommonVO true "参数"
  219. // @Success 200 {object} model.APIOK "请求成功"
  220. // @Router /ginapi/plugin-asterisk/meetme/unlock [post]
  221. func unLockMeetMe(ctx *gin.Context) {
  222. var data model.MeetMeCommonVO
  223. if err := ctx.ShouldBindJSON(&data); err != nil {
  224. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  225. return
  226. }
  227. action.UnLockMeetMe(data.Meetme)
  228. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data})
  229. }
  230. // @tags Asterisk-MeetMe
  231. // @Summary 关闭会议
  232. // @Description 关闭会议
  233. // @Security ApiKeyAuth
  234. // @Accept json
  235. // @Produce json
  236. // @Param data body model.MeetMeCommonVO true "参数"
  237. // @Success 200 {object} model.APIOK "请求成功"
  238. // @Router /ginapi/plugin-asterisk/meetme/end [post]
  239. func endMeetMe(ctx *gin.Context) {
  240. var data model.MeetMeCommonVO
  241. if err := ctx.ShouldBindJSON(&data); err != nil {
  242. ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
  243. return
  244. }
  245. action.EndMeetMe(data.Meetme)
  246. ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data})
  247. }