RoomController.java 13 KB

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