Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HYH.APSJ
Project
Project
Details
Activity
Releases
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
佟礼
HYH.APSJ
Commits
ffea8fc4
Commit
ffea8fc4
authored
Jul 07, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AI模型
parent
ca995cc5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
1 deletion
+113
-1
DiagnosisController.java
src/main/java/com/aps/controller/DiagnosisController.java
+113
-1
No files found.
src/main/java/com/aps/controller/DiagnosisController.java
View file @
ffea8fc4
...
...
@@ -5,6 +5,7 @@ import com.aps.model.ChromosomeData;
import
com.aps.model.MachineOption
;
import
com.aps.model.Operation
;
import
com.aps.parser.ChromosomeParser
;
import
com.aps.service.plan.SceneService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
...
...
@@ -34,6 +35,10 @@ public class DiagnosisController {
private
LLMClient
llmClient
;
private
static
final
String
UPLOAD_DIR
=
"uploads"
;
@Autowired
private
SceneService
sceneService
;
// 移除成员变量,改用Session存储
// 注意:ChromosomeParser不再使用@Autowired注入,而是每次请求创建新实例
...
...
@@ -235,6 +240,113 @@ public class DiagnosisController {
}
}
/**
* 加载并解析JSON文件
*/
private
Map
<
String
,
Object
>
loadChromosomeFile
(
String
sceneId
,
javax
.
servlet
.
http
.
HttpSession
session
)
{
try
{
if
(
sceneId
==
null
||
sceneId
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"场景ID不能为空"
);
}
File
file
=
sceneService
.
getCurrentChromosomeFile
(
sceneId
);
String
filePath
=
file
.
getPath
();
if
(
filePath
==
null
||
filePath
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"文件路径不能为空"
);
}
// 创建新的Parser实例(避免多用户数据共享)
ChromosomeParser
parser
=
new
ChromosomeParser
();
// 解析数据
parser
.
loadFromFile
(
filePath
);
// 获取基本信息和指标
Map
<
String
,
Object
>
basicInfo
=
parser
.
getBasicInfo
();
Map
<
String
,
Object
>
metrics
=
parser
.
calculateMetrics
();
String
summary
=
parser
.
generateSummary
();
// 将Parser实例存储到Session中,供后续操作使用
Map
<
String
,
Object
>
sessionData
=
getSessionData
(
session
);
sessionData
.
put
(
"parser"
,
parser
);
// ← 存储Parser实例
sessionData
.
put
(
"filePath"
,
filePath
);
sessionData
.
put
(
"summary"
,
summary
);
sessionData
.
put
(
"basicInfo"
,
basicInfo
);
sessionData
.
put
(
"metrics"
,
metrics
);
return
sessionData
;
}
catch
(
Exception
e
)
{
Map
<
String
,
Object
>
error
=
new
HashMap
<>();
error
.
put
(
"success"
,
false
);
error
.
put
(
"message"
,
"数据加载失败: "
+
e
.
getMessage
());
return
error
;
}
}
/**
* 执行AI诊断
*/
@PostMapping
(
"/diagnoseChromosome"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
diagnoseChromosome
(
@RequestBody
Map
<
String
,
Object
>
params
,
javax
.
servlet
.
http
.
HttpSession
session
)
{
try
{
// 从参数中获取sceneId
String
sceneId
=
(
String
)
params
.
get
(
"sceneId"
);
// 校验sceneId是否存在
if
(
sceneId
==
null
||
sceneId
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"场景ID不能为空"
);
}
Map
<
String
,
Object
>
sessionData
=
loadChromosomeFile
(
sceneId
,
session
);
if
(!
sessionData
.
containsKey
(
"summary"
))
{
throw
new
IllegalStateException
(
"请先加载数据"
);
}
// 从Session中获取Parser实例
ChromosomeParser
parser
=
(
ChromosomeParser
)
sessionData
.
get
(
"parser"
);
if
(
parser
==
null
)
{
throw
new
IllegalStateException
(
"解析器未初始化,请重新加载数据"
);
}
String
summary
=
(
String
)
sessionData
.
get
(
"summary"
);
// 调用AI诊断
String
rulesContext
=
"无特定规则约束。\n\n"
+
"请作为APS(高级计划与排程)系统专家,基于您的专业知识对以下排产方案进行自由诊断分析。\n\n"
+
"您可以从以下角度进行分析:\n"
+
"- 整体评估\n"
+
"- 瓶颈识别\n"
+
"- 效率分析\n"
+
"- 优化建议\n"
+
"- 风险评估\n"
;
List
<
String
>
diagnosisFocus
=
Arrays
.
asList
(
"全面分析"
);
String
report
=
llmClient
.
diagnoseSchedule
(
summary
,
rulesContext
,
diagnosisFocus
);
// 保存诊断报告(使用Session隔离)
sessionData
.
put
(
"diagnosisReport"
,
report
);
Map
<
String
,
Object
>
response
=
new
HashMap
<>();
response
.
put
(
"success"
,
true
);
response
.
put
(
"report"
,
report
);
response
.
put
(
"message"
,
"诊断完成"
);
return
ResponseEntity
.
ok
(
response
);
}
catch
(
Exception
e
)
{
Map
<
String
,
Object
>
error
=
new
HashMap
<>();
error
.
put
(
"success"
,
false
);
error
.
put
(
"message"
,
"诊断失败: "
+
e
.
getMessage
());
e
.
printStackTrace
();
return
ResponseEntity
.
status
(
500
).
body
(
error
);
}
}
/**
* 执行AI诊断
*/
...
...
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