1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
| package com.ruoyi.ai.assistant;
|
| import com.ruoyi.ai.tools.ManufacturingAgentTools;
| import org.springframework.stereotype.Component;
| import org.springframework.util.StringUtils;
|
| import java.util.regex.Matcher;
| import java.util.regex.Pattern;
|
| @Component
| public class ManufacturingIntentExecutor {
|
| private static final Pattern LIMIT_PATTERN = Pattern.compile("(前|最近)?(\\d{1,2})条");
| private static final Pattern DATE_PATTERN = Pattern.compile("(\\d{4}-\\d{2}-\\d{2})");
|
| private final ManufacturingAgentTools manufacturingAgentTools;
|
| public ManufacturingIntentExecutor(ManufacturingAgentTools manufacturingAgentTools) {
| this.manufacturingAgentTools = manufacturingAgentTools;
| }
|
| public String tryExecute(String memoryId, String message) {
| if (!StringUtils.hasText(message)) {
| return null;
| }
| String text = message.trim();
| String keyword = extractKeyword(text);
| Integer limit = extractLimit(text);
| String startDate = extractStartDate(text);
| String endDate = extractEndDate(text);
|
| if (containsAny(text, "预警", "告警", "风险", "提醒")) {
| return manufacturingAgentTools.getWarningBoard(memoryId, startDate, endDate, text);
| }
| if (containsAny(text, "分析", "统计", "趋势", "看板", "报表", "总览")) {
| return manufacturingAgentTools.analyzeFactory(memoryId, startDate, endDate, text);
| }
| if (containsAny(text, "办", "处理", "派工", "安排", "闭环", "跟进", "处置")) {
| return manufacturingAgentTools.planActions(memoryId, text);
| }
|
| if (containsAny(text, "生产现场", "现场", "车间")) {
| return manufacturingAgentTools.queryDomain(memoryId, "site", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "计划", "排产", "mps")) {
| return manufacturingAgentTools.queryDomain(memoryId, "plan", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "工单", "作业单", "任务单", "任务")) {
| return manufacturingAgentTools.queryDomain(memoryId, "workorder", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "设备", "维修", "保养", "故障")) {
| return manufacturingAgentTools.queryDomain(memoryId, "device", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "质量", "质检", "不合格", "检验")) {
| return manufacturingAgentTools.queryDomain(memoryId, "quality", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "物料", "库存", "库位", "入库", "出库")) {
| return manufacturingAgentTools.queryDomain(memoryId, "material", keyword, limit, startDate, endDate, text);
| }
| if (containsAny(text, "异常", "例外", "偏差")) {
| return manufacturingAgentTools.queryDomain(memoryId, "exception", keyword, limit, startDate, endDate, text);
| }
| return null;
| }
|
| private boolean containsAny(String text, String... keywords) {
| for (String keyword : keywords) {
| if (text.toLowerCase().contains(keyword.toLowerCase())) {
| return true;
| }
| }
| return false;
| }
|
| private Integer extractLimit(String text) {
| Matcher matcher = LIMIT_PATTERN.matcher(text);
| return matcher.find() ? Integer.parseInt(matcher.group(2)) : 10;
| }
|
| private String extractStartDate(String text) {
| Matcher matcher = DATE_PATTERN.matcher(text);
| return matcher.find() ? matcher.group(1) : null;
| }
|
| private String extractEndDate(String text) {
| Matcher matcher = DATE_PATTERN.matcher(text);
| if (!matcher.find()) {
| return null;
| }
| return matcher.find() ? matcher.group(1) : null;
| }
|
| private String extractKeyword(String text) {
| String cleaned = text
| .replace("查询", "")
| .replace("查看", "")
| .replace("帮我", "")
| .replace("请", "")
| .replace("一下", "")
| .replace("所有", "")
| .replace("全部", "")
| .replace("今年", "")
| .replace("本年", "")
| .replace("去年", "")
| .replace("本月", "")
| .replace("上月", "")
| .replace("本周", "")
| .replace("上周", "")
| .replace("今天", "")
| .replace("昨天", "")
| .replace("近30天", "")
| .replace("近7天", "")
| .replace("近15天", "")
| .replace("近60天", "")
| .replace("最近30天", "")
| .replace("最近7天", "")
| .replace("最近15天", "")
| .replace("最近60天", "")
| .replace("生产现场", "")
| .replace("现场", "")
| .replace("生产工单", "")
| .replace("生产", "")
| .replace("计划", "")
| .replace("排产", "")
| .replace("工单", "")
| .replace("设备", "")
| .replace("质量", "")
| .replace("物料", "")
| .replace("库存", "")
| .replace("异常", "")
| .replace("前10条", "")
| .replace("最近10条", "")
| .trim();
| return cleaned.length() >= 2 ? cleaned : null;
| }
| }
|
|