RoomController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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.entity.SysUser;
  7. import com.ym.mec.biz.dal.dao.CourseScheduleDao;
  8. import com.ym.mec.biz.dal.dao.CoursesGroupDao;
  9. import com.ym.mec.biz.dal.dao.TeacherDao;
  10. import com.ym.mec.biz.dal.entity.CourseSchedule;
  11. import com.ym.mec.biz.dal.entity.CoursesGroup;
  12. import com.ym.mec.biz.dal.entity.Teacher;
  13. import com.ym.mec.biz.dal.enums.SignStatusEnum;
  14. import com.ym.mec.biz.dal.enums.StudentAttendanceStatusEnum;
  15. import com.ym.pojo.*;
  16. import com.ym.service.RoomService;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.List;
  20. /**
  21. * Created by weiqinxiao on 2019/2/25.
  22. */
  23. @RestController
  24. @RequestMapping("/room")
  25. public class RoomController{
  26. @Autowired
  27. RoomService roomService;
  28. @Autowired
  29. private TeacherDao teacherDao;
  30. @Autowired
  31. private CourseScheduleDao courseScheduleDao;
  32. @RequestMapping(value = "/join", method = RequestMethod.POST)
  33. public Object joinRoom(@RequestBody ReqUserData data)
  34. throws ApiException, Exception {
  35. RoomResult roomResult = roomService.joinRoom(data.getUserName(), data.getRoomId(), data.isAudience(), data.isDisableCamera());
  36. return new BaseResponse<>(roomResult);
  37. }
  38. @RequestMapping(value = "/leave", method = RequestMethod.POST)
  39. public Object leaveRoom(@RequestBody ReqUserData data)
  40. throws ApiException, Exception {
  41. boolean result = roomService.leaveRoom(data.getRoomId());
  42. return new BaseResponse<>(result);
  43. }
  44. @RequestMapping(value = "/statusSync")
  45. public Object statusSync(@RequestBody String body) throws Exception {
  46. ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
  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 {
  122. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  123. }
  124. return new BaseResponse<>(result);
  125. }
  126. @RequestMapping(value = "/device/sync", method = RequestMethod.POST)
  127. public Object syncDeviceState(@RequestBody ReqDeviceControlData data)
  128. throws ApiException, Exception {
  129. boolean result;
  130. if (data.getCameraOn() != null) {
  131. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Camera, data.getCameraOn());
  132. } else if (data.getMicrophoneOn() != null) {
  133. result = roomService.syncDeviceState(data.getRoomId(), DeviceTypeEnum.Microphone, data.getMicrophoneOn());
  134. } else {
  135. throw new ApiException(ErrorEnum.ERR_REQUEST_PARA_ERR);
  136. }
  137. return new BaseResponse<>(result);
  138. }
  139. @RequestMapping(value = "/whiteboard/turn-page", method = RequestMethod.POST)
  140. public Object turnPage(@RequestBody ReqWhiteboardData data)
  141. throws ApiException, Exception {
  142. boolean result = roomService.turnWhiteBoardPage(data.getRoomId(), data.getWhiteboardId(), data.getPage());
  143. return new BaseResponse<>(result);
  144. }
  145. @RequestMapping(value = "/members", method = RequestMethod.GET)
  146. public Object getMembers(@RequestParam String roomId)
  147. throws ApiException, Exception {
  148. List<RoomResult.MemberResult> whiteboards = roomService.getMembers(roomId);
  149. return new BaseResponse<>(whiteboards);
  150. }
  151. @RequestMapping(value = "/speech/apply", method = RequestMethod.POST)
  152. public Object apply(@RequestBody ReqSpeechData data)
  153. throws ApiException, Exception {
  154. Boolean result = roomService.applySpeech(data.getRoomId());
  155. return new BaseResponse<>(result);
  156. }
  157. @RequestMapping(value = "/speech/approve", method = RequestMethod.POST)
  158. public Object approval(@RequestBody ReqSpeechData data)
  159. throws ApiException, Exception {
  160. Boolean result = roomService.approveSpeech(data.getRoomId(), data.getTicket());
  161. return new BaseResponse<>(result);
  162. }
  163. @RequestMapping(value = "/speech/reject", method = RequestMethod.POST)
  164. public Object reject(@RequestBody ReqSpeechData data)
  165. throws ApiException, Exception {
  166. Boolean result = roomService.rejectSpeech(data.getRoomId(), data.getTicket());
  167. return new BaseResponse<>(result);
  168. }
  169. @RequestMapping(value = "/transfer", method = RequestMethod.POST)
  170. public Object transfer(@RequestBody ReqUpgradeRoleData data)
  171. throws ApiException, Exception {
  172. Boolean result = roomService.transfer(data.getRoomId(), data.getUserId());
  173. return new BaseResponse<>(result);
  174. }
  175. @RequestMapping(value = "/upgrade/invite", method = RequestMethod.POST)
  176. public Object inviteUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  177. throws ApiException, Exception {
  178. Boolean result = roomService.inviteUpgradeRole(data.getRoomId(), data.getUserId(), data.getRole());
  179. return new BaseResponse<>(result);
  180. }
  181. @RequestMapping(value = "/upgrade/approve", method = RequestMethod.POST)
  182. public Object approveUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  183. throws ApiException, Exception {
  184. Boolean result = roomService.approveUpgradeRole(data.getRoomId(), data.getTicket());
  185. return new BaseResponse<>(result);
  186. }
  187. @RequestMapping(value = "/upgrade/reject", method = RequestMethod.POST)
  188. public Object rejectUpgradeRole(@RequestBody ReqUpgradeRoleData data)
  189. throws ApiException, Exception {
  190. Boolean result = roomService.rejectUpgradeRole(data.getRoomId(), data.getTicket());
  191. return new BaseResponse<>(result);
  192. }
  193. @RequestMapping(value = "/change-role", method = RequestMethod.POST)
  194. public Object changeRole(@RequestBody ReqChangeRole data)
  195. throws ApiException, Exception {
  196. Boolean result = roomService.changeRole(data.getRoomId(), data.getUserId(), data.getRole());
  197. return new BaseResponse<>(result);
  198. }
  199. @RequestMapping(value = "/members/online-status", method = RequestMethod.POST)
  200. public Object memberOnlineStatus(@RequestBody List<ReqMemberOnlineStatus> statusList,
  201. @RequestParam(value = "timestamp", required = false) String timestamp,
  202. @RequestParam(value = "nonce", required = false) String nonce,
  203. @RequestParam(value = "signature", required = false) String signature)
  204. throws ApiException, Exception {
  205. Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
  206. return new BaseResponse<>(result);
  207. }
  208. }