package com.zy.core.network.fake; import com.alibaba.fastjson.JSON; import com.zy.asrs.entity.DeviceConfig; import com.zy.core.model.CommandResponse; import com.zy.core.model.command.StationCommand; import com.zy.core.network.api.ZyStationConnectApi; import com.zy.core.network.entity.ZyStationStatusEntity; import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * 输送站假连接(模拟) */ public class ZyStationFakeConnect implements ZyStationConnectApi { private ZyStationStatusEntity status; private final DeviceConfig deviceConfig; private final ExecutorService executor = Executors.newSingleThreadExecutor(); public ZyStationFakeConnect(DeviceConfig deviceConfig) { this.deviceConfig = deviceConfig; this.status = JSON.parseObject(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class); if (this.status == null) { this.status = new ZyStationStatusEntity(); this.status.setStationId(deviceConfig.getDeviceNo()); } } @Override public boolean connect() { return true; } @Override public boolean disconnect() { return true; } @Override public List getStatus() { return Collections.singletonList(status); } @Override public CommandResponse sendCommand(StationCommand command) { CommandResponse response = new CommandResponse(false); executor.submit(() -> handleCommand(command)); response.setResult(true); return response; } private void handleCommand(StationCommand command) { // 简单的模拟:设置工作号和目标站,并模拟有物/可入/可出状态切换 this.status.setTaskNo(command.getTaskNo()); this.status.setTargetStaNo(command.getTargetStaNo()); // 模拟到站过程 this.status.setAutoing(true); this.status.setLoading(true); sleep(1000); // 模拟放下托盘 this.status.setInEnable(true); this.status.setOutEnable(false); sleep(1000); // 完成任务,复位状态 this.status.setLoading(false); this.status.setAutoing(false); this.status.setTaskNo(0); this.status.setInEnable(false); this.status.setOutEnable(true); } private void sleep(long ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { e.printStackTrace(); } } }