From 26fadbe307e0530d28128554405a4888ce1a1806 Mon Sep 17 00:00:00 2001 From: jqb Date: Mon, 20 Jul 2026 13:38:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(archive):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=E4=BD=93=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E5=AE=A2=E6=88=B7=E6=98=B5=E7=A7=B0=E4=B8=8E?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=82=AC=E6=B5=AE=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 前端:为发送人、接收人列添加悬浮提示展示完整ID,移除无用的消息动作列 2. 后端:新增企微客户昵称补全逻辑,实时拉取并更新数据库中缺失的客户名称 --- .../service/ArchiveSessionService.java | 43 +++++++++++++++++++ frontend/admin/src/pages/ArchiveList.tsx | 33 ++++++-------- 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/backend/archive-service/src/main/java/com/artedu/archive/service/ArchiveSessionService.java b/backend/archive-service/src/main/java/com/artedu/archive/service/ArchiveSessionService.java index 83c3286..d1b8020 100644 --- a/backend/archive-service/src/main/java/com/artedu/archive/service/ArchiveSessionService.java +++ b/backend/archive-service/src/main/java/com/artedu/archive/service/ArchiveSessionService.java @@ -1,5 +1,6 @@ package com.artedu.archive.service; +import com.artedu.archive.client.WeComApiClient; import com.artedu.archive.entity.ArchiveMessage; import com.artedu.archive.entity.Customer; import com.artedu.archive.entity.Staff; @@ -44,6 +45,9 @@ public class ArchiveSessionService { @Autowired private ArchiveMessageMapper archiveMessageMapper; + @Autowired + private WeComApiClient weComApiClient; + private static final java.time.format.DateTimeFormatter TIME_FORMATTER = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -80,9 +84,48 @@ public class ArchiveSessionService { Page pageResult = customerMapper.selectPage(new Page<>(page, size), wrapper); List list = pageResult.getRecords().stream().map(this::convertCustomerVO).collect(Collectors.toList()); + enrichCustomerNames(list); return PageResult.of(page, size, pageResult.getTotal(), list); } + /** + * 补全客户昵称:对名字为空或仍为 ID 的外部客户,实时从企微获取并更新数据库 + */ + private void enrichCustomerNames(List list) { + if (list == null || list.isEmpty()) { + return; + } + for (CustomerSessionVO vo : list) { + String customerId = vo.getCustomerId(); + String name = vo.getName(); + if (!isExternalUserId(customerId) || (name != null && !name.trim().isEmpty() && !customerId.equals(name))) { + continue; + } + try { + Map detail = weComApiClient.getExternalContact(customerId); + if (detail == null || detail.isEmpty()) { + continue; + } + Map contact = (Map) detail.get("external_contact"); + if (contact == null) { + continue; + } + String fetchedName = (String) contact.get("name"); + if (fetchedName == null || fetchedName.trim().isEmpty()) { + continue; + } + vo.setName(fetchedName); + Customer customer = customerMapper.selectByCustomerId(customerId, corpId); + if (customer != null) { + customer.setName(fetchedName); + customerMapper.updateById(customer); + } + } catch (Exception e) { + log.warn("实时获取客户昵称失败: customerId={}", customerId, e); + } + } + } + /** * 员工的会话列表 */ diff --git a/frontend/admin/src/pages/ArchiveList.tsx b/frontend/admin/src/pages/ArchiveList.tsx index b403ce6..7a317ce 100644 --- a/frontend/admin/src/pages/ArchiveList.tsx +++ b/frontend/admin/src/pages/ArchiveList.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react' -import { Table, Input, Select, Tag, Space, Card, Statistic, Row, Col, Button } from 'antd' +import { Table, Input, Select, Tag, Space, Card, Statistic, Row, Col, Button, Tooltip } from 'antd' import { MessageOutlined, FileTextOutlined, PictureOutlined, AudioOutlined, VideoCameraOutlined, FileOutlined, LinkOutlined, EnvironmentOutlined, SmileOutlined, AppstoreOutlined, WechatOutlined } from '@ant-design/icons' import request from '../utils/request' @@ -45,12 +45,6 @@ export default function ArchiveList() { EXTERNAL: '客户', } - const actionMap: Record = { - send: '发送消息', - recall: '撤回消息', - switch: '切换企业', - } - const loadData = async (page = 1, pageSize = 20) => { setLoading(true) try { @@ -260,7 +254,9 @@ export default function ArchiveList() { dataIndex: 'fromUser', width: 120, render: (fromUser: string, record: any) => ( - {record.fromUserName || fromUser} + + {record.fromUserName || fromUser} + ), }, { @@ -280,23 +276,20 @@ export default function ArchiveList() { width: 160, render: (time: string) => {time}, }, - { - title: '消息动作', - dataIndex: 'action', - width: 90, - align: 'center' as const, - render: (action: string) => {actionMap[action] || action}, - }, { title: '接收人', dataIndex: 'toUser', width: 200, ellipsis: true, - render: (_: any, record: any) => ( - - {parseReceivers(record.toUser, record.tolist)} - - ), + render: (_: any, record: any) => { + const ids = parseReceivers(record.toUser, record.tolist) + const names = record.toUserName || ids + return ( + + {names} + + ) + }, }, ]