huang
2025-11-18 1566e4c7604d85737ea67fe6757e71b8185fa48e
mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java
@@ -6,6 +6,7 @@
import com.mes.device.service.DeviceConfigService;
import com.mes.device.service.DeviceGroupRelationService;
import com.mes.device.service.DevicePlcOperationService;
import com.mes.device.util.ConfigJsonHelper;
import com.mes.device.vo.DeviceGroupVO;
import com.mes.device.vo.DevicePlcVO;
import com.mes.service.PlcTestWriteService;
@@ -247,13 +248,21 @@
            throw new IllegalArgumentException("设备信息为空");
        }
        // 优先从configJson中获取
        Map<String, Object> configParams = ConfigJsonHelper.parseToMap(device.getConfigJson(), objectMapper);
        Object plcProjectId = configParams.get(PLC_PROJECT_ID_KEY);
        if (plcProjectId != null) {
            return String.valueOf(plcProjectId);
        }
        // 其次从扩展参数中获取(兼容旧配置)
        String extra = device.getExtraParams();
        if (extra != null && !extra.isEmpty()) {
            try {
                Map<String, Object> extraParams = objectMapper.readValue(extra, new TypeReference<Map<String, Object>>() {});
                Object plcProjectId = extraParams.get(PLC_PROJECT_ID_KEY);
                if (plcProjectId != null) {
                    return String.valueOf(plcProjectId);
                Object plcProjectIdFromExtra = extraParams.get(PLC_PROJECT_ID_KEY);
                if (plcProjectIdFromExtra != null) {
                    return String.valueOf(plcProjectIdFromExtra);
                }
            } catch (Exception e) {
                log.warn("解析设备扩展参数失败, deviceId={}", device.getId(), e);
@@ -271,7 +280,7 @@
        throw new IllegalStateException("无法解析设备的 PLC 项目标识, deviceId=" + device.getId());
    }
    private enum PlcOperationType {
    public enum PlcOperationType {
        REQUEST("PLC请求", "PLC 请求发送成功", "PLC 请求发送失败"),
        REPORT("PLC汇报", "PLC 汇报模拟成功", "PLC 汇报模拟失败"),
        RESET("PLC重置", "PLC 状态已重置", "PLC 状态重置失败");