Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AI_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
AI_server
Commits
7273ec44
Commit
7273ec44
authored
Aug 08, 2025
by
chenjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
5934b553
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
39 deletions
+82
-39
cronJob.ts
src/data/cronJob.ts
+3
-2
aiAnswerData.ts
src/data/dataCenterInterface/aiAnswerData.ts
+79
-37
No files found.
src/data/cronJob.ts
View file @
7273ec44
...
@@ -7,7 +7,8 @@ import { BizError, SysError } from "../util/bizError";
...
@@ -7,7 +7,8 @@ import { BizError, SysError } from "../util/bizError";
let
accToken
=
""
;
let
accToken
=
""
;
export
async
function
getInterfaceByInterfaceName
(
url
,
body
)
{
export
async
function
getInterfaceByInterfaceName
(
url
,
body
)
{
let
reqResult
=
await
get
(
url
,
body
,
{});
let
headers
=
{
accept
:
"*/*"
,
Authorization
:
"Bearer 38a96559-8f70-4df8-87f9-af3eb58fcc27"
};
let
reqResult
=
await
post
(
url
,
body
,
headers
);
let
{
err
,
res
,
reqData
}:
any
=
reqResult
;
let
{
err
,
res
,
reqData
}:
any
=
reqResult
;
let
reqErrorMsg
=
""
;
let
reqErrorMsg
=
""
;
...
@@ -74,7 +75,7 @@ function post(url, body, headers) {
...
@@ -74,7 +75,7 @@ function post(url, body, headers) {
},
function
(
err
,
res
,
data
)
{
},
function
(
err
,
res
,
data
)
{
const
success
=
!
err
&&
res
&&
res
.
statusCode
==
200
;
const
success
=
!
err
&&
res
&&
res
.
statusCode
==
200
;
let
message
=
err
||
res
.
statusCode
||
""
;
let
message
=
err
||
res
.
statusCode
||
""
;
resolve
({
success
,
message
,
data
});
resolve
({
success
,
message
,
reqData
:
data
});
});
});
})
})
}
}
...
...
src/data/dataCenterInterface/aiAnswerData.ts
View file @
7273ec44
...
@@ -13,56 +13,86 @@ export async function getAIAnswerInterface(question, sceneUuids, threadId) {
...
@@ -13,56 +13,86 @@ export async function getAIAnswerInterface(question, sceneUuids, threadId) {
// let data = await getInterfaceByInterfaceName( dataCenterInterfaceConfig.answerText, body );
// let data = await getInterfaceByInterfaceName( dataCenterInterfaceConfig.answerText, body );
/**----------------test */
/**----------------test */
let
sample
=
{
header
:[],
data
:[]};
// let sample = {header:[], data:[]};
if
(
question
==
"营销项目三明市商务局2025年“福建有口福”餐饮促消费活动今年共出奖多少钱"
)
{
// if (question == "营销项目三明市商务局2025年“福建有口福”餐饮促消费活动今年共出奖多少钱") {
sample
.
header
=
[
"餐饮促消费活动今年共出奖"
];
// sample.header = ["餐饮促消费活动今年共出奖"];
sample
.
data
=
[[
"1000000"
]];
// sample.data = [["1000000"]];
// }
// if (question == "假设今天是2025年3月份的一天,项目25S3135000703单用户和单商户分别投入多少") {
// sample.header = ["单用户投入(整体)", "单商户投入(整体)"];
// sample.data = [["128.41497748946097", "4548.841094599493"]];
// }
// if (question == "谁负责的项目数最多,列出top5") {
// sample.header = ["负责部门", "营销项目编号(去重统计)"];
// sample.data = [
// [
// "张有怡",
// "7"
// ],
// [
// "林宇",
// "6"
// ],
// [
// "郭令玲",
// "6"
// ],
// [
// "欧阳旻",
// "4"
// ],
// [
// "周昀",
// "3"
// ]
// ];
// }
let
data
=
{
questionId
:
""
,
content
:
""
,
params
:[],
sample
:
null
}
}
if
(
question
==
"假设今天是2025年3月份的一天,项目25S3135000703单用户和单商户分别投入多少"
)
{
if
(
question
==
"今年营销项目带来多少收入"
)
{
sample
.
header
=
[
"单用户投入(整体)"
,
"单商户投入(整体)"
];
data
.
content
=
"为您查询:项目启动时间${filterValue1}的收入${filterValue3}为636181.6320754716552286"
;
sample
.
data
=
[[
"128.41497748946097"
,
"4548.841094599493"
]];
data
.
params
=
[
}
{
name
:
"filterValue1"
,
display
:
"大于等于2025-01-01"
},
{
name
:
"filterValue2"
,
display
:
"123"
},
if
(
question
==
"谁负责的项目数最多,列出top5"
)
{
{
name
:
"filterValue3"
,
display
:
"营销项目金额"
},
sample
.
header
=
[
"负责部门"
,
"营销项目编号(去重统计)"
];
sample
.
data
=
[
[
"张有怡"
,
"7"
],
[
"林宇"
,
"6"
],
[
"郭令玲"
,
"6"
],
[
"欧阳旻"
,
"4"
],
[
"周昀"
,
"3"
]
];
];
}
}
/**----------------test */
/**----------------test */
// let { questionId, content, params, sample } = data;
let
aiAnswerType
=
AIANSWERTYPE
.
表格
;
let
aiAnswerData
:
any
=
null
;
if
(
!
Object
.
keys
(
sample
).
length
)
{
let
{
questionId
,
content
,
params
,
sample
}
=
data
;
if
(
!
sample
)
{
let
aiAnswerStr
=
replacePlaceholders
(
content
,
params
);
// 1. 找到最后一个 "为" 的位置
let
lastWeiIndex
=
aiAnswerStr
.
lastIndexOf
(
"为"
);
let
beforeWei
=
""
;
let
afterWei
=
""
;
if
(
lastWeiIndex
!==
-
1
)
{
// 2. 截取 "为" 前面的部分(不包含"为")
beforeWei
=
aiAnswerStr
.
slice
(
0
,
lastWeiIndex
);
// 3. 截取 "为" 后面的部分(不包含"为")
afterWei
=
aiAnswerStr
.
slice
(
lastWeiIndex
+
1
);
// +1 跳过 "为" 字
}
aiAnswerType
=
AIANSWERTYPE
.
键值对
;
aiAnswerData
=
[{
key
:
beforeWei
,
value
:
afterWei
}];
}
else
if
(
!
Object
.
keys
(
sample
).
length
)
{
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample 为空"
,
sample
);
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample 为空"
,
sample
);
}
else
{
}
else
{
if
(
!
Array
.
isArray
(
sample
.
header
))
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample.header 不是数组"
,
sample
);
if
(
!
Array
.
isArray
(
sample
.
header
))
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample.header 不是数组"
,
sample
);
if
(
!
Array
.
isArray
(
sample
.
data
))
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample.data 不是数组"
,
sample
);
if
(
!
Array
.
isArray
(
sample
.
data
))
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample.data 不是数组"
,
sample
);
}
let
aiAnswerType
=
AIANSWERTYPE
.
表格
;
let
aiAnswerData
:
any
=
null
;
/**
/**
* 判断逻辑:
* 判断逻辑:
* 1、键值对条件(满足任一):
* 1、键值对条件(满足任一):
...
@@ -94,11 +124,23 @@ export async function getAIAnswerInterface(question, sceneUuids, threadId) {
...
@@ -94,11 +124,23 @@ export async function getAIAnswerInterface(question, sceneUuids, threadId) {
else
{
else
{
aiAnswerData
=
getTableData
(
sample
.
header
,
sample
.
data
);
aiAnswerData
=
getTableData
(
sample
.
header
,
sample
.
data
);
}
}
}
return
{
aiAnswerType
,
aiAnswerData
};
return
{
aiAnswerType
,
aiAnswerData
};
}
}
function
replacePlaceholders
(
content
,
params
)
{
// 使用正则表达式匹配所有${...}的占位符
return
content
.
replace
(
/
\$\{(\w
+
)\}
/g
,
(
match
,
paramName
)
=>
{
// 在params数组中查找name匹配的参数
const
param
=
params
.
find
(
p
=>
p
.
name
===
paramName
);
// 如果找到则返回display值,否则保持原样
return
param
?
param
.
display
:
match
;
});
}
function
isDateField
(
headerName
)
{
function
isDateField
(
headerName
)
{
// 简单检查header名称是否包含日期相关词汇
// 简单检查header名称是否包含日期相关词汇
const
dateKeywords
=
[
'日期'
,
'时间'
,
'day'
,
'date'
,
'month'
,
'year'
];
const
dateKeywords
=
[
'日期'
,
'时间'
,
'day'
,
'date'
,
'month'
,
'year'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment