package com.mes.interaction.workstation.base;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.mes.device.entity.DeviceConfig;
|
import com.mes.device.service.DevicePlcOperationService;
|
import com.mes.device.vo.DevicePlcVO;
|
import com.mes.interaction.BaseDeviceLogicHandler;
|
import com.mes.interaction.workstation.config.WorkstationLogicConfig;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import java.util.Map;
|
|
/**
|
* 卧转立系列设备的通用处理器基类
|
* 负责解析 workstation 配置、提供占位的执行模板,后续具体设备在子类中实现。
|
*
|
* @author mes
|
* @since 2025-11-24
|
*/
|
@Slf4j
|
public abstract class WorkstationBaseHandler extends BaseDeviceLogicHandler {
|
|
protected WorkstationBaseHandler(DevicePlcOperationService devicePlcOperationService) {
|
super(devicePlcOperationService);
|
}
|
|
/**
|
* 解析 workstation 相关配置
|
*/
|
protected WorkstationLogicConfig parseWorkstationConfig(Map<String, Object> logicParams) {
|
WorkstationLogicConfig config = new WorkstationLogicConfig();
|
if (logicParams == null) {
|
return config;
|
}
|
config.setScanIntervalMs(getLogicParam(logicParams, "scanIntervalMs", 10_000));
|
config.setTransferDelayMs(getLogicParam(logicParams, "transferDelayMs", 30_000));
|
config.setVehicleCapacity(getLogicParam(logicParams, "vehicleCapacity", 6000));
|
return config;
|
}
|
|
/**
|
* 默认实现:提示尚未实现具体逻辑
|
*/
|
@Override
|
protected DevicePlcVO.OperationResult doExecute(com.mes.device.entity.DeviceConfig deviceConfig,
|
String operation,
|
java.util.Map<String, Object> params,
|
java.util.Map<String, Object> logicParams) {
|
log.warn("当前设备逻辑尚未实现: deviceType={}, operation={}", deviceConfig.getDeviceType(), operation);
|
return DevicePlcVO.OperationResult.builder()
|
.success(false)
|
.message("设备逻辑待实现: " + deviceConfig.getDeviceType())
|
.build();
|
}
|
|
@Override
|
public String validateLogicParams(DeviceConfig deviceConfig) {
|
// 默认认为配置合法,具体校验交由子类实现
|
return null;
|
}
|
|
@Override
|
public String getDefaultLogicParams() {
|
Map<String, Object> defaults = new HashMap<>();
|
defaults.put("scanIntervalMs", 10_000);
|
defaults.put("transferDelayMs", 30_000);
|
defaults.put("vehicleCapacity", 6_000);
|
try {
|
return objectMapper.writeValueAsString(defaults);
|
} catch (JsonProcessingException e) {
|
return "{\"scanIntervalMs\":10000,\"transferDelayMs\":30000,\"vehicleCapacity\":6000}";
|
}
|
}
|
}
|