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
5934b553
Commit
5934b553
authored
Aug 06, 2025
by
chenjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口接入测试数据
parent
a11bcf18
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
9 deletions
+146
-9
package-lock.json
package-lock.json
+0
-0
aidata.ts
src/biz/aidata.ts
+7
-2
enum.ts
src/config/enum.ts
+11
-0
aiAnswerData.ts
src/data/dataCenterInterface/aiAnswerData.ts
+126
-6
router.ts
src/routers/router.ts
+2
-1
No files found.
package-lock.json
View file @
5934b553
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/biz/aidata.ts
View file @
5934b553
...
@@ -7,14 +7,18 @@ import { ERRORENUM } from "../config/errorEnum";
...
@@ -7,14 +7,18 @@ import { ERRORENUM } from "../config/errorEnum";
//ai智能问答
//ai智能问答
export
async
function
getAIAnswer
(
req
,
res
)
{
export
async
function
getAIAnswer
(
req
,
res
)
{
let
{
question
,
threadId
}
=
req
.
body
;
let
ret
:
any
=
{};
let
ret
:
any
=
{};
let
{
aiAnswerData
}
=
await
getAIAnswerInterface
()
;
let
sceneUuids
=
[
"11baa1d533e74a68b0503e6ef18016d4"
,
"34080148d14041eaaa60c622a03f7bc9"
,
"9a1022b6db784b3484dc7b8ea20590b4"
,
"06f751e96f8b4d6096d0be523b93ec5f"
]
;
let
{
aiAnswerType
,
aiAnswerData
}
=
await
getAIAnswerInterface
(
question
,
sceneUuids
,
threadId
);
ret
[
"aiAnswerType"
]
=
aiAnswerType
;
ret
[
"aiAnswerData"
]
=
aiAnswerData
;
res
.
send
(
ret
);
res
.
send
(
ret
);
}
}
\ No newline at end of file
src/config/enum.ts
View file @
5934b553
...
@@ -2,3 +2,14 @@ export enum INTERFACEREQUESTTYPEENUM {
...
@@ -2,3 +2,14 @@ export enum INTERFACEREQUESTTYPEENUM {
即时更新
=
1
,
即时更新
=
1
,
定时更新
定时更新
}
}
export
enum
AIANSWERTYPE
{
键值对
=
1
,
折线图
=
2
,
柱状图
=
3
,
饼图
=
4
,
表格
=
5
}
src/data/dataCenterInterface/aiAnswerData.ts
View file @
5934b553
...
@@ -3,17 +3,137 @@ import { SYSTEMERRORENUM } from "../../config/errorEnum";
...
@@ -3,17 +3,137 @@ import { SYSTEMERRORENUM } from "../../config/errorEnum";
import
{
dataCenterInterfaceConfig
}
from
"../../config/serverConfig"
;
import
{
dataCenterInterfaceConfig
}
from
"../../config/serverConfig"
;
import
{
SysError
}
from
"../../util/bizError"
;
import
{
SysError
}
from
"../../util/bizError"
;
import
{
getInterfaceByInterfaceName
}
from
"../cronJob"
;
import
{
getInterfaceByInterfaceName
}
from
"../cronJob"
;
import
{
AIANSWERTYPE
}
from
"../../config/enum"
;
//ai智能问答
//ai智能问答
export
async
function
getAIAnswerInterface
()
{
export
async
function
getAIAnswerInterface
(
question
,
sceneUuids
,
threadId
)
{
const
interfaceName
=
"获取问数结果信息"
;
const
interfaceName
=
"获取问数结果信息"
;
let
data
=
await
getInterfaceByInterfaceName
(
dataCenterInterfaceConfig
.
answerText
,
{}
)
;
let
body
=
{
question
,
sceneUuids
,
threadId
}
;
let
{
questionId
,
content
,
params
}
=
data
;
// let data = await getInterfaceByInterfaceName( dataCenterInterfaceConfig.answerText, body )
;
if
(
!
Array
.
isArray
(
params
)
)
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"params 不是数组"
,
params
);
/**----------------test */
let
sample
=
{
header
:[],
data
:[]};
if
(
question
==
"营销项目三明市商务局2025年“福建有口福”餐饮促消费活动今年共出奖多少钱"
)
{
sample
.
header
=
[
"餐饮促消费活动今年共出奖"
];
sample
.
data
=
[[
"1000000"
]];
}
let
aiAnswerData
=
[];
if
(
question
==
"假设今天是2025年3月份的一天,项目25S3135000703单用户和单商户分别投入多少"
)
{
sample
.
header
=
[
"单用户投入(整体)"
,
"单商户投入(整体)"
];
sample
.
data
=
[[
"128.41497748946097"
,
"4548.841094599493"
]];
}
return
{
aiAnswerData
};
if
(
question
==
"谁负责的项目数最多,列出top5"
)
{
sample
.
header
=
[
"负责部门"
,
"营销项目编号(去重统计)"
];
sample
.
data
=
[
[
"张有怡"
,
"7"
],
[
"林宇"
,
"6"
],
[
"郭令玲"
,
"6"
],
[
"欧阳旻"
,
"4"
],
[
"周昀"
,
"3"
]
];
}
/**----------------test */
// let { questionId, content, params, sample } = data;
if
(
!
Object
.
keys
(
sample
).
length
)
{
throw
new
SysError
(
SYSTEMERRORENUM
.
未按接口协议返回
,
interfaceName
,
"sample 为空"
,
sample
);
}
else
{
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
);
}
let
aiAnswerType
=
AIANSWERTYPE
.
表格
;
let
aiAnswerData
:
any
=
null
;
/**
* 判断逻辑:
* 1、键值对条件(满足任一):
* - header长度为1 且 data为单行单列
* - data为单行多列(适合展示为多个键值对)
* 2、图表条件:
* - header长度为2 且 data为多行,且第二列为数值
* 3、默认表格展示
*/
if
(
!
sample
.
header
||
!
sample
.
data
)
aiAnswerType
=
AIANSWERTYPE
.
键值对
;
// 键值对条件:单行数据
if
(
sample
.
data
.
length
===
1
)
{
aiAnswerType
=
AIANSWERTYPE
.
键值对
;
aiAnswerData
=
getKeyValue
(
sample
.
header
,
sample
.
data
);
}
// 图表条件:多行数据且第二列为数值
else
if
(
sample
.
header
.
length
===
2
&&
sample
.
data
.
every
(
row
=>
!
isNaN
(
parseFloat
(
row
[
1
]))
))
{
// 优先检查时间字段
if
(
isDateField
(
sample
.
header
[
0
]))
{
aiAnswerType
=
AIANSWERTYPE
.
折线图
;
}
else
{
aiAnswerType
=
AIANSWERTYPE
.
柱状图
;
}
aiAnswerData
=
getChartData
(
sample
.
header
,
sample
.
data
);
}
// 默认表格展示
else
{
aiAnswerData
=
getTableData
(
sample
.
header
,
sample
.
data
);
}
return
{
aiAnswerType
,
aiAnswerData
};
}
function
isDateField
(
headerName
)
{
// 简单检查header名称是否包含日期相关词汇
const
dateKeywords
=
[
'日期'
,
'时间'
,
'day'
,
'date'
,
'month'
,
'year'
];
return
dateKeywords
.
some
(
keyword
=>
headerName
.
toLowerCase
().
includes
(
keyword
.
toLowerCase
())
);
}
function
getKeyValue
(
header
,
data
)
{
let
keyvalue
=
[];
for
(
let
i
=
0
;
i
<
header
.
length
;
i
++
)
{
keyvalue
.
push
({
key
:
header
[
i
],
value
:
data
[
0
][
i
]})
}
return
keyvalue
;
}
function
getTableData
(
header
,
data
)
{
let
tableData
=
{
handerList
:
header
,
bodyList
:
data
};
return
tableData
;
}
}
function
getChartData
(
header
,
data
)
{
let
chartData
=
[];
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
chartData
.
push
({
key
:
data
[
i
][
0
],
value
:
data
[
i
][
1
]})
}
return
chartData
;
}
src/routers/router.ts
View file @
5934b553
...
@@ -4,5 +4,5 @@ import * as asyncHandler from 'express-async-handler'
...
@@ -4,5 +4,5 @@ import * as asyncHandler from 'express-async-handler'
import
*
as
aidataBiz
from
'../biz/aidata'
;
import
*
as
aidataBiz
from
'../biz/aidata'
;
export
function
setRouter
(
httpServer
){
export
function
setRouter
(
httpServer
){
httpServer
.
ge
t
(
'/aianswer'
,
asyncHandler
(
aidataBiz
.
getAIAnswer
));
httpServer
.
pos
t
(
'/aianswer'
,
asyncHandler
(
aidataBiz
.
getAIAnswer
));
}
}
\ No newline at end of file
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