RoomController.java 12 KB

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