RoomController.java 11 KB

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