Blame view

src/main/java/com/huaheng/pc/task/taskHeader/service/TaskHeaderRytaskService.java 26.4 KB
1
2
3
4
5
6
package com.huaheng.pc.task.taskHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.common.constant.QuantityConstant;
7
import com.huaheng.common.utils.DateUtils;
8
9
10
11
12
13
14
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
周鸿 authored
15
import com.huaheng.pc.config.location.mapper.LocationMapper;
16
17
18
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.points.domain.Points;
import com.huaheng.pc.config.points.service.PointsService;
19
20
21
22
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
23
24
25
26
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
tongzhonghao authored
27
import com.huaheng.pc.task.agvTask.domain.AgvTask;
28
29
30
31
32
33
34
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
周鸿 authored
35
import java.util.concurrent.atomic.AtomicInteger;
36
37
38
39
40
import java.util.stream.Collectors;

@Service
public class TaskHeaderRytaskService extends ServiceImpl<TaskHeaderMapper, TaskHeader> {
周鸿 authored
41
    private static AtomicInteger count=new AtomicInteger(1);
42
43
44

    @Resource
    private LocationService locationService;
45
    @Resource
46
    private TaskAssignService taskAssignService;
47
    @Resource
48
    private InventoryHeaderService inventoryHeaderService;
49
    @Resource
周鸿 authored
50
51
    private InventoryDetailService inventoryDetailService;
    @Resource
52
    private TaskHeaderService taskHeaderService;
53
    @Resource
54
    private PointsService pointsService;
55
56
57
58
59
60
61

    @Resource
    private ZoneService zoneService;
    @Resource
    private StationService stationService;
    @Resource
    private WorkTaskService workTaskService;
62
周鸿 authored
63
64
65
66
    @Resource
    private TaskHeaderMapper taskHeaderMapper;
    @Resource
    private LocationMapper locationMapper;
67
68
69
70
71
72
    @Resource
    private ContainerService containerService;
    @Resource
    private ConfigService configService;
    @Resource
    private TransferTaskService transferTaskService;
周鸿 authored
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    /**
     * 弃用方法
     */
//    /**展厅移库演示*/
//    public AjaxResult transferTask(String roadWay){
//        try {
////            if(roadWay.equals("1")){
////                s="M";
////            }else if(roadWay.equals("2")){
////                s="S";
////            }
//            if(!roadWay.equals("3")){
//                return AjaxResult.success();
xumiao authored
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
//            String warehouseCode = QuantityConstant.WAREHOUSE_CS;
//            final int t1 = getUnCompleteTaskList(warehouseCode);
//            if(t1>2){
//                return AjaxResult.success();
//            }
//            LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
//            queryWrapper.eq(Location::getWarehouseCode, QuantityConstant.WAREHOUSE_CS);
//            queryWrapper.eq(Location::getStatus,QuantityConstant.STATUS_LOCATION_EMPTY);
//            queryWrapper.eq(Location::getRoadway, roadWay);
//            queryWrapper.eq(Location::getZoneCode,QuantityConstant.ZONE_CODE_TYPE_LK);
//            queryWrapper.ne(Location::getContainerCode,"");
//            queryWrapper.isNotNull(Location::getContainerCode);
//            queryWrapper.last("limit 1");
//            Location location=locationService.getOne(queryWrapper);
//            if(StringUtils.isNull(location)){
//                return  AjaxResult.error();
//            }
//            //随机获取一个空库位
//
//            final AjaxResult ajax =createTransferTask(location.getCode());
//            if(ajax!=null&&!ajax.hasErr()){
//                TaskHeader data = (TaskHeader) ajax.getData();
//                taskAssignService.wcsTaskAssign(data);
//            }
//            return AjaxResult.success();
//        }catch (Exception e){
//            e.printStackTrace();
//            return AjaxResult.error();
//        }
//    }
//
120
    private  int getUnCompleteTaskList(String warehouseCode)  {
121
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
122
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, warehouseCode);
123
124
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_TRANSFER);
        taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
xumiao authored
125
        taskHeaderLambdaQueryWrapper.last("and (containerCode like 'L%' or containerCode like 'B%')");
126
127
128
        int taskHeaderList = this.count(taskHeaderLambdaQueryWrapper);
        return taskHeaderList;
    }
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
//    @Transactional(rollbackFor = Exception.class)
//    public AjaxResult createTransferTask(String sourceLocation) {
//        String warehouseCode=QuantityConstant.WAREHOUSE_CS;
//        Location location = locationService.getLocationByCode(sourceLocation,warehouseCode);
//        if(location==null){
//            return AjaxResult.error("源库位:"+sourceLocation+"未找到");
//        }
//        if(!location.getStatus().equals("empty")){
//            return AjaxResult.error("源库位:"+sourceLocation+"状态非空闲");
//        }
//        if(StringUtils.isEmpty(location.getContainerCode())){
//            return AjaxResult.error("源库位:"+sourceLocation+"不存在托盘");
//        }
//        if(!location.getZoneCode().equals("LK")){
//            return AjaxResult.error("该库位:"+sourceLocation+"不是立库库位");
//        }
//
//        if(location.getZoneCode().equals("LK")){
//            Integer integer = taskHeaderService.UncompleteCount(location.getContainerCode(), QuantityConstant.WAREHOUSE_CS);
//            if(integer > 0){
//                return AjaxResult.error(location.getContainerCode()+"该容器已有任务");
//            }
//        }
//        //这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//        //校验入库组盘
//        int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation,warehouseCode);
//        if(count1>0){
//            return AjaxResult.error("源库位:"+sourceLocation+"存在入库组盘,不能移库");
//        }
//        int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation,warehouseCode);
//        if(count2>0){
//            return AjaxResult.error("源库位:"+sourceLocation+"存在出库组盘,不能移库");
//        }
//        Location loc=new Location();
//        loc.setWarehouseCode(warehouseCode);
//        loc.setCode(sourceLocation);
//        loc.setRoadway("3");
//
//        int line;
//        int layer=(int)(Math.random()*10);
//        if (location.getContainerCode().startsWith("L")||location.getContainerCode().startsWith("B")) {
//            if(location.getIColumn()<=8){
//                line=(int)(Math.random()*9+8);
//            }else {
//                line=(int)(Math.random()*8);
//            }
//            loc = locationService.getOne(new LambdaQueryWrapper<Location>()
//            .ne(Location::getContainerCode,"")
//            .isNotNull(Location::getContainerCode)
//            .eq(Location::getIColumn,line)
//            .eq(Location::getILayer,layer)
//            .eq(Location::getStatus,QuantityConstant.STATUS_LOCATION_EMPTY)
//            .eq(Location::getRoadway,3)
//            .eq(Location::getZoneCode,QuantityConstant.ZONE_CODE_TYPE_LK)
//            .last("limit 1"));
//        }
//        if(loc ==null){
//            if(location.getContainerCode().startsWith("S")){
//                loc = locationService.getLocationOfRule(2);
//            }else if(location.getContainerCode().startsWith("M")){
//                loc = locationService.getLocationOfRule(1);
//            }else {
//                loc = locationService.getLocationOfRule(3);
//            }
//        }
//        if(loc == null){
//            return AjaxResult.error("立库库位已用完,无法移库");
//        }
//        Location location1 = locationService.getLocationByCode(sourceLocation, QuantityConstant.WAREHOUSE_CS);
//        Container container = containerService.getContainerByCode(location1.getContainerCode(), QuantityConstant.WAREHOUSE_CS);
//        TaskHeader task=new TaskHeader();
//        task.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
//        task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_WORK);
//        task.setRoadway(location.getRoadway());
//        task.setZoneCode(location.getZoneCode());
//        task.setContainerCode(location.getContainerCode());
//        task.setFromLocation(sourceLocation);
//        task.setToLocation(loc.getCode());
//        task.setCreatedBy("ck");
//        task=createTask(warehouseCode,task);
//
//        container.setLastStatus(container.getStatus());
//        container.setStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
//        containerService.updateById(container);
//        //更新货位状态为预定
//        location.setStatus(QuantityConstant.STATUS_LOCATION_LOCK);
//        loc.setStatus(QuantityConstant.STATUS_LOCATION_LOCK);
//        loc.setUserDef1("0");
//        locationService.updateById(location);
//        locationService.updateById(loc);
//        return AjaxResult.success(task);
//    }
221
222
    private TaskHeader selectFirstEntity( TaskHeader task){
223
224
225
226
227
228
229
230
231
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, 10);
        taskHeaderLambdaQueryWrapper.eq(StringUtils.isNotEmpty(task.getContainerCode()),TaskHeader::getContainerCode, task.getContainerCode());
        taskHeaderLambdaQueryWrapper.last("limit 1");
        return this.getOne(taskHeaderLambdaQueryWrapper);
    }
    /**库存监控出库查看*/
    @Transactional
    public AjaxResult checkLocationCode(String locationCode){
tongzhonghao authored
232
        String warehouseCode=QuantityConstant.WAREHOUSE_CS;
233
234
        Location location = new Location();
        location.setCode(locationCode);
tongzhonghao authored
235
        location.setWarehouseCode(warehouseCode);
236
237
        location.setDeleted(false);
        Location loc = locationService.selectFirstEntity(location);
tongzhonghao authored
238
        if(!loc.getStatus().equals(QuantityConstant.STATUS_LOCATION_EMPTY)){
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
            return AjaxResult.error(locationCode+"状态非空闲,操作失败");
        }
        if(StringUtils.isEmpty(loc.getContainerCode())){
            return AjaxResult.error(locationCode+"没有托盘,操作失败");
        }
        //生成出库查看任务
        TaskHeader task=new TaskHeader();
        task.setPort("1");
        if(loc.getLocationType().equals("A")) {
            task.setZoneCode("AGV");
        }else if(loc.getLocationType().equals("L")){
            task.setZoneCode("LK");
        }
        task.setRoadway(loc.getRoadway());
        task.setContainerCode(loc.getContainerCode());
        if(loc.getContainerCode().startsWith("S")){
            task.setPort("P1004");
        }else if(loc.getContainerCode().startsWith("L")||loc.getContainerCode().startsWith("B")){
            task.setPort("P1002");
        }
tongzhonghao authored
259
        task.setTaskType(QuantityConstant.TASK_TYPE_VIEW);
260
261
262
263
264
265
266
267
268
269
270
        task.setFromLocation(loc.getCode());
        task.setToLocation(loc.getCode());
        task.setCreatedBy("admin");
        task=createTask(warehouseCode,task);

        //如果是AGV的需要下发agv任务
        if(loc.getLocationType().equals("A")) {
            AgvTask model = new AgvTask();
            String containerCode = loc.getContainerCode();
            Points points = new Points();
            points.setGoodsShelfNo(containerCode.substring(0, 4));
tongzhonghao authored
271
            points.setWarehouseCode(QuantityConstant.WAREHOUSE_CS);
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
            points = pointsService.selectEntity(points);
            if (points != null && points.getIsLocked()!=1) {
                model.setTaskHeaderId(task.getId());
                model.setTaskDetailId(task.getId());
                model.setTaskType("pick");
                model.setShelfNo(points.getGoodsShelfNo());
                model.setStation("ws01");
                model.setFromLocationNo("");
                model.setToLocationNo("");
                if (containerCode.substring(5, 7).equals("1")) {
                    model.setOrientation("A");
                } else {
                    model.setOrientation("C");
                }
//                if (!acsService.TaskAssign(model).hasErr()) {
//                    points.setIsLocked(1);
//                    pointsService.updateById(points);
//                    model.setWarehouseCode(task.getWarehouseCode());
//                    model.setCompanyCode(task.getCompanyCode());
//                    agvTaskMapper.insertModel(model);
//                }
            }
        }
        //出库时先锁库位状态
        loc.setStatus("lock");
        locationService.updateById(loc);

        return AjaxResult.success(task.getId());

    }
303
    private TaskHeader createTask(String warehouseCode,TaskHeader task){
304
        task.setWarehouseCode(warehouseCode);
tongzhonghao authored
305
306
        task.setWarehouseCode(QuantityConstant.WAREHOUSE_CS);
        task.setCompanyCode(QuantityConstant.COMPANY_CS);
307
308
309
310
311
312
313
314
315
        //这里默认一个0
        task.setPriority(0);
        task.setPort(null);
        task.setStatus(1);
        task.setCreated(new Date());
        this.save(task);
        return task;
    }
316
    public void innerAutoPush(String[] areas) {
tongzhonghao authored
317
        String warehouseCode = QuantityConstant.WAREHOUSE_CS;
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
        for(String area : areas) {
            Zone zone = zoneService.getZoneByArea(area);
            LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
            inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getZoneCode, zone.getCode());
            List<InventoryHeader> inventoryHeaderList = inventoryHeaderService.list(inventoryHeaderLambdaQueryWrapper);
            List<InventoryHeader> removeInventoryHeaderList = new ArrayList<>();
            for(InventoryHeader inventoryHeader : inventoryHeaderList) {
                String locationCode = inventoryHeader.getLocationCode();
                Location location = locationService.getLocationByCode(locationCode, warehouseCode);
                if(location.getStatus().equals(QuantityConstant.STATUS_LOCATION_LOCK)) {
                    removeInventoryHeaderList.add(inventoryHeader);
                }
            }
            inventoryHeaderList.removeAll(removeInventoryHeaderList);
            int size = inventoryHeaderList.size();
            int index = 0;
            LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
            stationLambdaQueryWrapper.eq(Station::getArea, area)
                    .eq(Station::getType, QuantityConstant.STATION_PICK);
            List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
            List<Station> removeStation = new ArrayList<>();
            LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
            taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, zone.getCode())
                    .eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_VIEW)
                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
            List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
            for(Station station : stationList) {
                String port = station.getCode();
                for(TaskHeader taskHeader : taskHeaderList) {
                    if(port.equals(taskHeader.getPort())) {
                        removeStation.add(station);
                        break;
                    }
                }
            }
            stationList.removeAll(removeStation);
            for(int i=0; i < stationList.size(); i++) {
                Station station = stationList.get(i);
                InventoryHeader inventoryHeader = inventoryHeaderList.get(i);
                List<Integer> ids = new ArrayList<>();
                ids.add(inventoryHeader.getId());
                workTaskService.createCheckOutTaskByIds(ids, station.getCode());
            }
        }
    }
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
    public void moveLocationByRoadWay3(){
        //判断任务数量 是否可生成任务
        String warehouseCode = QuantityConstant.WAREHOUSE_CS;
        final int t1 = getUnCompleteTaskList(warehouseCode);
        if(t1>2){
            return ;
        }
        //获取可移库位
        List<Location> locations = locationService.list(new LambdaQueryWrapper<Location>()
                .eq(Location::getZoneCode, QuantityConstant.ZONE_CODE_TYPE_LK)
                .eq(Location::getRoadway, 3)
                .eq(Location::getWarehouseCode, QuantityConstant.WAREHOUSE_CS)
                .eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
                .ne(Location::getContainerCode, "")
                .orderByAsc(Location::getLastUpdated));
        List<String> codes = locations.stream().map(Location::getCode).collect(Collectors.toList());
        String currentLocation = codes.get(0);
        String toLocation =null;

        //获取空库位集
        List<Location> locationList = locationService.selectLocationByContainerEmpty(QuantityConstant.WAREHOUSE_CS, QuantityConstant.ZONE_CODE_TYPE_LK, "3");
        List<String> emptyLocations = locationList.stream().map(Location::getCode).collect(Collectors.toList());
        System.out.println(emptyLocations.size());
        emptyLocations.removeAll(codes);
        //获取移动二维距离
        String key = configService.getKey(QuantityConstant.SPACE_3D, QuantityConstant.WAREHOUSE_CS);
        //迭代获取

        int flag = 0;
        byte[] bytes = currentLocation.getBytes();
        for (String emptyLocation : emptyLocations) {
            byte[] locationBytes = emptyLocation.getBytes();
            for (int i = 1; i < locationBytes.length; i++) {
                flag += Math.abs(locationBytes[i]-bytes[i]);
            }
            if(flag > Integer.valueOf(key).intValue()){
                toLocation = emptyLocation;
                break;
            }
            flag = 0;
        }
        Location updateLocation = locationService.getLocationByCode(currentLocation, QuantityConstant.WAREHOUSE_CS);
        updateLocation.setLastUpdated(DateUtils.getNowDate());
        locationService.updateById(updateLocation);
        //创建任务
        AjaxResult transferTask = transferTaskService.createTransferTask(currentLocation, toLocation, QuantityConstant.WAREHOUSE_CS);
        if(transferTask.hasErr()){
            return;
        }
        //下发任务
        TaskHeader taskHeader = taskHeaderService.getById(Integer.valueOf(transferTask.getData().toString()));
        AjaxResult ajaxResult = taskAssignService.wcsTaskAssign(taskHeader);
        if(ajaxResult.hasErr()){
            return;
        }
        //修改任务状态
        taskHeader.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
        taskHeaderService.updateById(taskHeader);
    }
周鸿 authored
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
    public void transferTasks(String way){
        try {
            int t = taskHeaderMapper.getUnCompleteTaskList("S");
            if(t>2){ return; }
            int andIncrement = count.getAndIncrement();
            System.out.println("========================"+andIncrement+"=====================");
            if(andIncrement%3==0){
                way="双取单放";
                count.getAndSet(1);
            }else if(andIncrement%2==0){
                way="单取双放";
            }else {
                way="双取双放";
            }
            List<Location> locationAajacentIsNull= new ArrayList<>();
            List<Location> locationAajacentIsNull2= new ArrayList<>();
            AjaxResult ajaxResult1 =null;
            AjaxResult ajaxResult2 =null;
            Location locationSource1=new Location();
            Location locationSource2=new Location();
            Location locationTarget1=new Location();
            Location locationTarget2=new Location();
            if(way.equals("单取双放")){
                String source2=null;
                Location source = locationMapper.getLocationRoadWay(2);
                List<Location> locationAdjacent = locationMapper.getLocationAdjacent(source.getIColumn(), source.getILayer(),true);
                if(locationAdjacent==null){
                    return;
                }
                for(Location l2:locationAdjacent){
                    if(l2.getIColumn()!=source.getIColumn()-1&&l2.getIColumn()!=source.getIColumn()+1&&!l2.getContainerCode().equals(source.getContainerCode())){
                        source2=l2.getCode();
                        break;
                    }
                }
tongzhonghao authored
459
                locationService.pickAndplace(locationAajacentIsNull,false,locationSource1,locationSource2);
周鸿 authored
460
461
462
463
464
465
466
                if(StringUtils.isEmpty(locationSource1.getCode())||StringUtils.isEmpty(locationSource2.getCode())){
                    return;
                }
                ajaxResult1 = taskHeaderService.createTransferTasks(source.getCode(), locationSource1.getCode());
                ajaxResult2 = taskHeaderService.createTransferTasks(source2, locationSource2.getCode());
            }
            if(way.equals("双取单放")){
tongzhonghao authored
467
                locationService.pickAndplace(locationAajacentIsNull,true,locationSource1,locationSource2);
周鸿 authored
468
469
470
                if(StringUtils.isEmpty(locationSource1.getCode())||StringUtils.isEmpty(locationSource2.getCode())){
                    return;
                }
tongzhonghao authored
471
472
                ajaxResult1 = taskHeaderService.createTransferTask(locationSource1.getCode(), 2, QuantityConstant.COMPANY_CS);
                ajaxResult2 = taskHeaderService.createTransferTask(locationSource2.getCode(), 2, QuantityConstant.COMPANY_CS);
周鸿 authored
473
474
475
            }
            if(way.equals("双取双放")){
                //双取
tongzhonghao authored
476
                locationService.pickAndplace(locationAajacentIsNull,true,locationSource1,locationSource2);
周鸿 authored
477
478
479
480
                if(StringUtils.isEmpty(locationSource1.getCode())||StringUtils.isEmpty(locationSource2.getCode())){
                    return;
                }
                //双放
tongzhonghao authored
481
                locationService.pickAndplace(locationAajacentIsNull2,false,locationTarget1,locationTarget2);
周鸿 authored
482
483
484
485
                if(StringUtils.isEmpty(locationTarget1.getCode())||StringUtils.isEmpty(locationTarget2.getCode())){
                    return;
                }
                ajaxResult1 = taskHeaderService.createTransferTasks(locationSource1.getCode(),locationTarget1.getCode());
周鸿 authored
486
487
488
489
                if(ajaxResult1!=null&&!ajaxResult1.hasErr()){
                    ajaxResult2 = taskHeaderService.createTransferTasks(locationSource2.getCode(),locationTarget2.getCode());
                }
            }
tongzhonghao authored
490
491
492
493
494
495
//            if(ajaxResult2!=null&&!ajaxResult2.hasErr()){
//                TaskHeader data1 = (TaskHeader) ajaxResult1.getData();
//                TaskHeader data2 = (TaskHeader) ajaxResult2.getData();
//                taskAssignService.wcsTaskAssign(data1);
//                taskAssignService.wcsTaskAssign(data2);
//            }
周鸿 authored
496
497
498
499
        }catch (Exception e){
            e.printStackTrace();
        }
    }
周鸿 authored
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

    //堆落机演示下任务
    public AjaxResult shows(String zoneCode) {
        //查找靠后的库位,库位未锁定且有货物,靠后的优先
        List<Location> locations = locationService.selectListInventory(zoneCode);

        //根据库位查找库存
        List<InventoryDetail> invetorys =new ArrayList<>();
        for(Location location : locations) {
            LambdaQueryWrapper<InventoryDetail> invlambda= Wrappers.lambdaQuery();
            invlambda.eq(InventoryDetail::getLocationCode,location.getCode());
            invlambda.last("limit 1");
            InventoryDetail inventory = inventoryDetailService.getOne(invlambda);
            if (inventory != null) {
                invetorys.add(inventory);
            }
        }

        AjaxResult ajaxResult=createOutTask(invetorys);
        Object object =ajaxResult.getData();
        List<Integer> ids =(List<Integer>)object;
        for(Integer id :ids) {
            TaskHeader task = taskHeaderService.getById(id);
            taskAssignService.wcsTaskAssign(task);
        }
        return AjaxResult.success("成功");
    }

    /**出库查看 只到输送线*/
    @Transactional
    public AjaxResult createOutTask(List<InventoryDetail> inventories) {
        List<Integer> taskIds  = new ArrayList<>();
        for (InventoryDetail inventory : inventories){
            Location location =new Location();
            location.setCode(inventory.getLocationCode());
            location.setWarehouseCode(inventory.getWarehouseCode());
            location =locationService.selectFirstEntity(location);
            if(location!= null) {

                TaskHeader task = new TaskHeader();
                task.setWarehouseCode(inventory.getWarehouseCode());
                task.setCompanyCode(inventory.getCompanyCode());
                //这里默认一个0
                task.setPriority(0);
                task.setZoneCode(inventory.getZoneCode());
                if(inventory.getZoneCode().equals("LK")) {
                    task.setType(80);
                }else {
                    task.setType( 1000);
                }
                task.setPort("1");
                task.setRoadway(location.getRoadway());
                task.setContainerCode(inventory.getContainerCode());
                task.setStatus(1);
                task.setFromLocation(inventory.getLocationCode());
                task.setToLocation(inventory.getLocationCode());
                task.setCreated(new Date());
                task.setCreatedBy("KS110403");
                task.setLastUpdatedBy("KS110403");
                taskHeaderService.save(task);
                taskIds.add(task.getId());
                //更新库位状态
                location.setStatus("lock");
                locationService.updateById(location);
            }
        }
        return AjaxResult.success(taskIds);
    }
568
}