RoomController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 = "/statusImMsg")
  73. public void statusImMsg(@RequestBody String body) throws Exception {
  74. System.out.println("");
  75. }
  76. @RequestMapping(value = "/downgrade", method = RequestMethod.POST)
  77. public Object downRole(@RequestBody ReqChangeUserRoleData data)
  78. throws ApiException, Exception {
  79. boolean result = roomService.downgrade(data.getRoomId(), data.getUsers());
  80. return new BaseResponse<>(result);
  81. }
  82. @RequestMapping(value = "/kick", method = RequestMethod.POST)
  83. public Object kickMember(@RequestBody ReqUserData data)
  84. throws ApiException, Exception {
  85. boolean result = roomService.kickMember(data.getRoomId());
  86. return new BaseResponse<>(result);
  87. }
  88. //only teacher
  89. @RequestMapping(value = "/display", method = RequestMethod.POST)
  90. public Object display(@RequestBody ReqDisplayData data)
  91. throws ApiException, Exception {
  92. boolean result = roomService.display(data.getRoomId(), data.getType(), data.getUri(),data.getUserId());
  93. return new BaseResponse<>(result);
  94. }
  95. @RequestMapping(value = "/whiteboard/create", method = RequestMethod.POST)
  96. public Object createWhiteBoard(@RequestBody ReqWhiteboardData data)
  97. throws ApiException, Exception {
  98. String result = roomService.createWhiteBoard(data.getRoomId());
  99. return new BaseResponse<>(result);
  100. }
  101. @RequestMapping(value = "/whiteboard/delete", method = RequestMethod.POST)
  102. public Object destroyWhiteBoard(@RequestBody ReqWhiteboardData data)
  103. throws ApiException, Exception {
  104. boolean result = roomService.deleteWhiteboard(data.getRoomId(), data.getWhiteboardId());
  105. return new BaseResponse<>(result);
  106. }
  107. @RequestMapping(value = "/whiteboard/list", method = RequestMethod.GET)
  108. public Object getWhiteBoard(@RequestParam String roomId)
  109. throws ApiException, Exception {
  110. List<RoomResult.WhiteboardResult> whiteboards = roomService.getWhiteboard(roomId);
  111. return new BaseResponse<>(whiteboards);
  112. }
  113. @RequestMapping(value = "/device/approve", method = RequestMethod.POST)
  114. public Object approveControlDevice(@RequestBody ReqDeviceControlData data)
  115. throws ApiException, Exception {
  116. boolean result;
  117. result = roomService.approveControlDevice(data.getRoomId(), data.getTicket());
  118. return new BaseResponse<>(result);
  119. }
  120. @RequestMapping(value = "/device/reject", method = RequestMethod.POST)
  121. public Object rejectControlDevice(@RequestBody ReqDeviceControlData data)
  122. throws ApiException, Exception {
  123. boolean result;
  124. result = roomService.rejectControlDevice(data.getRoomId(), data.getTicket());
  125. return new BaseResponse<>(result);
  126. }
  127. @RequestMapping(value = "/device/control", method = RequestMethod.POST)
  128. public Object controlDevice(@RequestBody ReqDeviceControlData data)
  129. throws ApiException, Exception {
  130. boolean result;
  131. if (data.getCameraOn() != null) {
  132. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Camera, data.getCameraOn());
  133. } else if (data.getMicrophoneOn() != null) {
  134. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  135. } else if (data.getMusicModeOn() != null) {
  136. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  137. } else if (data.getHandUpOn() != null) {
  138. result = roomService.controlDevice(data.getRoomId(), data.getUserId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  139. } else {
  140. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  141. }
  142. return new BaseResponse<>(result);
  143. }
  144. @RequestMapping(value = "/device/batchControl", method = RequestMethod.POST)
  145. public Object batchControlDevice(@RequestBody ReqDeviceControlData data)throws Exception {
  146. log.info("batchControl: {}",JSONObject.toJSON(data));
  147. boolean result = roomService.batchControlDevice(data);
  148. return new BaseResponse<>(result);
  149. }
  150. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  151. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  152. throws ApiException, Exception {
  153. boolean result;
  154. if (data.getCameraOn() != null) {
  155. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  156. } else if (data.getMicrophoneOn() != null) {
  157. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  158. } else if (data.getMusicModeOn() != null) {
  159. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.MusicMode, data.getMusicModeOn());
  160. } else if (data.getHandUpOn() != null) {
  161. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.HandUp, data.getHandUpOn());
  162. } else {
  163. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  164. }
  165. return new BaseResponse<>(result);
  166. }
  167. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  168. public Object turnPage(@RequestBody ReqWhiteboardData data)
  169. throws ApiException, Exception {
  170. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  171. return new BaseResponse<>(result);
  172. }
  173. @RequestMapping(value = "/members", method = RequestMethod.GET)
  174. public Object getMembers(@RequestParam String roomId)
  175. throws ApiException, Exception {
  176. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  177. return new BaseResponse<>(whiteboards);
  178. }
  179. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  180. public Object apply(@RequestBody ReqSpeechData data)
  181. throws ApiException, Exception {
  182. Boolean result = roomService.applySpeech(data.getRoomId());
  183. return new BaseResponse<>(result);
  184. }
  185. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  186. public Object approval(@RequestBody ReqSpeechData data)
  187. throws ApiException, Exception {
  188. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  189. return new BaseResponse<>(result);
  190. }
  191. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  192. public Object reject(@RequestBody ReqSpeechData data)
  193. throws ApiException, Exception {
  194. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  195. return new BaseResponse<>(result);
  196. }
  197. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  198. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  199. throws ApiException, Exception {
  200. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  201. return new BaseResponse<>(result);
  202. }
  203. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  204. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  205. throws ApiException, Exception {
  206. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  207. return new BaseResponse<>(result);
  208. }
  209. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  210. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  211. throws ApiException, Exception {
  212. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  213. return new BaseResponse<>(result);
  214. }
  215. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  216. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  217. throws ApiException, Exception {
  218. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  219. return new BaseResponse<>(result);
  220. }
  221. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  222. public Object changeRole(@RequestBody ReqChangeRole data)
  223. throws ApiException, Exception {
  224. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  225. return new BaseResponse<>(result);
  226. }
  227. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  228. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  229. @RequestParam(value = "timestamp", required = false) String timestamp,
  230. @RequestParam(value = "nonce", required = false) String nonce,
  231. @RequestParam(value = "signature", required = false) String signature)
  232. throws ApiException, Exception {
  233. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  234. return new BaseResponse<>(result);
  235. }
  236. }