| | |
| | | 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 org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Created by vincent on 4/3/2024 |
| | | */ |
| | | @Component |
| | | //@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() { |
| | |
| | | // shuttle |
| | | MapWsShuttleVo shuttleVo = new MapWsShuttleVo(); |
| | | shuttleVo.setShuttleNo("1"); |
| | | shuttleVo.setCurLocNo("1-1-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<String> preTravelPath = generateFullTravelPath(10, 30, lev); |
| | | shuttleVo.setTravelPath(preTravelPath); |
| | | |
| | | |
| | | wsVo.getShuttleVos().add(shuttleVo); |
| | | |
| | | MapWebSocket.broadcast(JSON.toJSONString(wsVo)); |
| | | } |
| | | |
| | | private List<String> generateFullTravelPath(int maxRow, int maxBay, int currentLev) { |
| | | List<String> 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; |
| | | } |
| | | |
| | | } |