|
1
2
3
4
|
package com.huaheng.api.wcs.service.warecellAllocation;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
5
|
import com.huaheng.common.constant.Constants;
|
|
6
7
|
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
|
|
8
9
10
11
|
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
|
|
12
13
14
|
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationType.domain.LocationType;
|
|
15
|
import com.huaheng.pc.config.locationType.service.LocationTypeService;
|
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class LocationAllocationServiceImpl implements LocationAllocationService {
@Resource
private LocationService locationService;
@Resource
|
|
30
31
32
33
34
35
|
private LocationTypeService locationTypeService;
@Resource
private ContainerService containerService;
@Resource
private ContainerTypeService containerTypeService;
@Resource
|
|
36
37
38
|
private TaskHeaderService taskHeaderService;
@Override
|
|
39
|
public String allocation(String locationRule, String area, String warehouseCode, String containerCode) {
|
|
40
41
42
|
if (StringUtils.isEmpty(locationRule)) {
return null;
}
|
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
containerLambdaQueryWrapper.eq(Container::getCode, containerCode)
.eq(Container::getWarehouseCode, warehouseCode);
Container container = containerService.getOne(containerLambdaQueryWrapper);
LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType())
.eq(ContainerType::getWarehouseCode, warehouseCode);
ContainerType containerType = containerTypeService.getOne(containerTypeLambdaQueryWrapper);
String locationType = containerType.getLocationType();
List<LocationType> locationTypeList = new ArrayList<>();
String[] list = locationType.split(",");
for(String str : list) {
LambdaQueryWrapper<LocationType> locationTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
locationTypeLambdaQueryWrapper.eq(LocationType::getWarehouseCode, warehouseCode)
.eq(LocationType::getCode, str);
LocationType locationType1 = locationTypeService.getOne(locationTypeLambdaQueryWrapper);
locationTypeList.add(locationType1);
}
|
|
61
|
switch (locationRule) {
|
|
62
|
case Constants.DOUBLE_RK:
|
|
63
|
return doubleRk(area, warehouseCode, locationTypeList);
|
|
64
|
case Constants.SINGER_RK:
|
|
65
|
return singleRk(area, warehouseCode, locationTypeList);
|
|
66
67
68
69
70
71
72
|
}
return null;
}
/*
* 双伸位库位入库分配库位
*/
|
|
73
|
private String doubleRk(String area, String warehouseCode, List<LocationType> locationTypeList) {
|
|
74
|
LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
|
|
75
|
locationLambda.eq(Location::getArea, area).
|
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
eq(Location::getWarehouseCode, warehouseCode)
.eq(Location::getStatus, "empty")
.eq(Location::getRowFlag, 1)
.eq(Location::getContainerCode, "");
List<Location> locationList = locationService.list(locationLambda);
List<Location> removeLocaationList = new ArrayList<>();
for (Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
} else {
break;
}
}
locationList.removeAll(removeLocaationList);
if (locationList == null || locationList.size() == 0) {
locationLambda = Wrappers.lambdaQuery();
|
|
92
|
locationLambda.eq(Location::getArea, area).
|
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
eq(Location::getWarehouseCode, warehouseCode)
.eq(Location::getStatus, "empty")
.eq(Location::getRowFlag, 0)
.eq(Location::getContainerCode, "");
locationList = locationService.list(locationLambda);
removeLocaationList = new ArrayList<>();
for (Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
} else {
break;
}
}
locationList.removeAll(removeLocaationList);
}
|
|
108
|
String locationCode = filter(locationList, locationTypeList, area);
|
|
109
110
111
|
return locationCode;
}
|
|
112
113
114
|
/*
* 单伸位库位入库分配库位
*/
|
|
115
|
private String singleRk(String area, String warehouseCode, List<LocationType> locationTypeList) {
|
|
116
|
LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
|
|
117
|
locationLambda.eq(Location::getArea, area).
|
|
118
119
120
121
|
eq(Location::getWarehouseCode, warehouseCode)
.eq(Location::getStatus, "empty")
.eq(Location::getContainerCode, "");
List<Location> locationList = locationService.list(locationLambda);
|
|
122
|
String locationCode = filter(locationList, locationTypeList, area);
|
|
123
124
125
|
return locationCode;
}
|
|
126
|
private String filter(List<Location> locationList, List<LocationType> locationTypeList, String area) {
|
|
127
|
List<String> codeList = locationTypeList.stream().map(t -> t.getCode()).collect(Collectors.toList());
|
|
128
|
List<Location> newLocation = locationList.stream().filter(t -> codeList.contains(t.getLocationType()) && t.getArea().equals(area)).collect(Collectors.toList());
|
|
129
130
131
132
133
134
135
|
if (newLocation.isEmpty()) {
return null;
} else {
return newLocation.get(0).getCode();
}
}
}
|