RoomController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 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. try {
  75. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  76. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  77. String roomId = notify.getChannelId();
  78. String userId = notify.getUserId();
  79. switch (notify.getEvent()){
  80. case 11:
  81. //成员加入
  82. roomService.joinRoomSuccess(roomId, userId,null);
  83. break;
  84. case 12:
  85. //成员退出
  86. roomService.leaveRoomSuccess(roomId, userId,null);
  87. break;
  88. }
  89. }catch (Exception e){
  90. log.error(e.getLocalizedMessage());
  91. }
  92. }
  93. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  94. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  95. throws Exception {
  96. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  97. return new BaseResponse<>(result);
  98. }
  99. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  100. public Object kickMember(@RequestBody ReqUserData data)
  101. throws Exception {
  102. boolean result = roomService.kickMember(data.getRoomId());
  103. return new BaseResponse<>(result);
  104. }
  105. //only teacher
  106. @RequestMapping(value = "/display", method = RequestMethod.POST)
  107. public Object display(@RequestBody ReqDisplayData data)
  108. throws Exception {
  109. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  110. return new BaseResponse<>(result);
  111. }
  112. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  113. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  114. throws Exception {
  115. String result = roomService.createWhiteBoard(data.getRoomId());
  116. return new BaseResponse<>(result);
  117. }
  118. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  119. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  120. throws Exception {
  121. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  122. return new BaseResponse<>(result);
  123. }
  124. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  125. public Object getWhiteBoard(@RequestParam String roomId)
  126. throws Exception {
  127. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  128. return new BaseResponse<>(whiteboards);
  129. }
  130. @ApiOperation(value = "通知学员打开,麦克风、摄像头等权限请求")
  131. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  132. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  133. throws Exception {
  134. boolean result;
  135. result = roomService.approveControlDevice(data);
  136. return new BaseResponse<>(result);
  137. }
  138. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  139. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  140. throws Exception {
  141. boolean result;
  142. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  143. return new BaseResponse<>(result);
  144. }
  145. @ApiOperation(value = "学员麦克风、摄像头等开关控制")
  146. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  147. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  148. throws Exception {
  149. log.info("device_control: {}",JSONObject.toJSON(data));
  150. return new BaseResponse<>(roomService.controlDevice(data));
  151. }
  152. @ApiOperation(value = "学员伴奏下载状态回调")
  153. @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
  154. public Object adjustExamSong(@RequestBody ExamSongData examSongData) throws Exception {
  155. log.info("adjustExamSong: {}",JSONObject.toJSON(examSongData));
  156. roomService.adjustExamSong(examSongData.getRoomId(),examSongData.getStatus(),examSongData.getExamSongId());
  157. return new BaseResponse<>();
  158. }
  159. @ApiOperation(value = "学员伴奏下载状态回调")
  160. @RequestMapping(value = "adjustMusicScore", method = RequestMethod.POST)
  161. public Object adjustMusicScore(@RequestBody MusicScoreData musicScoreData) throws Exception {
  162. roomService.adjustMusicScore(musicScoreData);
  163. return new BaseResponse<>();
  164. }
  165. @ApiOperation(value = "学员麦克风、摄像头等开关批量控制")
  166. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  167. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  168. log.info("batchControl: {}",JSONObject.toJSON(data));
  169. return new BaseResponse<>(roomService.batchControlDevice(data));
  170. }
  171. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  172. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  173. throws Exception {
  174. log.info("syncDeviceState: {}",JSONObject.toJSON(data));
  175. return new BaseResponse<>(roomService.syncDeviceState(data));
  176. }
  177. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  178. public Object turnPage(@RequestBody ReqWhiteboardData data)
  179. throws Exception {
  180. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  181. return new BaseResponse<>(result);
  182. }
  183. @RequestMapping(value = "/members", method = RequestMethod.GET)
  184. public Object getMembers(@RequestParam String roomId)
  185. throws Exception {
  186. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  187. return new BaseResponse<>(whiteboards);
  188. }
  189. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  190. public Object apply(@RequestBody ReqSpeechData data)
  191. throws Exception {
  192. Boolean result = roomService.applySpeech(data.getRoomId());
  193. return new BaseResponse<>(result);
  194. }
  195. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  196. public Object approval(@RequestBody ReqSpeechData data)
  197. throws Exception {
  198. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  199. return new BaseResponse<>(result);
  200. }
  201. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  202. public Object reject(@RequestBody ReqSpeechData data)
  203. throws Exception {
  204. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  205. return new BaseResponse<>(result);
  206. }
  207. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  208. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  209. throws Exception {
  210. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  211. return new BaseResponse<>(result);
  212. }
  213. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  214. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  215. throws Exception {
  216. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  217. return new BaseResponse<>(result);
  218. }
  219. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  220. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  221. throws Exception {
  222. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  223. return new BaseResponse<>(result);
  224. }
  225. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  226. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  227. throws Exception {
  228. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  229. return new BaseResponse<>(result);
  230. }
  231. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  232. public Object changeRole(@RequestBody ReqChangeRole data)
  233. throws Exception {
  234. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  235. return new BaseResponse<>(result);
  236. }
  237. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  238. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  239. @RequestParam(value = "timestamp", required = false) String timestamp,
  240. @RequestParam(value = "nonce", required = false) String nonce,
  241. @RequestParam(value = "signature", required = false) String signature)
  242. throws Exception {
  243. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  244. return new BaseResponse<>(result);
  245. }
  246. }