Commit eace2005 by Liu

fix:提质增效时自动调用提问接口,用户画像&&工单接入工作流

parent cddd8c5b
...@@ -449,6 +449,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -449,6 +449,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
qaRecords: qaRes?.data || [], qaRecords: qaRes?.data || [],
}, },
})) }))
// 提质增效模式下,获取会话ID后立即调用提问接口
if (tool.toolId === '6712395743241') {
window.dispatchEvent(new CustomEvent('autoSubmitQuestion', {
detail: {
conversationId,
question: '',
toolId: tool.toolId,
recordType: 'B03',
busiType: '01',
},
}))
}
// 清除标记,避免影响后续路由切换 // 清除标记,避免影响后续路由切换
sessionStorage.removeItem('toolHistoryLoading') sessionStorage.removeItem('toolHistoryLoading')
} }
......
...@@ -141,9 +141,21 @@ export const Chat: React.FC = () => { ...@@ -141,9 +141,21 @@ export const Chat: React.FC = () => {
setAllItems((prevItems) => { setAllItems((prevItems) => {
const newItems = [...prevItems] // 创建数组的浅拷贝 const newItems = [...prevItems] // 创建数组的浅拷贝
const lastIndex = newItems.length - 1 const lastIndex = newItems.length - 1
if (lastIndex >= 0) { const isEmptyQuestion = !question.trim()
// 如果是空问题且最后一项不是AI回答,需要添加AI回答
if (isEmptyQuestion && (lastIndex < 0 || newItems[lastIndex].role !== 'ai')) {
newItems.push({
role: 'ai',
answerList: [{ answer: '' }],
} as ChatRecord)
}
const currentIndex = newItems.length - 1
if (currentIndex >= 0 && newItems[currentIndex].role === 'ai') {
// 创建最后一项的新对象,合并现有数据和新的 answer // 创建最后一项的新对象,合并现有数据和新的 answer
const originalAnswer = (newItems[lastIndex].answerList?.[0]?.answer || '') + (msg.content.data.answer ?? '\n') const existingAnswer = newItems[currentIndex].answerList?.[0] || {}
const originalAnswer = (existingAnswer.answer || '') + (msg.content.data.answer ?? '\n')
// 移除所有括号及其内容 // 移除所有括号及其内容
let filteredAnswer = originalAnswer.replace(/\([^)]*\)/g, '') let filteredAnswer = originalAnswer.replace(/\([^)]*\)/g, '')
// 去除 [参考文档《任意内容》 《任意内容》...] 格式的内容 // 去除 [参考文档《任意内容》 《任意内容》...] 格式的内容
...@@ -154,10 +166,9 @@ export const Chat: React.FC = () => { ...@@ -154,10 +166,9 @@ export const Chat: React.FC = () => {
// 在流式响应过程中,忽略服务器返回的 endAnswerFlag,避免过早禁用输入框 // 在流式响应过程中,忽略服务器返回的 endAnswerFlag,避免过早禁用输入框
const { endAnswerFlag: _omitEndAnswerFlag, ...dataWithoutEndFlag } = msg.content.data || {} const { endAnswerFlag: _omitEndAnswerFlag, ...dataWithoutEndFlag } = msg.content.data || {}
// 保留之前保存的 workFlowSessionId 和 recordId,避免被覆盖 // 保留之前保存的 workFlowSessionId 和 recordId,避免被覆盖
const existingAnswer = newItems[lastIndex].answerList?.[0] || {} newItems[currentIndex] = {
newItems[lastIndex] = { ...newItems[currentIndex],
...newItems[lastIndex], question: isEmptyQuestion ? undefined : question,
question,
answerList: [ answerList: [
{ {
...existingAnswer, ...existingAnswer,
...@@ -181,11 +192,22 @@ export const Chat: React.FC = () => { ...@@ -181,11 +192,22 @@ export const Chat: React.FC = () => {
setAllItems((prevItems) => { setAllItems((prevItems) => {
const newItems = [...prevItems] // 创建数组的浅拷贝 const newItems = [...prevItems] // 创建数组的浅拷贝
const lastIndex = newItems.length - 1 const lastIndex = newItems.length - 1
if (lastIndex >= 0) { const isEmptyQuestion = !question.trim()
// 如果是空问题且最后一项不是AI回答,需要添加AI回答
if (isEmptyQuestion && (lastIndex < 0 || newItems[lastIndex].role !== 'ai')) {
newItems.push({
role: 'ai',
answerList: [{ answer: '' }],
} as ChatRecord)
}
const currentIndex = newItems.length - 1
if (currentIndex >= 0 && newItems[currentIndex].role === 'ai') {
// 创建最后一项的新对象,合并现有数据和新的 answer // 创建最后一项的新对象,合并现有数据和新的 answer
newItems[lastIndex] = { newItems[currentIndex] = {
...newItems[lastIndex], ...newItems[currentIndex],
question, question: isEmptyQuestion ? undefined : question,
answerList: [ answerList: [
{ {
...msg.content.data, ...msg.content.data,
...@@ -206,7 +228,7 @@ export const Chat: React.FC = () => { ...@@ -206,7 +228,7 @@ export const Chat: React.FC = () => {
question: string, question: string,
productCode?: string, productCode?: string,
toolId?: string, toolId?: string,
extraParams?: { paramMap?: Record<string, string>, recordId?: string, recordType?: string, workFlowSessionId?: string, isReask?: boolean }, extraParams?: { paramMap?: Record<string, string>, recordId?: string, recordType?: string, workFlowSessionId?: string, isReask?: boolean, busiType?: string },
workFlowSessionId?: string, workFlowSessionId?: string,
recordId?: string, recordId?: string,
) => { ) => {
...@@ -224,7 +246,8 @@ export const Chat: React.FC = () => { ...@@ -224,7 +246,8 @@ export const Chat: React.FC = () => {
// 检查token // 检查token
await fetchCheckTokenApi() await fetchCheckTokenApi()
// 一次性添加用户问题和空的AI回答 // 如果 question 不为空,才添加用户问题和空的AI回答(自动提问时 question 为空,不显示)
if (question.trim()) {
setAllItems(prevItems => [ setAllItems(prevItems => [
...prevItems, ...prevItems,
{ {
...@@ -236,6 +259,7 @@ export const Chat: React.FC = () => { ...@@ -236,6 +259,7 @@ export const Chat: React.FC = () => {
answerList: [{ answer: '' }], answerList: [{ answer: '' }],
} as ChatRecord, } as ChatRecord,
]) ])
}
// 创建新的 AbortController // 创建新的 AbortController
abortControllerRef.current = new AbortController() abortControllerRef.current = new AbortController()
...@@ -304,6 +328,10 @@ export const Chat: React.FC = () => { ...@@ -304,6 +328,10 @@ export const Chat: React.FC = () => {
// 如果传入了 recordType,优先使用传入的值(workflow 提交场景) // 如果传入了 recordType,优先使用传入的值(workflow 提交场景)
if (extraParams?.recordType) { if (extraParams?.recordType) {
requestBody.recordType = extraParams.recordType requestBody.recordType = extraParams.recordType
// 如果同时传入了 busiType,也使用传入的值
if (extraParams?.busiType) {
requestBody.busiType = extraParams.busiType
}
} }
// 制度活化:toolId 为空字符串或 undefined // 制度活化:toolId 为空字符串或 undefined
else if (!resolvedToolId || resolvedToolId === '') { else if (!resolvedToolId || resolvedToolId === '') {
...@@ -314,7 +342,7 @@ export const Chat: React.FC = () => { ...@@ -314,7 +342,7 @@ export const Chat: React.FC = () => {
// 提质增效:toolId 为 6712395743241 // 提质增效:toolId 为 6712395743241
else if (resolvedToolId === '6712395743241') { else if (resolvedToolId === '6712395743241') {
requestBody.busiType = '01' requestBody.busiType = '01'
requestBody.recordType = 'B00' requestBody.recordType = 'B03'
} }
// 数据助手:toolId 为 6712395743240 // 数据助手:toolId 为 6712395743240
else if (resolvedToolId === '6712395743240') { else if (resolvedToolId === '6712395743240') {
...@@ -927,6 +955,21 @@ export const Chat: React.FC = () => { ...@@ -927,6 +955,21 @@ export const Chat: React.FC = () => {
} }
}, [dispatch]) }, [dispatch])
// 监听自动提问事件(提质增效模式下使用)
useEffect(() => {
const handleAutoSubmitQuestion = (event: CustomEvent) => {
const { conversationId, question, toolId, recordType, busiType } = event.detail
// 确保当前会话ID匹配
if (conversationId === currentIdRef.current) {
handleSubmitQuestion(question, undefined, toolId, { recordType, busiType })
}
}
window.addEventListener('autoSubmitQuestion', handleAutoSubmitQuestion as EventListener)
return () => {
window.removeEventListener('autoSubmitQuestion', handleAutoSubmitQuestion as EventListener)
}
}, [handleSubmitQuestion])
return ( return (
<div className={styles.scrollView}> <div className={styles.scrollView}>
<div className={`${styles.chatPage} relative`}> <div className={`${styles.chatPage} relative`}>
......
...@@ -434,7 +434,8 @@ export const TacticsChat: React.FC = () => { ...@@ -434,7 +434,8 @@ export const TacticsChat: React.FC = () => {
productCode, productCode,
toolId: resolvedToolId, toolId: resolvedToolId,
...(extra?.busiType ? { busiType: extra.busiType } : {}), ...(extra?.busiType ? { busiType: extra.busiType } : {}),
...(extra?.recordType ? { recordType: extra.recordType } : {}), // from=tactics&place=order 场景下,recordType 固定为 A11,不根据 extra.recordType 改变
...(orderMeta && shouldIncludeOrderMeta ? { recordType: 'A11' } : (extra?.recordType ? { recordType: extra.recordType } : {})),
...(extra?.numberType ? { numberType: extra.numberType } : {}), ...(extra?.numberType ? { numberType: extra.numberType } : {}),
} }
// 优先级:orderMeta > userMeta > tacticsMeta // 优先级:orderMeta > userMeta > tacticsMeta
...@@ -475,6 +476,8 @@ export const TacticsChat: React.FC = () => { ...@@ -475,6 +476,8 @@ export const TacticsChat: React.FC = () => {
} }
} }
requestBody.busiId = userId requestBody.busiId = userId
// from=tactics&place=order 场景下,recordType 固定为 A11
requestBody.recordType = 'A11'
} }
else if (userMeta?.place === 'user') { else if (userMeta?.place === 'user') {
requestBody.busiType ??= '02' requestBody.busiType ??= '02'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment