Commit 7818e75d authored by shiyu's avatar shiyu

用户修改头像和昵称同步到IM

parent 3bc0798f
...@@ -202,3 +202,4 @@ avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc3 ...@@ -202,3 +202,4 @@ avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc3
chat: chat:
model-url: https://xiaobai-fastapi.wanwudezhi.com/chat model-url: https://xiaobai-fastapi.wanwudezhi.com/chat
bing-search-url: https://xiaobai-fastapi.wanwudezhi.com/local_doc_qa/bing_search_chat
\ No newline at end of file
...@@ -199,3 +199,4 @@ avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc3 ...@@ -199,3 +199,4 @@ avatar-url: https://cdn.wanwudezhi.com/static/web-static/image/b888cc6cb9c004dc3
chat: chat:
model-url: https://xiaobai-fastapi.wanwudezhi.com/chat model-url: https://xiaobai-fastapi.wanwudezhi.com/chat
bing-search-url: https://xiaobai-fastapi.wanwudezhi.com/local_doc_qa/bing_search_chat
\ No newline at end of file
...@@ -17,6 +17,9 @@ public class ChatApi { ...@@ -17,6 +17,9 @@ public class ChatApi {
@Value("${chat.model-url}") @Value("${chat.model-url}")
private String chatModelUrl; private String chatModelUrl;
@Value("${chat.bing-search-url}")
private String bingSearchUrl;
public String chatWithModel(String question) { public String chatWithModel(String question) {
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(chatModelUrl); OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(chatModelUrl);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
...@@ -28,4 +31,17 @@ public class ChatApi { ...@@ -28,4 +31,17 @@ public class ChatApi {
logger.info("[chatWithModel] response :{}", responseStr); logger.info("[chatWithModel] response :{}", responseStr);
return responseStr; return responseStr;
} }
public String chatWithBingSearch(String question) {
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(bingSearchUrl);
Map<String, Object> map = new HashMap<>();
map.put("question", question);
map.put("history", null);
okHttpUtil.addParams(map);
okHttpUtil.post(true);
String responseStr = okHttpUtil.async();
logger.info("[chatWithModel] response :{}", responseStr);
return responseStr;
}
} }
...@@ -114,6 +114,7 @@ public class UserServiceImpl implements UserService { ...@@ -114,6 +114,7 @@ public class UserServiceImpl implements UserService {
AiAssistantDao aiAssistantDao; AiAssistantDao aiAssistantDao;
@Override @Override
public Result regCaptcha(UserRequestDto dto) { public Result regCaptcha(UserRequestDto dto) {
try { try {
...@@ -319,6 +320,14 @@ public class UserServiceImpl implements UserService { ...@@ -319,6 +320,14 @@ public class UserServiceImpl implements UserService {
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId()); String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60); redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改昵称成功"); logger.info("【请求结束】用户修改昵称成功");
//修改后的昵称同步到IM
Result synResult = chatUserApi.importUser(user);
if (synResult.getSuccess()) {
logger.info("用户id:{}, 修改后的昵称同步到IM成功", user.getId());
} else {
logger.error("用户id:{}, 修改后的昵称同步到IM失败 :{}", user.getId(), synResult.getErrmsg());
}
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("用户修改昵称失败", e); logger.error("用户修改昵称失败", e);
...@@ -342,6 +351,14 @@ public class UserServiceImpl implements UserService { ...@@ -342,6 +351,14 @@ public class UserServiceImpl implements UserService {
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId()); String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, resultUser, 2 * 60 * 60); redisUtil.set(userKey, resultUser, 2 * 60 * 60);
logger.info("【请求结束】用户修改头像成功"); logger.info("【请求结束】用户修改头像成功");
//修改后的头像同步到IM
Result synResult = chatUserApi.importUser(user);
if (synResult.getSuccess()) {
logger.info("用户id:{}, 修改后的头像同步到IM成功", user.getId());
} else {
logger.error("用户id:{}, 修改后的头像同步到IM失败 :{}", user.getId(), synResult.getErrmsg());
}
return Result.success(); return Result.success();
} catch (Exception e) { } catch (Exception e) {
logger.error("用户修改头像失败", e); logger.error("用户修改头像失败", e);
......
...@@ -57,6 +57,12 @@ public class ChatApiTest { ...@@ -57,6 +57,12 @@ public class ChatApiTest {
chatApi.chatWithModel(question); chatApi.chatWithModel(question);
} }
@Test
public void chatWithBingSearch() {
String question = "什么是站洋";
chatApi.chatWithBingSearch(question);
}
@Test @Test
public void getUserSig() { public void getUserSig() {
tlsSigApi.refreshUserSig("cjxc"); tlsSigApi.refreshUserSig("cjxc");
...@@ -136,7 +142,7 @@ public class ChatApiTest { ...@@ -136,7 +142,7 @@ public class ChatApiTest {
@Test @Test
public void getChatList() { public void getChatList() {
IMChatRequestDto imChatRequestDto = new IMChatRequestDto(); IMChatRequestDto imChatRequestDto = new IMChatRequestDto();
imChatRequestDto.setUserId(269L); imChatRequestDto.setUserId(238L);
conversationApi.getChatList(imChatRequestDto); conversationApi.getChatList(imChatRequestDto);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment