RoomController.java 13 KB

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