RoomController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.RoomService;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. /**
  13. * Created by weiqinxiao on 2019/2/25.
  14. */
  15. @RestController
  16. @RequestMapping("/room")
  17. @Slf4j
  18. public class RoomController{
  19. @Autowired
  20. RoomService roomService;
  21. @RequestMapping(value = "/join", method = RequestMethod.POST)
  22. public Object joinRoom(@RequestBody ReqUserData data)
  23. throws ApiException, Exception {
  24. RoomResult roomResult = roomService.joinRoom(data.getUserName(), data.getRoomId(), data.isAudience(), data.isDisableCamera(),data.isMusicMode());
  25. return new BaseResponse<>(roomResult);
  26. }
  27. @RequestMapping(value = "/signIn", method = RequestMethod.POST)
  28. public Object signIn(Long roomId){
  29. roomService.signIn(roomId);
  30. return new BaseResponse<>();
  31. }
  32. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  33. public Object leaveRoom(@RequestBody ReqUserData data)
  34. throws ApiException, Exception {
  35. boolean result = roomService.leaveRoom(data.getRoomId());
  36. return new BaseResponse<>(result);
  37. }
  38. @RequestMapping(value = "/sendImPlayMidiMessage", method = RequestMethod.POST)
  39. public Object sendImPlayMidiMessage(@RequestBody PlayMidiMessageData playMidiMessageData){
  40. roomService.sendImPlayMidiMessage(playMidiMessageData);
  41. return new BaseResponse<>();
  42. }
  43. @RequestMapping(value = "/statusSync")
  44. public Object statusSync(@RequestBody String body) throws Exception {
  45. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  46. log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
  47. boolean result = false;
  48. if(notify.getEvent() == 12 || notify.getEvent() == 3){
  49. result = roomService.statusSync(notify.getChannelId(), notify.getUserId());
  50. }else if(notify.getEvent() == 11){
  51. // Teacher teacher = teacherDao.get(Integer.parseInt(notify.getUserId()));
  52. // Long roomId = Long.parseLong(notify.getChannelId().substring(1));
  53. // CourseSchedule courseSchedule = courseScheduleDao.get(roomId);
  54. // if(teacher != null && teacher.getId().equals(courseSchedule.getActualTeacherId())){
  55. // roomService.joinRoom(teacher.getRealName(),roomId.toString(),false,false);
  56. // }else {
  57. // roomService.joinRoom(teacher.getUsername(),roomId.toString(),false,false);
  58. // }
  59. }
  60. return new BaseResponse<>(result);
  61. }
  62. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  63. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  64. throws ApiException, Exception {
  65. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  66. return new BaseResponse<>(result);
  67. }
  68. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  69. public Object kickMember(@RequestBody ReqUserData data)
  70. throws ApiException, Exception {
  71. boolean result = roomService.kickMember(data.getRoomId());
  72. return new BaseResponse<>(result);
  73. }
  74. //only teacher
  75. @RequestMapping(value = "/display", method = RequestMethod.POST)
  76. public Object display(@RequestBody ReqDisplayData data)
  77. throws ApiException, Exception {
  78. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri());
  79. return new BaseResponse<>(result);
  80. }
  81. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  82. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  83. throws ApiException, Exception {
  84. String result = roomService.createWhiteBoard(data.getRoomId());
  85. return new BaseResponse<>(result);
  86. }
  87. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  88. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  89. throws ApiException, Exception {
  90. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  91. return new BaseResponse<>(result);
  92. }
  93. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  94. public Object getWhiteBoard(@RequestParam String roomId)
  95. throws ApiException, Exception {
  96. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  97. return new BaseResponse<>(whiteboards);
  98. }
  99. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  100. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  101. throws ApiException, Exception {
  102. boolean result;
  103. result = roomService.approveControlDevice(data.getRoomId(), data.getTicket());
  104. return new BaseResponse<>(result);
  105. }
  106. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  107. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  108. throws ApiException, Exception {
  109. boolean result;
  110. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  111. return new BaseResponse<>(result);
  112. }
  113. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  114. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  115. throws ApiException, Exception {
  116. boolean result;
  117. if (data.getCameraOn() != null) {
  118. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Camera, data.getCameraOn());
  119. } else if (data.getMicrophoneOn() != null) {
  120. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  121. } else if (data.getMusicModeOn() != null) {
  122. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  123. } else {
  124. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  125. }
  126. return new BaseResponse<>(result);
  127. }
  128. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  129. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  130. log.info("batchControl: {}",JSONObject.toJSON(data));
  131. boolean result = roomService.batchControlDevice(data);
  132. return new BaseResponse<>(result);
  133. }
  134. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  135. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  136. throws ApiException, Exception {
  137. boolean result;
  138. if (data.getCameraOn() != null) {
  139. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  140. } else if (data.getMicrophoneOn() != null) {
  141. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  142. } else if (data.getMusicModeOn() != null) {
  143. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  144. } else {
  145. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  146. }
  147. return new BaseResponse<>(result);
  148. }
  149. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  150. public Object turnPage(@RequestBody ReqWhiteboardData data)
  151. throws ApiException, Exception {
  152. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  153. return new BaseResponse<>(result);
  154. }
  155. @RequestMapping(value = "/members", method = RequestMethod.GET)
  156. public Object getMembers(@RequestParam String roomId)
  157. throws ApiException, Exception {
  158. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  159. return new BaseResponse<>(whiteboards);
  160. }
  161. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  162. public Object apply(@RequestBody ReqSpeechData data)
  163. throws ApiException, Exception {
  164. Boolean result = roomService.applySpeech(data.getRoomId());
  165. return new BaseResponse<>(result);
  166. }
  167. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  168. public Object approval(@RequestBody ReqSpeechData data)
  169. throws ApiException, Exception {
  170. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  171. return new BaseResponse<>(result);
  172. }
  173. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  174. public Object reject(@RequestBody ReqSpeechData data)
  175. throws ApiException, Exception {
  176. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  177. return new BaseResponse<>(result);
  178. }
  179. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  180. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  181. throws ApiException, Exception {
  182. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  183. return new BaseResponse<>(result);
  184. }
  185. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  186. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  187. throws ApiException, Exception {
  188. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  189. return new BaseResponse<>(result);
  190. }
  191. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  192. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  193. throws ApiException, Exception {
  194. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  195. return new BaseResponse<>(result);
  196. }
  197. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  198. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  199. throws ApiException, Exception {
  200. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  201. return new BaseResponse<>(result);
  202. }
  203. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  204. public Object changeRole(@RequestBody ReqChangeRole data)
  205. throws ApiException, Exception {
  206. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  207. return new BaseResponse<>(result);
  208. }
  209. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  210. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  211. @RequestParam(value = "timestamp", required = false) String timestamp,
  212. @RequestParam(value = "nonce", required = false) String nonce,
  213. @RequestParam(value = "signature", required = false) String signature)
  214. throws ApiException, Exception {
  215. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  216. return new BaseResponse<>(result);
  217. }
  218. }