Commit 96967ea01d65addb3800663f648f85ef46482cc7
1 parent
6f5b3d05
fix: 定时删除已出库的平库容器和库位
Showing
1 changed file
with
45 additions
and
40 deletions
src/main/java/com/huaheng/pc/monitor/job/task/RyTask.java
... | ... | @@ -58,6 +58,7 @@ import com.huaheng.pc.task.taskHeader.service.TaskHeaderService; |
58 | 58 | import com.huaheng.pc.task.taskHeader.service.WorkTaskService; |
59 | 59 | import org.apache.commons.collections.MapUtils; |
60 | 60 | import org.springframework.stereotype.Component; |
61 | +import org.springframework.transaction.annotation.Transactional; | |
61 | 62 | import org.springframework.ui.ModelMap; |
62 | 63 | |
63 | 64 | import javax.annotation.Resource; |
... | ... | @@ -348,72 +349,76 @@ public class RyTask extends BaseController { |
348 | 349 | /** |
349 | 350 | * 删除已出库的平库容器和库位 |
350 | 351 | */ |
352 | + @Transactional | |
351 | 353 | public void deleteFlatContainerLocation() { |
352 | - //删除容器 | |
353 | - List<TaskHeader> taskList = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>().ne(TaskHeader::getStatus, 100)); | |
354 | + List<TaskHeader> taskList = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>().ne(TaskHeader::getStatus, 100).eq(TaskHeader::getFlat, 1)); | |
354 | 355 | List<InventoryHeader> inventoryList = inventoryHeaderService.list(new LambdaQueryWrapper<InventoryHeader>().ne(InventoryHeader::getZoneCode, "L")); |
356 | + | |
357 | + //删除容器 | |
355 | 358 | List<Container> containerList = containerService.list(new LambdaQueryWrapper<Container>() |
356 | - .and(wrapper -> wrapper.isNull(Container::getLocationCode).or().eq(Container::getLocationCode, "")) | |
357 | 359 | .eq(Container::getStatus, "empty") |
358 | 360 | .eq(Container::getFlat, 1)); |
361 | + | |
359 | 362 | if (!containerList.isEmpty()) { |
360 | - //取出containerList的code | |
363 | + List<Container> deleteContainerList = new ArrayList<>(); | |
361 | 364 | List<String> containerCodeList = containerList.stream().map(Container::getCode).collect(Collectors.toList()); |
362 | - //如果containerCodeList在库存表和任务表中存在就不删除,其他的删除Container | |
363 | - for (Container container : containerList) { | |
364 | - boolean flag = false; | |
365 | + | |
366 | + if (!taskList.isEmpty()) { | |
365 | 367 | for (TaskHeader taskHeader : taskList) { |
366 | 368 | if (containerCodeList.contains(taskHeader.getContainerCode())) { |
367 | - flag = true; | |
368 | - break; | |
369 | + deleteContainerList.add(containerList.stream().filter(container -> container.getCode().equals(taskHeader.getContainerCode())).findFirst().get()); | |
369 | 370 | } |
370 | 371 | } |
371 | - if (flag) { | |
372 | - continue; | |
373 | - } | |
372 | + } | |
373 | + if (!inventoryList.isEmpty()) { | |
374 | 374 | for (InventoryHeader inventoryHeader : inventoryList) { |
375 | 375 | if (containerCodeList.contains(inventoryHeader.getContainerCode())) { |
376 | - flag = true; | |
377 | - break; | |
376 | + deleteContainerList.add(containerList.stream().filter(container -> container.getCode().equals(inventoryHeader.getContainerCode())).findFirst().get()); | |
378 | 377 | } |
379 | 378 | } |
380 | - if (flag) { | |
381 | - continue; | |
382 | - } | |
383 | - containerService.removeById(container.getId()); | |
379 | + } | |
380 | + containerCodeList.removeAll(deleteContainerList.stream().map(Container::getCode).collect(Collectors.toList())); | |
381 | + if (!containerCodeList.isEmpty()) { | |
382 | + containerService.remove(new LambdaQueryWrapper<Container>().in(Container::getCode, containerCodeList)); | |
384 | 383 | } |
385 | 384 | } |
386 | 385 | |
386 | + | |
387 | 387 | //删除库位 |
388 | 388 | List<Location> locationList = locationService.list(new LambdaQueryWrapper<Location>() |
389 | - .and(wrapper -> wrapper.isNull(Location::getContainerCode).or().eq(Location::getContainerCode, "")) | |
390 | 389 | .eq(Location::getStatus, "empty") |
391 | 390 | .ne(Location::getZoneCode, "L")); |
392 | - if (!locationList.isEmpty()) { | |
393 | - List<String> locationCodeList = locationList.stream().map(Location::getCode).collect(Collectors.toList()); | |
394 | - for (Location location : locationList) { | |
395 | - boolean flag = false; | |
396 | - for (TaskHeader taskHeader : taskList) { | |
397 | - if (locationCodeList.contains(taskHeader.getFromLocation())) { | |
398 | - flag = true; | |
399 | - break; | |
400 | - } | |
401 | - } | |
402 | - if (flag) { | |
403 | - continue; | |
404 | - } | |
405 | - for (InventoryHeader inventoryHeader : inventoryList) { | |
406 | - if (locationCodeList.contains(inventoryHeader.getLocationCode())) { | |
407 | - flag = true; | |
408 | - break; | |
409 | - } | |
391 | + | |
392 | + if (locationList.isEmpty()) { | |
393 | + return; | |
394 | + } | |
395 | + | |
396 | + List<Location> deleteLocationList = new ArrayList<>(); | |
397 | + List<String> locationCodeList = locationList.stream().map(Location::getCode).collect(Collectors.toList()); | |
398 | + if (!taskList.isEmpty()) { | |
399 | + for (TaskHeader taskHeader : taskList) { | |
400 | + if (locationCodeList.contains(taskHeader.getFromLocation())) { | |
401 | + deleteLocationList.add(locationList.stream().filter(location -> location.getCode().equals(taskHeader.getFromLocation())).findFirst().get()); | |
410 | 402 | } |
411 | - if (flag) { | |
412 | - continue; | |
403 | + } | |
404 | + } | |
405 | + if (!inventoryList.isEmpty()) { | |
406 | + for (InventoryHeader inventoryHeader : inventoryList) { | |
407 | + if (locationCodeList.contains(inventoryHeader.getLocationCode())) { | |
408 | + deleteLocationList.add(locationList.stream().filter(location -> location.getCode().equals(inventoryHeader.getLocationCode())).findFirst().get()); | |
413 | 409 | } |
414 | - locationService.removeById(location.getId()); | |
415 | 410 | } |
416 | 411 | } |
412 | + locationCodeList.removeAll(deleteLocationList.stream().map(Location::getCode).collect(Collectors.toList())); | |
413 | + | |
414 | + if (locationCodeList.isEmpty()) { | |
415 | + return; | |
416 | + } | |
417 | + | |
418 | + //删除库位 | |
419 | + locationService.remove(new LambdaQueryWrapper<Location>().in(Location::getCode, locationCodeList)); | |
420 | + | |
421 | + | |
417 | 422 | } |
418 | 423 | |
419 | 424 | |
... | ... |