Browse Source

修改域名功能、转接客服功能

master
[yxf] 3 weeks ago
parent
commit
924b74b3b2
  1. 3
      im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java
  2. 46
      im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java
  3. 84
      im-uniapp/App.vue
  4. 44
      im-uniapp/pages/chat/chat-box.vue
  5. 30
      im-uniapp/pages/login/login.vue
  6. 1144
      im-uniapp/store/chatStore.js

3
im-platform/src/main/java/com/bx/implatform/service/impl/FriendServiceImpl.java

@ -107,7 +107,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
log.info("删除好友,用户id:{},好友id:{}", userId, friendId); log.info("删除好友,用户id:{},好友id:{}", userId, friendId);
} }
@Cacheable(key = "#userId1+':'+#userId2") // @Cacheable(key = "#userId1+':'+#userId2")
@Override @Override
public Boolean isFriend(Long userId1, Long userId2) { public Boolean isFriend(Long userId1, Long userId2) {
LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<Friend> wrapper = Wrappers.lambdaQuery();
@ -117,6 +117,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
return this.exists(wrapper); return this.exists(wrapper);
} }
/** /**
* 单向绑定好友关系 * 单向绑定好友关系
* *

46
im-platform/src/main/java/com/bx/implatform/service/impl/PlatformConfigurationServiceImpl.java

@ -1,7 +1,5 @@
package com.bx.implatform.service.impl; package com.bx.implatform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bx.implatform.entity.PlatformConfiguration; import com.bx.implatform.entity.PlatformConfiguration;
import com.bx.implatform.mapper.PlatformConfigurationMapper; import com.bx.implatform.mapper.PlatformConfigurationMapper;
@ -11,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -25,23 +25,51 @@ public class PlatformConfigurationServiceImpl extends ServiceImpl<PlatformConfig
return null; return null;
} }
List<String> inputDomains = Arrays.stream(sourceUrl.split("\n")) List<String> inputList = Arrays.stream(sourceUrl.split("\n"))
.map(String::trim) .map(String::trim)
.filter(StringUtils::hasText) .filter(StringUtils::hasText)
.toList(); .toList();
List<PlatformConfiguration> allConfigs = this.list(); List<PlatformConfiguration> allConfigs = this.list();
for (String input : inputDomains) { for (String input : inputList) {
for (PlatformConfiguration config : allConfigs) { try {
String dbDomain = config.getDomainName(); String inputHost = extractHost(input);
if (StringUtils.hasText(dbDomain) && dbDomain.contains(input)) { if (inputHost == null) continue;
log.info("【匹配成功】平台:{},匹配规则:{}", config.getPlatformName(), input);
return config.getPlatformName(); for (PlatformConfiguration config : allConfigs) {
String dbDomain = config.getDomainName();
if (!StringUtils.hasText(dbDomain)) continue;
String dbHost = extractHost(dbDomain);
if (inputHost.equals(dbHost)) {
log.info("【精确匹配成功】平台:{},匹配域名:{}", config.getPlatformName(), inputHost);
return config.getPlatformName();
}
} }
} catch (Exception e) {
log.warn("解析域名失败: {}", input);
} }
} }
return null; return null;
} }
/**
* 通用提取纯净域名方法
*/
private String extractHost(String urlStr) {
try {
// 如果不是http开头,手动补全,防止报错
if (!urlStr.startsWith("http")) {
urlStr = "http://" + urlStr;
}
URL url = new URL(urlStr);
return url.getHost();
} catch (MalformedURLException e) {
return null;
}
}
} }

84
im-uniapp/App.vue

@ -42,7 +42,9 @@ export default {
this.configStore.setAppInit(true); this.configStore.setAppInit(true);
} }
}); });
// console.log(cmd, msgInfo);
wsApi.onMessage((cmd, msgInfo) => { wsApi.onMessage((cmd, msgInfo) => {
console.log(cmd, msgInfo);
if (cmd == 2) { if (cmd == 2) {
// 线 // 线
// uni.showModal({ // uni.showModal({
@ -79,40 +81,17 @@ export default {
this.configStore.setAppInit(false); this.configStore.setAppInit(false);
} }
}) })
wsApi.onMessage((cmd, msgInfo) => {
if (cmd == 2) {
//
this.exit();
} else if (cmd == 3) {
//
this.handlePrivateMessage(msgInfo);
} else if (cmd == 4) {
//
this.handleGroupMessage(msgInfo);
} else if (cmd == 5) {
//
this.handleSystemMessage(msgInfo);
} else if (cmd == 6) {
//
this.handleCustomerChanged(msgInfo);
}
});
}, },
// //
//
handleCustomerChanged(msgInfo) { handleCustomerChanged(msgInfo) {
console.log('【客服转接】后台下发变更通知', msgInfo);
// msgInfo oldKfId idnewKfId id
const oldKfId = msgInfo.oldKfId; const oldKfId = msgInfo.oldKfId;
const newKfId = msgInfo.newKfId; const newKfId = msgInfo.newKfId;
// ========== -> ==========
if (oldKfId && newKfId && oldKfId != newKfId) { if (oldKfId && newKfId && oldKfId != newKfId) {
const oldChat = this.chatStore.findChatByFriend(oldKfId); const oldChat = this.chatStore.findChatByFriend(oldKfId);
const newChat = this.chatStore.findChatByFriend(newKfId); const newChat = this.chatStore.findChatByFriend(newKfId);
if (oldChat && oldChat.messages.length > 0) { if (oldChat && oldChat.messages.length > 0) {
console.log('【开始强制合并】旧客服', oldKfId, '→ 新客服', newKfId);
// //
this.chatStore.mergeOldCustomerToNew(oldKfId, newKfId); this.chatStore.mergeOldCustomerToNew(oldKfId, newKfId);
} }
@ -212,34 +191,40 @@ export default {
}) })
}, },
handlePrivateMessage(msg) { handlePrivateMessage(msg) {
//
msg.selfSend = msg.sendId == this.userStore.userInfo.id; msg.selfSend = msg.sendId == this.userStore.userInfo.id;
// id // id
let friendId = msg.selfSend ? msg.recvId : msg.sendId; let friendId = msg.selfSend ? msg.recvId : msg.sendId;
// if (!msg.selfSend) {
let existingFriend = this.friendStore.findFriend(friendId); let friend = this.friendStore.findFriend(friendId);
if (!existingFriend && !msg.selfSend) { if (!friend) {
console.log("收到未知用户消息,刷新应用:", friendId); this.chatStore.forceMergeAllOldCustomerToNew(friendId);
this.loadStore().then(() => { //
// #ifdef H5 uni.showToast({
window.location.reload(); title: "客服已更换,刷新中...",
// #endif icon: "none",
duration: 1500
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef MP-WEIXIN
uni.reLaunch({
url: '/pages/chat/chat'
}); });
// #endif
}); setTimeout(() => {
// #ifdef H5
return; window.location.reload();
// #endif
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef MP-WEIXIN
uni.reLaunch({
url: '/pages/chat/chat'
});
// #endif
}, 800);
// return;
}
} }
// //
let chatInfo = { let chatInfo = {
@ -470,7 +455,6 @@ export default {
return group; return group;
}, },
exit() { exit() {
console.log("exit");
this.isExit = true; this.isExit = true;
wsApi.close(3099); wsApi.close(3099);
uni.removeStorageSync("loginInfo"); uni.removeStorageSync("loginInfo");
@ -543,7 +527,6 @@ export default {
this.pullOfflineMessage(); this.pullOfflineMessage();
this.configStore.setAppInit(true); this.configStore.setAppInit(true);
}).catch((e) => { }).catch((e) => {
console.log(e);
this.exit(); this.exit();
}) })
}, },
@ -585,14 +568,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
const btn = document.querySelector('.btn-send'); const btn = document.querySelector('.btn-send');
if (btn) { if (btn) {
console.log('按钮找到:', btn);
//
const listeners = getEventListeners?.(btn); const listeners = getEventListeners?.(btn);
console.log('按钮事件监听器:', listeners);
//
btn.addEventListener('click', (e) => { btn.addEventListener('click', (e) => {
console.log('原生点击事件触发');
this.sendTextMessage(); this.sendTextMessage();
}); });
} }

44
im-uniapp/pages/chat/chat-box.vue

@ -227,7 +227,10 @@
<script> <script>
import UNI_APP from "@/.env.js"; import UNI_APP from "@/.env.js";
import useFriendStore from "@/store/friendStore.js";
import useUserStore from "@/store/userStore.js";
import useChatStore from "@/store/chatStore.js";
import useGroupStore from "@/store/groupStore.js";
export default { export default {
data() { data() {
return { return {
@ -285,6 +288,43 @@ export default {
}; };
}, },
methods: { methods: {
//
autoMergeOldCustomerOnRefresh() {
try {
const userStore = useUserStore();
const chatStore = useChatStore();
if (!this.isPrivate || !userStore.userInfo?.id) return;
const currentKfId = this.currentTargetId;
if (!currentKfId) return;
//
chatStore.forceMergeAllOldCustomerToNew(currentKfId);
//
setTimeout(() => {
this.reloadChatMessages(currentKfId);
}, 300);
} catch (e) {
console.log("自动合并失败", e);
}
},
reloadChatMessages(targetId) {
try {
const chat = this.chatStore.chats.find(
(c) => c.targetId == targetId && c.type === "PRIVATE"
);
if (chat) {
// 500
this.$forceUpdate();
this.$nextTick(() => {
this.scrollToBottom();
});
}
} catch (e) {}
},
// //
selectLang(lang) { selectLang(lang) {
this.currentLang = lang; this.currentLang = lang;
@ -1656,7 +1696,7 @@ export default {
await this.getSetting(); await this.getSetting();
this.$nextTick(() => this.scrollToBottom()); this.$nextTick(() => this.scrollToBottom());
this.autoMergeOldCustomerOnRefresh();
} catch (err) { } catch (err) {
console.error("错误:", err); console.error("错误:", err);
} finally { } finally {

30
im-uniapp/pages/login/login.vue

@ -20,24 +20,28 @@ export default {
password: '', password: '',
ip: '', ip: '',
sourceUrl: '', sourceUrl: '',
uniqueToken: '' ,// token uniqueToken: '',
kefuid: '' // ID kefuid: ''
} }
} }
}, },
methods: { methods: {
// //
getSourceUrl() { getSourceUrl() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options || {};
if (options.from) {
this.dataForm.sourceUrl = options.from;
}
// #ifdef H5 // #ifdef H5
this.dataForm.sourceUrl = window.location.origin; const referrer = document.referrer;
if (referrer) {
this.dataForm.sourceUrl = referrer;
} else {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options || {};
if (options.from) {
this.dataForm.sourceUrl = options.from;
} else {
this.dataForm.sourceUrl = window.location.origin;
}
}
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -65,12 +69,10 @@ export default {
if (options.token) { if (options.token) {
this.dataForm.uniqueToken = options.token; this.dataForm.uniqueToken = options.token;
console.log("从options获取到token:", this.dataForm.uniqueToken);
} }
if (options.kefuid) { if (options.kefuid) {
this.dataForm.kefuid = options.kefuid; this.dataForm.kefuid = options.kefuid;
console.log("从options获取到kefuid:", this.dataForm.kefuid);
} }
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
@ -79,12 +81,10 @@ export default {
if (token) { if (token) {
this.dataForm.uniqueToken = token; this.dataForm.uniqueToken = token;
console.log("从URL解析获取到token:", this.dataForm.uniqueToken);
} }
if (kefuid) { if (kefuid) {
this.dataForm.kefuid = kefuid; this.dataForm.kefuid = kefuid;
console.log("从URL解析获取到kefuid:", this.dataForm.kefuid);
} }
// #endif // #endif

1144
im-uniapp/store/chatStore.js

File diff suppressed because it is too large
Loading…
Cancel
Save