RoomController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package com.ym.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ym.common.ApiException;
  4. import com.ym.common.BaseResponse;
  5. import com.ym.common.ErrorEnum;
  6. import com.ym.pojo.*;
  7. import com.ym.service.MessageService;
  8. import com.ym.service.RoomService;
  9. import lombok.extern.slf4j.Slf4j;
  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 = "/leave", method = RequestMethod.POST)
  30. public Object leaveRoom(@RequestBody ReqUserData data){
  31. return new BaseResponse<>();
  32. }
  33. @RequestMapping(value = "/queryNoJoinStu", method = RequestMethod.GET)
  34. public Object queryNoJoinStu(String roomId){
  35. return new BaseResponse<>(roomService.queryNoJoinStu(roomId));
  36. }
  37. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  38. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData) throws Exception {
  39. roomService.sendImPlayMidiMessage(playMidiMessageData);
  40. return new BaseResponse<>();
  41. }
  42. @RequestMapping(value = "/statusSync")
  43. public void statusSync(@RequestBody String body) throws Exception {
  44. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  45. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  46. String roomId = notify.getChannelId();
  47. String userId = notify.getUserId();
  48. switch (notify.getEvent()){
  49. case 11:
  50. //成员加入
  51. roomService.joinRoomSuccess(roomId, userId);
  52. break;
  53. case 12:
  54. //成员退出
  55. roomService.leaveRoomSuccess(roomId, userId);
  56. break;
  57. }
  58. }
  59. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  60. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  61. throws Exception {
  62. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  63. return new BaseResponse<>(result);
  64. }
  65. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  66. public Object kickMember(@RequestBody ReqUserData data)
  67. throws Exception {
  68. boolean result = roomService.kickMember(data.getRoomId());
  69. return new BaseResponse<>(result);
  70. }
  71. //only teacher
  72. @RequestMapping(value = "/display", method = RequestMethod.POST)
  73. public Object display(@RequestBody ReqDisplayData data)
  74. throws Exception {
  75. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  76. return new BaseResponse<>(result);
  77. }
  78. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  79. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  80. throws Exception {
  81. String result = roomService.createWhiteBoard(data.getRoomId());
  82. return new BaseResponse<>(result);
  83. }
  84. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  85. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  86. throws Exception {
  87. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  88. return new BaseResponse<>(result);
  89. }
  90. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  91. public Object getWhiteBoard(@RequestParam String roomId)
  92. throws Exception {
  93. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  94. return new BaseResponse<>(whiteboards);
  95. }
  96. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  97. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  98. throws Exception {
  99. boolean result;
  100. result = roomService.approveControlDevice(data.getRoomId(), data.getTicket());
  101. return new BaseResponse<>(result);
  102. }
  103. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  104. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  105. throws Exception {
  106. boolean result;
  107. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  108. return new BaseResponse<>(result);
  109. }
  110. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  111. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  112. throws Exception {
  113. boolean result;
  114. if (data.getCameraOn() != null) {
  115. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Camera, data.getCameraOn());
  116. } else if (data.getMicrophoneOn() != null) {
  117. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  118. } else if (data.getMusicModeOn() != null) {
  119. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  120. } else if (data.getHandUpOn() != null) {
  121. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  122. } else {
  123. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  124. }
  125. return new BaseResponse<>(result);
  126. }
  127. @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
  128. public Object pushDownloadExamSongMsg(Long roomId,Integer examSongId) throws Exception {
  129. roomService.pushDownloadExamSongMsg(roomId,examSongId);
  130. return new BaseResponse<>();
  131. }
  132. @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
  133. public Object adjustExamSong(Long roomId,Integer status,Integer examSongId) throws Exception {
  134. roomService.adjustExamSong(roomId,status,examSongId);
  135. return new BaseResponse<>();
  136. }
  137. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  138. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  139. log.info("batchControl: {}",JSONObject.toJSON(data));
  140. boolean result = roomService.batchControlDevice(data);
  141. return new BaseResponse<>(result);
  142. }
  143. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  144. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  145. throws Exception {
  146. boolean result;
  147. if (data.getCameraOn() != null) {
  148. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  149. } else if (data.getMicrophoneOn() != null) {
  150. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  151. } else if (data.getMusicModeOn() != null) {
  152. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  153. } else if (data.getHandUpOn() != null) {
  154. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  155. } else {
  156. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  157. }
  158. return new BaseResponse<>(result);
  159. }
  160. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  161. public Object turnPage(@RequestBody ReqWhiteboardData data)
  162. throws Exception {
  163. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  164. return new BaseResponse<>(result);
  165. }
  166. @RequestMapping(value = "/members", method = RequestMethod.GET)
  167. public Object getMembers(@RequestParam String roomId)
  168. throws Exception {
  169. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  170. return new BaseResponse<>(whiteboards);
  171. }
  172. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  173. public Object apply(@RequestBody ReqSpeechData data)
  174. throws Exception {
  175. Boolean result = roomService.applySpeech(data.getRoomId());
  176. return new BaseResponse<>(result);
  177. }
  178. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  179. public Object approval(@RequestBody ReqSpeechData data)
  180. throws Exception {
  181. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  182. return new BaseResponse<>(result);
  183. }
  184. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  185. public Object reject(@RequestBody ReqSpeechData data)
  186. throws Exception {
  187. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  188. return new BaseResponse<>(result);
  189. }
  190. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  191. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  192. throws Exception {
  193. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  194. return new BaseResponse<>(result);
  195. }
  196. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  197. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  198. throws Exception {
  199. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  200. return new BaseResponse<>(result);
  201. }
  202. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  203. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  204. throws Exception {
  205. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  206. return new BaseResponse<>(result);
  207. }
  208. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  209. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  210. throws Exception {
  211. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  212. return new BaseResponse<>(result);
  213. }
  214. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  215. public Object changeRole(@RequestBody ReqChangeRole data)
  216. throws Exception {
  217. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  218. return new BaseResponse<>(result);
  219. }
  220. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  221. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  222. @RequestParam(value = "timestamp", required = false) String timestamp,
  223. @RequestParam(value = "nonce", required = false) String nonce,
  224. @RequestParam(value = "signature", required = false) String signature)
  225. throws Exception {
  226. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  227. return new BaseResponse<>(result);
  228. }
  229. }