| | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.core.News; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | |
| | | private final DeviceConfig deviceConfig; |
| | | // 允许并行执行多个命令任务(固定线程池)。如需更高并发可调整大小。 |
| | | private final ExecutorService executor = Executors |
| | | .newFixedThreadPool(Math.max(2, Runtime.getRuntime().availableProcessors())); |
| | | .newFixedThreadPool(9999); |
| | | |
| | | public ZyStationFakeConnect(DeviceConfig deviceConfig) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | } |
| | | |
| | | private void handleCommand(StationCommand command) { |
| | | News.info("[WCS Debug] 站点仿真模拟已启动,命令数据={}", JSON.toJSONString(command)); |
| | | Integer taskNo = command.getTaskNo(); |
| | | Integer stationId = command.getStationId(); |
| | | Integer targetStationId = command.getTargetStaNo(); |
| | | |
| | | if(taskNo == 0 && targetStationId == 0){ |
| | | //清空站点 |
| | | resetStation(stationId); |
| | | return; |
| | | } |
| | | |
| | | if (taskNo == 9999 && targetStationId == 0) { |
| | | //生成仿真数据 |
| | | generateFakeData(stationId, taskNo); |
| | | return; |
| | | } |
| | | |
| | | if (taskNo == 9998 && targetStationId == 0) { |
| | | //生成出库站点仿真数据 |
| | | generateFakeOutStationData(stationId); |
| | | return; |
| | | } |
| | | |
| | | String startLev = String.valueOf(stationId).substring(0, 1); |
| | | String endLev = String.valueOf(targetStationId).substring(0, 1); |
| | |
| | | }else { |
| | | diffLevCommand(command); |
| | | } |
| | | } |
| | | |
| | | private void generateFakeData(Integer stationId, Integer taskNo) { |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | return; |
| | | } |
| | | |
| | | status.setTaskNo(taskNo); |
| | | status.setLoading(true); |
| | | status.setBarcode(String.valueOf(System.currentTimeMillis())); |
| | | } |
| | | |
| | | private void generateFakeOutStationData(Integer stationId) { |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | return; |
| | | } |
| | | |
| | | status.setLoading(true); |
| | | } |
| | | |
| | | private void resetStation(Integer stationId) { |
| | | ZyStationStatusEntity status = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null); |
| | | if (status == null) { |
| | | return; |
| | | } |
| | | |
| | | status.setTaskNo(0); |
| | | status.setLoading(false); |
| | | status.setBarcode(""); |
| | | } |
| | | |
| | | private void currentLevCommand(StationCommand command) { |
| | |
| | | return; |
| | | } |
| | | |
| | | stationMove(navigateNodes, taskNo, targetStationId); |
| | | stationMove(navigateNodes, taskNo, targetStationId, false); |
| | | } |
| | | |
| | | private void diffLevCommand(StationCommand command) { |
| | |
| | | return; |
| | | } |
| | | |
| | | stationMove(navigateNodes, taskNo, stationId); |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId); |
| | | stationMove(navigateNodes, taskNo, stationId, true); |
| | | stationMove(targetNavigateNodes, taskNo, targetStationId, false); |
| | | } |
| | | |
| | | private void stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId) { |
| | | private void stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData) { |
| | | Integer lastStationId = null; |
| | | for (int i = 0; i < navigateNodes.size(); i++) { |
| | | NavigateNode navigateNode = navigateNodes.get(i); |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (nextStatus.getTaskNo() == 0) { |
| | | if (nextStatus.getTaskNo() == 0 || nextStatus.getTaskNo() == 9999) { |
| | | break; |
| | | } |
| | | |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | |
| | | synchronized (status) { |
| | | status.setTaskNo(taskNo); |
| | | status.setTargetStaNo(targetStationId); |
| | | status.setLoading(true); |
| | | } |
| | | |
| | | if (lastStationId != null) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | synchronized (status) { |
| | | status.setTaskNo(taskNo); |
| | | status.setTargetStaNo(targetStationId); |
| | | status.setLoading(true); |
| | | } |
| | | |
| | | lastStationId = currentStationId; |
| | | sleep(1000); |
| | | } |
| | | |
| | | sleep(10000); |
| | | if (lastStationId != null) { |
| | | Integer finalLastStationId = lastStationId; |
| | | ZyStationStatusEntity lastStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(finalLastStationId)).findFirst().orElse(null); |
| | | if (lastStatus != null) { |
| | | synchronized (lastStatus) { |
| | | lastStatus.setTaskNo(0); |
| | | lastStatus.setTargetStaNo(0); |
| | | lastStatus.setLoading(false); |
| | | if (clearData) { |
| | | sleep(10000); |
| | | if (lastStationId != null) { |
| | | Integer finalLastStationId = lastStationId; |
| | | ZyStationStatusEntity lastStatus = statusList.stream() |
| | | .filter(item -> item.getStationId().equals(finalLastStationId)).findFirst().orElse(null); |
| | | if (lastStatus != null) { |
| | | synchronized (lastStatus) { |
| | | lastStatus.setTaskNo(0); |
| | | lastStatus.setTargetStaNo(0); |
| | | lastStatus.setLoading(false); |
| | | } |
| | | } |
| | | } |
| | | } |