RoomController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package com.ym.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ym.common.BaseResponse;
  4. import com.ym.pojo.*;
  5. import com.ym.service.MessageService;
  6. import com.ym.service.RoomService;
  7. import io.swagger.annotations.ApiOperation;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. @RestController
  13. @RequestMapping("/room")
  14. @Slf4j
  15. public class RoomController{
  16. @Autowired
  17. RoomService roomService;
  18. @Autowired
  19. MessageService messageService;
  20. @RequestMapping(value = "/join", method = RequestMethod.POST)
  21. public BaseResponse joinRoom(@RequestBody ReqUserData data) throws Exception {
  22. return new BaseResponse(roomService.joinRoom(data.getRoomId()));
  23. }
  24. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  25. public Object signIn(Long roomId){
  26. return new BaseResponse<>();
  27. }
  28. @RequestMapping(value = "/statusImMsg", method = RequestMethod.POST)
  29. public Object statusImMsg(ImMsg imMsg){
  30. return new BaseResponse<>();
  31. }
  32. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  33. public Object leaveRoom(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  34. //成员退出
  35. roomService.leaveRoomSuccess(roomStatusNotify.getRoomId(), roomStatusNotify.getUserId(),roomStatusNotify.getDeviceNum());
  36. return new BaseResponse<>();
  37. }
  38. @RequestMapping(value = "/queryNoJoinStu", method = RequestMethod.GET)
  39. public Object queryNoJoinStu(String roomId){
  40. return new BaseResponse<>(roomService.queryNoJoinStu(roomId));
  41. }
  42. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  43. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData) throws Exception {
  44. log.info("sendImPlayMidiMessage: {}",JSONObject.toJSON(playMidiMessageData));
  45. roomService.sendImPlayMidiMessage(playMidiMessageData);
  46. return new BaseResponse<>();
  47. }
  48. @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
  49. public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
  50. roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
  51. return new BaseResponse<>();
  52. }
  53. @ApiOperation(value = "老师通知学员下载伴奏")
  54. @RequestMapping(value = "pushDownloadMusicScoreMsg", method = RequestMethod.POST)
  55. public Object pushDownloadMusicScoreMsg(@RequestBody MusicScoreData musicScoreData) throws Exception {
  56. roomService.pushDownloadMusicScoreMsg(musicScoreData);
  57. return new BaseResponse<>();
  58. }
  59. @RequestMapping(value = "joinRoomStatusNotify", method = RequestMethod.POST)
  60. public Object joinRoomStatusNotify(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  61. log.info("joinRoomStatusNotify: {}",JSONObject.toJSON(roomStatusNotify));
  62. String roomId = roomStatusNotify.getRoomId();
  63. String userId = roomStatusNotify.getUserId();
  64. String deviceNum = roomStatusNotify.getDeviceNum();
  65. if(roomStatusNotify.isRequestStatus()){
  66. roomService.joinRoomSuccess(roomId, userId,deviceNum);
  67. }else {
  68. roomService.joinRoomFailure(roomId, userId);
  69. }
  70. return new BaseResponse<>();
  71. }
  72. @RequestMapping(value = "/statusSync")
  73. public void statusSync(@RequestBody String body) throws Exception {
  74. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  75. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  76. String roomId = notify.getChannelId();
  77. String userId = notify.getUserId();
  78. switch (notify.getEvent()){
  79. case 11:
  80. //成员加入
  81. roomService.joinRoomSuccess(roomId, userId,null);
  82. break;
  83. case 12:
  84. //成员退出
  85. roomService.leaveRoomSuccess(roomId, userId,null);
  86. break;
  87. }
  88. }
  89. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  90. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  91. throws Exception {
  92. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  93. return new BaseResponse<>(result);
  94. }
  95. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  96. public Object kickMember(@RequestBody ReqUserData data)
  97. throws Exception {
  98. boolean result = roomService.kickMember(data.getRoomId());
  99. return new BaseResponse<>(result);
  100. }
  101. //only teacher
  102. @RequestMapping(value = "/display", method = RequestMethod.POST)
  103. public Object display(@RequestBody ReqDisplayData data)
  104. throws Exception {
  105. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  106. return new BaseResponse<>(result);
  107. }
  108. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  109. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  110. throws Exception {
  111. String result = roomService.createWhiteBoard(data.getRoomId());
  112. return new BaseResponse<>(result);
  113. }
  114. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  115. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  116. throws Exception {
  117. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  118. return new BaseResponse<>(result);
  119. }
  120. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  121. public Object getWhiteBoard(@RequestParam String roomId)
  122. throws Exception {
  123. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  124. return new BaseResponse<>(whiteboards);
  125. }
  126. @ApiOperation(value = "通知学员打开,麦克风、摄像头等权限请求")
  127. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  128. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  129. throws Exception {
  130. boolean result;
  131. result = roomService.approveControlDevice(data);
  132. return new BaseResponse<>(result);
  133. }
  134. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  135. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  136. throws Exception {
  137. boolean result;
  138. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  139. return new BaseResponse<>(result);
  140. }
  141. @ApiOperation(value = "学员麦克风、摄像头等开关控制")
  142. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  143. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  144. throws Exception {
  145. log.info("device_control: {}",JSONObject.toJSON(data));
  146. return new BaseResponse<>(roomService.controlDevice(data));
  147. }
  148. @ApiOperation(value = "学员伴奏下载状态回调")
  149. @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
  150. public Object adjustExamSong(@RequestBody ExamSongData examSongData) throws Exception {
  151. log.info("adjustExamSong: {}",JSONObject.toJSON(examSongData));
  152. roomService.adjustExamSong(examSongData.getRoomId(),examSongData.getStatus(),examSongData.getExamSongId());
  153. return new BaseResponse<>();
  154. }
  155. @ApiOperation(value = "学员伴奏下载状态回调")
  156. @RequestMapping(value = "adjustMusicScore", method = RequestMethod.POST)
  157. public Object adjustMusicScore(@RequestBody MusicScoreData musicScoreData) throws Exception {
  158. roomService.adjustMusicScore(musicScoreData);
  159. return new BaseResponse<>();
  160. }
  161. @ApiOperation(value = "学员麦克风、摄像头等开关批量控制")
  162. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  163. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  164. log.info("batchControl: {}",JSONObject.toJSON(data));
  165. return new BaseResponse<>(roomService.batchControlDevice(data));
  166. }
  167. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  168. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  169. throws Exception {
  170. log.info("syncDeviceState: {}",JSONObject.toJSON(data));
  171. return new BaseResponse<>(roomService.syncDeviceState(data));
  172. }
  173. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  174. public Object turnPage(@RequestBody ReqWhiteboardData data)
  175. throws Exception {
  176. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  177. return new BaseResponse<>(result);
  178. }
  179. @RequestMapping(value = "/members", method = RequestMethod.GET)
  180. public Object getMembers(@RequestParam String roomId)
  181. throws Exception {
  182. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  183. return new BaseResponse<>(whiteboards);
  184. }
  185. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  186. public Object apply(@RequestBody ReqSpeechData data)
  187. throws Exception {
  188. Boolean result = roomService.applySpeech(data.getRoomId());
  189. return new BaseResponse<>(result);
  190. }
  191. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  192. public Object approval(@RequestBody ReqSpeechData data)
  193. throws Exception {
  194. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  195. return new BaseResponse<>(result);
  196. }
  197. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  198. public Object reject(@RequestBody ReqSpeechData data)
  199. throws Exception {
  200. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  201. return new BaseResponse<>(result);
  202. }
  203. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  204. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  205. throws Exception {
  206. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  207. return new BaseResponse<>(result);
  208. }
  209. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  210. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  211. throws Exception {
  212. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  213. return new BaseResponse<>(result);
  214. }
  215. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  216. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  217. throws Exception {
  218. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  219. return new BaseResponse<>(result);
  220. }
  221. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  222. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  223. throws Exception {
  224. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  225. return new BaseResponse<>(result);
  226. }
  227. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  228. public Object changeRole(@RequestBody ReqChangeRole data)
  229. throws Exception {
  230. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  231. return new BaseResponse<>(result);
  232. }
  233. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  234. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  235. @RequestParam(value = "timestamp", required = false) String timestamp,
  236. @RequestParam(value = "nonce", required = false) String nonce,
  237. @RequestParam(value = "signature", required = false) String signature)
  238. throws Exception {
  239. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  240. return new BaseResponse<>(result);
  241. }
  242. }