RoomController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.data.redis.core.RedisTemplate;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.util.List;
  14. @RestController
  15. @RequestMapping("/room")
  16. @Slf4j
  17. public class RoomController{
  18. @Autowired
  19. RoomService roomService;
  20. @Autowired
  21. MessageService messageService;
  22. @Autowired
  23. private RedisTemplate<String,String> redisTemplate;
  24. @RequestMapping(value = "/join", method = RequestMethod.POST)
  25. public Object joinRoom(@RequestBody ReqUserData data) throws Exception {
  26. return new BaseResponse<>(roomService.joinRoom(data.getRoomId()));
  27. }
  28. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  29. public Object signIn(Long roomId){
  30. return new BaseResponse<>();
  31. }
  32. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  33. public Object leaveRoom(@RequestBody ReqUserData data){
  34. return new BaseResponse<>();
  35. }
  36. @RequestMapping(value = "/queryNoJoinStu", method = RequestMethod.GET)
  37. public Object queryNoJoinStu(String roomId){
  38. return new BaseResponse<>(roomService.queryNoJoinStu(roomId));
  39. }
  40. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  41. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData) throws Exception {
  42. roomService.sendImPlayMidiMessage(playMidiMessageData);
  43. return new BaseResponse<>();
  44. }
  45. @RequestMapping(value = "pushDownloadExamSongMsg", method = RequestMethod.POST)
  46. public Object pushDownloadExamSongMsg(@RequestBody ExamSongData examSongData) throws Exception {
  47. roomService.pushDownloadExamSongMsg(examSongData.getRoomId(),examSongData.getExamSongId());
  48. return new BaseResponse<>();
  49. }
  50. @RequestMapping(value = "joinRoomStatusNotify", method = RequestMethod.POST)
  51. public Object joinRoomStatusNotify(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
  52. log.info("joinRoomStatusNotify: {}",JSONObject.toJSON(roomStatusNotify));
  53. String roomId = roomStatusNotify.getRoomId();
  54. String userId = roomStatusNotify.getUserId();
  55. if(roomStatusNotify.isRequestStatus()){
  56. roomService.joinRoomSuccess(roomId, userId);
  57. }else {
  58. roomService.joinRoomFailure(roomId, userId);
  59. }
  60. return new BaseResponse<>();
  61. }
  62. @RequestMapping(value = "/statusSync")
  63. public void statusSync(@RequestBody String body) throws Exception {
  64. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  65. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  66. String roomId = notify.getChannelId();
  67. String userId = notify.getUserId();
  68. switch (notify.getEvent()){
  69. case 11:
  70. //成员加入
  71. roomService.joinRoomSuccess(roomId, userId);
  72. break;
  73. case 12:
  74. //成员退出
  75. roomService.leaveRoomSuccess(roomId, userId);
  76. break;
  77. }
  78. }
  79. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  80. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  81. throws Exception {
  82. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  83. return new BaseResponse<>(result);
  84. }
  85. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  86. public Object kickMember(@RequestBody ReqUserData data)
  87. throws Exception {
  88. boolean result = roomService.kickMember(data.getRoomId());
  89. return new BaseResponse<>(result);
  90. }
  91. //only teacher
  92. @RequestMapping(value = "/display", method = RequestMethod.POST)
  93. public Object display(@RequestBody ReqDisplayData data)
  94. throws Exception {
  95. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  96. return new BaseResponse<>(result);
  97. }
  98. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  99. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  100. throws Exception {
  101. String result = roomService.createWhiteBoard(data.getRoomId());
  102. return new BaseResponse<>(result);
  103. }
  104. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  105. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  106. throws Exception {
  107. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  108. return new BaseResponse<>(result);
  109. }
  110. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  111. public Object getWhiteBoard(@RequestParam String roomId)
  112. throws Exception {
  113. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  114. return new BaseResponse<>(whiteboards);
  115. }
  116. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  117. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  118. throws Exception {
  119. boolean result;
  120. result = roomService.approveControlDevice(data.getRoomId(), data.getTicket());
  121. return new BaseResponse<>(result);
  122. }
  123. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  124. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  125. throws Exception {
  126. boolean result;
  127. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  128. return new BaseResponse<>(result);
  129. }
  130. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  131. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  132. throws Exception {
  133. boolean result;
  134. if (data.getCameraOn() != null) {
  135. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Camera, data.getCameraOn());
  136. } else if (data.getMicrophoneOn() != null) {
  137. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  138. } else if (data.getMusicModeOn() != null) {
  139. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  140. } else if (data.getHandUpOn() != null) {
  141. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  142. }else if (data.getPlaySongOn() != null) {
  143. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.PlaySong, data.getPlaySongOn());
  144. } else {
  145. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  146. }
  147. return new BaseResponse<>(result);
  148. }
  149. @RequestMapping(value = "adjustExamSong", method = RequestMethod.POST)
  150. public Object adjustExamSong(@RequestBody ExamSongData examSongData) throws Exception {
  151. roomService.adjustExamSong(examSongData.getRoomId(),examSongData.getStatus(),examSongData.getExamSongId());
  152. return new BaseResponse<>();
  153. }
  154. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  155. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  156. log.info("batchControl: {}",JSONObject.toJSON(data));
  157. boolean result = roomService.batchControlDevice(data);
  158. return new BaseResponse<>(result);
  159. }
  160. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  161. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  162. throws Exception {
  163. boolean result;
  164. if (data.getCameraOn() != null) {
  165. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  166. } else if (data.getMicrophoneOn() != null) {
  167. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  168. } else if (data.getMusicModeOn() != null) {
  169. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  170. } else if (data.getHandUpOn() != null) {
  171. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  172. } else {
  173. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  174. }
  175. return new BaseResponse<>(result);
  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. }