RoomController.java 12 KB

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