package asterisk import ( "errors" "fmt" "net/http" "pbx-api-gin/api/model" "pbx-api-gin/internal/app/ami/action" amiModel "pbx-api-gin/internal/app/ami/model" "pbx-api-gin/internal/app/mysql" "pbx-api-gin/pkg/lfshook" "strings" "github.com/gin-gonic/gin" "github.com/mitchellh/mapstructure" ) // @tags Asterisk-MeetMe // @Summary 查看所有会议室 // @Description 会议室列表 // @Security ApiKeyAuth // @Accept json // @Produce json // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/list [get] func listMeetMe(ctx *gin.Context) { amiRooms, _ := action.ListRoomMeetMe(make(map[string]string)) var meets []model.MeetMe if err := mysql.DBOrmInstance.Find(&meets); err != nil { lfshook.NewLogger().Errorf("db index error %+v", err) ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "db error"}) return } numRoomMap := make(map[string]*amiModel.MeetMeListRooms) for _, room := range amiRooms { numRoomMap[room.Conference] = room } rooms := make([]*model.MeetMeRoom, 0) for _, meet := range meets { room := &model.MeetMeRoom{ MeetMe: meet, } if data, has := numRoomMap[meet.Conference]; has { mapstructure.Decode(data, room) } rooms = append(rooms, room) } ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: rooms}) } // @tags Asterisk-MeetMe // @Summary 查看指定会议室 // @Description 会议室信息 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param conference query string true "会议室号" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/room [get] func room(ctx *gin.Context) { conference := ctx.Query("conference") if conference == "" { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: errors.New("conference is empty").Error()}) return } items, err := action.ListMeetMe(conference) if err != nil { lfshook.NewLogger().Warn(err) } // 查询 room 信息 var roomInfo *amiModel.MeetMeListRooms amiRooms, _ := action.ListRoomMeetMe(make(map[string]string)) for _, room := range amiRooms { if room.Conference == conference { roomInfo = room break } } meet := model.MeetMe{Conference: conference} if _, err := mysql.DBOrmInstance.Get(&meet); err != nil { lfshook.NewLogger().Errorf("db get error %+v", err) ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "db error"}) return } room := &model.MeetMeRoom{ MeetMe: meet, } mapstructure.Decode(roomInfo, room) ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: gin.H{"items": items, "room": room}}) } // @tags Asterisk-MeetMe // @Summary 邀请会议 // @Description 邀请会议 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeInviteVO true "加入会议参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/invite [post] func inviteMeetMe(ctx *gin.Context) { var data model.MeetMeInviteVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } // 根据参数确定主叫, 再考虑用户登录的分机信息 myExtension := "" if myExtension == "" { ID, _ := ctx.Get("ID") myExtension = "==================" if myExtension == "" { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: fmt.Sprintf("not found user extension by ID %d", ID)}) return } } dialplan := "default" action.IviteMeetMe(data.Meetme, strings.Join(data.Extensions, ","), dialplan, myExtension) ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data}) } // @tags Asterisk-MeetMe // @Summary 踢出会议 // @Description 踢出会议 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/kick [post] func kickMeetMe(ctx *gin.Context) { var data model.MeetMeVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } err := action.KickMeetMe(data.Meetme, strings.Join(data.UserNum, ",")) if err != nil { ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: err.Error()}) return } ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data}) } // @tags Asterisk-MeetMe // @Summary 禁言 // @Description 禁言 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/mute [post] func muteMeetMe(ctx *gin.Context) { var data model.MeetMeVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } var hasError bool for _, number := range data.UserNum { _, err := action.MuteMeetMe(data.Meetme, number) if err != nil { lfshook.NewLogger().Error(err) hasError = true } } if hasError { ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "check error.log"}) return } ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: ""}) } // @tags Asterisk-MeetMe // @Summary 取消禁言 // @Description 取消禁言 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/unmute [post] func unMuteMeetMe(ctx *gin.Context) { var data model.MeetMeVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } var hasError bool for _, number := range data.UserNum { _, err := action.UnMuteMeetMe(data.Meetme, number) if err != nil { lfshook.NewLogger().Error(err) hasError = true } } if hasError { ctx.JSON(http.StatusInternalServerError, model.APIError{ErrorMessage: "check error.log"}) return } ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: "mute ok"}) } // @tags Asterisk-MeetMe // @Summary 开启锁定 // @Description 开启锁定 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeCommonVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/lock [post] func lockMeetMe(ctx *gin.Context) { var data model.MeetMeCommonVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } action.LockMeetMe(data.Meetme) ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data}) } // @tags Asterisk-MeetMe // @Summary 关闭锁定 // @Description 关闭锁定 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeCommonVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/unlock [post] func unLockMeetMe(ctx *gin.Context) { var data model.MeetMeCommonVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } action.UnLockMeetMe(data.Meetme) ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data}) } // @tags Asterisk-MeetMe // @Summary 关闭会议 // @Description 关闭会议 // @Security ApiKeyAuth // @Accept json // @Produce json // @Param data body model.MeetMeCommonVO true "参数" // @Success 200 {object} model.APIOK "请求成功" // @Router /ginapi/plugin-asterisk/meetme/end [post] func endMeetMe(ctx *gin.Context) { var data model.MeetMeCommonVO if err := ctx.ShouldBindJSON(&data); err != nil { ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()}) return } action.EndMeetMe(data.Meetme) ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: data}) }