OrderRoomIdController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package me.zhengjie.application.admin.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.corundumstudio.socketio.SocketIOClient;
  5. import lombok.RequiredArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import me.zhengjie.annotation.rest.AnonymousPostMapping;
  8. import me.zhengjie.base.AppBaseResponse;
  9. import me.zhengjie.base.ResultCode;
  10. import me.zhengjie.base.util.ApplicationContextUtil;
  11. import me.zhengjie.base.util.FileUploadUtil;
  12. import me.zhengjie.base.websocket.AppPcBindSocketIo;
  13. import me.zhengjie.base.websocket.AppSocketClientCache;
  14. import me.zhengjie.base.websocket.PcSocketClientCache;
  15. import me.zhengjie.dao.mybatis.entity.OrderRoomIdEntity;
  16. import me.zhengjie.dao.mybatis.mapper.OrderRoomIdMapper;
  17. import org.apache.commons.collections4.CollectionUtils;
  18. import org.apache.commons.collections4.MapUtils;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.validation.annotation.Validated;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RestController;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Set;
  28. import java.util.UUID;
  29. @RestController
  30. @Validated
  31. @RequestMapping("/orderRoom")
  32. @Slf4j
  33. @RequiredArgsConstructor
  34. public class OrderRoomIdController {
  35. private final OrderRoomIdMapper orderRoomIdMapper;
  36. private final ApplicationContextUtil contextUtil;
  37. private final AppPcBindSocketIo appRelatePc;
  38. private final PcSocketClientCache pcSocketClientCache;
  39. private final AppSocketClientCache appSocketClientCache;
  40. /**
  41. * 查询视频
  42. *
  43. * @return
  44. */
  45. @RequestMapping("/getVideo")
  46. public AppBaseResponse<?> getVideo(@RequestBody String json) {
  47. AppBaseResponse<JSONObject> rep = new AppBaseResponse<>();
  48. JSONObject jsonObj = JSONObject.parseObject(json);
  49. QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
  50. queryWrapper.eq("business_no", jsonObj.getString("businessNo"));
  51. queryWrapper.orderByDesc("update_time");
  52. List<OrderRoomIdEntity> orderRoomList = orderRoomIdMapper.selectList(queryWrapper);
  53. if (orderRoomList != null && orderRoomList.size() > 0) {
  54. OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
  55. // 处理
  56. String appUrl = orderRoomId.getAppVideoUrl();
  57. if (StringUtils.isNotBlank(appUrl)) {
  58. appUrl = FileUploadUtil.getFileUrl(appUrl);
  59. orderRoomId.setAppVideoUrl(appUrl);
  60. }
  61. String pcUrl = orderRoomId.getPcVideoUrl();
  62. if (StringUtils.isNotBlank(pcUrl)) {
  63. pcUrl = FileUploadUtil.getFileUrl(pcUrl);
  64. orderRoomId.setPcVideoUrl(pcUrl);
  65. }
  66. rep.setResult(orderRoomId);
  67. }
  68. return rep;
  69. }
  70. /**
  71. * 查询 房间号
  72. *
  73. * @return
  74. */
  75. // @RequestMapping
  76. @AnonymousPostMapping("/getRooId")
  77. public AppBaseResponse<?> getRooId(@RequestBody String json) {
  78. log.info("全部的消息:" + json);
  79. JSONObject jsonObj = JSONObject.parseObject(json);
  80. String socketId = jsonObj.getString("socketId");
  81. JSONObject socketObj = isPushUserName(socketId);
  82. if (socketObj != null) {
  83. String accountId = socketObj.getString("accountId");
  84. String businessNo = socketObj.getString("businessNo");
  85. Set<String> userNames = appRelatePc.getBindNotary(businessNo);
  86. for (String userName : userNames) {
  87. HashMap<UUID, SocketIOClient> userClient = pcSocketClientCache.getUserClient(userName);
  88. if (userClient != null) {
  89. for (SocketIOClient client : userClient.values()) {
  90. if (!userName.equalsIgnoreCase(accountId))
  91. client.sendEvent("closeDialog", "closeDialog");
  92. }
  93. }
  94. }
  95. List<JSONObject> bindNotarys = new ArrayList<>();
  96. jsonObj = new JSONObject();
  97. jsonObj.put("userName", socketObj.getString("accountId"));
  98. bindNotarys.add(jsonObj);
  99. String notaryJson = JSONObject.toJSONString(bindNotarys);
  100. appRelatePc.setBusinessNo(businessNo, notaryJson, 60 * 30);
  101. // 如果确定的,关闭其他弹框
  102. return AppBaseResponse.succ(socketObj);
  103. }
  104. return AppBaseResponse.error(ResultCode.NOT_EXISTS);
  105. }
  106. /**
  107. * 包含推送的用户
  108. *
  109. * @param socketId
  110. * @return
  111. */
  112. private JSONObject isPushUserName(String socketId) {
  113. List<JSONObject> data = appRelatePc.socketIoTime(socketId);
  114. // try
  115. String userName = contextUtil.getCurrentUsername();
  116. if (data != null && data.size() > 0) {
  117. for (JSONObject socketObj : data) {
  118. if (socketObj.getString("accountId").equalsIgnoreCase(userName)) {
  119. return socketObj;
  120. }
  121. }
  122. }
  123. return null;
  124. }
  125. /**
  126. * 取消
  127. *
  128. * @param json
  129. * @return
  130. */
  131. @AnonymousPostMapping("/cancel")
  132. public AppBaseResponse<?> cancel(@RequestBody String json) {
  133. JSONObject jsonObj = JSONObject.parseObject(json);
  134. String socketId = jsonObj.getString("socketId");
  135. JSONObject socketObj = isPushUserName(socketId);
  136. if (socketObj == null) {
  137. return AppBaseResponse.success();
  138. }
  139. String businessNo = socketObj.getString("businessNo");
  140. log.info("pc端取消公证员绑定人员:{} ",businessNo);
  141. appRelatePc.removeNotary(businessNo, socketObj.getString("accountId"));
  142. // Set<String> notarys = appRelatePc.getBindNotary(businessNo);
  143. // if (CollectionUtils.isEmpty(notarys) || notarys.size() == 1) {
  144. // // 直接删除这条数据
  145. // appRelatePc.delBusinessNo(businessNo);
  146. // // TDOO 发送给app。取消了视频通话
  147. // sendAppMsg(businessNo);
  148. // return AppBaseResponse.success();
  149. // }
  150. // notarys.remove(socketObj.getString("accountId"));
  151. // // 保存没有取消的时间
  152. // appRelatePc.setNoCancelNotary(notarys, businessNo);
  153. return AppBaseResponse.success();
  154. }
  155. private void sendAppMsg(String businessNo) {
  156. HashMap<UUID, SocketIOClient> appSocketIo = appSocketClientCache.getUserClient(businessNo);
  157. if (MapUtils.isNotEmpty(appSocketIo)) {
  158. appSocketIo.forEach((uuid, socketIOClient) -> {
  159. socketIOClient.sendEvent("cancelEvent", "cancel");
  160. });
  161. }
  162. }
  163. /**
  164. * 结束视频
  165. *
  166. * @return
  167. */
  168. @RequestMapping("/endVideo")
  169. public AppBaseResponse<?> endVideo(@RequestBody String json) {
  170. JSONObject jsonObj = JSONObject.parseObject(json);
  171. String businessNo = jsonObj.getString("businessNo");
  172. appRelatePc.delBusinessNo(businessNo);
  173. return AppBaseResponse.success();
  174. }
  175. }