|
1
2
|
package com.huaheng.pc.task.taskHeader.service;
|
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
5
6
|
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.common.constant.CodeConstans;
|
|
7
|
import com.huaheng.common.utils.Wrappers;
|
|
8
9
10
11
12
|
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
13
|
import com.huaheng.pc.config.container.domain.Container;
|
|
14
15
16
|
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
17
18
|
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
|
|
34
|
import java.util.Date;
|
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import java.util.List;
import java.util.stream.Collectors;
/**
* 移库任务
*/
@Service
public class TransferTaskService {
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private ContainerService containerService;
@Resource
private LocationService locationService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryTransactionService inventoryTransactionService;
|
|
58
59
60
61
62
|
@Resource
private LocationTypeService locationTypeService;
@Resource
private TaskAssignService taskAssignService;
|
|
63
64
65
66
67
68
69
|
/**
* 创建立库移库任务
* @param sourceLocationCode 源库位
* @param desLocationCode 目的库位
* @return
*/
|
|
70
|
@Transactional(rollbackFor = Exception.class)
|
|
71
72
73
|
public AjaxResult createTransferTask(String sourceLocationCode, String desLocationCode, String warehouseCode) {
Location sourceLocation = locationService.getLocationByCode(sourceLocationCode, warehouseCode);
Location desLocation = locationService.getLocationByCode(desLocationCode, warehouseCode);
|
|
74
|
Integer preTaskNo = 0;
|
|
75
|
if (StringUtils.isNull(sourceLocation)) {
|
|
76
|
return AjaxResult.error("移出(源)库位:" + sourceLocation + "未找到");
|
|
77
|
}
|
|
78
|
if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(sourceLocation.getStatus())) {
|
|
79
|
return AjaxResult.error("移出(源)库位:" + sourceLocation + "状态非空闲");
|
|
80
81
|
}
if (StringUtils.isEmpty(sourceLocation.getContainerCode())) {
|
|
82
|
return AjaxResult.error("移出(源)库位:" + sourceLocation + "不存在托盘");
|
|
83
84
85
|
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
|
|
86
|
if (inventoryHeaderService.getUncompleteReceiptContainer(sourceLocationCode, warehouseCode) > 0) {
|
|
87
|
return AjaxResult.error("移出(源)库位:" + sourceLocation + "存在入库组盘,不能移库");
|
|
88
|
}
|
|
89
|
if (inventoryHeaderService.getUncompleteShipmentContainer(sourceLocationCode, warehouseCode) > 0) {
|
|
90
|
return AjaxResult.error("移出(源)库位:" + sourceLocation + "存在出库组盘,不能移库");
|
|
91
92
|
}
if (StringUtils.isNull(desLocation)) {
|
|
93
|
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "未找到");
|
|
94
|
}
|
|
95
|
if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(desLocation.getStatus())) {
|
|
96
|
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "状态非空闲");
|
|
97
98
|
}
if (StringUtils.isNotEmpty(desLocation.getContainerCode())) {
|
|
99
|
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "存在托盘");
|
|
100
|
}
|
|
101
|
|
|
102
|
if (taskHeaderService.getUncompleteTaskInNear(desLocation) > 0) {
|
|
103
|
return AjaxResult.error("移入(目标)库位:" + desLocationCode + "旁边存在任务,请完成任务以后再分配");
|
|
104
|
}
|
|
105
|
if(!sourceLocation.getRoadway().equals(desLocation.getRoadway())) {
|
|
106
|
return AjaxResult.error("移入(目标)库位和移出(源)库位不在同一个巷道");
|
|
107
|
}
|
|
108
|
|
|
109
|
if(!sourceLocation.getHigh().equals(desLocation.getHigh())) {
|
|
110
|
return AjaxResult.error("移入(目标)库位和移出(源)库位高度不一样");
|
|
111
112
|
}
|
|
113
|
if(!sourceLocation.getLocationType().equals(desLocation.getLocationType())) {
|
|
114
|
return AjaxResult.error("移入(目标)库位和移出(源)库位库位类型不一样");
|
|
115
116
|
}
|
|
117
|
if(!sourceLocation.getArea().equals(desLocation.getArea())) {
|
|
118
|
return AjaxResult.error("移入(目标)库位和移出(源)库位不在同一个区域");
|
|
119
120
|
}
|
|
121
122
123
124
125
|
//创建移库任务前,记录托盘的状态
Container container = containerService.getContainerByCode(sourceLocation.getContainerCode());
container.setLastStatus(container.getStatus());
containerService.updateById(container);
|
|
126
|
if(sourceLocation.getRowFlag() == QuantityConstant.ROW_OUT) {
|
|
127
128
129
130
131
|
Location location1 = locationService.getNear(sourceLocation); //内侧库位
String locationCode = location1.getCode();
if(StringUtils.isNotEmpty(location1.getContainerCode())) {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getFromLocation, locationCode)
|
|
132
|
.eq(TaskHeader::getWarehouseCode, warehouseCode)
|
|
133
134
135
136
137
|
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
preTaskNo = taskHeader.getId();
} else {
|
|
138
|
return AjaxResult.error("移出(源)库位:" + sourceLocationCode + "旁边库位有托盘无法移库");
|
|
139
140
141
142
|
}
} else {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getToLocation, locationCode)
|
|
143
|
.eq(TaskHeader::getWarehouseCode, warehouseCode)
|
|
144
145
146
|
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
|
|
147
|
return AjaxResult.error("移出(源)库位:" + sourceLocationCode + "旁边库位有任务无法移库");
|
|
148
149
150
151
|
}
}
}
|
|
152
153
|
|
|
154
|
TaskHeader taskHeader = new TaskHeader();
|
|
155
|
// taskHeader.setCompanyCode(in);
|
|
156
|
taskHeader.setWarehouseCode(warehouseCode);
|
|
157
|
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
158
|
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_WORK);
|
|
159
|
taskHeader.setZoneCode(sourceLocation.getZoneCode());
|
|
160
|
taskHeader.setContainerCode(sourceLocation.getContainerCode());
|
|
161
|
taskHeader.setRoadway(sourceLocation.getRoadway());
|
|
162
163
164
|
taskHeader.setFromLocation(sourceLocationCode);
taskHeader.setToLocation(desLocationCode);
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
165
|
taskHeader.setPreTaskNo(preTaskNo);
|
|
166
167
168
169
170
171
172
173
174
175
|
LambdaUpdateWrapper<InventoryDetail> detailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
detailLambdaUpdateWrapper.eq(InventoryDetail::getWarehouseCode, warehouseCode);
detailLambdaUpdateWrapper.eq(InventoryDetail::getLocationCode, sourceLocationCode);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(detailLambdaUpdateWrapper);
if(inventoryDetailList!=null&&inventoryDetailList.size()>0){
taskHeader.setCompanyCode(inventoryDetailList.get(0).getCompanyCode());
}
|
|
176
|
if (!taskHeaderService.save(taskHeader)) {
|
|
177
178
|
throw new ServiceException("创建任务失败");
}
|
|
179
180
181
182
183
|
locationService.updateStatus(sourceLocationCode, QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
locationService.updateStatus(desLocationCode, QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
containerService.updateLocationCodeAndStatus(sourceLocation.getContainerCode(),
sourceLocationCode, QuantityConstant.STATUS_CONTAINER_LOCK, warehouseCode);
|
|
184
|
|
|
185
186
187
188
189
190
|
for (InventoryDetail inventoryDetail : inventoryDetailList) {
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(taskHeader.getId());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());;
|
|
191
|
taskDetail.setCompanyCode(inventoryDetail.getCompanyCode());
|
|
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
|
taskDetail.setMaterialCode(inventoryDetail.getMaterialCode());
taskDetail.setMaterialName(inventoryDetail.getMaterialName());
taskDetail.setMaterialSpec(inventoryDetail.getMaterialSpec());
taskDetail.setMaterialUnit(inventoryDetail.getMaterialUnit());
taskDetail.setQty(inventoryDetail.getQty());
taskDetail.setFromLocation(inventoryDetail.getLocationCode());
taskDetail.setToLocation(desLocationCode);
taskDetail.setContainerCode(inventoryDetail.getContainerCode());
taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
taskDetail.setReferenceCode(inventoryDetail.getReferCode());
taskDetail.setAttribute1(inventoryDetail.getAttribute1());
taskDetail.setAttribute2(inventoryDetail.getAttribute2());
taskDetail.setAttribute3(inventoryDetail.getAttribute3());
taskDetail.setBatch(inventoryDetail.getBatch());
taskDetail.setLot(inventoryDetail.getLot());
taskDetail.setProjectNo(inventoryDetail.getProjectNo());
taskDetail.setManufactureDate(inventoryDetail.getManufactureDate());
taskDetail.setExpirationDate(inventoryDetail.getExpirationDate());
taskDetail.setAgingDate(inventoryDetail.getAgingDate());
taskDetail.setInventorySts(inventoryDetail.getInventorySts());
taskDetail.setFromInventoryId(inventoryDetail.getId());
taskDetail.setToInventoryId(inventoryDetail.getId());
if (!taskDetailService.save(taskDetail) || !inventoryDetailService.updateById(inventoryDetail)) {
throw new ServiceException("创建任务失败");
}
}
return AjaxResult.success(taskHeader.getId());
}
/**
* 完成移库任务
* @param taskHeader
*/
|
|
225
|
public AjaxResult completeTransferTask(TaskHeader taskHeader) {
|
|
226
227
228
229
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(taskHeader.getId());
/* 库存头表id*/
List<Integer> inventoryHeadIdList = new ArrayList<>();
|
|
230
231
|
String warehouseCode = taskHeader.getWarehouseCode();
InventoryDetail inventoryDetail = null;
|
|
232
233
234
235
236
237
|
Container container1 = containerService.getContainerByCode(
taskHeader.getContainerCode(), warehouseCode);
container1.setMovementCount(container1.getMovementCount() + 1);
containerService.updateById(container1);
|
|
238
239
|
for (TaskDetail taskDetail : taskDetailList) {
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
240
|
inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
|
|
241
242
243
244
245
246
|
inventoryHeadIdList.add(inventoryDetail.getInventoryHeaderId());
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(taskDetail.getWarehouseCode());
inventoryTransaction.setCompanyCode(taskDetail.getCompanyCode());
inventoryTransaction.setLocationCode(taskDetail.getToLocation());
inventoryTransaction.setContainerCode(taskDetail.getContainerCode());
|
|
247
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_TRANSFERINTO);
|
|
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
inventoryTransaction.setMaterialCode(taskDetail.getMaterialCode());
inventoryTransaction.setMaterialName(taskDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(taskDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(taskDetail.getMaterialUnit());
inventoryTransaction.setTaskQty(taskDetail.getQty());
inventoryTransaction.setInventorySts(taskDetail.getInventorySts());
inventoryTransaction.setReferCode(taskDetail.getReferenceCode());
inventoryTransaction.setBatch(taskDetail.getBatch());
inventoryTransaction.setLot(taskDetail.getLot());
inventoryTransaction.setProjectNo(taskDetail.getProjectNo());
inventoryTransaction.setQcCheck(taskDetail.getQcCheck());
inventoryTransaction.setManufactureDate(taskDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(taskDetail.getExpirationDate());
inventoryTransaction.setAgingDate(taskDetail.getAgingDate());
inventoryTransaction.setAttributeId(String.valueOf(taskDetail.getAttributeId()));
inventoryTransaction.setAttribute1(taskDetail.getAttribute1());
inventoryTransaction.setAttribute2(taskDetail.getAttribute2());
inventoryTransaction.setAttribute3(taskDetail.getAttribute3());
inventoryTransactionService.save(inventoryTransaction);
|
|
267
268
269
|
inventoryTransaction.setLocationCode(taskDetail.getFromLocation());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_TRANSFEROUT);
inventoryTransactionService.save(inventoryTransaction);
|
|
270
|
}
|
|
271
272
273
274
|
if (taskDetailList.size() != 0 ){
taskDetailService.saveOrUpdateBatch(taskDetailList);
}
if (!taskHeaderService.saveOrUpdate(taskHeader)) {
|
|
275
276
|
throw new ServiceException("任务单据状态更新失败!");
}
|
|
277
|
if(inventoryDetail != null) {
|
|
278
279
|
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_SOME, warehouseCode);
|
|
280
|
} else {
|
|
281
|
Container container = containerService.getContainerByCode(taskHeader.getContainerCode(),taskHeader.getWarehouseCode());
|
|
282
|
if(StringUtils.isNotEmpty(container.getLastStatus())&&container.getLastStatus().equalsIgnoreCase(QuantityConstant.STATUS_CONTAINER_MANY)) {
|
|
283
284
285
286
287
288
289
290
291
292
|
//恢复托盘组的状态
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_MANY, warehouseCode);
container = containerService.getContainerByCode(taskHeader.getContainerCode());
container.setLastStatus(QuantityConstant.EMPTY_STRING);
containerService.updateById(container);
}else {
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(),
taskHeader.getToLocation(), QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
}
|
|
293
|
}
|
|
294
295
296
297
|
locationService.updateContainerCodeAndStatus(taskHeader.getFromLocation(), "",
QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
locationService.updateContainerCodeAndStatus(taskHeader.getToLocation(), taskHeader.getContainerCode(),
QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
|
|
298
299
300
301
302
303
304
|
inventoryHeadIdList = inventoryHeadIdList.stream().distinct().collect(Collectors.toList());
LambdaUpdateWrapper<InventoryHeader> headerUpdateWrapper = Wrappers.lambdaUpdate();
headerUpdateWrapper.set(InventoryHeader::getLocationCode, taskHeader.getToLocation())
.in(InventoryHeader::getId, inventoryHeadIdList);
LambdaUpdateWrapper<InventoryDetail> detailUpdateWrapper = Wrappers.lambdaUpdate();
detailUpdateWrapper.set(InventoryDetail::getLocationCode, taskHeader.getToLocation())
.in(InventoryDetail::getInventoryHeaderId, inventoryHeadIdList);
|
|
305
306
307
308
309
|
if (inventoryHeadIdList.size() != 0) {
if (!inventoryHeaderService.update(headerUpdateWrapper) ||
!inventoryDetailService.update(detailUpdateWrapper)) {
throw new ServiceException("完成任务失败");
}
|
|
310
|
}
|
|
311
|
return AjaxResult.success("完成移库任务成功");
|
|
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
|
//判断是否需要移库
public void doubletransfer(TaskHeader task) {
if(task.getTaskType() == 300 || task.getTaskType() == 600){
task.setToLocation(task.getFromLocation());
}
//判断任务的库位不为空
if(StringUtils.isNotEmpty(task.getToLocation())){
Location location = new Location();
location.setCode(task.getToLocation());
location.setWarehouseCode(task.getWarehouseCode());
location =locationService.selectFirstEntity(location);
if(location == null){
throw new ServiceException("任务的库位错误,系统没有此库位");
}
//判断库位是否为为内部库位,并且外部库位锁定
if(location.getIRow().intValue() == CodeConstans.INTERNELLOCATION.intValue()){
Location loca = new Location();
loca.setIRow(CodeConstans.EXTERNALLOCATION);
loca.setIColumn(location.getIColumn());
loca.setILayer(location.getILayer());
loca.setIGrid(location.getIGrid());
loca.setWarehouseCode(location.getWarehouseCode());
loca = locationService.selectFirstEntity(loca);
if(loca == null){
throw new ServiceException("外侧库位在系统不存在");
}
if(loca.getStatus().equals("lock") && StringUtils.isNotEmpty(loca.getUserDef1()) && loca.getUserDef1().equals("1")){
throw new ServiceException(task.getContainerCode() + "此托盘外部库位有进库任务,请等待下发");
}
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getFromLocation, loca.getCode())
.eq(TaskHeader::getWarehouseCode, loca.getWarehouseCode());
taskHeaderLambdaQueryWrapper.last("limit 1");
TaskHeader task1 = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(task1 !=null && task1.getFirstStatus() == 1){
throw new ServiceException("先下发库位号为"+loca.getCode()+"的任务");
}
//外部库位绑定了容器时,需要移库任务
if(loca !=null && StringUtils.isNotEmpty(loca.getContainerCode()) && loca.getStatus().equals("empty")){
//查看库位类型
LambdaQueryWrapper<LocationType> lambda = Wrappers.lambdaQuery();
lambda.eq(LocationType::getCode, loca.getLocationType())
.eq(LocationType::getWarehouseCode, loca.getWarehouseCode());
LocationType locationType=locationTypeService.getOne(lambda);
if(locationType ==null){
throw new ServiceException("该库位的库位类型不存在");
}
// 查找可移库的空库位
List<String> locationss=new ArrayList<>();
//查出外侧有货,内测无货的库位
List<String> locationlist =locationService.selectlistEnpty();
if(!locationlist.isEmpty()){
locationss.addAll(locationlist);
}
//如果此库位为外部库位,则查找所有内部库位是否有任务,且其内部库位是否是绑定状态
List<Location> locationList =new ArrayList<>();
List<Location> locations = locationService.selectCode();
if(locations!=null && locations.size()>0) {
//筛选内部库位
for(Location item :locations){
if(item.getIRow().intValue()== CodeConstans.INTERNELLOCATION.intValue()){
locationList.add(item);
}
}
//筛选外部库位
if(locationList!=null && locationList.size()>0) {
for (Location item : locationList) {
Location condition = new Location();
condition.setIRow(2);
condition.setIColumn(item.getIColumn());
condition.setIGrid(item.getIGrid());
condition.setILayer(item.getILayer());
condition.setZoneCode("LK");
condition = locationService.selectFirstEntity(condition);
locationss.add(condition.getCode());
}
}
}
Container container =containerService.getContainerByCode(loca.getContainerCode());
Location loc = locationTypeService.checkTypeV1(Double.valueOf(locationType.getLength()), Double.valueOf(locationType.getWidth()),
Double.valueOf(container.getUserDef1()), null, ShiroUtils.getWarehouseCode(), locationss, container);
List<Integer> taskIds = new ArrayList<>();
if(loc !=null){
this.createTransferTask2(loca.getCode(),task.getCompanyCode());
TaskHeader tas = new TaskHeader();
tas.setZoneCode("LK");
tas.setStatus(1);
tas.setFromLocation(loca.getCode());
|
|
416
|
tas.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
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
|
tas = selectFirstEntity(tas);
if(tas !=null){
taskIds.add(tas.getId());
}
}else {
//移库任务
List<String> locatinCodes = new ArrayList<>();
locatinCodes.add(loca.getCode());
taskIds = this.createOutPutTask(locatinCodes);
}
if(!taskIds.isEmpty()){
TaskHeader task2 =taskHeaderService.getById(taskIds.get(0));
taskAssignService.wcsTaskAssign(task2);
task2.setStatus(10);
taskHeaderService.updateById(task2);
}
}
}
}
}
public TaskHeader selectFirstEntity(TaskHeader tas){
LambdaQueryWrapper<TaskHeader> lambda = Wrappers.lambdaQuery();
lambda.eq(StringUtils.isNotEmpty(tas.getContainerCode()),TaskHeader::getContainerCode, tas.getContainerCode())
|
|
443
|
.eq(StringUtils.isNotNull(tas.getZoneCode()) && StringUtils.isNotEmpty(tas.getZoneCode()),TaskHeader::getZoneCode, tas.getZoneCode())
|
|
444
|
.eq(StringUtils.isNotNull(tas.getStatus()),TaskHeader::getStatus, tas.getStatus())
|
|
445
446
447
|
.eq(StringUtils.isNotNull(tas.getFromLocation()) && StringUtils.isNotEmpty(tas.getFromLocation()),TaskHeader::getFromLocation, tas.getFromLocation())
.eq(StringUtils.isNotNull(tas.getTaskType()) ,TaskHeader::getTaskType, tas.getTaskType());
lambda.last("limit 1");
|
|
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
|
return taskHeaderService.getOne(lambda);
}
public List<Integer> createOutPutTask(List<String> locations){
List<Integer> taskIds = new ArrayList<>();
for(String code: locations){
Location temp = new Location();
temp.setCode(code);
Location loc = locationService.selectFirstEntity(temp);
if(loc.getStatus().equals("lock")){
throw new ServiceException("该库位已锁定,有其他任务");
}
Container container =containerService.getContainerByCode(loc.getContainerCode());
if(loc.getZoneCode().equals("LK") || loc.getZoneCode().equals("XC")){
if(StringUtils.isEmpty(loc.getContainerCode())){
throw new ServiceException("该库位没有托盘");
}
TaskHeader task =new TaskHeader();
task.setContainerCode(loc.getContainerCode());
task.setStatus(10);
task =this.selectFirstEntity(task);
if(task!=null){
throw new ServiceException("该容器已有任务");
}
TaskHeader task1 =new TaskHeader();
task1.setContainerCode(loc.getContainerCode());
task1.setStatus(1);
task1 =this.selectFirstEntity(task1);
if(task1!=null){
throw new ServiceException("该容器已有任务");
}
}
if(loc.getLocationType().equals("DM") || loc.getLocationType().equals("XN")){
continue;
}
if(!loc.getStatus().equals("empty")){
throw new ServiceException(code+"状态非空闲,操作失败");
}
if(StringUtils.isEmpty(loc.getContainerCode())){
throw new ServiceException(code+"没有托盘,操作失败");
}
TaskHeader task = new TaskHeader();
task.setWarehouseCode(ShiroUtils.getWarehouseCode());
task.setCompanyCode(container.getCompanyCode());
//这里默认一个0
task.setPriority(0);
task.setZoneCode(loc.getZoneCode());
task.setTaskType(900);
task.setPort("1");
task.setZoneCode(loc.getZoneCode());
task.setRoadway(loc.getRoadway());
task.setContainerCode(loc.getContainerCode());
task.setStatus(1);
task.setFromLocation(loc.getCode());
task.setToLocation(loc.getCode());
task.setCreated(new Date());
task.setCreatedBy(ShiroUtils.getLoginName());
task.setCreated(new Date());
taskHeaderService.save(task);
taskIds.add(task.getId());
//更新库位状态
loc.setStatus("lock");
locationService.updateById(loc);
}
return taskIds;
}
@Transactional
public AjaxResult createTransferTask2(String sourceLocation, String companyCode) {
Location temp1 = new Location();
temp1.setCode(sourceLocation);
Location location = locationService.selectFirstEntity(temp1);
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") && !location.getZoneCode().equals("XC")){
return AjaxResult.error("该库位:"+sourceLocation+"不是立库库位");
}
if(location.getZoneCode().equals("LK") || location.getZoneCode().equals("XC")){
TaskHeader task =new TaskHeader();
task.setContainerCode(location.getContainerCode());
task.setStatus(10);
task =this.selectFirstEntity(task);
if(task!=null){
return AjaxResult.error(location.getContainerCode()+"该容器已有任务");
}
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation,ShiroUtils.getWarehouseCode());
if(count1>0){
return AjaxResult.error("源库位:"+sourceLocation+"存在入库组盘,不能移库");
}
int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation,ShiroUtils.getWarehouseCode());
if(count2>0){
return AjaxResult.error("源库位:"+sourceLocation+"存在出库组盘,不能移库");
}
//判断是否为内测库位
if(location.getIRow().intValue() == CodeConstans.INTERNELLOCATION.intValue()) {
Location loca = new Location();
loca.setIRow(CodeConstans.EXTERNALLOCATION);
loca.setIColumn(location.getIColumn());
loca.setILayer(location.getILayer());
loca.setIGrid(location.getIGrid());
loca.setWarehouseCode(location.getWarehouseCode());
loca = locationService.selectFirstEntity(loca);
if (loca == null) {
throw new ServiceException("外侧库位在系统不存在");
}
//外部库位绑定了容器时,需要移库任务
if (loca != null && StringUtils.isNotEmpty(loca.getContainerCode()) && loca.getStatus().equals("empty")) {
//查看库位类型
LocationType locationTypee = new LocationType();
locationTypee.setWarehouseCode(loca.getWarehouseCode());
locationTypee.setCode(loca.getLocationType());
locationTypee = locationTypeService.getLocationTypeByDoamin(locationTypee);
if (locationTypee == null) {
throw new ServiceException("该库位的库位类型不存在");
}
Container containerl = containerService.getContainerByCode(loca.getContainerCode(),loca.getWarehouseCode());
Location local = locationTypeService.checkType(Double.valueOf(locationTypee.getLength()),Double.valueOf(locationTypee.getWidth()),
Double.valueOf(containerl.getUserDef1()),Double.valueOf(locationTypee.getMaxWeight()), ShiroUtils.getWarehouseCode(),loca.getCode(),containerl);
List<String> locationss=new ArrayList<>();
List<String> locationlist =locationService.selectlistEnpty();
if(!locationlist.isEmpty()){
locationss.addAll(locationlist);
}
//如果此库位为外部库位,则查找所有内部库位是否有任务,且其内部库位是否是绑定状态
List<Location> locationList =new ArrayList<>();
List<Location> locations = locationService.selectCode();
if(locations!=null && locations.size()>0) {
//筛选内部库位
for(Location item :locations){
if(item.getIRow().intValue()== CodeConstans.INTERNELLOCATION.intValue()){
locationList.add(item);
}
}
//筛选外部库位
if(locationList!=null && locationList.size()>0) {
for (Location item : locationList) {
Location condition = new Location();
condition.setIRow(2);
condition.setIColumn(item.getIColumn());
condition.setIGrid(item.getIGrid());
condition.setILayer(item.getILayer());
condition.setZoneCode("LK");
condition = locationService.selectFirstEntity(condition);
locationss.add(condition.getCode());
}
}
}
if(!locationss.isEmpty()) {
local = locationTypeService.checkTypeV1(Double.valueOf(locationTypee.getLength()),Double.valueOf(locationTypee.getWidth()),
Double.valueOf(containerl.getUserDef1()),Double.valueOf(locationTypee.getMaxWeight()), ShiroUtils.getWarehouseCode(),locationss,containerl);
}
if(local == null){
throw new ServiceException("没有空库位");
}
TaskHeader task = new TaskHeader();
task.setWarehouseCode(ShiroUtils.getWarehouseCode());
task.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
//这里默认一个0
task.setPriority(0);
|
|
635
|
task.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
636
637
|
//对移库来说,这个没啥用
task.setPort(null);
|
|
638
|
task.setRoadway(loca.getRoadway());
|
|
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
task.setZoneCode(loca.getZoneCode());
task.setContainerCode(loca.getContainerCode());
task.setStatus(1);
task.setCreated(new Date());
task.setFromLocation(loca.getCode());
task.setToLocation(local.getCode());
task.setCreated(new Date());
task.setCreatedBy(ShiroUtils.getLoginName());
taskHeaderService.save(task);
//更新货位状态为预定
local.setStatus("lock");
local.setUserDef1("1");
loca.setStatus("lock");
locationService.updateById(loca);
locationService.updateById(local);
}
}
Container container =containerService.getContainerByCode(location.getContainerCode(),location.getWarehouseCode());
LocationType locationType =new LocationType();
locationType.setWarehouseCode(location.getWarehouseCode());
locationType.setCode(location.getLocationType());
locationType = locationTypeService.getLocationTypeByDoamin(locationType);
//查找可移入的库位
//通过限制条件查找库位类型列表
Location locat = new Location();
|
|
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
|
if(container.getContainerType().equals(QuantityConstant.CONTAINER_TYPEC)){
locat = locationService.getLocationOfRule();
}else {
locat = locationTypeService.checkType(Double.valueOf(locationType.getLength()), Double.valueOf(locationType.getWidth()),
Double.valueOf(container.getUserDef1()), Double.valueOf(locationType.getMaxWeight()), ShiroUtils.getWarehouseCode(), location.getCode(), container);
List<String> locationsss=new ArrayList<>();
List<String> locationlists =locationService.selectlistEnpty();
if(!locationlists.isEmpty()){
locationsss.addAll(locationlists);
}
//如果此库位为外部库位,则查找所有内部库位是否有任务,且其内部库位是否是绑定状态
List<Location> locationList =new ArrayList<>();
List<Location> locations = locationService.selectCode();
if(locations!=null && locations.size()>0) {
//筛选内部库位
for(Location item :locations){
if(item.getIRow().intValue()== CodeConstans.INTERNELLOCATION.intValue()){
locationList.add(item);
}
}
//筛选外部库位
if(locationList!=null && locationList.size()>0) {
for (Location item : locationList) {
Location condition = new Location();
condition.setIRow(2);
condition.setIColumn(item.getIColumn());
condition.setIGrid(item.getIGrid());
condition.setILayer(item.getILayer());
condition.setZoneCode("LK");
condition = locationService.selectFirstEntity(condition);
locationsss.add(condition.getCode());
}
locat = locationTypeService.checkTypeV1(Double.valueOf(locationType.getLength()),Double.valueOf(locationType.getWidth()),
Double.valueOf(container.getUserDef1()),Double.valueOf(locationType.getMaxWeight()), ShiroUtils.getWarehouseCode(),locationsss,container);
}
}
if(!locationsss.isEmpty()) {
locat = locationTypeService.checkTypeV1(Double.valueOf(locationType.getLength()),Double.valueOf(locationType.getWidth()),
Double.valueOf(container.getUserDef1()),Double.valueOf(locationType.getMaxWeight()), ShiroUtils.getWarehouseCode(),locationsss,container);
}
}
if(locat == null){
throw new ServiceException("没有空库位");
}
TaskHeader task = new TaskHeader();
|
|
721
722
723
724
|
task.setWarehouseCode(ShiroUtils.getWarehouseCode());
task.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
//这里默认一个0
task.setPriority(0);
|
|
725
|
task.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
726
|
//对移库来说,这个没啥用
|
|
727
|
task.setPort(null);
|
|
728
|
task.setRoadway(location.getRoadway());
|
|
729
730
|
task.setZoneCode(location.getZoneCode());
task.setContainerCode(location.getContainerCode());
|
|
731
732
733
|
task.setStatus(1);
task.setFromLocation(sourceLocation);
task.setToLocation(locat.getCode());
|
|
734
735
|
task.setCreated(new Date());
task.setCreatedBy(ShiroUtils.getLoginName());
|
|
736
|
taskHeaderService.save(task);
|
|
737
738
739
740
|
//更新货位状态为预定
location.setStatus("lock");
locat.setStatus("lock");
locat.setUserDef1("0");
|
|
741
742
743
744
|
locationService.updateById(location);
locationService.updateById(locat);
return AjaxResult.success(task);
// return AjaxResult.success("");
|
|
745
746
|
}
|
|
747
|
}
|