LocationAllocationServiceImpl.java
17.3 KB
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
package com.huaheng.api.wcs.service.warecellAllocation;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
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.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.util.stream.Collectors.toList;
@Service
public class LocationAllocationServiceImpl implements LocationAllocationService {
@Resource
private LocationService locationService;
@Resource
private LocationTypeService locationTypeService;
@Resource
private ContainerService containerService;
@Resource
private ContainerTypeService containerTypeService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ZoneService zoneService;
@Resource
private ConfigService configService;
@Override
public String allocation(int locationRule, List<String> locationTypeCodeList,
int high, String area, List<String> raodWays, String warehouseCode,
String containerCode, String materialAreaCode) {
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);
List<LocationType> locationTypeList = new ArrayList<>();
if (containerType != null) {
String locationType = containerType.getLocationType();
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);
if (locationType1 != null) {
locationTypeList.add(locationType1);
}
}
} else {
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
if (zone != null) {
LambdaQueryWrapper<LocationType> locationTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
locationTypeLambdaQueryWrapper.eq(LocationType::getWarehouseCode, warehouseCode)
.eq(LocationType::getZoneCode, zone.getCode());
locationTypeList = locationTypeService.list(locationTypeLambdaQueryWrapper);
}
}
List<String> locationTypeCodes = locationTypeList.stream().
map(t -> t.getCode()).collect(toList());
List<String> mergelocationTypeCodeList = locationTypeCodeList.stream().filter(item -> locationTypeCodes.contains(item)).collect(toList());
switch (locationRule) {
case QuantityConstant.DOUBLE_FORK:
if (warehouseCode.equals(QuantityConstant.WAREHOUSE_XZ)) {
return doubleRkXZ(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
} else {
return doubleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
}
case QuantityConstant.SINGLE_FORK:
return singleRk(area, raodWays, high, warehouseCode, mergelocationTypeCodeList, materialAreaCode);
}
return null;
}
/**
* 双伸位库位入库分配库位--徐州
*/
private String doubleRkXZ(String area, List<String> roadWays, int high, String warehouseCode,
List<String> locationTypeCodeList, String materialAreaCode) {
if (roadWays == null || roadWays.size() < 1) {
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area);
locationLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
roadWays = locationList.stream().map(Location::getRoadway).distinct().collect(toList());
}
String value = configService.getKey(QuantityConstant.DOUBLE_FORK_RESERVE_LOCATION, warehouseCode);
int reserveNumber = 0;
if (StringUtils.isNotEmpty(value)) {
reserveNumber = Integer.parseInt(value);
}
StopWatch stopWatch = new StopWatch();
stopWatch.start("aaa");
List<String> removeRoadWays = new ArrayList<>();
for (String roadWay : roadWays) {
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.eq(Location::getHigh, high)
.eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
.in(Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
.last("ORDER BY iLayer asc, id asc limit 20");
// .last("ORDER BY iColumn desc, iLayer asc, id asc limit 20");
List<Location> totalLocationList = locationService.list(locationLambdaQueryWrapper);
if (totalLocationList.size() <= reserveNumber) {
removeRoadWays.add(roadWay);
}
}
stopWatch.stop();
System.out.println("waste aa:" + stopWatch.getLastTaskTimeMillis());
stopWatch.start("bbb");
roadWays.removeAll(removeRoadWays);
Collections.shuffle(roadWays);
String roadWay = roadWays.get(0);
LambdaQueryWrapper<Location> locationLambda = com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery();
locationLambda.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.eq(Location::getHigh, high)
.eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
.eq(Location::getRowFlag, QuantityConstant.ROW_OUT)
.in(Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
.last("ORDER BY iLayer asc, id asc limit 20");
List<Location> locationList = locationService.list(locationLambda);
List<Location> removeLocaationList = new ArrayList<>();
if (locationList != null && locationList.size() > 0) {
for (Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNearXZ(location1) > 0) {
removeLocaationList.add(location1);
}
}
}
locationList.removeAll(removeLocaationList);
stopWatch.stop();
System.out.println("waste bb:" + stopWatch.getLastTaskTimeMillis());
if (locationList == null || locationList.size() == 0) {
locationLambda = com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery();
locationLambda.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.eq(Location::getHigh, high)
.eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
.eq(Location::getRowFlag, QuantityConstant.ROW_IN)
.in(Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
.last("ORDER BY iLayer asc, id asc limit 20");
locationList = locationService.list(locationLambda);
removeLocaationList = new ArrayList<>();
if (locationList != null && locationList.size() > 0) {
for (Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNearXZ(location1) > 0) {
removeLocaationList.add(location1);
}
}
}
locationList.removeAll(removeLocaationList);
}
if (locationList == null || locationList.size() == 0) {
return null;
}
Location location = locationList.stream().findFirst().orElse(null);
String locationCode = location.getCode();
return locationCode;
}
/**
* 双伸位库位入库分配库位
*/
private String doubleRk(String area, List<String> roadWays, int high, String warehouseCode,
List<String> locationTypeCodeList, String materialAreaCode) {
if (roadWays == null) {
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area);
List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
roadWays = locationList.stream().map(Location::getRoadway).distinct().collect(toList());
}
String value = configService.getKey(QuantityConstant.DOUBLE_FORK_RESERVE_LOCATION, warehouseCode);
int reserveNumber = Integer.parseInt(value);
List<String> removeRoadWays = new ArrayList<>();
for (String roadWay : roadWays) {
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.eq(StringUtils.isNotEmpty(roadWay), Location::getRoadway, roadWay)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.ge(Location::getHigh, high)
// .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
.in(!warehouseCode.equalsIgnoreCase("KS0001"), Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
.last(warehouseCode.equalsIgnoreCase("KS0001"), "ORDER BY high ASC, CASE WHEN iRow=3 THEN 1 WHEN iRow=1 THEN 2 WHEN iRow=2 THEN 3 END");
List<Location> totalLocationList = locationService.list(locationLambdaQueryWrapper);
if (totalLocationList.size() <= reserveNumber) {
removeRoadWays.add(roadWay);
}
}
roadWays.removeAll(removeRoadWays);
LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
locationLambda.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.ge(Location::getHigh, high)
// .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
// .eq(Location::getRowFlag, QuantityConstant.ROW_OUT)
.in(!warehouseCode.equalsIgnoreCase("KS0001"), Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
.last(warehouseCode.equalsIgnoreCase("KS0001"), "ORDER BY high ASC, CASE WHEN iRow=3 THEN 1 WHEN iRow=1 THEN 2 WHEN iRow=2 THEN 3 END");
List<Location> locationList = locationService.list(locationLambda);
List<Location> removeLocaationList = new ArrayList<>();
if (locationList != null && locationList.size() > 0) {
for (Location location1 : locationList) {
//查出未完成
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
}
if (warehouseCode.equalsIgnoreCase("KS0001") && location1.getIRow() == 1) {
} else {
Location insideNear = locationService.getInsideNear(location1);
if (insideNear != null && StringUtils.isNotEmpty(insideNear.getContainerCode())) {
removeLocaationList.add(location1);
}
}
}
}
locationList.removeAll(removeLocaationList);
if (locationList == null || locationList.size() == 0) {
locationLambda = Wrappers.lambdaQuery();
locationLambda.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.ge(Location::getHigh, high)
// .eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
// .eq(Location::getRowFlag, QuantityConstant.ROW_IN)
.in(!warehouseCode.equalsIgnoreCase("KS0001"), Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "")
//昆山立库优先行顺序 1,3,2
.last(warehouseCode.equalsIgnoreCase("KS0001"), "ORDER BY high ASC, CASE WHEN iRow=3 THEN 1 WHEN iRow=1 THEN 2 WHEN iRow=2 THEN 3 END ");
locationList = locationService.list(locationLambda);
removeLocaationList = new ArrayList<>();
if (locationList != null && locationList.size() > 0) {
for (Location location1 : locationList) {
if (taskHeaderService.getUncompleteTaskInNear(location1) > 0) {
removeLocaationList.add(location1);
}
}
}
locationList.removeAll(removeLocaationList);
}
if (locationList == null || locationList.size() == 0) {
return null;
}
Location location = locationList.stream().findFirst().orElse(null);
String locationCode = location.getCode();
return locationCode;
}
/**
* 单伸位库位入库分配库位
*/
private String singleRk(String area, List<String> roadWays, int high, String warehouseCode,
List<String> locationTypeCodeList, String materialAreaCode) {
LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery();
locationLambda.eq(Location::getArea, area).
eq(Location::getWarehouseCode, warehouseCode)
.in(StringUtils.isNotEmpty(roadWays), Location::getRoadway, roadWays)
.eq(Location::getStatus, QuantityConstant.STATUS_LOCATION_EMPTY)
.le(Location::getHigh, high)
.eq(StringUtils.isNotEmpty(materialAreaCode), Location::getMaterialAreaCode, materialAreaCode)
.in(Location::getLocationType, locationTypeCodeList)
.eq(Location::getContainerCode, "");
locationLambda.last("ORDER BY high ASC, id asc");
List<Location> locationList = locationService.list(locationLambda);
if (locationList == null || locationList.size() == 0) {
return null;
}
Location location = locationList.stream().findFirst().orElse(null);
String locationCode = location.getCode();
return locationCode;
}
}