feat: full-field display for group/call/sms (raw_json + drawers)

Mirrors the Customer/Message/Staff/Accounts pattern: backend exposes the
verbatim upstream record on the response schema; the frontend list shows
source-matching columns and a row-click opens an all-fields el-drawer with
Chinese-labeled camelCase keys (unknown keys roll up under 其他).

Backend (yunke-server/app/api/schemas.py)
- GroupOut / PhoneCallOut / SmsOut: add raw_json: dict[str, Any] | None
  (Pydantic v2 from_attributes picks up the existing ORM column).
- Tests: extend tests/test_api_{groups,calls,sms}.py with a per-schema
  raw_json round-trip assertion (phone_call + voice_call payload shapes
  both covered for calls).

Frontend (yunkes)
- src/utils/{groupFields,callFields,smsFields}.ts: 中文 label map +
  grouped sections + readField (structured-column preference) +
  toDisplayField (image / time / audio / bool / status / direction).
- src/api/types.ts: add raw_json to Group / PhoneCall / Sms.
- src/views/GroupList.vue: richer columns (群名/群ID/成员数/群主/归属微信/
  消息数/最近聊天/渠道) + all-fields drawer (chatRoomId/chatRoomName,
  memberCount/memberIds, headImageUrl, wechatId/wechatNickName,
  userName/userPhone/userId, messageCount/ownMessageCount,
  lossMembers/addMembers, lastChatTime/updateTime).
- src/views/CallList.vue: keeps existing columns + adds all-fields drawer
  (id/startCallTime, callDuration/callSeconds/ringTime, callStatus/
  incomingCall, userId/userIdName/departmentId, callNumber/simPhone/
  simNumber/imei, recordFile/isUpload/downloadCount/aiAsr/qcStatus/
  planCustomerName/version + voice-call extras ossFileName/duration/
  startTime/endTime/remark). Drawer plays recording inline via audio
  render kind; existing play-record dialog retained.
- src/views/SmsList.vue: keeps existing columns + adds all-fields drawer
  (id/customerPhone, sms/smsSub, sender, direction, userId/
  senderDepartment, receiveName, createTime, simPhone/simNumber, source)
  with a full-body preview block at the top.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-05 10:12:49 +08:00
parent fd86adfb63
commit 0d466c4e4a
11 changed files with 1442 additions and 92 deletions
+109
View File
@@ -73,10 +73,119 @@ async def test_default_list_returns_all_ordered_desc(make_client):
"call_number",
"sim_phone",
"record_file",
"raw_json",
):
assert key in body["items"][0]
async def test_raw_json_serializes_verbatim(make_client):
"""``raw_json`` round-trips the verbatim upstream call record.
Phone-call and voice-call payloads carry different camelCase shapes; both
must come back unmolested so the all-fields drawer can render every column
the 云客 通话记录 page shows. Rows without a blob serialize as JSON null.
"""
async def seed(session: AsyncSession) -> None:
await _seed(session)
session.add_all(
[
PhoneCall(
call_id="c_phone_raw",
channel="phone_call",
user_id="u1",
user_id_name="Alice",
start_call_time=9000,
call_duration=12,
call_status=2,
incoming_call=0,
raw_json={
"id": "c_phone_raw",
"startCallTime": 9000,
"callDuration": 12,
"callSeconds": 12,
"ringTime": 3,
"callStatus": 2,
"incomingCall": 0,
"userId": "u1",
"userIdName": "Alice",
"departmentId": "d1",
"callNumber": "13800000000",
"simPhone": "13900000000",
"simNumber": "1",
"imei": "356938035643809",
"recordFile": "https://oss/c_phone_raw.mp3",
"isUpload": 1,
"downloadCount": 2,
"aiAsr": "translated text",
"qcStatus": 1,
"planCustomerName": "Carol",
"version": "v1",
},
),
PhoneCall(
call_id="c_voice_raw",
channel="voice_call",
user_id="u2",
user_id_name="Bob",
start_call_time=9500,
call_duration=20,
raw_json={
"ossFileName": "voice/c_voice_raw.mp3",
"duration": 20,
"startTime": 9500,
"endTime": 9520,
"remark": "voice memo",
"userId": "u2",
},
),
]
)
await session.commit()
client = await make_client(seed)
r = await client.get("/api/calls", params={"start": 9000})
assert r.status_code == 200
by_id = {it["call_id"]: it for it in r.json()["items"]}
assert by_id["c_phone_raw"]["raw_json"] == {
"id": "c_phone_raw",
"startCallTime": 9000,
"callDuration": 12,
"callSeconds": 12,
"ringTime": 3,
"callStatus": 2,
"incomingCall": 0,
"userId": "u1",
"userIdName": "Alice",
"departmentId": "d1",
"callNumber": "13800000000",
"simPhone": "13900000000",
"simNumber": "1",
"imei": "356938035643809",
"recordFile": "https://oss/c_phone_raw.mp3",
"isUpload": 1,
"downloadCount": 2,
"aiAsr": "translated text",
"qcStatus": 1,
"planCustomerName": "Carol",
"version": "v1",
}
# Voice-call payload shape round-trips too.
assert by_id["c_voice_raw"]["raw_json"] == {
"ossFileName": "voice/c_voice_raw.mp3",
"duration": 20,
"startTime": 9500,
"endTime": 9520,
"remark": "voice memo",
"userId": "u2",
}
# Seeded without an explicit raw_json -> JSON null.
assert by_id.get("c3", {}).get("raw_json") is None
async def test_filter_by_user_id(make_client):
"""``?user_id=u1`` -> 2 calls for Alice."""
client = await make_client(_seed)
+70
View File
@@ -82,10 +82,80 @@ async def test_default_list_returns_all_ordered_desc(make_client):
"member_count",
"message_count",
"last_chat_time",
"raw_json",
):
assert key in body["items"][0]
async def test_raw_json_serializes_verbatim(make_client):
"""``raw_json`` round-trips the verbatim upstream chatroom record.
Seeded blobs must come back unmolested (every camelCase key preserved) so
the all-fields drawer can render every column the 云客 群管理 page shows.
Rows without a blob serialize as JSON null.
"""
async def seed(session: AsyncSession) -> None:
await _seed(session)
session.add(
ChatGroup(
room_id="room_raw@chatroom",
channel="wechat",
room_name="Raw Team",
owner_account_id="wx_owner_1",
member_count=4,
last_chat_time=9000,
raw_json={
"chatRoomId": "room_raw@chatroom",
"chatRoomName": "Raw Team",
"memberCount": 4,
"memberIds": "wx_a;wx_b;wx_c;wx_d",
"headImageUrl": "https://oss/raw.jpg",
"wechatId": "wx_owner_1",
"wechatNickName": "WxOne",
"userName": "owner_login",
"userPhone": "13800000000",
"userId": "u_owner",
"messageCount": 42,
"ownMessageCount": 7,
"lossMembers": 1,
"addMembers": 2,
"lastChatTime": 9000,
"updateTime": 9999,
},
)
)
await session.commit()
client = await make_client(seed)
r = await client.get("/api/groups", params={"owner_account_id": "wx_owner_1"})
assert r.status_code == 200
by_id = {it["room_id"]: it for it in r.json()["items"]}
raw = by_id["room_raw@chatroom"]["raw_json"]
assert raw == {
"chatRoomId": "room_raw@chatroom",
"chatRoomName": "Raw Team",
"memberCount": 4,
"memberIds": "wx_a;wx_b;wx_c;wx_d",
"headImageUrl": "https://oss/raw.jpg",
"wechatId": "wx_owner_1",
"wechatNickName": "WxOne",
"userName": "owner_login",
"userPhone": "13800000000",
"userId": "u_owner",
"messageCount": 42,
"ownMessageCount": 7,
"lossMembers": 1,
"addMembers": 2,
"lastChatTime": 9000,
"updateTime": 9999,
}
# Seeded without an explicit raw_json -> JSON null (not omitted, not error).
assert by_id["room_a@chatroom"]["raw_json"] is None
async def test_filter_by_channel_whatsapp(make_client):
"""``?channel=whatsapp`` -> the single WA group."""
client = await make_client(_seed)
+66
View File
@@ -69,10 +69,76 @@ async def test_default_list_returns_all_ordered_desc(make_client):
"receive_name",
"create_time",
"sim_phone",
"raw_json",
):
assert key in body["items"][0]
async def test_raw_json_serializes_verbatim(make_client):
"""``raw_json`` round-trips the verbatim upstream SMS record.
Every camelCase key must come back unmolested so the all-fields drawer can
render every column the 云客 短信记录 page shows. Rows without a blob
serialize as JSON null.
"""
async def seed(session: AsyncSession) -> None:
await _seed(session)
session.add(
Sms(
sms_id="s_raw",
channel="sms",
user_id="u1",
receive_name="Alice",
content_preview="raw body",
content="raw body full text",
create_time=9000,
direction=1,
customer_phone="999",
raw_json={
"id": "s_raw",
"customerPhone": "999",
"sms": "raw body full text",
"smsSub": "raw body",
"sender": "111",
"direction": 1,
"userId": "u1",
"senderDepartment": "Sales",
"receiveName": "Alice",
"createTime": 9000,
"simPhone": "13900000000",
"simNumber": "1",
"source": "yunke",
},
)
)
await session.commit()
client = await make_client(seed)
r = await client.get("/api/sms", params={"user_id": "u1"})
assert r.status_code == 200
by_id = {it["sms_id"]: it for it in r.json()["items"]}
assert by_id["s_raw"]["raw_json"] == {
"id": "s_raw",
"customerPhone": "999",
"sms": "raw body full text",
"smsSub": "raw body",
"sender": "111",
"direction": 1,
"userId": "u1",
"senderDepartment": "Sales",
"receiveName": "Alice",
"createTime": 9000,
"simPhone": "13900000000",
"simNumber": "1",
"source": "yunke",
}
# Seeded without an explicit raw_json -> JSON null.
assert by_id["s1"]["raw_json"] is None
async def test_filter_by_user_id(make_client):
"""``?user_id=u1`` -> 2 SMS for Alice."""
client = await make_client(_seed)