|
|
@@ -1,31 +1,35 @@
|
|
|
package me.zhengjie.application.user.app.mq;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.corundumstudio.socketio.SocketIOClient;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhengjie.application.admin.service.dto.JwtUserDto;
|
|
|
import me.zhengjie.application.admin.service.dto.RoleSmallDto;
|
|
|
import me.zhengjie.application.admin.service.dto.UserDto;
|
|
|
-import me.zhengjie.application.bank.service.SysUserService;
|
|
|
import me.zhengjie.base.util.ApplicationContextUtil;
|
|
|
-import me.zhengjie.base.util.WebSocketMap;
|
|
|
-import me.zhengjie.base.websocket.AppSocketServer;
|
|
|
+import me.zhengjie.websocket.AppPcBindSocketIo;
|
|
|
+import me.zhengjie.websocket.AppSocketClientCache;
|
|
|
+import me.zhengjie.websocket.PcSocketClientCache;
|
|
|
import me.zhengjie.dao.mybatis.ContractOrderRepository;
|
|
|
import me.zhengjie.dao.mybatis.entity.ContractOrderEntity;
|
|
|
import me.zhengjie.dao.mybatis.entity.SysUserEntity;
|
|
|
import me.zhengjie.dao.mybatis.mapper.SysUserMapper;
|
|
|
import me.zhengjie.security.service.OnlineUserService;
|
|
|
import me.zhengjie.security.service.dto.OnlineUserDto;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.connection.Message;
|
|
|
import org.springframework.data.redis.connection.MessageListener;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.CopyOnWriteArraySet;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
@@ -36,9 +40,12 @@ public class WebSocketReceiver implements MessageListener {
|
|
|
private final SysUserMapper sysUserMapper;
|
|
|
private final ApplicationContextUtil contextUtil;
|
|
|
private final ContractOrderRepository contractOrderRepository;
|
|
|
+ private final PcSocketClientCache socketClient;
|
|
|
+ private final AppPcBindSocketIo appRelatePc;
|
|
|
|
|
|
/**
|
|
|
* 推送公证员接单消息
|
|
|
+ *
|
|
|
* @param message 接收到的Json消息
|
|
|
* @param pattern 未使用参数
|
|
|
*/
|
|
|
@@ -52,7 +59,8 @@ public class WebSocketReceiver implements MessageListener {
|
|
|
String businessNo = jsonObj.getString("businessNo");
|
|
|
String appUserId = jsonObj.getString("appUserId");
|
|
|
String taskId = jsonObj.getString("taskId");
|
|
|
- List<OnlineUserDto> users = onlineUserService.getAllLoginUser();
|
|
|
+ // 删除这条数据是为了方便测试使用
|
|
|
+ appRelatePc.delBusinessNo(businessNo);
|
|
|
// share_userId
|
|
|
ContractOrderEntity notaryOrder = contractOrderRepository.getContractOrderWithBizNo(businessNo);
|
|
|
SysUserEntity sysUser = sysUserMapper.selectById(notaryOrder.getCustomerId());
|
|
|
@@ -61,47 +69,97 @@ public class WebSocketReceiver implements MessageListener {
|
|
|
List<JSONObject> list = new ArrayList<>();
|
|
|
String notaryId = "notary_" + notaryOrder.getNotaryOfficeId();
|
|
|
log.info("判断登录的公证处和查询的公证处比较:" + notaryId);
|
|
|
- WebSocketMap.set(socketId, list);
|
|
|
+ // WebSocketMap.set(socketId, list);
|
|
|
+ List<JSONObject> bindNotarys = new ArrayList<>();
|
|
|
+
|
|
|
+ Set<String> userNames = getOnlineNotary(notaryId);
|
|
|
+ for (String userName : userNames) {
|
|
|
+
|
|
|
+ HashMap<UUID, SocketIOClient> socketServers = socketClient.getUserClient(userName);
|
|
|
+ if (socketServers != null) {
|
|
|
+ for (SocketIOClient socketClient : socketServers.values()) {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("accountId", userName);
|
|
|
+ obj.put("orderId", orderId);
|
|
|
+ obj.put("roomId", roomId);
|
|
|
+ obj.put("prodId", notaryOrder.getProdId());
|
|
|
+ obj.put("contractType", notaryOrder.getContractType());
|
|
|
+ obj.put("businessNo", businessNo);
|
|
|
+ obj.put("customerIdCard", sysUser.getIdCard());
|
|
|
+ obj.put("userId", sysUser.getUserId());
|
|
|
+ obj.put("customerId", sysUser.getUserId());
|
|
|
+ obj.put("customerName", sysUser.getNickName());
|
|
|
+ obj.put("appUserId", appUserId);
|
|
|
+ obj.put("taskId", taskId);
|
|
|
+ // 这里只有推送才会增加
|
|
|
+ list.add(obj);
|
|
|
+ // 推送的消息
|
|
|
+ obj = new JSONObject();
|
|
|
+ obj.put("socketId", socketId);
|
|
|
+ obj.put("orderId", orderId);
|
|
|
+ obj.put("businessNo", businessNo);
|
|
|
+ obj.put("customerName", sysUser.getNickName());
|
|
|
+ obj.put("borrowerName", notaryOrder.getName());
|
|
|
+ obj.put("consultNo", notaryOrder.getConsultNo());
|
|
|
+ obj.put("bankName", notaryOrder.getBankName());
|
|
|
+ obj.put("appUserId", appUserId);
|
|
|
+ obj.put("taskId", taskId);
|
|
|
+ log.info("socket数据的推送给页面:" + notaryId);
|
|
|
+ // AppSocketServer.sendInfo(webSocket, obj.toString(), userDto.getUsername());
|
|
|
+ // 这里保证,只有空闲的才推送,
|
|
|
+ JSONObject bindnotary = new JSONObject();
|
|
|
+ // 用户名,绑定的
|
|
|
+ bindnotary.put("userName", userName);
|
|
|
+ bindNotarys.add(bindnotary);
|
|
|
+
|
|
|
+ socketClient.sendEvent("pcVideoEvent", obj.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ // 判断是否有值
|
|
|
+ if (CollectionUtils.isNotEmpty(list))
|
|
|
+ appRelatePc.socketIoTime(socketId, JSONObject.toJSONString(list));
|
|
|
+ // 这里是绑定所有的公证员
|
|
|
+ if (CollectionUtils.isNotEmpty(list))
|
|
|
+ appRelatePc.setBusinessNo(businessNo, JSONObject.toJSONString(bindNotarys), 35);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到所有的公证员
|
|
|
+ *
|
|
|
+ * @param notaryId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Set<String> getOnlineNotary(String notaryId) {
|
|
|
+
|
|
|
+ List<OnlineUserDto> users = onlineUserService.getAllLoginUser();
|
|
|
+ // 这里是绑定所有的公证员
|
|
|
+ Set<String> usernames = appRelatePc.getAllBindNotary();
|
|
|
+ Set<String> online = new HashSet<>();
|
|
|
for (OnlineUserDto user : users) {
|
|
|
JwtUserDto userDto = contextUtil.getUserByKey(user.getOnlineToken());
|
|
|
String orgId = userDto.getUser().getOrgId();
|
|
|
- if (StringUtils.isNotBlank(orgId) && orgId.equalsIgnoreCase(notaryId) && isNotrayUser(userDto.getUser())) {
|
|
|
- CopyOnWriteArraySet<AppSocketServer> socketServers = AppSocketServer.getWebSocketSet();
|
|
|
- log.info("得到所有的websocket对象:" + socketServers);
|
|
|
- for (AppSocketServer webSocket : socketServers) {
|
|
|
- if (webSocket.getSname().equalsIgnoreCase(userDto.getUsername())) {
|
|
|
- JSONObject obj = new JSONObject();
|
|
|
- obj.put("accountId", userDto.getUsername());
|
|
|
- obj.put("orderId", orderId);
|
|
|
- obj.put("roomId", roomId);
|
|
|
- obj.put("prodId", notaryOrder.getProdId());
|
|
|
- obj.put("contractType", notaryOrder.getContractType());
|
|
|
- obj.put("businessNo", businessNo);
|
|
|
- obj.put("customerIdCard", sysUser.getIdCard());
|
|
|
- obj.put("userId", sysUser.getUserId());
|
|
|
- obj.put("customerId", sysUser.getUserId());
|
|
|
- obj.put("customerName", sysUser.getNickName());
|
|
|
- obj.put("customerName", sysUser.getNickName());
|
|
|
- obj.put("appUserId",appUserId);
|
|
|
- obj.put("taskId",taskId);
|
|
|
- list.add(obj);
|
|
|
- // 重新实例化
|
|
|
- obj = new JSONObject();
|
|
|
- obj.put("socketId", socketId);
|
|
|
- obj.put("orderId", orderId);
|
|
|
- obj.put("businessNo", businessNo);
|
|
|
- obj.put("customerName", sysUser.getNickName());
|
|
|
- obj.put("borrowerName", notaryOrder.getName());
|
|
|
- obj.put("consultNo", notaryOrder.getConsultNo());
|
|
|
- obj.put("bankName", notaryOrder.getBankName());
|
|
|
- obj.put("appUserId", appUserId);
|
|
|
- obj.put("taskId", taskId);
|
|
|
- log.info("socket数据的推送给页面:" + notaryId);
|
|
|
- AppSocketServer.sendInfo(webSocket, obj.toString(), userDto.getUsername());
|
|
|
- }
|
|
|
- }
|
|
|
+ if (isOrgId(orgId, notaryId) && isNotrayUser(userDto.getUser())
|
|
|
+ && !usernames.contains(userDto.getUsername())) {
|
|
|
+ online.add(userDto.getUsername());
|
|
|
}
|
|
|
}
|
|
|
+ return online;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断公证处和银行绑定关系
|
|
|
+ *
|
|
|
+ * @param user 在线用户对象
|
|
|
+ * @return 返回是否公证员boolean值
|
|
|
+ */
|
|
|
+ private boolean isOrgId(String orgId, String notaryId) {
|
|
|
+ if (StringUtils.isNotBlank(orgId) && orgId.equalsIgnoreCase(notaryId)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -112,8 +170,8 @@ public class WebSocketReceiver implements MessageListener {
|
|
|
*/
|
|
|
private boolean isNotrayUser(UserDto user) {
|
|
|
Set<RoleSmallDto> roles = user.getRoles();
|
|
|
- for(RoleSmallDto role:roles){
|
|
|
- if("公证员".equals(role.getName())){
|
|
|
+ for (RoleSmallDto role : roles) {
|
|
|
+ if ("公证员".equals(role.getName())) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|