RoomController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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.FactoryBean;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.util.List;
  13. @RestController
  14. @RequestMapping("/room")
  15. @Slf4j
  16. public class RoomController{
  17. @Autowired
  18. RoomService roomService;
  19. @Autowired
  20. MessageService messageService;
  21. @RequestMapping(value = "/join", method = RequestMethod.POST)
  22. public Object joinRoom(@RequestBody ReqUserData data) throws Exception {
  23. return new BaseResponse<>(roomService.joinRoom(data.getRoomId()));
  24. }
  25. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  26. public Object signIn(Long roomId){
  27. return new BaseResponse<>();
  28. }
  29. @RequestMapping(value = "/statusImMsg", method = RequestMethod.POST)
  30. public Object statusImMsg(ImMsg imMsg){
  31. return new BaseResponse<>();
  32. }
  33. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  34. public Object leaveRoom(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  35. //成员退出
  36. roomService.leaveRoomSuccess(roomStatusNotify.getRoomId(), roomStatusNotify.getUserId(),roomStatusNotify.getDeviceNum());
  37. return new BaseResponse<>();
  38. }
  39. @RequestMapping(value = "/queryNoJoinStu", method = RequestMethod.GET)
  40. public Object queryNoJoinStu(String roomId){
  41. return new BaseResponse<>(roomService.queryNoJoinStu(roomId));
  42. }
  43. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  44. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData) throws Exception {
  45. log.info("sendImPlayMidiMessage: {}",JSONObject.toJSON(playMidiMessageData));
  46. roomService.sendImPlayMidiMessage(playMidiMessageData);
  47. return new BaseResponse<>();
  48. }
  49. @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
  50. public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
  51. roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
  52. return new BaseResponse<>();
  53. }
  54. @ApiOperation(value = "老师通知学员下载伴奏")
  55. @RequestMapping(value = "pushDownloadMusicScoreMsg", method = RequestMethod.POST)
  56. public Object pushDownloadMusicScoreMsg(@RequestBody MusicScoreData musicScoreData) throws Exception {
  57. roomService.pushDownloadMusicScoreMsg(musicScoreData);
  58. return new BaseResponse<>();
  59. }
  60. @RequestMapping(value = "joinRoomStatusNotify", method = RequestMethod.POST)
  61. public Object joinRoomStatusNotify(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  62. log.info("joinRoomStatusNotify: {}",JSONObject.toJSON(roomStatusNotify));
  63. String roomId = roomStatusNotify.getRoomId();
  64. String userId = roomStatusNotify.getUserId();
  65. String deviceNum = roomStatusNotify.getDeviceNum();
  66. if(roomStatusNotify.isRequestStatus()){
  67. roomService.joinRoomSuccess(roomId, userId,deviceNum);
  68. }else {
  69. roomService.joinRoomFailure(roomId, userId);
  70. }
  71. return new BaseResponse<>();
  72. }
  73. @RequestMapping(value = "/statusSync")
  74. public void statusSync(@RequestBody String body) throws Exception {
  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. }
  90. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  91. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  92. throws Exception {
  93. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  94. return new BaseResponse<>(result);
  95. }
  96. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  97. public Object kickMember(@RequestBody ReqUserData data)
  98. throws Exception {
  99. boolean result = roomService.kickMember(data.getRoomId());
  100. return new BaseResponse<>(result);
  101. }
  102. //only teacher
  103. @RequestMapping(value = "/display", method = RequestMethod.POST)
  104. public Object display(@RequestBody ReqDisplayData data)
  105. throws Exception {
  106. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  107. return new BaseResponse<>(result);
  108. }
  109. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  110. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  111. throws Exception {
  112. String result = roomService.createWhiteBoard(data.getRoomId());
  113. return new BaseResponse<>(result);
  114. }
  115. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  116. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  117. throws Exception {
  118. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  119. return new BaseResponse<>(result);
  120. }
  121. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  122. public Object getWhiteBoard(@RequestParam String roomId)
  123. throws Exception {
  124. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  125. return new BaseResponse<>(whiteboards);
  126. }
  127. @ApiOperation(value = "通知学员打开,麦克风、摄像头等权限请求")
  128. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  129. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  130. throws Exception {
  131. boolean result;
  132. result = roomService.approveControlDevice(data);
  133. return new BaseResponse<>(result);
  134. }
  135. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  136. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  137. throws Exception {
  138. boolean result;
  139. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  140. return new BaseResponse<>(result);
  141. }
  142. @ApiOperation(value = "学员麦克风、摄像头等开关控制")
  143. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  144. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  145. throws Exception {
  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. }