meetme.go 7.8 KB

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