|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.baidu.dev2.thirdparty.jackson.databind.JsonMappingException;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
@@ -16,6 +17,7 @@ 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.config.saas.ProjectConfig;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.domain.FsUserCompanyUser;
|
|
|
import com.fs.course.domain.FsUserCourse;
|
|
|
@@ -33,7 +35,6 @@ 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.domain.FsImMsgSendDetail;
|
|
|
import com.fs.im.domain.FsImMsgSendLog;
|
|
|
import com.fs.im.domain.ImSendLog;
|
|
|
@@ -45,6 +46,8 @@ 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.fs.system.domain.SysConfig;
|
|
|
+import com.fs.system.mapper.SysConfigMapper;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
import com.google.common.base.Joiner;
|
|
|
import lombok.Data;
|
|
|
@@ -67,8 +70,6 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class OpenIMServiceImpl implements OpenIMService {
|
|
|
- @Autowired
|
|
|
- IMConfig imConfig;
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
@Autowired
|
|
|
@@ -102,14 +103,30 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
private FsImMsgSendDetailServiceImpl fsImMsgSendDetailServiceImpl;
|
|
|
@Autowired
|
|
|
private FsCourseWatchLogMapper fsCourseWatchLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
+ /**
|
|
|
+ * 查询配置文件
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProjectConfig.OpenIM getImConfig(){
|
|
|
+
|
|
|
+ String configKey = "projectConfig";
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey(configKey);
|
|
|
|
|
|
+ ProjectConfig projectConfig = com.alibaba.fastjson.JSONObject.parseObject(sysConfig.getConfigValue(),ProjectConfig.class);
|
|
|
|
|
|
+ ProjectConfig.OpenIM im = projectConfig.getOpenIM();
|
|
|
+ return im;
|
|
|
+ }
|
|
|
// @Value("${openIM.prefix}")
|
|
|
// private String openImPrefix;
|
|
|
/*@Autowired
|
|
|
private IFsUserService fsUserService;*/
|
|
|
@Override
|
|
|
public String getAdminToken() {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
Object cachedTokenObj = redisCache.getCacheObject("openImAdminToken:" + imConfig.getUserID());
|
|
|
if (cachedTokenObj != null) {
|
|
|
return cachedTokenObj.toString();
|
|
|
@@ -120,7 +137,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
String adminToken = null;
|
|
|
// 发起 HTTP POST 请求,获取管理员 token
|
|
|
try {
|
|
|
- String response = HttpRequest.post(IMConfig.URL+"/auth/get_admin_token")
|
|
|
+ String response = HttpRequest.post(imConfig.getUrl()+"/auth/get_admin_token")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.body(requestBody.toString())
|
|
|
.execute()
|
|
|
@@ -288,6 +305,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
}
|
|
|
|
|
|
private String getIMList( String recvID,String conversationId) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
int pageNumber = 1;
|
|
|
int pageSize = 20;
|
|
|
int maxPages = 10; // 最大搜索页数,防止无限循环
|
|
|
@@ -300,7 +318,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
pagination.put("pageNumber", pageNumber);
|
|
|
pagination.put("showNumber", pageSize);
|
|
|
requestBody.put("pagination", pagination);
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/conversation/get_owner_conversation")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/conversation/get_owner_conversation")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(requestBody.toString())
|
|
|
@@ -338,93 +356,6 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
}
|
|
|
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(IMConfig.URL+"/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(IMConfig.URL+"/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(IMConfig.URL+"/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
|
|
|
@@ -432,6 +363,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
*/
|
|
|
@Override
|
|
|
public OpenImResponseDTO updateUserInfo(CompanyUser companyUser){
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
String adminToken = getAdminToken();
|
|
|
long time = System.currentTimeMillis();
|
|
|
OpenImResponseDTO responseDTO = null;
|
|
|
@@ -441,7 +373,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
paramMap.put("userIDs", userIDs);
|
|
|
|
|
|
String jsonBody = JSONUtil.toJsonStr(paramMap);
|
|
|
- String result1 = HttpRequest.post(IMConfig.URL+"/user/get_users_info")
|
|
|
+ String result1 = HttpRequest.post(imConfig.getUrl()+"/user/get_users_info")
|
|
|
.header("operationID", String.valueOf(time))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonBody)
|
|
|
@@ -463,7 +395,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
Map<String, Object> bodyMap = new HashMap<>();
|
|
|
bodyMap.put("userInfo", updateUserInfo);
|
|
|
String jsonBody1 = JSONUtil.toJsonStr(bodyMap);
|
|
|
- String result2 = HttpRequest.post(IMConfig.URL+"/user/update_user_info_ex")
|
|
|
+ String result2 = HttpRequest.post(imConfig.getUrl()+"/user/update_user_info_ex")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonBody1)
|
|
|
@@ -496,10 +428,11 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
|
|
|
@Override
|
|
|
public OpenImResponseDTO openIMSendMsg(OpenImMsgDTO openImMsgDTO) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
log.info("进入发消息的方法");
|
|
|
String adminToken = getAdminToken();
|
|
|
JSONObject jsonObject = new JSONObject(openImMsgDTO);
|
|
|
- String url = IMConfig.URL+"/msg/send_msg";
|
|
|
+ String url = imConfig.getUrl()+"/msg/send_msg";
|
|
|
log.info("请求url: {}",url);
|
|
|
log.info("发送消息的请求体:\n{}", jsonObject.toString());
|
|
|
long time = new Date().getTime();
|
|
|
@@ -811,7 +744,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
String adminToken = getAdminToken();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
String requestBody = objectMapper.writeValueAsString(dto);
|
|
|
-
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
int retryCount = 0;
|
|
|
int maxRetries = 3;
|
|
|
OpenImResponseDTO responseDTO = null;
|
|
|
@@ -819,7 +752,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
while (retryCount < maxRetries) {
|
|
|
try {
|
|
|
JSONObject jsonObject = new JSONObject(dto);
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/conversation/set_conversations")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/conversation/set_conversations")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonObject.toString())
|
|
|
@@ -847,11 +780,12 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
*/
|
|
|
@Override
|
|
|
public OpenImResponseDTO isFriend(String userID1, String userID2) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
String adminToken = getAdminToken();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("userID1",userID1);
|
|
|
jsonObject.put("userID2",userID2);
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/friend/is_friend")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/friend/is_friend")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonObject.toString())
|
|
|
@@ -865,6 +799,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
*/
|
|
|
@Override
|
|
|
public OpenImResponseDTO importFriend(String ownerUserID, List<String> friendUserIDs) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
//先检查用户是否存在好友关系
|
|
|
List<String> newFriendIds = new ArrayList<>();
|
|
|
for (String friendUserID : friendUserIDs) {
|
|
|
@@ -888,7 +823,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("ownerUserID",ownerUserID);
|
|
|
jsonObject.put("friendUserIDs",newFriendIds);
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/friend/import_friend")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/friend/import_friend")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonObject.toString())
|
|
|
@@ -905,6 +840,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
* @return
|
|
|
*/@Override
|
|
|
public R accountCheck(String userId,String type){
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
String adminToken = getAdminToken();
|
|
|
JSONObject requestBody = new JSONObject();
|
|
|
// 解析响应
|
|
|
@@ -925,7 +861,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
requestBody = new JSONObject();
|
|
|
userIds.add(userId);
|
|
|
requestBody.put("checkUserIDs", userIds);
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/user/account_check")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/user/account_check")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(requestBody.toString())
|
|
|
@@ -986,7 +922,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
requestBody = new JSONObject();
|
|
|
userIds.add(userId);
|
|
|
requestBody.put("users", users);
|
|
|
- HttpRequest.post(IMConfig.URL+"/user/user_register")
|
|
|
+ HttpRequest.post(imConfig.getUrl()+"/user/user_register")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken).body(requestBody.toString()).execute().body();
|
|
|
}
|
|
|
@@ -1001,7 +937,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
requestBody = new JSONObject();
|
|
|
requestBody.put("platformID",5);
|
|
|
requestBody.put("userID",userId);
|
|
|
- String body1 = HttpRequest.post(IMConfig.URL+"/auth/get_user_token")
|
|
|
+ String body1 = HttpRequest.post(imConfig.getUrl()+"/auth/get_user_token")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(requestBody.toString()).execute().body();
|
|
|
@@ -1062,10 +998,11 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public OpenImResponseDTO openIMBatchSendMsg(OpenImBatchMsgDTO openImBatchMsgDTO) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
log.info("========================== 批量发送消息 ==========================");
|
|
|
String adminToken = getAdminToken();
|
|
|
JSONObject jsonObject = new JSONObject(openImBatchMsgDTO);
|
|
|
- String url = IMConfig.URL+"/msg/batch_send_msg";
|
|
|
+ String url = imConfig.getUrl()+"/msg/batch_send_msg";
|
|
|
log.info("请求url: {},\n请求参数:{}", url, jsonObject);
|
|
|
long timestamp = System.currentTimeMillis();
|
|
|
log.info("请求header,operationID:{},token:{}", timestamp, adminToken);
|
|
|
@@ -1479,6 +1416,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
* @return
|
|
|
*/
|
|
|
public OpenImResponseDTO updateFriendByDianBo(String ownerUserID, List<String> friendUserIDs,String cropId) {
|
|
|
+ ProjectConfig.OpenIM imConfig = getImConfig();
|
|
|
//先检查用户是否存在好友关系
|
|
|
//List<String> newFriendIds = new ArrayList<>();
|
|
|
for (String friendUserID : friendUserIDs) {
|
|
|
@@ -1504,7 +1442,7 @@ public class OpenIMServiceImpl implements OpenIMService {
|
|
|
jsonObject.put("ownerUserID",ownerUserID);
|
|
|
jsonObject.put("friendUserIDs",friendUserIDs);
|
|
|
jsonObject.put("remark",remark.get(0));
|
|
|
- String body = HttpRequest.post(IMConfig.URL+"/friend/update_friends")
|
|
|
+ String body = HttpRequest.post(imConfig.getUrl()+"/friend/update_friends")
|
|
|
.header("operationID", String.valueOf(System.currentTimeMillis()))
|
|
|
.header("token", adminToken)
|
|
|
.body(jsonObject.toString())
|