RoomController.java 12 KB

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