| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /**
- * 研判上下文组装
- *
- * 把持续联系页的「筛选条件 + 当前结果集」规整成后端要的 context 快照,
- * 并产出「条件是否变更」的签名 —— 抽屉开着时用户改了条件再查询,
- * 只提示「可重新分析」,不打断正在跑的流(一次分析 = 一个会话 = 一份上下文)。
- */
- import { computed, type Ref } from 'vue';
- import type { InsightCreateParams, InsightFilterSnapshot, InsightRowSnapshot } from '@/call/api/types/insight';
- /** 页面传给抽屉的筛选条件(已归一化,抽屉不关心页面表单的内部形状) */
- export interface ContinuousInsightFilters {
- /** 分析对象(本方姓名);空数组 = 全案对象人员 */
- personNames: string[];
- /** 持续联系月数阈值 */
- monthVal?: number;
- startDate?: string;
- endDate?: string;
- otherName?: string;
- otherPhone?: string;
- /** 条件命中的关系对总数 */
- total?: number;
- }
- /** 默认研判规模(后端 maxTopN=200 兜底截断) */
- export const DEFAULT_TOP_N = 100;
- /** 抽屉里的轻量 TOP N 开关(提示词 token 成本与覆盖度的折中) */
- export const TOP_N_OPTIONS = [50, 100, 200];
- /** 结果快照的一行(兼容页面 mapRow 后的 `{ raw: CallContinuousDTO }` 与裸 DTO 两种形态) */
- function toSnapshotRow(item: any): InsightRowSnapshot {
- const raw = item?.raw ?? item ?? {};
- return {
- personName: raw.personName ?? item?.selfName,
- otherName: raw.otherName ?? item?.otherName,
- otherPhone: raw.otherPhone ?? item?.otherNumber,
- pairContMonthCount: Number(raw.pairContMonthCount ?? item?.durationValue ?? 0) || 0,
- pairTotalCalls: Number(raw.pairTotalCalls ?? raw.pairTotalCall ?? raw.totalCalls ?? item?.count ?? 0) || 0,
- continuousStartMonth: raw.continuousStartMonth,
- continuousEndMonth: raw.continuousEndMonth,
- };
- }
- export function useInsightContext(filters: Ref<ContinuousInsightFilters>, rows: Ref<any[]>) {
- /** 条件签名:只含用户可见条件,用于「条件已变更」提示 */
- const filterSignature = computed(() =>
- JSON.stringify({
- personNames: [...(filters.value.personNames || [])].sort(),
- monthVal: filters.value.monthVal ?? null,
- startDate: filters.value.startDate ?? null,
- endDate: filters.value.endDate ?? null,
- otherName: filters.value.otherName ?? null,
- otherPhone: filters.value.otherPhone ?? null,
- }),
- );
- /** 快照签名:条件 + 结果集(行数与前若干行足以判定是否同一批数据) */
- const snapshotSignature = computed(() => {
- const head = (rows.value || [])
- .slice(0, 5)
- .map((item) => `${item?.selfName ?? item?.raw?.personName}|${item?.otherNumber ?? item?.raw?.otherPhone}`)
- .join(',');
- return `${filterSignature.value}#${rows.value?.length || 0}#${head}`;
- });
- /** 按持续月数降序取前 N 对(页面已排过序,这里再兜一次,保证与提示词口径一致) */
- const buildRows = (topN: number): InsightRowSnapshot[] =>
- [...(rows.value || [])]
- .map(toSnapshotRow)
- .sort((a, b) => (b.pairContMonthCount || 0) - (a.pairContMonthCount || 0))
- .slice(0, topN);
- const buildFilterSnapshot = (): InsightFilterSnapshot => {
- const f = filters.value || ({} as ContinuousInsightFilters);
- return {
- personNames: f.personNames?.length ? [...f.personNames] : undefined,
- monthVal: f.monthVal,
- startDate: f.startDate,
- endDate: f.endDate,
- otherName: f.otherName || undefined,
- otherPhone: f.otherPhone || undefined,
- total: f.total ?? rows.value?.length ?? 0,
- };
- };
- /** 组装创建会话入参 */
- const buildCreateParams = (caseId: string, topN = DEFAULT_TOP_N): InsightCreateParams => ({
- caseId,
- scope: 'BATCH',
- filters: buildFilterSnapshot(),
- rows: buildRows(topN),
- topN,
- });
- return { filterSignature, snapshotSignature, buildCreateParams };
- }
|