| | |
| | | |
| | | @Override |
| | | public InteractionResult execute(InteractionContext context) { |
| | | List<String> processed = context.getProcessedGlassIds(); |
| | | if (CollectionUtils.isEmpty(processed)) { |
| | | return InteractionResult.waitResult("没有可存储的玻璃", null); |
| | | } |
| | | try { |
| | | // 前置条件验证 |
| | | if (context.getCurrentDevice() == null) { |
| | | return InteractionResult.fail("设备配置不存在"); |
| | | } |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("storedCount", processed.size()); |
| | | data.put("storedGlasses", processed); |
| | | return InteractionResult.success(data); |
| | | // 优先使用处理后的玻璃ID,如果没有则使用上大车的玻璃ID |
| | | List<String> processed = context.getProcessedGlassIds(); |
| | | if (CollectionUtils.isEmpty(processed)) { |
| | | processed = context.getLoadedGlassIds(); |
| | | if (CollectionUtils.isEmpty(processed)) { |
| | | // 尝试从共享数据获取 |
| | | Object processedGlasses = context.getSharedData().get("processedGlasses"); |
| | | if (processedGlasses instanceof List) { |
| | | @SuppressWarnings("unchecked") |
| | | List<String> list = (List<String>) processedGlasses; |
| | | processed = list; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (CollectionUtils.isEmpty(processed)) { |
| | | return InteractionResult.waitResult("没有可存储的玻璃", null); |
| | | } |
| | | |
| | | // 验证玻璃ID |
| | | for (String glassId : processed) { |
| | | if (glassId == null || glassId.trim().isEmpty()) { |
| | | return InteractionResult.fail("玻璃ID不能为空"); |
| | | } |
| | | } |
| | | |
| | | // 执行存储操作 |
| | | context.getSharedData().put("storedGlasses", processed); |
| | | context.getSharedData().put("storageTime", System.currentTimeMillis()); |
| | | |
| | | // 后置条件检查 |
| | | Object stored = context.getSharedData().get("storedGlasses"); |
| | | if (stored == null) { |
| | | return InteractionResult.fail("玻璃存储失败:存储数据为空"); |
| | | } |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("storedCount", processed.size()); |
| | | data.put("storedGlasses", processed); |
| | | data.put("deviceId", context.getCurrentDevice().getId()); |
| | | data.put("deviceCode", context.getCurrentDevice().getDeviceCode()); |
| | | return InteractionResult.success(data); |
| | | } catch (Exception e) { |
| | | return InteractionResult.fail("玻璃存储交互执行异常: " + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |