#
luxiaotao1123
2024-04-12 5c0622d48c825ca4b75f63dda78d51ed75bc7a2f
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
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<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;
    }
 
}