fix(dashboard): normalize legacy customer profile data

This commit is contained in:
wmq
2026-08-03 01:58:02 +08:00
parent d585fabb7a
commit 45b94374b0
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -1127,13 +1127,24 @@ const kinds = {
} }
function withDefaults(kind, body) { function withDefaults(kind, body) {
if (kind === 'customers') { if (kind === 'customers') {
const source = body && typeof body === 'object' ? body : {}
const value = { const value = {
name: '', company: '', country: '', channel: 'telegram', email: '', phone: '', name: '', company: '', country: '', channel: 'telegram', email: '', phone: '',
telegram: '', products: [], tags: [], source: 'telegram', stage: 'new', telegram: '', products: [], tags: [], source: 'telegram', stage: 'new',
intentScore: 0, intentLevel: 'low', sentiment: 'neutral', riskLevel: 'none', intentScore: 0, intentLevel: 'low', sentiment: 'neutral', riskLevel: 'none',
valueLevel: 'D', isKey: false, ownerId: null, valueLevel: 'D', isKey: false, ownerId: null,
aiProfile: { summary: '', keyPoints: [], nextActions: [] }, aiProfile: { summary: '', keyPoints: [], nextActions: [] },
...body, ...source,
products: Array.isArray(source.products) ? source.products : [],
tags: Array.isArray(source.tags) ? source.tags : [],
aiProfile: {
summary: '',
keyPoints: [],
nextActions: [],
...(source.aiProfile && typeof source.aiProfile === 'object' ? source.aiProfile : {}),
keyPoints: Array.isArray(source.aiProfile?.keyPoints) ? source.aiProfile.keyPoints : [],
nextActions: Array.isArray(source.aiProfile?.nextActions) ? source.aiProfile.nextActions : [],
},
} }
return { return {
...value, ...value,
@@ -4493,7 +4504,8 @@ async function businessDataset(tenantId) {
app.get('/api/dashboard/overview', async (req, res) => { app.get('/api/dashboard/overview', async (req, res) => {
const data = await businessDataset(req.auth.tenantId) const data = await businessDataset(req.auth.tenantId)
const { customers, conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data const { conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data
const customers = data.customers.map((customer) => withDefaults('customers', customer))
const unread = conversations.reduce((n, x) => n + Number(x.unreadCount || 0), 0) const unread = conversations.reduce((n, x) => n + Number(x.unreadCount || 0), 0)
const today = dateKey() const today = dateKey()
const won = opportunities.filter((item) => item.stage === 'won').length const won = opportunities.filter((item) => item.stage === 'won').length
+1 -1
View File
@@ -235,7 +235,7 @@ export function DashboardPage() {
<CountryFlag code={c.country} withName={false} /> <CountryFlag code={c.country} withName={false} />
</div> </div>
<p className="mt-0.5 truncate text-xs text-muted-foreground"> <p className="mt-0.5 truncate text-xs text-muted-foreground">
{c.products[0] ?? '—'} · 建议:{c.aiProfile.nextActions[0] ?? '跟进'} {c.products?.[0] ?? '—'} · 建议:{c.aiProfile?.nextActions?.[0] ?? '跟进'}
</p> </p>
</div> </div>
<div className="flex shrink-0 flex-col items-end gap-1"> <div className="flex shrink-0 flex-col items-end gap-1">