This commit is contained in:
2025-10-03 17:53:52 +08:00
parent a08dc8b17d
commit 860ccb17f2

View File

@@ -45,9 +45,9 @@ public class InstructionServiceImpl implements IInstructionService {
public List<String> execute(String command) { public List<String> execute(String command) {
// 存储接收的消息到Redis队列 // 存储接收的消息到Redis队列
storeMessageToRedis("instruction:request", command); storeMessageToRedis("instruction:request", command);
List<String> result; List<String> result;
if (command == null || command.trim().isEmpty()) { if (command == null || command.trim().isEmpty()) {
result = Collections.singletonList("请输入指令"); result = Collections.singletonList("请输入指令");
} else { } else {
@@ -72,14 +72,14 @@ public class InstructionServiceImpl implements IInstructionService {
result = Collections.singletonList(helpText()); result = Collections.singletonList(helpText());
} }
} }
// 存储返回的消息到Redis队列 // 存储返回的消息到Redis队列
String response = result != null ? String.join("\n", result) : ""; String response = result != null ? String.join("\n", result) : "";
storeMessageToRedis("instruction:response", response); storeMessageToRedis("instruction:response", response);
return result; return result;
} }
/** /**
* 将消息存储到Redis队列最多保留100条 * 将消息存储到Redis队列最多保留100条
* @param key Redis键 * @param key Redis键
@@ -101,13 +101,13 @@ public class InstructionServiceImpl implements IInstructionService {
System.err.println("存储消息到Redis失败: " + e.getMessage()); System.err.println("存储消息到Redis失败: " + e.getMessage());
} }
} }
@Override @Override
public List<String> getHistory(String type, Integer limit) { public List<String> getHistory(String type, Integer limit) {
if (stringRedisTemplate == null) { if (stringRedisTemplate == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
try { try {
// 确定Redis键 // 确定Redis键
String key; String key;
@@ -118,13 +118,13 @@ public class InstructionServiceImpl implements IInstructionService {
} else { } else {
return Collections.emptyList(); return Collections.emptyList();
} }
// 确定获取数量默认100条 // 确定获取数量默认100条
int count = (limit != null && limit > 0) ? Math.min(limit, 100) : 100; int count = (limit != null && limit > 0) ? Math.min(limit, 100) : 100;
// 从Redis获取历史消息索引0到count-1 // 从Redis获取历史消息索引0到count-1
List<String> messages = stringRedisTemplate.opsForList().range(key, 0, count - 1); List<String> messages = stringRedisTemplate.opsForList().range(key, 0, count - 1);
return messages != null ? messages : Collections.emptyList(); return messages != null ? messages : Collections.emptyList();
} catch (Exception e) { } catch (Exception e) {
System.err.println("获取历史消息失败: " + e.getMessage()); System.err.println("获取历史消息失败: " + e.getMessage());
@@ -279,21 +279,14 @@ public class InstructionServiceImpl implements IInstructionService {
private static final HashMap<String, String> productWithJF = new HashMap<>(); private static final HashMap<String, String> productWithJF = new HashMap<>();
static { static {
/**
* 130 productWithJF.put("ZQD110F-EB031", "https://u.jd.com/0gGPOZX");
* https://u.jd.com/S1BkTIS productWithJF.put("ZQD130F-EB130", "https://u.jd.com/0OGTvHh");
* 130B productWithJF.put("ZQD130F-EB130B", "https://u.jd.com/0GGWEOR");
* https://u.jd.com/S1BkvGO productWithJF.put("ZQD150F-EB150", "https://u.jd.com/0O8BYjb");
* 150 productWithJF.put("ZQD180F-EB200", "https://u.jd.com/0gGSoiN");
* https://u.jd.com/SaBkAXo productWithJF.put("ZQD115F-12LCS", "https://u.jd.com/0DGSFcH");
* 180 productWithJF.put("CXW-298-IQ92DPRO", "https://u.jd.com/0OG04su");
* https://u.jd.com/SDBkTJg
* */
productWithJF.put("ZQD130F-EB130", "https://u.jd.com/S1BkTIS");
productWithJF.put("ZQD130F-EB130B", "https://u.jd.com/S1BkvGO");
productWithJF.put("ZQD150F-EB150", "https://u.jd.com/SaBkAXo");
productWithJF.put("ZQD180F-EB200", "https://u.jd.com/SDBkTJg");
productWithJF.put("CXW-298-IQ92DPRO", "https://u.jd.com/SrWlqkb");
} }
private static final List<String> phoneWithTF = new ArrayList<>(); private static final List<String> phoneWithTF = new ArrayList<>();