| | |
| | | return mainProcessPseudocodeService.queryMainProcessPseudocode(refresh); |
| | | } |
| | | |
| | | @Override |
| | | public Object buildDiagnosisSnapshot(JSONObject args) { |
| | | String wh = mustStr(args, "warehouseCode"); |
| | | List<String> crnDeviceNos = optStrList(args, "crnDeviceNos"); |
| | | List<String> taskIds = optStrList(args, "taskIds"); |
| | | int lookbackSeconds = optInt(args, "lookbackSeconds", 300); |
| | | int logMaxLines = optInt(args, "logMaxLines", 600); |
| | | boolean includeConfig = optBool(args, "includeConfig", true); |
| | | |
| | | long now = System.currentTimeMillis(); |
| | | long fromTs = now - lookbackSeconds * 1000L; |
| | | |
| | | // 1) crn devices |
| | | JSONObject devArgs = new JSONObject(); |
| | | devArgs.put("deviceNos", crnDeviceNos); |
| | | JSONObject devices = (JSONObject) getCrnDeviceStatus(devArgs); |
| | | |
| | | // 2) tasks |
| | | JSONObject taskArgs = new JSONObject(); |
| | | taskArgs.put("warehouseCode", wh); |
| | | taskArgs.put("taskIds", taskIds); |
| | | taskArgs.put("limit", 200); |
| | | JSONObject tasks = (JSONObject) getTasks(taskArgs); |
| | | |
| | | // 3) logs (一次性取回,然后做分桶+排序+截断) |
| | | JSONObject logArgs = new JSONObject(); |
| | | logArgs.put("warehouseCode", wh); |
| | | logArgs.put("fromTs", fromTs); |
| | | logArgs.put("toTs", now); |
| | | // logArgs.put("deviceIds", deviceIds); |
| | | logArgs.put("taskIds", taskIds); |
| | | logArgs.put("maxLines", logMaxLines); |
| | | JSONObject logs = (JSONObject) getLogs(logArgs); |
| | | |
| | | // 4) 结构化快照输出(建议:分桶) |
| | | JSONObject snapshot = new JSONObject(); |
| | | snapshot.put("warehouseCode", wh); |
| | | snapshot.put("generatedTs", now); |
| | | snapshot.put("timeRange", new JSONObject() |
| | | .fluentPut("fromTs", fromTs) |
| | | .fluentPut("toTs", now) |
| | | .fluentPut("lookbackSeconds", lookbackSeconds)); |
| | | |
| | | snapshot.put("devices", devices); |
| | | snapshot.put("tasks", tasks); |
| | | snapshot.put("logs", logs); |
| | | |
| | | JSONArray hints = new JSONArray(); |
| | | hints.add("Prefer diagnosing with snapshot.devices + snapshot.tasks + snapshot.logs"); |
| | | hints.add("Logs are already filtered by time range; if missing, expand lookbackSeconds"); |
| | | snapshot.put("hints", hints); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("snapshot", snapshot); |
| | | return data; |
| | | } |
| | | |
| | | // --------- helpers --------- |
| | | |
| | | private String mustStr(JSONObject o, String key) { |
| | | if (o == null || o.getString(key) == null || o.getString(key).trim().isEmpty()) |
| | | throw new IllegalArgumentException(key + " is required"); |
| | | return o.getString(key).trim(); |
| | | } |
| | | |
| | | private long mustLong(JSONObject o, String key) { |
| | | if (o == null || !o.containsKey(key)) throw new IllegalArgumentException(key + " is required"); |
| | | return o.getLongValue(key); |
| | | } |
| | | |
| | | private int optInt(JSONObject o, String key, int def) { |
| | | if (o == null || !o.containsKey(key)) return def; |