#
Junjie
2025-04-17 035c1e94569a2c043f232f3452d25ad2e51bcf23
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package com.zy.asrs.wcs.core.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.common.utils.HttpHandler;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.common.SnowflakeIdWorker;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.core.domain.dto.BasLiftStaDto;
import com.zy.asrs.wcs.core.domain.param.AgvTaskCreateParam;
import com.zy.asrs.wcs.core.domain.param.CreateInTaskParam;
import com.zy.asrs.wcs.core.domain.param.CreateOutTaskParam;
import com.zy.asrs.wcs.core.domain.param.CreateWcsTaskParam;
import com.zy.asrs.wcs.core.entity.*;
import com.zy.asrs.wcs.core.model.enums.TaskCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.*;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.enums.WorkModeType;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import com.zy.asrs.wcs.system.entity.Dict;
import com.zy.asrs.wcs.system.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
@Service("openService")
@Slf4j
public class OpenServiceImpl implements OpenService {
 
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskCtgService taskCtgService;
    @Autowired
    private LocService locService;
    @Autowired
    private DictService dictService;
    @Autowired
    private BasConveyorPathService basConveyorPathService;
    @Autowired
    private BasConveyorStaService basConveyorStaService;
    @Autowired
    private BasConveyorService basConveyorService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private BasLiftService basLiftService;
    @Autowired
    private TaskCacheService taskCacheService;
 
 
    @Override
    @Transactional
    public R createInTask(CreateInTaskParam param, CreateWcsTaskParam createWcsTaskParam) {
        //获取入库任务类型
        TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                .eq(TaskCtg::getStatus, 1));
        if (taskCtg == null) {
            throw new CoolException("任务类型异常");
        }
 
        Long hostId = 1L;//默认主仓库
 
        Loc loc = locService.selectByLocNo(param.getDestLoc());
        if (loc == null) {
            throw new CoolException("库位号不存在");
        }
 
        //获取严格模式参数
        boolean mapStrict = true;//默认严格模式
        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "shuttleMapStrict"));
        if (dict != null) {
            mapStrict = Boolean.parseBoolean(dict.getValue());
        }
 
        if (mapStrict && !loc.getLocStsFlag().equals("O")) {
            throw new CoolException("库位状态不满足入库条件");
        }
 
        Task one = taskService.getOne(new LambdaQueryWrapper<Task>()
                .eq(Task::getTaskCtg, taskCtg.getId())
                .eq(Task::getOriginSite, param.getOriginSite())
                .eq(Task::getDestSite, param.getDestSite())
                .eq(Task::getDestLoc, param.getDestLoc()));
        if (one != null) {
            throw new CoolException("任务已存在");
        }
 
        String destSite = param.getDestSite();
        if (Cools.isEmpty(param.getDestSite())) {
            //目标站为空则使用WCS系统内置路径
            BasConveyorPath path = basConveyorPathService.getOne(new LambdaQueryWrapper<BasConveyorPath>()
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId())
                    .eq(BasConveyorPath::getHostId, hostId)
                    .eq(BasConveyorPath::getStnNo, param.getOriginSite()));
            if(path == null) {
                throw new CoolException("内置路径不存在");
            }
            destSite = String.valueOf(path.getDeviceStn());
        }
 
        //判断出入库模式
        BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>()
                .eq(BasConveyorSta::getSiteNo, destSite));
        if (!basConveyorSta.getWorkMode().equals((int) WorkModeType.PAKIN_MODE.id)) {
            //不是入库模式,检测是否可切换入库
            //获取出库任务类型
            TaskCtg taskInCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                    .eq(TaskCtg::getStatus, 1));
            if (taskInCtg == null) {
                throw new CoolException("任务类型异常");
            }
            List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                    .eq(Task::getTaskCtg, taskInCtg.getId()));
            if (!tasks.isEmpty()) {
                throw new CoolException("当前存在出库任务,无法切换入库模式");
            }
 
            BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
            if(basConveyor == null) {
                throw new CoolException("输送线不存在");
            }
 
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
            if(devpThread == null) {
                throw new CoolException("输送线线程不存在");
            }
 
            boolean result = devpThread.switchWorkMode(Integer.parseInt(destSite), WorkModeType.PAKIN_MODE.id);
            if (!result) {
                throw new CoolException("模式切换失败");
            }
        }
 
        //优先级
        Integer priority = 10;
        if (param.getPriority() != null) {
            priority = param.getPriority();
        }
 
        if (createWcsTaskParam != null) {
            //转发agv
            if (!createWcsTaskParam.getFrmPos().equals("06YZ0001")){
                try {
                    AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
                    getInRequestParam(agvTaskCreateParam, createWcsTaskParam);
                    String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit");
                    if (!httpRequest.equals("SUCCESS")){
                        throw new CoolException("转发AGV任务失败" + httpRequest);
                    }
 
                    Task task = new Task();
                    task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
                    task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
                    task.setWmsTaskNo(param.getTaskNo());
                    task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
                    task.setTaskCtg(taskCtg.getId());
                    task.setPriority(priority);
                    task.setOriginSite(param.getOriginSite());
                    task.setOriginLoc(null);
                    task.setDestSite(destSite);
                    task.setDestLoc(param.getDestLoc());
                    task.setZpallet(param.getBarcode());
                    task.setIoTime(new Date());
                    task.setStartTime(new Date());
                    task.setStatus(1);
                    task.setMemo("");
                    task.setShuttleNo(null);//等待主线程分配小车
                    task.setRecordLoc("Y");//记录库存信息
                    task.setHostId(hostId);//临时控制只允许host为1
                    task.setMemo(param.getEndSite());
 
                    boolean result = taskService.save(task);
                    if (!result) {
                        throw new CoolException("生成入库任务失败!");
                    }
                }catch (Exception e){
                    throw new CoolException("转发AGV任务出错" + e.getMessage());
                }
            }else {
                Task task = new Task();
                task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
                task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
                task.setWmsTaskNo(param.getTaskNo());
                task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
                task.setTaskCtg(taskCtg.getId());
                task.setPriority(priority);
                task.setOriginSite(param.getOriginSite());
                task.setOriginLoc(null);
                task.setDestSite(destSite);
                task.setDestLoc(param.getDestLoc());
                task.setZpallet(param.getBarcode());
                task.setIoTime(new Date());
                task.setStartTime(new Date());
                task.setStatus(1);
                task.setMemo("");
                task.setShuttleNo(null);//等待主线程分配小车
                task.setRecordLoc("Y");//记录库存信息
                task.setHostId(hostId);//临时控制只允许host为1
                task.setMemo(param.getEndSite());
 
                boolean result = taskService.save(task);
                if (!result) {
                    throw new CoolException("生成入库任务失败!");
                }
            }
        }else {
            Task task = new Task();
            task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
            task.setTaskNo(String.valueOf(Utils.getTaskNo("IN")));
            task.setWmsTaskNo(param.getTaskNo());
            task.setTaskSts(TaskStsType.NEW_INBOUND.sts);
            task.setTaskCtg(taskCtg.getId());
            task.setPriority(priority);
            task.setOriginSite(param.getOriginSite());
            task.setOriginLoc(null);
            task.setDestSite(destSite);
            task.setDestLoc(param.getDestLoc());
            task.setZpallet(param.getBarcode());
            task.setIoTime(new Date());
            task.setStartTime(new Date());
            task.setStatus(1);
            task.setMemo("");
            task.setShuttleNo(null);//等待主线程分配小车
            task.setRecordLoc("Y");//记录库存信息
            task.setHostId(hostId);//临时控制只允许host为1
            task.setMemo(param.getEndSite());
 
            boolean result = taskService.save(task);
            if (!result) {
                throw new CoolException("生成入库任务失败!");
            }
        }
 
        return R.ok();
    }
 
    @Override
    @Transactional
    public R createOutTask(CreateOutTaskParam param, CreateWcsTaskParam createWcsTaskParam) {
        //获取出库任务类型
        TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                .eq(TaskCtg::getStatus, 1));
        if (taskCtg == null) {
            throw new CoolException("任务类型异常");
        }
 
        Long hostId = 1L;//默认主仓库
 
        Loc loc = locService.selectByLocNo(param.getOriginLoc());
        if (loc == null) {
            throw new CoolException("库位号不存在");
        }
 
        //获取严格模式参数
        boolean mapStrict = true;//默认严格模式
        Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "shuttleMapStrict"));
        if (dict != null) {
            mapStrict = Boolean.parseBoolean(dict.getValue());
        }
 
        if (mapStrict && !loc.getLocStsFlag().equals("F")) {
            throw new CoolException("库位状态不满足出库条件");
        }
 
        Task one = taskService.getOne(new LambdaQueryWrapper<Task>()
                .eq(Task::getTaskCtg, taskCtg.getId())
                .eq(Task::getOriginSite, param.getOriginSite())
                .eq(Task::getOriginLoc, param.getOriginLoc())
                .eq(Task::getDestSite, param.getDestSite()));
        if (one != null) {
            throw new CoolException("任务已存在");
        }
 
        String originSite = param.getOriginSite();
        if (Cools.isEmpty(param.getOriginSite())) {
            //使用WCS系统内置路径
            BasConveyorPath path = basConveyorPathService.getOne(new LambdaQueryWrapper<BasConveyorPath>()
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId())
                    .eq(BasConveyorPath::getHostId, hostId)
                    .eq(BasConveyorPath::getStnNo, param.getDestSite()));
            if (path == null) {
                throw new CoolException("内置路径不存在");
            }
            Integer deviceNo = path.getDeviceNo();//获取提升机号
            BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>().eq(BasLift::getLiftNo, deviceNo).eq(BasLift::getHostId, hostId));
            if (basLift == null) {
                throw new CoolException("提升机对象不存在");
            }
            List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class);
            BasLiftStaDto originStaDto = null;
            for (BasLiftStaDto sta : staList) {
                if (sta.getLev() == Utils.getLev(param.getOriginLoc())) {
                    originStaDto = sta;
                    break;
                }
            }
 
            if (originStaDto == null) {
                throw new CoolException("源站不存在");
            }
 
            originSite = String.valueOf(originStaDto.getStaNo());
        }
 
        //判断出入库模式
        BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>()
                .eq(BasConveyorSta::getSiteNo, originSite));
        if (!basConveyorSta.getWorkMode().equals((int) WorkModeType.PAKOUT_MODE.id)) {
            //不是出库模式,检测是否可切换出库
            //获取入库任务类型
            TaskCtg taskInCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                    .eq(TaskCtg::getStatus, 1));
            if (taskInCtg == null) {
                throw new CoolException("任务类型异常");
            }
            List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                    .eq(Task::getTaskCtg, taskInCtg.getId()));
            if (!tasks.isEmpty()) {
                throw new CoolException("当前存在入库任务,无法切换出库模式");
            }
 
            BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
            if (basConveyor == null) {
                throw new CoolException("输送线不存在");
            }
 
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
            if (devpThread == null) {
                throw new CoolException("输送线线程不存在");
            }
 
            boolean result = devpThread.switchWorkMode(Integer.parseInt(originSite), WorkModeType.PAKOUT_MODE.id);
            if (!result) {
                throw new CoolException("模式切换失败");
            }
        }
 
        //优先级
        Integer priority = 10;
        if (param.getPriority() != null) {
            priority = param.getPriority();
        }
 
        Task task = new Task();
        task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
        task.setTaskNo(String.valueOf(Utils.getTaskNo("OUT")));
        task.setWmsTaskNo(param.getTaskNo());
        task.setTaskSts(TaskStsType.NEW_OUTBOUND.sts);
        task.setTaskCtg(taskCtg.getId());
        task.setPriority(priority);
        task.setOriginSite(originSite);
        task.setOriginLoc(param.getOriginLoc());
        task.setDestSite(param.getDestSite());
        task.setDestLoc(null);
        task.setIoTime(new Date());
        task.setStartTime(new Date());
        task.setStatus(1);
        task.setMemo(param.getEndSite());
        task.setShuttleNo(null);//等待主线程分配小车
        task.setRecordLoc("Y");//记录库存信息
        task.setHostId(hostId);//临时控制只允许host为1
        task.setZpallet(param.getZpallet());
 
        boolean result = taskService.save(task);
        if (!result) {
            throw new CoolException("生成出库任务失败!");
        }
 
        return R.ok();
    }
 
    @Override
    @Transactional
    public HashMap<String, Object> executeWcsTaskCache(CreateWcsTaskParam param) {
        HashMap<String, Object> map = new HashMap<>();
        String sta = "06YZ";
        String loc = "0601KW";
        if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,6).equals(loc)){
 
            CreateInTaskParam createInTaskParam = new CreateInTaskParam();
            createInTaskParam.setTaskNo(param.getRequestPK());
            createInTaskParam.setDestLoc(getWMStoWCSLocNo(param.getToPos()));
            createInTaskParam.setOriginSite("100");
            createInTaskParam.setBarcode(param.getContNo());
            createInTaskParam.setPriority(Integer.valueOf(param.getTrkPrty()));
            createInTaskParam.setEndSite(param.getToPos());
            R inTask = null;
            try {
                inTask = this.createInTask(createInTaskParam, param);
                int code = (int) inTask.get("code");
                if (code == 200){
                    map.put("success", "1");
                    map.put("message", inTask.get("msg"));
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                }else {
                    map.put("success", "0");
                    map.put("message", inTask.get("msg"));
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                }
 
            }catch (Exception e){
                map.put("success", "0");
                map.put("message", e.getMessage());
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:" + JSONObject.toJSONString(map));
                return map;
            }
        } else if (param.getFrmPos().substring(0,6).equals(loc) && param.getToPos().substring(0,4).equals(sta)) {
            CreateOutTaskParam createOutTaskParam = new CreateOutTaskParam();
            createOutTaskParam.setTaskNo(param.getRequestPK());
            createOutTaskParam.setOriginLoc(getWMStoWCSLocNo(param.getFrmPos()));
            createOutTaskParam.setOriginSite("101");
            createOutTaskParam.setDestSite("100");
            createOutTaskParam.setPriority(Integer.valueOf(param.getTrkPrty()));
            createOutTaskParam.setEndSite(param.getToPos());
            createOutTaskParam.setZpallet(param.getContNo());
            R outTask = null;
            try {
                outTask = this.createOutTask(createOutTaskParam, param);
 
                int code = (int) outTask.get("code");
                if (code == 200){
                    map.put("success", "1");
                    map.put("message", outTask.get("msg"));
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                }else {
                    map.put("success", "0");
                    map.put("message", outTask.get("msg"));
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                }
 
            }catch (Exception e){
                map.put("success", "0");
                map.put("message", e.getMessage());
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:"+JSONObject.toJSONString(map));
                return map;
            }
 
        } else if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,4).equals(sta)) {
            try {
                AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
                getTransmitRequestParam(agvTaskCreateParam,param);
                String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit");
                if (!httpRequest.equals("SUCCESS")){
                    map.put("success", "0");
                    map.put("message", httpRequest);
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                    log.info("返回mes信息:"+JSONObject.toJSONString(map));
                    return map;
                }
            }catch (Exception e){
                map.put("success", "0");
                map.put("message", "转发AGV任务出错");
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:"+JSONObject.toJSONString(map));
                return map;
            }
 
        } else {
            map.put("success", "0");
            map.put("message", "未找到对应任务类型");
            map.put("result", "");
            map.put("requestPK", param.getRequestPK());
        }
 
        return map;
    }
 
    @Override
    public HashMap<String, Object> createWcsTaskCache(CreateWcsTaskParam param) {
        HashMap<String, Object> map = new HashMap<>();
        String sta = "06YZ";
        String loc = "0601KW";
        if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,6).equals(loc)){
            //入库
            TaskCache taskCache = new TaskCache();
            taskCache.setTaskType(1);
            taskCache.setTaskParam(JSON.toJSONString(param));
            boolean save = taskCacheService.save(taskCache);
            if (!save) {
                map.put("success", "0");
                map.put("message", "生成任务出错");
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:"+JSONObject.toJSONString(map));
                return map;
            }
            map.put("success", "1");
            map.put("message", "success");
            map.put("result", "");
            map.put("requestPK", param.getRequestPK());
            return map;
        } else if (param.getFrmPos().substring(0,6).equals(loc) && param.getToPos().substring(0,4).equals(sta)) {
            //出库
            TaskCache taskCache = new TaskCache();
            taskCache.setTaskType(2);
            taskCache.setTaskParam(JSON.toJSONString(param));
            boolean save = taskCacheService.save(taskCache);
            if (!save) {
                map.put("success", "0");
                map.put("message", "生成任务出错");
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:"+JSONObject.toJSONString(map));
                return map;
            }
            map.put("success", "1");
            map.put("message", "success");
            map.put("result", "");
            map.put("requestPK", param.getRequestPK());
        } else if (param.getFrmPos().substring(0,4).equals(sta) && param.getToPos().substring(0,4).equals(sta)) {
            try {
                AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
                getTransmitRequestParam(agvTaskCreateParam,param);
                String httpRequest = doHttpRequest(agvTaskCreateParam, "172.18.16.248:443", "/rcs/rtas/api/robot/controller/task/submit");
                if (!httpRequest.equals("SUCCESS")){
                    map.put("success", "0");
                    map.put("message", httpRequest);
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                    log.info("返回mes信息:"+JSONObject.toJSONString(map));
                    return map;
                }else {
                    map.put("success", "1");
                    map.put("message", "success");
                    map.put("result", "");
                    map.put("requestPK", param.getRequestPK());
                    log.info("返回mes信息:"+JSONObject.toJSONString(map));
                    return map;
                }
            }catch (Exception e){
                map.put("success", "0");
                map.put("message", "转发AGV任务出错");
                map.put("result", "");
                map.put("requestPK", param.getRequestPK());
                log.info("返回mes信息:"+JSONObject.toJSONString(map));
                return map;
            }
 
        } else {
            map.put("success", "0");
            map.put("message", "未找到对应任务类型");
            map.put("result", "");
            map.put("requestPK", param.getRequestPK());
        }
 
        return map;
    }
 
    private void getInRequestParam(AgvTaskCreateParam agvTaskCreateParam,CreateWcsTaskParam param){
        List<AgvTaskCreateParam.AgvTaskParam> agvTaskParamList = Arrays.asList(
                //起始位
                new AgvTaskCreateParam.AgvTaskParam("SITE",param.getFrmPos(),0,1),
                //目标位
                new AgvTaskCreateParam.AgvTaskParam("SITE","06YZ0001",1,1)
        );
        List<AgvTaskCreateParam.carrierInfoParam> carrierInfoParam = Arrays.asList(
                //起始位
                new AgvTaskCreateParam.carrierInfoParam()
 
        );
        agvTaskCreateParam.setTaskType("F01");
        agvTaskCreateParam.setInitPriority(param.getTrkPrty());
        agvTaskCreateParam.setRobotTaskCode(param.getRequestPK());
        agvTaskCreateParam.setTargetRoute(agvTaskParamList);
        agvTaskCreateParam.setCarrierInfo(carrierInfoParam);
 
    }
    private void getTransmitRequestParam(AgvTaskCreateParam agvTaskCreateParam,CreateWcsTaskParam param){
        List<AgvTaskCreateParam.AgvTaskParam> agvTaskParamList = Arrays.asList(
                //起始位
                new AgvTaskCreateParam.AgvTaskParam("SITE",param.getFrmPos(),0,1),
                //目标位
                new AgvTaskCreateParam.AgvTaskParam("SITE",param.getToPos(),1,1)
        );
        List<AgvTaskCreateParam.carrierInfoParam> carrierInfoParam = Arrays.asList(
                //起始位
                new AgvTaskCreateParam.carrierInfoParam()
 
        );
        agvTaskCreateParam.setTaskType("F01");
        agvTaskCreateParam.setInitPriority(param.getTrkPrty());
        agvTaskCreateParam.setRobotTaskCode(param.getRequestPK());
        agvTaskCreateParam.setTargetRoute(agvTaskParamList);
        agvTaskCreateParam.setCarrierInfo(carrierInfoParam);
 
    }
    private String doHttpRequest(AgvTaskCreateParam requestParam, String url, String path){
        String response = "";
        String success = "error";
        Map<String, Object> map = new HashMap<>();
        map.put("Content-Type", "application/json;charset=UTF-8");
        map.put("X-lr-request-id", requestParam.getRobotTaskCode());
        map.put("X-lr-version", 4.1);
        map.put("X-lr-trace-id", "{{$guid}}");
        try {
            response = new HttpHandler.Builder()
                    .setHeaders(map)
                    .setUri(url)
                    .setHttps(true)
                    .setPath(path)
                    .setJson(JSONObject.toJSONString(requestParam))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
 
            String code = jsonObject.get("code").toString();
            if(code.equals("SUCCESS")){
                success = "SUCCESS";
            }else {
                success = jsonObject.get("message").toString();
            }
            log.info("转发agv任务:请求体:"+JSONObject.toJSONString(requestParam)+",返回值:"+jsonObject);
        }catch (Exception e){
 
        }
        return success;
    }
 
    public static String getWMStoWCSLocNo(String loc){
        String locNo = "";
        int row = Integer.parseInt(loc.substring(6,8));
        int bay = Integer.parseInt(loc.substring(8,10));
        int lev = Integer.parseInt(loc.substring(10,12));
        if (row == 2){
            row = 3;
        }
        locNo = row +"-"+bay+"-"+lev;
        return locNo;
    }
}