| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package me.zhengjie.application.admin.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.corundumstudio.socketio.SocketIOClient;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import me.zhengjie.annotation.rest.AnonymousPostMapping;
- import me.zhengjie.base.AppBaseResponse;
- import me.zhengjie.base.ResultCode;
- import me.zhengjie.base.util.ApplicationContextUtil;
- import me.zhengjie.base.util.FileUploadUtil;
- import me.zhengjie.base.websocket.AppPcBindSocketIo;
- import me.zhengjie.base.websocket.AppSocketClientCache;
- import me.zhengjie.base.websocket.PcSocketClientCache;
- import me.zhengjie.dao.mybatis.entity.OrderRoomIdEntity;
- import me.zhengjie.dao.mybatis.mapper.OrderRoomIdMapper;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.commons.collections4.MapUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Set;
- import java.util.UUID;
- @RestController
- @Validated
- @RequestMapping("/orderRoom")
- @Slf4j
- @RequiredArgsConstructor
- public class OrderRoomIdController {
- private final OrderRoomIdMapper orderRoomIdMapper;
- private final ApplicationContextUtil contextUtil;
- private final AppPcBindSocketIo appRelatePc;
- private final PcSocketClientCache pcSocketClientCache;
- private final AppSocketClientCache appSocketClientCache;
- /**
- * 查询视频
- *
- * @return
- */
- @RequestMapping("/getVideo")
- public AppBaseResponse<?> getVideo(@RequestBody String json) {
- AppBaseResponse<JSONObject> rep = new AppBaseResponse<>();
- JSONObject jsonObj = JSONObject.parseObject(json);
- QueryWrapper<OrderRoomIdEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("business_no", jsonObj.getString("businessNo"));
- queryWrapper.orderByDesc("update_time");
- List<OrderRoomIdEntity> orderRoomList = orderRoomIdMapper.selectList(queryWrapper);
- if (orderRoomList != null && orderRoomList.size() > 0) {
- OrderRoomIdEntity orderRoomId = orderRoomList.get(0);
- // 处理
- String appUrl = orderRoomId.getAppVideoUrl();
- if (StringUtils.isNotBlank(appUrl)) {
- appUrl = FileUploadUtil.getFileUrl(appUrl);
- orderRoomId.setAppVideoUrl(appUrl);
- }
- String pcUrl = orderRoomId.getPcVideoUrl();
- if (StringUtils.isNotBlank(pcUrl)) {
- pcUrl = FileUploadUtil.getFileUrl(pcUrl);
- orderRoomId.setPcVideoUrl(pcUrl);
- }
- rep.setResult(orderRoomId);
- }
- return rep;
- }
- /**
- * 查询 房间号
- *
- * @return
- */
- // @RequestMapping
- @AnonymousPostMapping("/getRooId")
- public AppBaseResponse<?> getRooId(@RequestBody String json) {
- log.info("全部的消息:" + json);
- JSONObject jsonObj = JSONObject.parseObject(json);
- String socketId = jsonObj.getString("socketId");
- JSONObject socketObj = isPushUserName(socketId);
- if (socketObj != null) {
- String accountId = socketObj.getString("accountId");
- String businessNo = socketObj.getString("businessNo");
- Set<String> userNames = appRelatePc.getBindNotary(businessNo);
- for (String userName : userNames) {
- HashMap<UUID, SocketIOClient> userClient = pcSocketClientCache.getUserClient(userName);
- if (userClient != null) {
- for (SocketIOClient client : userClient.values()) {
- if (!userName.equalsIgnoreCase(accountId))
- client.sendEvent("closeDialog", "closeDialog");
- }
- }
- }
- List<JSONObject> bindNotarys = new ArrayList<>();
- jsonObj = new JSONObject();
- jsonObj.put("userName", socketObj.getString("accountId"));
- bindNotarys.add(jsonObj);
- String notaryJson = JSONObject.toJSONString(bindNotarys);
- appRelatePc.setBusinessNo(businessNo, notaryJson, 60 * 30);
- // 如果确定的,关闭其他弹框
- return AppBaseResponse.succ(socketObj);
- }
- return AppBaseResponse.error(ResultCode.NOT_EXISTS);
- }
- /**
- * 包含推送的用户
- *
- * @param socketId
- * @return
- */
- private JSONObject isPushUserName(String socketId) {
- List<JSONObject> data = appRelatePc.socketIoTime(socketId);
- // try
- String userName = contextUtil.getCurrentUsername();
- if (data != null && data.size() > 0) {
- for (JSONObject socketObj : data) {
- if (socketObj.getString("accountId").equalsIgnoreCase(userName)) {
- return socketObj;
- }
- }
- }
- return null;
- }
- /**
- * 取消
- *
- * @param json
- * @return
- */
- @AnonymousPostMapping("/cancel")
- public AppBaseResponse<?> cancel(@RequestBody String json) {
- JSONObject jsonObj = JSONObject.parseObject(json);
- String socketId = jsonObj.getString("socketId");
- JSONObject socketObj = isPushUserName(socketId);
- if (socketObj == null) {
- return AppBaseResponse.success();
- }
-
- String businessNo = socketObj.getString("businessNo");
- log.info("pc端取消公证员绑定人员:{} ",businessNo);
- appRelatePc.removeNotary(businessNo, socketObj.getString("accountId"));
- // Set<String> notarys = appRelatePc.getBindNotary(businessNo);
- // if (CollectionUtils.isEmpty(notarys) || notarys.size() == 1) {
- // // 直接删除这条数据
- // appRelatePc.delBusinessNo(businessNo);
- // // TDOO 发送给app。取消了视频通话
- // sendAppMsg(businessNo);
- // return AppBaseResponse.success();
- // }
- // notarys.remove(socketObj.getString("accountId"));
- // // 保存没有取消的时间
- // appRelatePc.setNoCancelNotary(notarys, businessNo);
- return AppBaseResponse.success();
- }
- private void sendAppMsg(String businessNo) {
- HashMap<UUID, SocketIOClient> appSocketIo = appSocketClientCache.getUserClient(businessNo);
- if (MapUtils.isNotEmpty(appSocketIo)) {
- appSocketIo.forEach((uuid, socketIOClient) -> {
- socketIOClient.sendEvent("cancelEvent", "cancel");
- });
- }
- }
- /**
- * 结束视频
- *
- * @return
- */
- @RequestMapping("/endVideo")
- public AppBaseResponse<?> endVideo(@RequestBody String json) {
- JSONObject jsonObj = JSONObject.parseObject(json);
- String businessNo = jsonObj.getString("businessNo");
- appRelatePc.delBusinessNo(businessNo);
- return AppBaseResponse.success();
- }
- }
|