luxiaotao1123
2024-04-08 9d0acfb65c80c4948c305ca01338f894b87346a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 org.springframework.stereotype.Component;
 
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<String> preTravelPath = generatePreTravelPath(row, bay, lev, shouldIncreaseBay, 10);
        shuttleVo.setPreTravelPath(preTravelPath);
 
 
        wsVo.getShuttleVos().add(shuttleVo);
 
        MapWebSocket.broadcast(JSON.toJSONString(wsVo));
    }
 
    private List<String> generatePreTravelPath(int currentRow, int currentBay, int currentLev, boolean increasingBay, int pathLength) {
        List<String> path = new ArrayList<>();
        int tempRow = currentRow;
        int tempBay = currentBay;
        boolean tempIncreaseBay = increasingBay;
 
        for (int i = 0; i < pathLength; i++) {
            if (tempIncreaseBay) {
                if (tempBay < 30) {
                    tempBay++;
                } else {
                    if (tempRow < 10) {
                        tempRow++;
                    } else {
                        tempRow = 1;  // 如果 row 已经是最大,则回到起始位置
                    }
                    tempIncreaseBay = false;
                }
            } else {
                if (tempBay > 1) {
                    tempBay--;
                } else {
                    if (tempRow < 10) {
                        tempRow++;
                    } else {
                        tempRow = 1;  // 如果 row 已经是最大,则回到起始位置
                    }
                    tempIncreaseBay = true;
                }
            }
            // 将生成的库位号加入路径列表
            path.add(Utils.getLocNo(tempRow, tempBay, currentLev));
        }
 
        return path;
    }
 
}