This commit is contained in:
van
2026-10-22 01:27:58 +08:00
parent 5bac007465
commit d61316fc62
2 changed files with 197 additions and 70 deletions
+13 -4
View File
@@ -9,13 +9,13 @@ export function previewOrderProfitStats(query) {
})
}
/** 套固定提示词调用已配置大模型;push=true 时推企微 */
/** 提交 AI 分析,接口立即返回,结果在调用记录里 */
export function analyzeOrderProfit(data) {
return request({
url: '/jarvis/order-profit-analysis/analyze',
method: 'post',
data,
timeout: 180000
timeout: 20000
})
}
@@ -28,13 +28,22 @@ export function latestOrderProfitAnalysis(periodType) {
})
}
/** 测试推送(分析当天/所选周期并推企微) */
/** 提交测试推送,接口立即返回 */
export function testOrderProfitPush(data) {
return request({
url: '/jarvis/order-profit-analysis/test',
method: 'post',
data,
timeout: 180000
timeout: 20000
})
}
/** 大模型调用记录:时间、耗时、返回 */
export function listOrderProfitCallLogs(limit) {
return request({
url: '/jarvis/order-profit-analysis/call-logs',
method: 'get',
params: { limit: limit || 30 }
})
}
+184 -66
View File
@@ -1,5 +1,5 @@
<template>
<div class="app-container profit-analysis" :class="{ 'profit-analysis--mobile': mobileLayout }" v-loading="loading">
<div class="app-container profit-analysis" :class="{ 'profit-analysis--mobile': mobileLayout }">
<el-card class="filter-card">
<div slot="header" class="filter-card-header">
<span class="filter-card-title">慢单利润 / 订单 AI 分析</span>
@@ -31,18 +31,18 @@
/>
</el-form-item>
<el-form-item v-if="!mobileLayout">
<el-button type="primary" icon="el-icon-search" @click="loadStats">预览统计</el-button>
<el-button type="success" icon="el-icon-magic-stick" :loading="analyzing" @click="runAnalyze(false)">AI 分析</el-button>
<el-button type="warning" icon="el-icon-s-promotion" :loading="analyzing" @click="runAnalyze(true)">分析并推送</el-button>
<el-button type="danger" plain icon="el-icon-position" :loading="testing" @click="runTest">测试推送</el-button>
<el-button icon="el-icon-time" @click="loadLatest">最近一次</el-button>
<el-button type="primary" icon="el-icon-search" :loading="statsLoading" @click="loadStats">预览统计</el-button>
<el-button type="success" icon="el-icon-magic-stick" :loading="submitting" @click="runAnalyze(false)">AI 分析</el-button>
<el-button type="warning" icon="el-icon-s-promotion" :loading="submitting" @click="runAnalyze(true)">分析并推送</el-button>
<el-button type="danger" plain icon="el-icon-position" :loading="submitting" @click="runTest">测试推送</el-button>
<el-button icon="el-icon-time" :loading="statsLoading" @click="loadLatest">最近一次</el-button>
</el-form-item>
<div v-else class="mobile-actions">
<el-button type="primary" icon="el-icon-search" @click="loadStats">看数据</el-button>
<el-button icon="el-icon-time" @click="loadLatest">最近一次</el-button>
<el-button class="span-2" type="warning" icon="el-icon-s-promotion" :loading="analyzing" @click="runAnalyze(true)">分析并推送</el-button>
<el-button type="success" plain icon="el-icon-magic-stick" :loading="analyzing" @click="runAnalyze(false)">只分析</el-button>
<el-button type="danger" plain icon="el-icon-position" :loading="testing" @click="runTest">测试推送</el-button>
<el-button type="primary" icon="el-icon-search" :loading="statsLoading" @click="loadStats">看数据</el-button>
<el-button icon="el-icon-time" :loading="statsLoading" @click="loadLatest">最近一次</el-button>
<el-button class="span-2" type="warning" icon="el-icon-s-promotion" :loading="submitting" @click="runAnalyze(true)">分析并推送</el-button>
<el-button type="success" plain icon="el-icon-magic-stick" :loading="submitting" @click="runAnalyze(false)">只分析</el-button>
<el-button type="danger" plain icon="el-icon-position" :loading="submitting" @click="runTest">测试推送</el-button>
</div>
</el-form>
</el-card>
@@ -156,6 +156,54 @@
<pre class="report-text">{{ report }}</pre>
</el-card>
<el-card class="log-card" shadow="hover">
<div slot="header" class="report-header">
<span>调用记录</span>
<el-button type="text" icon="el-icon-refresh" :loading="callsLoading" @click="loadCallLogs(false)">刷新</el-button>
</div>
<div v-if="mobileLayout" class="log-list">
<div v-if="!callLogs.length" class="group-empty">暂无调用记录</div>
<div v-for="row in callLogs" :key="row.id" class="log-item" @click="showCallReport(row)">
<div class="log-item-top">
<span>{{ row.periodLabel || '—' }}</span>
<el-tag :type="callStatusTag(row.status)" size="mini">{{ callStatusLabel(row.status) }}</el-tag>
</div>
<div class="log-item-sub">{{ row.startedAt }} · {{ triggerLabel(row.trigger) }} · 耗时 {{ formatDuration(row) }} · 模型 {{ formatMs(row.llmDurationMs) }}</div>
<div class="log-item-sub">返回 {{ fmtNum(row.replyChars) }} 字<span v-if="row.push"> · {{ row.pushed ? '已推送' : '未推送' }}</span></div>
<div v-if="row.aiError || row.pushError" class="log-item-err">{{ row.aiError || row.pushError }}</div>
</div>
</div>
<el-table v-else :data="callLogs" stripe size="small" max-height="420" empty-text="暂无调用记录">
<el-table-column prop="startedAt" label="开始" width="160" />
<el-table-column label="状态" width="88">
<template slot-scope="scope">
<el-tag :type="callStatusTag(scope.row.status)" size="mini">{{ callStatusLabel(scope.row.status) }}</el-tag>
</template>
</el-table-column>
<el-table-column label="耗时" width="90">
<template slot-scope="scope">{{ formatDuration(scope.row) }}</template>
</el-table-column>
<el-table-column label="模型耗时" width="100">
<template slot-scope="scope">{{ formatMs(scope.row.llmDurationMs) }}</template>
</el-table-column>
<el-table-column prop="periodLabel" label="周期" min-width="150" show-overflow-tooltip />
<el-table-column label="来源" width="72">
<template slot-scope="scope">{{ triggerLabel(scope.row.trigger) }}</template>
</el-table-column>
<el-table-column label="返回" width="80">
<template slot-scope="scope">{{ fmtNum(scope.row.replyChars) }} 字</template>
</el-table-column>
<el-table-column label="说明" min-width="160" show-overflow-tooltip>
<template slot-scope="scope">{{ scope.row.aiError || scope.row.pushError || (scope.row.status === 'running' ? '进行中' : '—') }}</template>
</el-table-column>
<el-table-column label="操作" width="80" fixed="right">
<template slot-scope="scope">
<el-button type="text" size="mini" @click="showCallReport(scope.row)">返回</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<el-card class="log-card" shadow="hover">
<div slot="header" class="report-header">
<span>发送记录</span>
@@ -201,7 +249,7 @@
</el-table>
</el-card>
<el-dialog title="发送内容" :visible.sync="logDialogVisible" :width="mobileLayout ? '92%' : '640px'" append-to-body>
<el-dialog :title="logDialogTitle" :visible.sync="logDialogVisible" :width="mobileLayout ? '92%' : '640px'" append-to-body>
<p class="log-dialog-meta">{{ logDialogMeta }}</p>
<pre class="report-text">{{ logDialogReport }}</pre>
</el-dialog>
@@ -214,15 +262,18 @@
</template>
<script>
import { previewOrderProfitStats, analyzeOrderProfit, latestOrderProfitAnalysis, testOrderProfitPush, listOrderProfitSendLogs } from '@/api/system/orderProfitAnalysis'
import { previewOrderProfitStats, analyzeOrderProfit, latestOrderProfitAnalysis, testOrderProfitPush, listOrderProfitSendLogs, listOrderProfitCallLogs } from '@/api/system/orderProfitAnalysis'
export default {
name: 'SlowOrderProfitAnalysis',
data() {
return {
loading: false,
analyzing: false,
testing: false,
statsLoading: false,
submitting: false,
callLogs: [],
callsLoading: false,
pendingCallId: '',
pollTimer: null,
periodType: 'day',
anchorDate: '',
stats: null,
@@ -234,6 +285,7 @@ export default {
sendLogs: [],
logsLoading: false,
logDialogVisible: false,
logDialogTitle: '发送内容',
logDialogMeta: '',
logDialogReport: '',
llmJson: ''
@@ -301,6 +353,10 @@ export default {
created() {
this.loadStats()
this.loadSendLogs()
this.loadCallLogs(true)
},
beforeDestroy() {
this.stopCallPoll()
},
methods: {
queryDate() {
@@ -357,7 +413,7 @@ export default {
this.pushed = !!data.pushed
},
async loadStats() {
this.loading = true
this.statsLoading = true
try {
const res = await previewOrderProfitStats({
periodType: this.periodType,
@@ -374,66 +430,127 @@ export default {
} catch (e) {
this.$message.error('预览失败:' + (e.message || '未知错误'))
} finally {
this.loading = false
this.statsLoading = false
}
},
async runAnalyze(push) {
this.analyzing = true
this.loading = true
try {
const res = await analyzeOrderProfit({
periodType: this.periodType,
date: this.queryDate(),
push
})
if (res.code === 200) {
this.applyPayload(res.data)
if (push) {
this.loadSendLogs()
}
if (push && res.data && res.data.pushed) {
this.$message.success('分析完成并已推送')
} else if (res.data && res.data.aiError) {
this.$message.warning('已生成数字摘要(大模型失败)')
} else {
this.$message.success('分析完成')
}
} else {
this.$message.error(res.msg || '分析失败')
}
} catch (e) {
this.$message.error('分析失败:' + (e.message || '未知错误'))
} finally {
this.analyzing = false
this.loading = false
}
await this.submitCall(analyzeOrderProfit, {
periodType: this.periodType,
date: this.queryDate(),
push,
trigger: 'manual'
}, push ? '已提交,推送结果会出现在调用记录' : '已提交,结果会出现在调用记录')
},
async runTest() {
this.testing = true
this.loading = true
await this.submitCall(testOrderProfitPush, {
periodType: this.periodType,
date: this.queryDate()
}, '已提交测试推送,结果会出现在调用记录')
},
async submitCall(request, payload, okText) {
this.submitting = true
try {
const res = await testOrderProfitPush({
periodType: this.periodType,
date: this.queryDate()
})
const res = await request(payload)
if (res.code === 200) {
this.applyPayload(res.data)
this.loadSendLogs()
if (res.data && res.data.pushed) {
this.$message.success('测试推送已发出')
} else {
this.$message.error((res.data && res.data.pushError) || '测试推送失败')
}
this.pendingCallId = (res.data && res.data.id) || ''
this.$message.success(okText)
this.ensureCallPoll()
this.loadCallLogs(true)
} else {
this.$message.error(res.msg || '测试失败')
this.$message.error(res.msg || '提交失败')
}
} catch (e) {
this.$message.error('测试失败:' + (e.message || '未知错误'))
this.$message.error('提交失败:' + (e.message || '未知错误'))
} finally {
this.testing = false
this.loading = false
this.submitting = false
}
},
async loadCallLogs(silent) {
if (!silent) this.callsLoading = true
try {
const res = await listOrderProfitCallLogs(30)
if (res.code === 200) {
const rows = Array.isArray(res.data) ? res.data : []
this.callLogs = rows
this.noticePendingCall(rows)
if (rows.some(row => row.status === 'running')) {
this.ensureCallPoll()
} else {
this.stopCallPoll()
}
} else if (!silent) {
this.$message.error(res.msg || '读取调用记录失败')
}
} catch (e) {
if (!silent) {
this.$message.error('读取调用记录失败:' + (e.message || '未知错误'))
}
} finally {
if (!silent) this.callsLoading = false
}
},
ensureCallPoll() {
if (this.pollTimer) return
this.pollTimer = setInterval(() => this.loadCallLogs(true), 2000)
},
stopCallPoll() {
if (this.pollTimer) {
clearInterval(this.pollTimer)
this.pollTimer = null
}
},
noticePendingCall(rows) {
if (!this.pendingCallId) return
const hit = (rows || []).find(row => row.id === this.pendingCallId)
if (!hit || hit.status === 'running') return
this.pendingCallId = ''
this.report = hit.report || ''
this.periodLabel = hit.periodLabel || ''
this.aiError = hit.aiError || ''
this.pushError = hit.pushError || ''
if (hit.aiError) {
this.$message.warning('调用结束:' + hit.aiError)
} else if (hit.pushed) {
this.$message.success('分析完成并已推送')
} else {
this.$message.success('分析完成')
}
this.loadSendLogs()
},
formatMs(ms) {
if (ms == null || ms === '') return '—'
const n = Number(ms)
if (Number.isNaN(n) || n < 0) return '—'
if (n < 1000) return n + ' ms'
return (n / 1000).toFixed(1) + ' 秒'
},
formatDuration(row) {
if (!row) return '—'
if (row.durationMs != null && row.durationMs !== '') return this.formatMs(row.durationMs)
if (row.status === 'running' && row.startedAtMs) {
return this.formatMs(Date.now() - Number(row.startedAtMs))
}
return '—'
},
callStatusLabel(status) {
if (status === 'running') return '进行中'
if (status === 'success') return '成功'
if (status === 'failed') return '失败'
return status || '—'
},
callStatusTag(status) {
if (status === 'running') return 'warning'
if (status === 'success') return 'success'
if (status === 'failed') return 'danger'
return 'info'
},
showCallReport(row) {
if (!row) return
this.logDialogTitle = '调用返回'
this.logDialogMeta = [row.startedAt, this.callStatusLabel(row.status), '耗时 ' + this.formatDuration(row), '模型 ' + this.formatMs(row.llmDurationMs), row.periodLabel].filter(Boolean).join(' · ')
this.logDialogReport = row.report || row.aiError || '(尚无返回)'
this.logDialogVisible = true
},
async loadSendLogs() {
this.logsLoading = true
try {
@@ -459,12 +576,13 @@ export default {
},
showLogReport(row) {
if (!row) return
this.logDialogTitle = '发送内容'
this.logDialogMeta = [row.sentAt, this.triggerLabel(row.trigger), row.periodLabel, row.toUser].filter(Boolean).join(' · ')
this.logDialogReport = row.report || '(无正文)'
this.logDialogVisible = true
},
async loadLatest() {
this.loading = true
this.statsLoading = true
try {
const res = await latestOrderProfitAnalysis(this.periodType)
if (res.code === 200 && res.data && Object.keys(res.data).length) {
@@ -475,7 +593,7 @@ export default {
} catch (e) {
this.$message.error('读取失败:' + (e.message || '未知错误'))
} finally {
this.loading = false
this.statsLoading = false
}
},
copyReport() {