#
luxiaotao1123
2024-12-06 1060750d8d49c9d555f15b260ec22de7bd6524a9
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//package com.zy.acs.manager.core;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.zy.acs.manager.common.domain.TaskDto;
//import com.zy.acs.manager.core.service.MainService;
//import com.zy.acs.manager.core.service.MapService;
//import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam;
//import com.zy.acs.manager.manager.entity.*;
//import com.zy.acs.manager.manager.enums.BusStsType;
//import com.zy.acs.manager.manager.enums.LocStsType;
//import com.zy.acs.manager.manager.enums.TaskStsType;
//import com.zy.acs.manager.manager.enums.TaskTypeType;
//import com.zy.acs.manager.manager.service.*;
//import com.zy.acs.manager.system.controller.BaseController;
//import com.zy.acs.manager.system.service.ConfigService;
//import com.zy.acs.framework.common.Cools;
//import com.zy.acs.framework.common.R;
//import com.zy.acs.framework.common.SnowflakeIdWorker;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
///**
// * Created by vincent on 2023/6/20
// */
//@RestController
//@RequestMapping("/test")
//public class TestController extends BaseController {
//
//    @Autowired
//    private BusService busService;
//    @Autowired
//    private MainService mainService;
//    @Autowired
//    private SnowflakeIdWorker snowflakeIdWorker;
//    @Autowired
//    private AgvModelService agvModelService;
//    @Autowired
//    private AgvService agvService;
//    @Autowired
//    private AgvDetailService agvDetailService;
//    @Autowired
//    private TaskService taskService;
//    @Autowired
//    private CodeService codeService;
//    @Autowired
//    private MapService mapService;
//
//
///*
//TRUNCATE man_bus;
//TRUNCATE man_task;
//TRUNCATE man_action;
//UPDATE man_loc SET loc_sts = 16 WHERE loc_sts = 18;
//UPDATE man_loc SET loc_sts = 15 WHERE loc_sts = 17;
//*/
//
//    @Value("${auto.move}")
//    private Boolean autoMove;
//    @Value("${auto.demo}")
//    private Boolean autoDemo;
//    @Value("${auto.demo1}")
//    private Boolean autoDemo1;
//    @Value("${auto.demo2}")
//    private Boolean autoDemo2;
//    @Value("${auto.size}")
//    private Integer autoSize;
//    @Autowired
//    private LocService locService;
//    @Autowired
//    private ConfigService configService;
//
//    // http://localhost:9090/test/auto/move
//    @GetMapping("/auto/move")
//    public R autoMove() {
//        this.autoMove = !this.autoMove;
//        return R.ok().add(Cools.add("autoMove", this.autoMove));
//    }
//
//    @Scheduled(cron = "0/1 * * * * ? ")
//    private void move1() throws InterruptedException {
//        if (!this.autoMove) { return; }
//        Agv agv = agvService.selectByUuid("1");
//        AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
//        if (taskService.count(new LambdaQueryWrapper<Task>()
//                .eq(Task::getAgvId, agv.getId())
//                .and(i -> {
//                    i.eq(Task::getTaskSts, TaskStsType.WAITING.val())
//                            .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
//                            .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
//                })) > 0) {
//            return;
//        }
//        if (!agvService.judgeEnable(agv.getId())) {
//            return;
//        }
//        Code randomCode = this.getRandomCode(agvDetail);
//        if (null == randomCode) {
//            return;
//        }
//        if (mainService.buildMinorTask(agv, agvDetail, TaskTypeType.MOVE, randomCode.getData())) {
//            System.out.println(agv.getUuid() + "开始走行演示...");
//        }
//    }
////    @Scheduled(cron = "0 */3 * * * ? ")
//    @Scheduled(cron = "0/1 * * * * ? ")
//    private void move2() throws InterruptedException {
//        if (!this.autoMove) { return; }
//        Agv agv = agvService.selectByUuid("2");
//        AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
//        if (taskService.count(new LambdaQueryWrapper<Task>()
//                .eq(Task::getAgvId, agv.getId())
//                .and(i -> {
//                    i.eq(Task::getTaskSts, TaskStsType.WAITING.val())
//                            .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val())
//                            .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val());
//                })) > 0) {
//            return;
//        }
//        if (!agvService.judgeEnable(agv.getId())) {
//            return;
//        }
//        Code randomCode = this.getRandomCode(agvDetail);
//        if (null == randomCode) {
//            return;
//        }
//        if (mainService.buildMinorTask(agv, agvDetail, TaskTypeType.MOVE, randomCode.getData())) {
//            System.out.println(agv.getUuid() + "开始走行演示...");
//        }
//    }
//
//    public Code getRandomCode(AgvDetail agvDetail) {
//        Code startCode = codeService.getById(agvDetail.getRecentCode());
//        List<String> notInCodeList = new ArrayList<>();
//        notInCodeList.add("00000024");
//        notInCodeList.add("00000025");
//        notInCodeList.add("00000026");
//        notInCodeList.add("00000027");
//        notInCodeList.add("00000028");
//        notInCodeList.add("00000029");
//        notInCodeList.add("00000023");
//        notInCodeList.add("00000035");
//        List<Code> list = codeService.list(new LambdaQueryWrapper<Code>().notIn(Code::getData, notInCodeList));
//        Collections.shuffle(list);
//        for (Code endCode : list) {
//            List<String> pathList = mapService.validFeasibility(startCode, endCode);
//            if (pathList.size() >= 5) {
//                return endCode;
//            }
//        }
//        return list.stream().findFirst().orElse(null);
//    }
//
//    // http://localhost:9090/test/auto?size=1
//    @GetMapping("/auto")
//    public R auto(@RequestParam(value = "size", required = false) Integer size) {
//        if (null != size) {
//            this.autoSize = size;
//        }
//        this.autoDemo = !this.autoDemo;
//        return R.ok(Cools.add("autoDemo", this.autoDemo));
//    }
//
//    @Scheduled(cron = "0/1 * * * * ? ")
//    private void demo() throws InterruptedException {
//        if (!this.autoDemo) { return; }
//        int busLimit = configService.getVal("busLimit", Integer.class);
//        if (autoSize != null) {
//            busLimit = autoSize;
//        }
//        busLimit = 2;
//        AgvModel agvModel = agvModelService.list(new LambdaQueryWrapper<>()).stream().findFirst().orElse(null);
//        if (null != agvModel) {
//            busLimit = agvModel.getBackpack() * 2;
//        }
//        // 在库
//        int stock = 0;
//        List<Loc> stockList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.STOCK.val())
//                .ge(Loc::getRow, 1)
//                .le(Loc::getRow, 2)
//        );
//        Collections.shuffle(stockList);
//        if (stockList.size() > busLimit) {
//            stockList = stockList.subList(0, busLimit);
//        }
//        stock = stockList.size();
//        if (stock == 0) { return;}
//
//        // 空闲
//        List<Loc> idleList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.IDLE.val())
//                .ge(Loc::getRow, 1)
//                .le(Loc::getRow, 2)
//        );
//        Collections.shuffle(idleList);
//        if (idleList.size() > stock) {
//            idleList = idleList.subList(0, stock);
//        }
//
//        if (stockList.size() == idleList.size()) {
//            OpenBusSubmitParam param = new OpenBusSubmitParam();
//            param.setBatch("batchNo");
//            for (int i = 0; i < stock; i++) {
//                Loc stockLoc = stockList.get(i);
//                Loc idleLoc = idleList.get(i);
//
//                TaskDto taskDto = new TaskDto();
//                taskDto.setOriLoc(stockLoc.getLocNo());
//                taskDto.setDestLoc(idleLoc.getLocNo());
//                taskDto.setSeqNum(String.valueOf(snowflakeIdWorker.nextId()).substring(15, 19));
//
//                param.getTaskList().add(taskDto);
//
//            }
//
//            if (Cools.isEmpty(busService.selectBySts(BusStsType.RECEIVE, "autoDemo"))
//                    && Cools.isEmpty(busService.selectBySts(BusStsType.PROGRESS, "autoDemo"))
//            ) {
//                mainService.generateBusAndTask(param, "autoDemo");
//            }
//
//        }
//
//    }
//
//
//    // http://localhost:9090/test/auto1?size=1
//    @GetMapping("/auto1")
//    public R auto1(@RequestParam(value = "size", required = false) Integer size) {
//       if (null != size) {
//           this.autoSize = size;
//       }
//       this.autoDemo1 = !this.autoDemo1;
//        return R.ok(Cools.add("autoDemo", this.autoDemo1));
//    }
//
//    @Scheduled(cron = "0/3 * * * * ? ")
//    private void demo1() throws InterruptedException {
//        if (!this.autoDemo1) { return; }
//        int busLimit = configService.getVal("busLimit", Integer.class);
//        if (autoSize != null) {
//            busLimit = autoSize;
//        }
//        // 在库
//        int stock = 0;
//        List<Loc> stockList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.STOCK.val())
//                .ge(Loc::getRow, 1)
//                .le(Loc::getRow, 2)
//        );
//        Collections.shuffle(stockList);
//        if (stockList.size() > busLimit) {
//            stockList = stockList.subList(0, busLimit);
//        }
//        stock = stockList.size();
//        if (stock == 0) { return;}
//
//        // 空闲
//        List<Loc> idleList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.IDLE.val())
//                .ge(Loc::getRow, 1)
//                .le(Loc::getRow, 2)
//        );
//        Collections.shuffle(idleList);
//        if (idleList.size() > stock) {
//            idleList = idleList.subList(0, stock);
//        }
//
//        if (stockList.size() == idleList.size()) {
//            OpenBusSubmitParam param = new OpenBusSubmitParam();
//            param.setBatch("batchNo");
//            for (int i = 0; i < stock; i++) {
//                Loc stockLoc = stockList.get(i);
//                Loc idleLoc = idleList.get(i);
//
//                TaskDto taskDto = new TaskDto();
//                taskDto.setOriLoc(stockLoc.getLocNo());
//                taskDto.setDestLoc(idleLoc.getLocNo());
//                taskDto.setSeqNum(String.valueOf(snowflakeIdWorker.nextId()).substring(15, 19));
//
//                param.getTaskList().add(taskDto);
//
//            }
//
//            if (Cools.isEmpty(busService.selectBySts(BusStsType.RECEIVE, "autoDemo1"))
//                    && Cools.isEmpty(busService.selectBySts(BusStsType.PROGRESS, "autoDemo1"))
//            ) {
//                mainService.generateBusAndTask(param, "autoDemo1");
//            }
//
//        }
//
//    }
//
//    // http://localhost:9090/test/auto2?size=1
//    @GetMapping("/auto2")
//    public R auto2(@RequestParam(value = "size", required = false) Integer size) {
//        if (null != size) {
//            this.autoSize = size;
//        }
//        this.autoDemo2 = !this.autoDemo2;
//        return R.ok(Cools.add("autoDemo", this.autoDemo2));
//    }
//
//    @Scheduled(cron = "0/3 * * * * ? ")
//    private void demo2() throws InterruptedException {
//        if (!this.autoDemo2) { return; }
//        int busLimit = configService.getVal("busLimit", Integer.class);
//        if (autoSize != null) {
//            busLimit = autoSize;
//        }
//        // 在库
//        int stock = 0;
//        List<Loc> stockList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.STOCK.val())
//                .ge(Loc::getRow, 3)
//                .le(Loc::getRow, 4)
//        );
//        Collections.shuffle(stockList);
//        if (stockList.size() > busLimit) {
//            stockList = stockList.subList(0, busLimit);
//        }
//        stock = stockList.size();
//        if (stock == 0) { return;}
//
//        // 空闲
//        List<Loc> idleList = locService.list(new LambdaQueryWrapper<Loc>()
//                .eq(Loc::getLocSts, LocStsType.IDLE.val())
//                .ge(Loc::getRow, 3)
//                .le(Loc::getRow, 4)
//        );
//        Collections.shuffle(idleList);
//        if (idleList.size() > stock) {
//            idleList = idleList.subList(0, stock);
//        }
//
//        if (stockList.size() == idleList.size()) {
//            OpenBusSubmitParam param = new OpenBusSubmitParam();
//            param.setBatch("batchNo");
//            for (int i = 0; i < stock; i++) {
//                Loc stockLoc = stockList.get(i);
//                Loc idleLoc = idleList.get(i);
//
//                TaskDto taskDto = new TaskDto();
//                taskDto.setOriLoc(stockLoc.getLocNo());
//                taskDto.setDestLoc(idleLoc.getLocNo());
//                taskDto.setSeqNum(String.valueOf(snowflakeIdWorker.nextId()).substring(15, 19));
//
//                param.getTaskList().add(taskDto);
//
//            }
//
//            if (Cools.isEmpty(busService.selectBySts(BusStsType.RECEIVE, "autoDemo2"))
//                    && Cools.isEmpty(busService.selectBySts(BusStsType.PROGRESS, "autoDemo2"))
//            ) {
//                mainService.generateBusAndTask(param, "autoDemo2");
//            }
//
//        }
//
//    }
//
//}