|
@@ -0,0 +1,882 @@
|
|
|
|
+package com.fs.im.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
|
+import com.fs.fastGpt.service.AiHookService;
|
|
|
|
+import com.fs.his.domain.FsDoctor;
|
|
|
|
+import com.fs.his.domain.FsFollow;
|
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
|
+import com.fs.his.dto.PayloadDTO;
|
|
|
|
+import com.fs.his.mapper.FsDoctorMapper;
|
|
|
|
+import com.fs.his.mapper.FsFollowMapper;
|
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
|
+import com.fs.im.config.IMConfig;
|
|
|
|
+import com.fs.im.dto.OpenImConversationDTO;
|
|
|
|
+import com.fs.im.dto.OpenImEditConversationDTO;
|
|
|
|
+import com.fs.im.dto.OpenImMsgDTO;
|
|
|
|
+import com.fs.im.dto.OpenImResponseDTO;
|
|
|
|
+import com.fs.im.service.OpenIMService;
|
|
|
|
+import com.fs.im.vo.OpenImMsgCallBackVO;
|
|
|
|
+import com.fs.im.vo.OpenImResponseDTOTest;
|
|
|
|
+import com.fs.qw.mapper.QwExternalContactMapper;
|
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
|
+import lombok.Data;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.json.JSONArray;
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+@Slf4j
|
|
|
|
+public class OpenIMServiceImpl implements OpenIMService {
|
|
|
|
+ @Autowired
|
|
|
|
+ IMConfig imConfig;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsUserMapper fsUserMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsDoctorMapper fsDoctorMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsFollowMapper fsFollowMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private QwExternalContactMapper qwExternalContactMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ @Lazy
|
|
|
|
+ private AiHookService aiHookService;
|
|
|
|
+ /*@Autowired
|
|
|
|
+ private IFsUserService fsUserService;*/
|
|
|
|
+ @Override
|
|
|
|
+ public String getAdminToken() {
|
|
|
|
+ Object cachedTokenObj = redisCache.getCacheObject("openImAdminToken:" + imConfig.getUserID());
|
|
|
|
+ if (cachedTokenObj != null) {
|
|
|
|
+ return cachedTokenObj.toString();
|
|
|
|
+ }
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
|
+ requestBody.put("secret", imConfig.getSecret()); // 预设的管理员密钥
|
|
|
|
+ requestBody.put("userID", imConfig.getUserID()); // 管理员 userID
|
|
|
|
+ String adminToken = null;
|
|
|
|
+ // 发起 HTTP POST 请求,获取管理员 token
|
|
|
|
+ try {
|
|
|
|
+ String response = HttpRequest.post("https://web.im.cdwjyyh.com/api/auth/get_admin_token")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .body(requestBody.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+
|
|
|
|
+ JSONObject jsonResponse = new JSONObject(response);
|
|
|
|
+ if (jsonResponse.getInt("errCode") == 0) {
|
|
|
|
+ JSONObject data = jsonResponse.getJSONObject("data");
|
|
|
|
+ adminToken = data.getString("token");
|
|
|
|
+ redisCache.setCacheObject("openImAdminToken:" + imConfig.getUserID(), adminToken,
|
|
|
|
+ data.getInt("expireTimeSeconds"), TimeUnit.SECONDS);
|
|
|
|
+ return adminToken;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // 可以记录日志
|
|
|
|
+ log.error("获取管理员 token 失败", e);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO AiAutoReply(OpenImMsgCallBackVO openImMsgDTO) throws JsonProcessingException {
|
|
|
|
+ try {
|
|
|
|
+ String sendID = openImMsgDTO.getSendID();
|
|
|
|
+ // 如果发送人不是用户 直接返回 不做自动回复
|
|
|
|
+ if (!sendID.startsWith("U")) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String recvType = "2"; // 接收信息人类型 2销售,3医生 默认销售
|
|
|
|
+ OpenImMsgDTO.OfflinePushInfo offlinePushInfo = new OpenImMsgDTO.OfflinePushInfo();
|
|
|
|
+ // 初始化ObjectMapper对象,用于JSON序列化和反序列化
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ // 初始化消息DTO对象
|
|
|
|
+ OpenImMsgDTO replyMsg = new OpenImMsgDTO();
|
|
|
|
+ String recvID = openImMsgDTO.getRecvID();
|
|
|
|
+ Long companyId = 0L;
|
|
|
|
+ if (recvID.startsWith("D")) {
|
|
|
|
+ // 因为主要是销售想接入ai ,所以医生不回复,只回复销售 下面暂时保留
|
|
|
|
+ return null;
|
|
|
|
+// FsDoctor fsDoctor = fsDoctorMapper.selectFsDoctorByDoctorId(Long.parseLong(recvID.replace("D", "")));
|
|
|
|
+// if (null != fsDoctor && StringUtils.isNotEmpty(fsDoctor.getAvatar())) {
|
|
|
|
+// offlinePushInfo.setTitle(fsDoctor.getDoctorName());
|
|
|
|
+// replyMsg.setSenderFaceURL(fsDoctor.getAvatar());
|
|
|
|
+// }
|
|
|
|
+ } else if (recvID.startsWith("C")) {
|
|
|
|
+ CompanyUser company = companyUserMapper.selectCompanyUserByUserId(Long.parseLong(recvID.replace("C", "")));
|
|
|
|
+ companyId = company.getCompanyId();
|
|
|
|
+ if (null != company && StringUtils.isNotEmpty(company.getAvatar())) {
|
|
|
|
+ offlinePushInfo.setTitle(company.getImNickName());
|
|
|
|
+ replyMsg.setSenderFaceURL(company.getAvatar());
|
|
|
|
+ }
|
|
|
|
+ recvType = "2";
|
|
|
|
+ }
|
|
|
|
+ // 对接收者ID进行账户校验
|
|
|
|
+ accountCheck(recvID.toString(), recvType);
|
|
|
|
+ if (companyId == 0L) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ // ai接口智能回复
|
|
|
|
+ R r = aiHookService.AiReply(openImMsgDTO, companyId);
|
|
|
|
+ if (r.get("code").equals(500)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String aiReplyContent = r.get("content").toString();
|
|
|
|
+
|
|
|
|
+ // 设置消息的发送者ID、接收者ID、内容类型等基础信息
|
|
|
|
+ // 将发送者和接收者交换一下
|
|
|
|
+ replyMsg.setSendID(recvID);
|
|
|
|
+ replyMsg.setRecvID(sendID);
|
|
|
|
+ replyMsg.setContentType(101);
|
|
|
|
+ replyMsg.setSenderPlatformID(5);
|
|
|
|
+ replyMsg.setSessionType(1);
|
|
|
|
+
|
|
|
|
+ // 初始化消息内容对象
|
|
|
|
+ OpenImMsgDTO.Content content = new OpenImMsgDTO.Content();
|
|
|
|
+ // 初始化负载数据对象,并设置数据内容
|
|
|
|
+ PayloadDTO payload = new PayloadDTO();
|
|
|
|
+ payload.setData(aiReplyContent);
|
|
|
|
+
|
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
|
+ extension.setTitle("快速回复"); // 可选标题
|
|
|
|
+ payload.setExtension(extension);
|
|
|
|
+ OpenImMsgDTO.ImData imData = new OpenImMsgDTO.ImData();
|
|
|
|
+ imData.setPayload(payload);
|
|
|
|
+ String imJson = objectMapper.writeValueAsString(imData);
|
|
|
|
+ content.setData(imJson);
|
|
|
|
+ content.setContent(aiReplyContent);
|
|
|
|
+ replyMsg.setContent(content);
|
|
|
|
+ offlinePushInfo.setDesc("快速回复");
|
|
|
|
+ offlinePushInfo.setIOSBadgeCount(true);
|
|
|
|
+ offlinePushInfo.setIOSPushSound("");
|
|
|
|
+ replyMsg.setOfflinePushInfo(offlinePushInfo);
|
|
|
|
+ // 发送消息
|
|
|
|
+ OpenImResponseDTO response = openIMSendMsg(replyMsg);
|
|
|
|
+ if (response.getErrCode() == 0) {
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
+ OpenImEditConversationDTO openImEditConversationDTO = new OpenImEditConversationDTO();
|
|
|
|
+ ArrayList<String> userIDs = new ArrayList<>();
|
|
|
|
+ userIDs.add(recvID);
|
|
|
|
+ openImEditConversationDTO.setUserIDs(userIDs);
|
|
|
|
+ OpenImConversationDTO openImConversationDTO = new OpenImConversationDTO();
|
|
|
|
+ openImConversationDTO.setConversationID("si_" + recvID + "_" + sendID);
|
|
|
|
+ openImConversationDTO.setConversationType(1);
|
|
|
|
+ openImConversationDTO.setUserID(sendID);
|
|
|
|
+ openImEditConversationDTO.setConversation(openImConversationDTO);
|
|
|
|
+ OpenImResponseDTO openImResponseDTO1 = editConversation(openImEditConversationDTO);
|
|
|
|
+ log.info("修改回话返回参数:{}", openImResponseDTO1);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("openImMsgCallBack,自动销售回复消息,发送消息失败:", e);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //批量修改销售名称,由昵称-公司名,改为昵称
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiJpbUFkbWluIiwiUGxhdGZvcm1JRCI6MTAsImV4cCI6MTc1OTkxMDgwNywiaWF0IjoxNzUyMTM0ODAyfQ.y0akpb-TnOBqJewPUD13tnUeR1iF41A3CcgaXXsjyKE";
|
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
|
+ int pageSize = 5000;
|
|
|
|
+ int pageNumber = 1;
|
|
|
|
+
|
|
|
|
+ while (true) {
|
|
|
|
+ // 构建分页查询请求体
|
|
|
|
+ JSONObject requestPage = new JSONObject();
|
|
|
|
+ JSONObject pagination = new JSONObject();
|
|
|
|
+ pagination.put("pageNumber", pageNumber);
|
|
|
|
+ pagination.put("showNumber", pageSize);
|
|
|
|
+ requestPage.put("pagination", pagination);
|
|
|
|
+
|
|
|
|
+ String result = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/get_all_users_uid")
|
|
|
|
+ .header("operationID", String.valueOf(time))
|
|
|
|
+ .header("token", token)
|
|
|
|
+ .body(requestPage.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+
|
|
|
|
+ OpenImResponseDTO responseDTO = JSONUtil.toBean(result, OpenImResponseDTO.class);
|
|
|
|
+ List<String> userIDs = (List<String>) responseDTO.getData().get("userIDs");
|
|
|
|
+
|
|
|
|
+ if (CollectionUtil.isEmpty(userIDs)) {
|
|
|
|
+ System.out.println("数据为空,处理结束");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 过滤出以C开头的用户ID
|
|
|
|
+ List<String> userIds = userIDs.stream()
|
|
|
|
+ .filter(uid -> uid.startsWith("C"))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (CollectionUtil.isNotEmpty(userIds)) {
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
+ paramMap.put("userIDs", userIds);
|
|
|
|
+
|
|
|
|
+ String jsonBody = JSONUtil.toJsonStr(paramMap);
|
|
|
|
+ String result1 = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/get_users_info")
|
|
|
|
+ .header("operationID", String.valueOf(time))
|
|
|
|
+ .header("token", token)
|
|
|
|
+ .body(jsonBody)
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+
|
|
|
|
+ OpenImResponseDTOTest responseDTO1 = JSONUtil.toBean(result1, OpenImResponseDTOTest.class);
|
|
|
|
+ List<UserInfo> users = responseDTO1.getData().getUsersInfo();
|
|
|
|
+
|
|
|
|
+ for (UserInfo user : users) {
|
|
|
|
+ if (StringUtil.isNotEmpty(user.getNickname()) && user.getNickname().contains("-")) {
|
|
|
|
+ UpdateUserInfo updateUserInfo = new UpdateUserInfo();
|
|
|
|
+ updateUserInfo.setUserID(user.getUserID());
|
|
|
|
+ updateUserInfo.setNickname(user.getNickname().split("-")[0]);
|
|
|
|
+ updateUserInfo.setFaceURL(Optional.ofNullable(user.getFaceURL()).orElse(""));
|
|
|
|
+ updateUserInfo.setEx(Optional.ofNullable(user.getEx()).orElse(""));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> bodyMap = new HashMap<>();
|
|
|
|
+ bodyMap.put("userInfo", updateUserInfo);
|
|
|
|
+
|
|
|
|
+ String jsonBody1 = JSONUtil.toJsonStr(bodyMap);
|
|
|
|
+ String result2 = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/update_user_info_ex")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", token)
|
|
|
|
+ .body(jsonBody1)
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+
|
|
|
|
+ OpenImResponseDTO responseDTO2 = JSONUtil.toBean(result2, OpenImResponseDTO.class);
|
|
|
|
+ if (responseDTO2.getErrCode() != 0) {
|
|
|
|
+ System.out.println("更新失败 userID=" + user.getUserID() + ",错误信息:" + responseDTO2.getErrMsg());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println("已处理第 " + pageNumber + " 页,共处理用户数:" + userIDs.size());
|
|
|
|
+ if (userIDs.size() < pageSize) {
|
|
|
|
+ System.out.println("已是最后一页,处理完毕!");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ pageNumber++; // 下一页
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改im用户信息
|
|
|
|
+ * @param companyUser
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO updateUserInfo(CompanyUser companyUser){
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
|
+ OpenImResponseDTO responseDTO = null;
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
+ ArrayList<String> userIDs = new ArrayList<>();
|
|
|
|
+ userIDs.add("C"+companyUser.getUserId());
|
|
|
|
+ paramMap.put("userIDs", userIDs);
|
|
|
|
+
|
|
|
|
+ String jsonBody = JSONUtil.toJsonStr(paramMap);
|
|
|
|
+ String result1 = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/get_users_info")
|
|
|
|
+ .header("operationID", String.valueOf(time))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonBody)
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ UpdateUserInfo updateUserInfo = new UpdateUserInfo();
|
|
|
|
+ OpenImResponseDTOTest responseDTO1 = JSONUtil.toBean(result1, OpenImResponseDTOTest.class);
|
|
|
|
+ List<UserInfo> users = responseDTO1.getData().getUsersInfo();
|
|
|
|
+ if (users.size()<=0){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (UserInfo user : users) {
|
|
|
|
+ updateUserInfo.setUserID(user.getUserID());
|
|
|
|
+ updateUserInfo.setNickname(StringUtils.isNotEmpty(companyUser.getImNickName())?companyUser.getImNickName():companyUser.getNickName());
|
|
|
|
+ updateUserInfo.setFaceURL(Optional.ofNullable(user.getFaceURL()).orElse(""));
|
|
|
|
+ updateUserInfo.setEx(Optional.ofNullable(user.getEx()).orElse(""));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> bodyMap = new HashMap<>();
|
|
|
|
+ bodyMap.put("userInfo", updateUserInfo);
|
|
|
|
+ String jsonBody1 = JSONUtil.toJsonStr(bodyMap);
|
|
|
|
+ String result2 = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/update_user_info_ex")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonBody1)
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ responseDTO= JSONUtil.toBean(result2,OpenImResponseDTO.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+ @Data
|
|
|
|
+ public static class UpdateUserInfo {
|
|
|
|
+ private String userID;
|
|
|
|
+ private String nickname;
|
|
|
|
+ private String faceURL = "";
|
|
|
|
+ private String ex = "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Data
|
|
|
|
+ public class UserInfo {
|
|
|
|
+ private String userID;
|
|
|
|
+ private String nickname;
|
|
|
|
+ private String faceURL;
|
|
|
|
+ private String ex;
|
|
|
|
+ private Long createTime;
|
|
|
|
+ private Integer appMangerLevel;
|
|
|
|
+ private Integer globalRecvMsgOpt;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO openIMSendMsg(OpenImMsgDTO openImMsgDTO) {
|
|
|
|
+ log.info("进入发消息的方法");
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ JSONObject jsonObject = new JSONObject(openImMsgDTO);
|
|
|
|
+ log.info("发送消息的请求体:\n{}", jsonObject.toString());
|
|
|
|
+ long time = new Date().getTime();
|
|
|
|
+ String result = HttpRequest.post("https://web.im.cdwjyyh.com/api/msg/send_msg")
|
|
|
|
+ .header("operationID", time + "")
|
|
|
|
+ .header("token",adminToken)
|
|
|
|
+ .body(jsonObject.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ OpenImResponseDTO responseDTO= JSONUtil.toBean(result,OpenImResponseDTO.class);
|
|
|
|
+ log.info("发送消息返回内容:\n{}", responseDTO);
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO sendCourse(Long userId,Long companyUserId,String url,String title,String linkImageUrl,String cropId) throws JsonProcessingException {
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ //userId = 61l;
|
|
|
|
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略null字段
|
|
|
|
+ checkAndImportFriendByDianBo(companyUserId,userId.toString(),cropId);
|
|
|
|
+ OpenImMsgDTO.Content content = new OpenImMsgDTO.Content();
|
|
|
|
+ OpenImMsgDTO.ImData imData = new OpenImMsgDTO.ImData();
|
|
|
|
+ PayloadDTO payload = new PayloadDTO();
|
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
|
+ payload.setData("course");
|
|
|
|
+ extension.setTitle(title);
|
|
|
|
+ extension.setAppRealLink(url);
|
|
|
|
+ extension.setSendTime(new Date());
|
|
|
|
+ extension.setCourseUrl(linkImageUrl);
|
|
|
|
+ payload.setExtension(extension);
|
|
|
|
+ imData.setPayload(payload);
|
|
|
|
+ String imJson = objectMapper.writeValueAsString(imData);
|
|
|
|
+ content.setData(imJson);
|
|
|
|
+
|
|
|
|
+ OpenImMsgDTO.OfflinePushInfo offlinePushInfo = new OpenImMsgDTO.OfflinePushInfo();
|
|
|
|
+ offlinePushInfo.setDesc(title);
|
|
|
|
+ offlinePushInfo.setTitle("芳华未来");
|
|
|
|
+ offlinePushInfo.setIOSBadgeCount(true);
|
|
|
|
+ offlinePushInfo.setIOSPushSound("");
|
|
|
|
+
|
|
|
|
+ OpenImMsgDTO openImMsgDTO = new OpenImMsgDTO();
|
|
|
|
+ openImMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
|
+ openImMsgDTO.setContent(content);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ openImMsgDTO.setSendID("C"+companyUserId);
|
|
|
|
+ openImMsgDTO.setRecvID("U"+userId);
|
|
|
|
+ openImMsgDTO.setContentType(110);
|
|
|
|
+ openImMsgDTO.setSessionType(1);
|
|
|
|
+ // 输出格式化JSON日志
|
|
|
|
+ log.info("课程消息:\n{}", objectMapper.writeValueAsString(openImMsgDTO));
|
|
|
|
+ OpenImResponseDTO openImResponseDTO = openIMSendMsg(openImMsgDTO);
|
|
|
|
+ openImMsgDTO = null;
|
|
|
|
+ content = null;
|
|
|
|
+ return openImResponseDTO;
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO sendUtil(String sendID, String recvID, Integer contentType, String payloadData, String diagnose,String title,String followId,String orderId,String ex) throws JsonProcessingException {
|
|
|
|
+ try {
|
|
|
|
+ OpenImMsgDTO.OfflinePushInfo offlinePushInfo = new OpenImMsgDTO.OfflinePushInfo();
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ OpenImMsgDTO openImMsgDTO = new OpenImMsgDTO();
|
|
|
|
+ if (sendID.startsWith("D")){
|
|
|
|
+ FsDoctor fsDoctor = fsDoctorMapper.selectFsDoctorByDoctorId(Long.parseLong(sendID.replace("D","")));
|
|
|
|
+ //FsUser fsUser = fsUserService.selectFsUserByUserId(sendID);
|
|
|
|
+ if (null!=fsDoctor&&StringUtils.isNotEmpty(fsDoctor.getAvatar())){
|
|
|
|
+ offlinePushInfo.setTitle(fsDoctor.getDoctorName());
|
|
|
|
+ openImMsgDTO.setSenderFaceURL(fsDoctor.getAvatar());
|
|
|
|
+ }
|
|
|
|
+ }else if (sendID.startsWith("C")){
|
|
|
|
+ CompanyUser company = companyUserMapper.selectCompanyUserByUserId(Long.parseLong(sendID.replace("C", "")));
|
|
|
|
+ if (null!=company&&StringUtils.isNotEmpty(company.getAvatar())){
|
|
|
|
+ offlinePushInfo.setTitle(company.getImNickName());
|
|
|
|
+ openImMsgDTO.setSenderFaceURL(company.getAvatar());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ accountCheck(recvID.toString(),"1");
|
|
|
|
+ openImMsgDTO.setSendID(sendID);
|
|
|
|
+ openImMsgDTO.setRecvID(recvID);
|
|
|
|
+ openImMsgDTO.setContentType(contentType);
|
|
|
|
+ openImMsgDTO.setSenderPlatformID(5);
|
|
|
|
+ openImMsgDTO.setSessionType(1);
|
|
|
|
+ if (StringUtils.isNotEmpty(ex)){
|
|
|
|
+ openImMsgDTO.setEx(ex);
|
|
|
|
+ }
|
|
|
|
+ OpenImMsgDTO.Content content = new OpenImMsgDTO.Content();
|
|
|
|
+ //content.setContent(ext);
|
|
|
|
+ PayloadDTO payload = new PayloadDTO();
|
|
|
|
+ payload.setData(payloadData);
|
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
|
+ //extension.setDiagnose(diagnose);
|
|
|
|
+ if (StringUtils.isNotEmpty(title)){
|
|
|
|
+ extension.setTitle(title);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(diagnose)){
|
|
|
|
+ extension.setDiagnose(diagnose);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(followId)){
|
|
|
|
+ //随访医生与患者加好友
|
|
|
|
+ ArrayList<String> userIds = new ArrayList<>();
|
|
|
|
+ userIds.add(recvID);
|
|
|
|
+ importFriend(sendID,userIds);
|
|
|
|
+ extension.setFollowId(followId);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(orderId)){
|
|
|
|
+ payload.setDescription(orderId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ payload.setExtension(extension);
|
|
|
|
+ OpenImMsgDTO.ImData imData = new OpenImMsgDTO.ImData();
|
|
|
|
+
|
|
|
|
+ imData.setPayload(payload);
|
|
|
|
+
|
|
|
|
+ String imJson = objectMapper.writeValueAsString(imData);
|
|
|
|
+ content.setData(imJson);
|
|
|
|
+ openImMsgDTO.setContent(content);
|
|
|
|
+ if (contentType == 101){
|
|
|
|
+ content.setContent(title);
|
|
|
|
+ }
|
|
|
|
+ //cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject(openImMsgDTO);
|
|
|
|
+
|
|
|
|
+ //openImMsgDTO.setEx(payload);
|
|
|
|
+
|
|
|
|
+ offlinePushInfo.setDesc(title);
|
|
|
|
+
|
|
|
|
+ offlinePushInfo.setIOSBadgeCount(true);
|
|
|
|
+ offlinePushInfo.setIOSPushSound("");
|
|
|
|
+ openImMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
|
+ OpenImResponseDTO openImResponseDTO = openIMSendMsg(openImMsgDTO);
|
|
|
|
+ if (openImResponseDTO.getErrCode()==0){
|
|
|
|
+ Thread.sleep(1000 );
|
|
|
|
+ OpenImEditConversationDTO openImEditConversationDTO = new OpenImEditConversationDTO();
|
|
|
|
+ ArrayList<String> userIDs = new ArrayList<>();
|
|
|
|
+ userIDs.add(sendID);
|
|
|
|
+ openImEditConversationDTO.setUserIDs(userIDs);
|
|
|
|
+ OpenImConversationDTO openImConversationDTO = new OpenImConversationDTO();
|
|
|
|
+ openImConversationDTO.setConversationID("si_"+sendID+"_"+recvID);
|
|
|
|
+ openImConversationDTO.setConversationType(1);
|
|
|
|
+ openImConversationDTO.setUserID(recvID);
|
|
|
|
+ openImConversationDTO.setEx(ex);
|
|
|
|
+ log.info("更新到会话的ex的值:{}",ex);
|
|
|
|
+ openImEditConversationDTO.setConversation(openImConversationDTO);
|
|
|
|
+
|
|
|
|
+ OpenImResponseDTO openImResponseDTO1 = editConversation(openImEditConversationDTO);
|
|
|
|
+ log.info("修改回话返回参数:{}",openImResponseDTO1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return openImResponseDTO;
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public OpenImResponseDTO sendUtilUserToDoctor(String sendID, String recvID, Integer contentType, String payloadData, String diagnose,String title,String followId,String orderId,String ex) throws JsonProcessingException {
|
|
|
|
+ try {
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ OpenImMsgDTO openImMsgDTO = new OpenImMsgDTO();
|
|
|
|
+ if (sendID.startsWith("U")){
|
|
|
|
+ //FsDoctor fsDoctor = fsDoctorMapper.selectFsDoctorByDoctorId(Long.parseLong(sendID.replace("D","")));
|
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(Long.parseLong(sendID.replace("U","")));
|
|
|
|
+ if (null!=fsUser&&StringUtils.isNotEmpty(fsUser.getAvatar())){
|
|
|
|
+ openImMsgDTO.setSenderFaceURL(fsUser.getAvatar());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ accountCheck(sendID.toString(),"1");
|
|
|
|
+ openImMsgDTO.setSendID(sendID);
|
|
|
|
+ openImMsgDTO.setRecvID(recvID);
|
|
|
|
+ openImMsgDTO.setContentType(contentType);
|
|
|
|
+ openImMsgDTO.setSenderPlatformID(5);
|
|
|
|
+ openImMsgDTO.setSessionType(1);
|
|
|
|
+ if (StringUtils.isNotEmpty(ex)){
|
|
|
|
+ openImMsgDTO.setEx(ex);
|
|
|
|
+ }
|
|
|
|
+ OpenImMsgDTO.Content content = new OpenImMsgDTO.Content();
|
|
|
|
+ //content.setContent(ext);
|
|
|
|
+ PayloadDTO payload = new PayloadDTO();
|
|
|
|
+ payload.setData(payloadData);
|
|
|
|
+ PayloadDTO.Extension extension = new PayloadDTO.Extension();
|
|
|
|
+ extension.setDiagnose(diagnose);
|
|
|
|
+ if (StringUtils.isNotEmpty(title)){
|
|
|
|
+ extension.setTitle(title);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(diagnose)){
|
|
|
|
+ extension.setDiagnose(diagnose);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(followId)){
|
|
|
|
+ FsFollow follow=fsFollowMapper.selectFsFollowByFollowId(Long.parseLong(followId));
|
|
|
|
+
|
|
|
|
+ //随访医生与患者加好友
|
|
|
|
+ ArrayList<String> userIds = new ArrayList<>();
|
|
|
|
+ userIds.add(recvID);
|
|
|
|
+ importFriend(sendID,userIds);
|
|
|
|
+ extension.setFollowId(followId);
|
|
|
|
+ extension.setWriteStatus(follow.getWriteStatus().toString());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(orderId)){
|
|
|
|
+ payload.setDescription(orderId);
|
|
|
|
+ }
|
|
|
|
+ payload.setExtension(extension);
|
|
|
|
+ OpenImMsgDTO.ImData imData = new OpenImMsgDTO.ImData();
|
|
|
|
+
|
|
|
|
+ imData.setPayload(payload);
|
|
|
|
+
|
|
|
|
+ String imJson = objectMapper.writeValueAsString(imData);
|
|
|
|
+ content.setData(imJson);
|
|
|
|
+ openImMsgDTO.setContent(content);
|
|
|
|
+
|
|
|
|
+ //cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject(openImMsgDTO);
|
|
|
|
+
|
|
|
|
+ //openImMsgDTO.setEx(payload);
|
|
|
|
+ OpenImMsgDTO.OfflinePushInfo offlinePushInfo = new OpenImMsgDTO.OfflinePushInfo();
|
|
|
|
+ offlinePushInfo.setDesc(title);
|
|
|
|
+ offlinePushInfo.setTitle("芳华未来");
|
|
|
|
+ offlinePushInfo.setIOSBadgeCount(true);
|
|
|
|
+ offlinePushInfo.setIOSPushSound("");
|
|
|
|
+ openImMsgDTO.setOfflinePushInfo(offlinePushInfo);
|
|
|
|
+ OpenImResponseDTO openImResponseDTO = openIMSendMsg(openImMsgDTO);
|
|
|
|
+ if (openImResponseDTO.getErrCode()==0){
|
|
|
|
+ Thread.sleep(1000 );
|
|
|
|
+ OpenImEditConversationDTO openImEditConversationDTO = new OpenImEditConversationDTO();
|
|
|
|
+ ArrayList<String> userIDs = new ArrayList<>();
|
|
|
|
+ userIDs.add(sendID);
|
|
|
|
+ openImEditConversationDTO.setUserIDs(userIDs);
|
|
|
|
+ OpenImConversationDTO openImConversationDTO = new OpenImConversationDTO();
|
|
|
|
+ openImConversationDTO.setConversationID("si_"+sendID+"_"+recvID);
|
|
|
|
+ openImConversationDTO.setConversationType(1);
|
|
|
|
+ openImConversationDTO.setUserID(recvID);
|
|
|
|
+ openImConversationDTO.setEx(ex);
|
|
|
|
+ log.info("更新到会话的ex的值:{}",ex);
|
|
|
|
+ openImEditConversationDTO.setConversation(openImConversationDTO);
|
|
|
|
+
|
|
|
|
+ OpenImResponseDTO openImResponseDTO1 = editConversation(openImEditConversationDTO);
|
|
|
|
+ log.info("修改回话返回参数:{}",openImResponseDTO1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return openImResponseDTO;
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 修改会话
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public OpenImResponseDTO editConversation(OpenImEditConversationDTO dto) throws JsonProcessingException, InterruptedException {
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
+ String requestBody = objectMapper.writeValueAsString(dto);
|
|
|
|
+
|
|
|
|
+ int retryCount = 0;
|
|
|
|
+ int maxRetries = 3;
|
|
|
|
+ OpenImResponseDTO responseDTO = null;
|
|
|
|
+
|
|
|
|
+ while (retryCount < maxRetries) {
|
|
|
|
+ try {
|
|
|
|
+ JSONObject jsonObject = new JSONObject(dto);
|
|
|
|
+ String body = HttpRequest.post("https://web.im.cdwjyyh.com/api/conversation/set_conversations")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonObject.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ responseDTO = JSONUtil.toBean(body, OpenImResponseDTO.class);
|
|
|
|
+
|
|
|
|
+ if (responseDTO.getErrCode() == 0) {
|
|
|
|
+ break; // 成功则退出重试
|
|
|
|
+ } else if (responseDTO.getErrCode() == 1501) {
|
|
|
|
+ adminToken = getAdminToken(); // 刷新token
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("修改会话失败,重试次数: {}", retryCount, e);
|
|
|
|
+ }
|
|
|
|
+ retryCount++;
|
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
|
+ Thread.sleep(1000 * retryCount); // 指数退避
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 检查两个用户是否存在好友关系
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO isFriend(String userID1, String userID2) {
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("userID1",userID1);
|
|
|
|
+ jsonObject.put("userID2",userID2);
|
|
|
|
+ String body = HttpRequest.post("https://web.im.cdwjyyh.com/api/friend/is_friend")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonObject.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ OpenImResponseDTO responseDTO= JSONUtil.toBean(body,OpenImResponseDTO.class);
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 添加好友
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public OpenImResponseDTO importFriend(String ownerUserID, List<String> friendUserIDs) {
|
|
|
|
+ //先检查用户是否存在好友关系
|
|
|
|
+ List<String> newFriendIds = new ArrayList<>();
|
|
|
|
+ for (String friendUserID : friendUserIDs) {
|
|
|
|
+ OpenImResponseDTO friend = isFriend(ownerUserID,friendUserID);
|
|
|
|
+ if (friend.getErrCode()==0){
|
|
|
|
+ Object data = friend.getData();
|
|
|
|
+ cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(data);
|
|
|
|
+ Boolean inUser1Friends = (Boolean)jsonObject.get("inUser1Friends");
|
|
|
|
+ Boolean inUser2Friends = (Boolean)jsonObject.get("inUser2Friends");
|
|
|
|
+ //如果不存在好友关系
|
|
|
|
+ if (!inUser1Friends&&!inUser2Friends){
|
|
|
|
+ newFriendIds.add(friendUserID);
|
|
|
|
+ //friendUserIDs.remove(friendUserID);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (newFriendIds.size()<=0){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("ownerUserID",ownerUserID);
|
|
|
|
+ jsonObject.put("friendUserIDs",newFriendIds);
|
|
|
|
+ String body = HttpRequest.post("https://web.im.cdwjyyh.com/api/friend/import_friend")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonObject.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ OpenImResponseDTO responseDTO= JSONUtil.toBean(body,OpenImResponseDTO.class);
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通用注册im
|
|
|
|
+ * @param userId
|
|
|
|
+ * @param type 1用户,2销售,3医生
|
|
|
|
+ * @return
|
|
|
|
+ */@Override
|
|
|
|
+ public R accountCheck(String userId,String type){
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
|
+ // 解析响应
|
|
|
|
+ if (StringUtil.isNotEmpty(adminToken)) {
|
|
|
|
+ //查询用户是否注册
|
|
|
|
+ /*switch (type){
|
|
|
|
+ case "1":
|
|
|
|
+ userId = "U"+userId;
|
|
|
|
+ break;
|
|
|
|
+ case "2":
|
|
|
|
+ userId = userId;
|
|
|
|
+ break;
|
|
|
|
+ case "3":
|
|
|
|
+ userId = userId;
|
|
|
|
+ break;
|
|
|
|
+ }*/
|
|
|
|
+ ArrayList<String> userIds = new ArrayList<>();
|
|
|
|
+ requestBody = new JSONObject();
|
|
|
|
+ userIds.add(userId);
|
|
|
|
+ requestBody.put("checkUserIDs", userIds);
|
|
|
|
+ String body = HttpRequest.post("https://web.im.cdwjyyh.com/api/user/account_check")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(requestBody.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ JSONObject jsonObject = new JSONObject(body);
|
|
|
|
+ JSONArray results = jsonObject.getJSONObject("data").getJSONArray("results");
|
|
|
|
+ if (results != null && results.length() > 0) {
|
|
|
|
+ JSONObject resultObj = results.getJSONObject(0);
|
|
|
|
+ int accountStatus = resultObj.getInt("accountStatus");
|
|
|
|
+ //未注册自动注册
|
|
|
|
+ if (accountStatus==0){
|
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
|
+ ArrayList<Object> users = new ArrayList<>();
|
|
|
|
+ String s = "";
|
|
|
|
+ switch (type){
|
|
|
|
+ case "2":
|
|
|
|
+ s = userId.replaceFirst("^C", "");
|
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(Long.parseLong(s));
|
|
|
|
+ if (null==companyUser){
|
|
|
|
+ return R.error("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ Company company = companyMapper.selectCompanyById(companyUser.getCompanyId());
|
|
|
|
+ map.put("userID",userId);
|
|
|
|
+ map.put("nickname",companyUser.getImNickName());
|
|
|
|
+ map.put("faceURL",companyUser.getAvatar());
|
|
|
|
+ break;
|
|
|
|
+ case "1":
|
|
|
|
+ s = userId.replaceFirst("^U", "");
|
|
|
|
+ FsUser fsUser = fsUserMapper.selectFsUserByUserId(Long.parseLong(s));
|
|
|
|
+ if (null==fsUser){
|
|
|
|
+ return R.error("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ map.put("userID",userId);
|
|
|
|
+ map.put("nickname",StringUtils.isEmpty(fsUser.getNickName())?"微信用户":fsUser.getNickName());
|
|
|
|
+ map.put("faceURL",fsUser.getAvatar());
|
|
|
|
+ break;
|
|
|
|
+ case "3":
|
|
|
|
+ s = userId.replaceFirst("^D", "");
|
|
|
|
+ FsDoctor fsDoctor = fsDoctorMapper.selectFsDoctorByDoctorId(Long.parseLong(s));
|
|
|
|
+ if (null==fsDoctor){
|
|
|
|
+ return R.error("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ map.put("userID",userId);
|
|
|
|
+ map.put("nickname",fsDoctor.getDoctorName());
|
|
|
|
+ map.put("faceURL",fsDoctor.getAvatar());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ users.add(map);
|
|
|
|
+ requestBody = new JSONObject();
|
|
|
|
+ userIds.add(userId);
|
|
|
|
+ requestBody.put("users", users);
|
|
|
|
+ HttpRequest.post("https://web.im.cdwjyyh.com/api/user/user_register")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken).body(requestBody.toString()).execute().body();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return R.error("返回结果为空");
|
|
|
|
+ }
|
|
|
|
+ /* HashMap<String, String> tokenMap = new HashMap<>();
|
|
|
|
+ tokenMap.put("platformID","1");
|
|
|
|
+ tokenMap.put("userID",userId);*/
|
|
|
|
+ requestBody = new JSONObject();
|
|
|
|
+ requestBody.put("platformID",5);
|
|
|
|
+ requestBody.put("userID",userId);
|
|
|
|
+ String body1 = HttpRequest.post("https://web.im.cdwjyyh.com/api/auth/get_user_token")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(requestBody.toString()).execute().body();
|
|
|
|
+ JSONObject userJson = new JSONObject(body1);
|
|
|
|
+ Integer errCode = (Integer)userJson.get("errCode");
|
|
|
|
+ if (errCode==0){
|
|
|
|
+ JSONObject userData = userJson.getJSONObject("data");
|
|
|
|
+ String userToken = userData.getString("token");
|
|
|
|
+ return R.ok().put("token", userToken);
|
|
|
|
+ }
|
|
|
|
+ return R.error("注册失败");
|
|
|
|
+ } else {
|
|
|
|
+ return R.error("获取管理员token失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @Async
|
|
|
|
+ @Override
|
|
|
|
+ public void checkAndImportFriend(Long companyUserId,String fsUserId) {
|
|
|
|
+ try {
|
|
|
|
+ // 注册账号
|
|
|
|
+ accountCheck("C" + companyUserId, "2");
|
|
|
|
+ accountCheck("U"+fsUserId, "1");
|
|
|
|
+
|
|
|
|
+ // 导入好友关系
|
|
|
|
+ ArrayList<String> userIds = new ArrayList<>();
|
|
|
|
+ userIds.add("U" + fsUserId);
|
|
|
|
+ importFriend("C" + companyUserId, userIds);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("异步执行IM注册/添加好友失败:", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ @Override
|
|
|
|
+ public void checkAndImportFriendByDianBo(Long companyUserId,String fsUserId,String cropId) {
|
|
|
|
+ try {
|
|
|
|
+ // 注册账号
|
|
|
|
+ accountCheck("C" + companyUserId, "2");
|
|
|
|
+ accountCheck("U"+fsUserId, "1");
|
|
|
|
+
|
|
|
|
+ // 导入好友关系
|
|
|
|
+ ArrayList<String> userIds = new ArrayList<>();
|
|
|
|
+ userIds.add("U" + fsUserId);
|
|
|
|
+ importFriend("C" + companyUserId, userIds);
|
|
|
|
+ updateFriendByDianBo("C" + companyUserId, userIds,cropId);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("异步执行IM注册/添加好友失败:", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改好友信息
|
|
|
|
+ * @param ownerUserID
|
|
|
|
+ * @param friendUserIDs
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public OpenImResponseDTO updateFriendByDianBo(String ownerUserID, List<String> friendUserIDs,String cropId) {
|
|
|
|
+ //先检查用户是否存在好友关系
|
|
|
|
+ //List<String> newFriendIds = new ArrayList<>();
|
|
|
|
+ for (String friendUserID : friendUserIDs) {
|
|
|
|
+ OpenImResponseDTO friend = isFriend(ownerUserID,friendUserID);
|
|
|
|
+ if (friend.getErrCode()==0){
|
|
|
|
+ Object data = friend.getData();
|
|
|
|
+ cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(data);
|
|
|
|
+ Boolean inUser1Friends = (Boolean)jsonObject.get("inUser1Friends");
|
|
|
|
+ Boolean inUser2Friends = (Boolean)jsonObject.get("inUser2Friends");
|
|
|
|
+ //如果不存在好友关系,则不执行im修改好友信息
|
|
|
|
+ if (!inUser1Friends&&!inUser2Friends){
|
|
|
|
+ return null;
|
|
|
|
+ //friendUserIDs.remove(friendUserID);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<String> remark = qwExternalContactMapper.selectRemarkByCompanyUserAndFsUser(friendUserIDs.get(0).replaceFirst("^U", ""), ownerUserID.replaceFirst("^C", ""),cropId);
|
|
|
|
+ if (CollectionUtils.isEmpty(remark)||remark.size()<=0){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String adminToken = getAdminToken();
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("ownerUserID",ownerUserID);
|
|
|
|
+ jsonObject.put("friendUserIDs",friendUserIDs);
|
|
|
|
+ jsonObject.put("remark",remark.get(0));
|
|
|
|
+ String body = HttpRequest.post("https://web.im.cdwjyyh.com/api/friend/update_friends")
|
|
|
|
+ .header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
|
+ .header("token", adminToken)
|
|
|
|
+ .body(jsonObject.toString())
|
|
|
|
+ .execute()
|
|
|
|
+ .body();
|
|
|
|
+ OpenImResponseDTO responseDTO= JSONUtil.toBean(body,OpenImResponseDTO.class);
|
|
|
|
+ return responseDTO;
|
|
|
|
+ }
|
|
|
|
+}
|