package com.zy.asrs.wcs.core.map.websocket; import com.alibaba.fastjson.JSON; import com.zy.asrs.wcs.core.map.entity.MapWsShuttleVo; import com.zy.asrs.wcs.core.map.entity.MapWsVo; import com.zy.asrs.wcs.core.utils.Utils; import org.springframework.scheduling.annotation.Scheduled; import java.util.ArrayList; import java.util.List; /** * Created by vincent on 4/3/2024 */ //@Component public class MockScheduler { private int row = 1; private int bay = 1; private int lev = 1; private boolean shouldIncreaseBay = true; @Scheduled(cron = "0/1 * * * * ? ") public void mock() { MapWsVo wsVo = new MapWsVo(); // shuttle MapWsShuttleVo shuttleVo = new MapWsShuttleVo(); shuttleVo.setShuttleNo("1"); if (shouldIncreaseBay) { if (bay < 30) { bay++; } else { // bay 达到 30 后,row 先增 1 if (row < 10) { row++; } else { row = 1; // 如果 row 已经是最大,则回到起始位置 } shouldIncreaseBay = false; } } else { if (bay > 1) { bay--; } else { // bay 减到 1 后,则 row 先增 1 if (row < 10) { row++; } else { row = 1; // 如果 row 已经是最大,则回到起始位置 } shouldIncreaseBay = true; } } shuttleVo.setCurLocNo(Utils.getLocNo(row, bay, lev)); List preTravelPath = generateFullTravelPath(10, 30, lev); shuttleVo.setTravelPath(preTravelPath); wsVo.getShuttleVos().add(shuttleVo); MapWebSocket.broadcast(JSON.toJSONString(wsVo)); } private List generateFullTravelPath(int maxRow, int maxBay, int currentLev) { List fullPath = new ArrayList<>(); boolean increasingBay = true; // 假设从 bay = 1 开始递增 for (int currentRow = 1; currentRow <= maxRow; currentRow++) { if (increasingBay) { for (int currentBay = 1; currentBay <= maxBay; currentBay++) { fullPath.add(Utils.getLocNo(currentRow, currentBay, currentLev)); } } else { for (int currentBay = maxBay; currentBay >= 1; currentBay--) { fullPath.add(Utils.getLocNo(currentRow, currentBay, currentLev)); } } increasingBay = !increasingBay; // 到达每行的末尾时改变bay的递增/递减方向 } return fullPath; } }