huang
2025-11-20 366ba040d2447bacd3455299425e3166f1f992bb
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
package com.mes.interaction.flow;
 
import com.mes.device.entity.DeviceConfig;
import com.mes.interaction.DeviceInteraction;
import com.mes.interaction.base.InteractionContext;
import com.mes.interaction.base.InteractionResult;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 大理片交互实现
 */
@Component
public class LargeGlassInteraction implements DeviceInteraction {
 
    @Override
    public String getDeviceType() {
        return DeviceConfig.DeviceType.LARGE_GLASS;
    }
 
    @Override
    public InteractionResult execute(InteractionContext context) {
        try {
            // 前置条件验证
            if (context.getCurrentDevice() == null) {
                return InteractionResult.fail("设备配置不存在");
            }
 
            // 检查上大车是否完成
            Object source = context.getSharedData().get("glassesFromVehicle");
            List<String> glassQueue = castList(source);
            if (CollectionUtils.isEmpty(glassQueue)) {
                // 也尝试从上下文获取
                glassQueue = context.getLoadedGlassIds();
                if (CollectionUtils.isEmpty(glassQueue)) {
                    return InteractionResult.waitResult("等待上大车输出", null);
                }
            }
 
            // 验证玻璃ID
            for (String glassId : glassQueue) {
                if (glassId == null || glassId.trim().isEmpty()) {
                    return InteractionResult.fail("玻璃ID不能为空");
                }
            }
 
            // 执行大理片处理
            List<String> processed = new ArrayList<>(glassQueue);
            context.setProcessedGlassIds(processed);
            context.getSharedData().put("processedGlasses", processed);
            context.getSharedData().put("largeGlassProcessTime", System.currentTimeMillis());
 
            // 后置条件检查
            if (context.getProcessedGlassIds().isEmpty()) {
                return InteractionResult.fail("大理片处理失败:处理后的玻璃ID列表为空");
            }
 
            Map<String, Object> data = new HashMap<>();
            data.put("processedCount", processed.size());
            data.put("processedGlasses", 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());
        }
    }
 
    @SuppressWarnings("unchecked")
    private List<String> castList(Object value) {
        if (value instanceof List) {
            return (List<String>) value;
        }
        return null;
    }
}