EmptyContainerController.java
17.7 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
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
package com.huaheng.api.wcs.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.api.wcs.service.warecellAllocation.LocationAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
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.locationHigh.domain.LocationHigh;
import com.huaheng.pc.config.locationHigh.service.LocationHighService;
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.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/API/WMS/v2")
public class EmptyContainerController extends BaseController {
@Resource
private WorkTaskService workTaskService;
@Resource
private LocationAllocationService allocationService;
@Resource
private ConfigService configService;
@Resource
private ZoneService zoneService;
@Resource
private LocationService locationService;
@Resource
private LocationTypeService locationTypeService;
@Resource
private LocationHighService locationHighService;
@Resource
private ContainerService containerService;
@Resource
private ContainerTypeService containerTypeService;
@Autowired
private AddressService addressService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskAssignService taskAssignService;
@Resource
private InventoryHeaderService inventoryHeaderService;
/**
* 生成空托盘入库任务
* @return
*/
@PostMapping("/manyEmptyIn")
@Log(title = "任务-任务管理", operating = "生成空托盘组入库任务", action = BusinessType.INSERT)
@ResponseBody
@Transactional
@ApiLogger(apiName = "manyEmptyIn", from="ROBOT")
public AjaxResult manyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerManyEmptyIn(manyEmptyDomain);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 生成空托盘出库任务
* @return
*/
@PostMapping("/manyEmptyOut")
@Log(title = "任务-任务管理", operating = "生成空托盘组出库任务", action = BusinessType.INSERT)
@ResponseBody
@Transactional
@ApiLogger(apiName = "manyEmptyOut", from="ROBOT")
public AjaxResult manyEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerManyEmptyOut(manyEmptyDomain);
return ajaxResult;
}
});
return ajaxResult;
}
private AjaxResult innerManyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
if(manyEmptyDomain == null){
throw new ServiceException("空托盘组参数不对!");
}
//获得容器编号
String containerCode = manyEmptyDomain.getContainerCode();
//获得仓库编码
String warehouseCode = manyEmptyDomain.getWarehouseCode();
//获得区域
String area = manyEmptyDomain.getArea();
//获得巷道
String roadWay = manyEmptyDomain.getRoadWay();
List<String> roadWays = new ArrayList<>();
//将巷道添加到集合
roadWays.add(roadWay);
//设置为单伸位
String value = configService.getKey(QuantityConstant.RULE_ALLOCATION);
//获得高度
String height = manyEmptyDomain.getHeight();
if (StringUtils.isEmpty(value)) {
return AjaxResult.error("未绑定定位规则");
}
int allocationRule = Integer.parseInt(value);
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据区域筛选
zoneLambdaQueryWrapper.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
if(zone == null) {
return AjaxResult.error("分配库位时,没有找到库区");
}
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据容器编码,仓库编码,任务状态筛选
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getContainerCode, containerCode)
.eq(TaskHeader::getWarehouseCode, warehouseCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
return AjaxResult.success("已经生成空托盘组任务");
}
//查询满足条件的库位类型
LambdaQueryWrapper<LocationType> lambdaQueryWrapper = Wrappers.lambdaQuery();
//根据库区编码,仓库编码筛选
lambdaQueryWrapper.eq(LocationType::getZoneCode, zone.getCode())
.eq(LocationType::getWarehouseCode, warehouseCode);
List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper);
if(locationTypeList == null) {
return AjaxResult.error("分配库位时,没有找到库位类型");
}
//将库位编码封装到集合中
List<String> locationTypeCodeList = locationTypeList.stream().
map(t -> t.getCode()).collect(Collectors.toList());
int highHeight = Float.valueOf(height).intValue();
LambdaQueryWrapper<LocationHigh> locationHighLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据库位高度值,库位类型编码筛选
locationHighLambdaQueryWrapper.eq(LocationHigh::getHighLevel, highHeight)
.in(LocationHigh::getLocationTypeCode, locationTypeCodeList);
LocationHigh locationHigh = locationHighService.getOne(locationHighLambdaQueryWrapper);
int high = locationHigh.getHigh();
//调用获得单伸位的方法获得库位编码
String locationCode = allocationService.allocation(allocationRule, locationTypeCodeList, high, area,
roadWays, warehouseCode, containerCode, null);
if(locationCode == null) {
return AjaxResult.error("分配库位时,没有找到库位");
}
//调用创建入库任务的方法
return workTaskService.createManyEmptyIn(containerCode, locationCode, warehouseCode);
}
private AjaxResult innerManyEmptyOut(ManyEmptyDomain manyEmptyDomain) {
if(manyEmptyDomain == null){
throw new ServiceException("空托盘组参数不对!");
}
//设置仓库编码
String warehouseCode = manyEmptyDomain.getWarehouseCode();
//设置区域
String area = manyEmptyDomain.getArea();
//设置出库口
String port = manyEmptyDomain.getPort();
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据容器状态和仓库编码筛选
containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_MANY)
.eq(Container::getWarehouseCode, warehouseCode);
List<Container> containerList = containerService.list(containerLambdaQueryWrapper);
List<Container> removeContainerList = new ArrayList<>();
if(containerList != null && containerList.size() > 0) {
for(Container container : containerList) {
//库位编码
String locationCode = container.getLocationCode();
//根据库位编码和仓库编码获取
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
if(!location.getArea().equals(area)) {
//将区域不一样的容器添加到集合中
removeContainerList.add(container);
}
}
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
//筛选区域
zoneLambdaQueryWrapper.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据任务状态,任务类型,出库口,库区编码
taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, port);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, zone.getCode());
if("7".equals(area)){
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getUserDef2, "1");
}else{
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_MANY_EMPTYSHIPMENT);
}
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
//给WcsTask实体类设置值
WcsTask wcsTask = new WcsTask();
//任务类型
wcsTask.setTaskType(taskHeader.getTaskType());
//任务编号
wcsTask.setTaskNo(String.valueOf(taskHeader.getId()));
//容器编号
wcsTask.setContainerCode(taskHeader.getContainerCode());
//仓库编码
wcsTask.setWarehouseCode(warehouseCode);
//原库位
wcsTask.setFromLocationCode(taskHeader.getFromLocation());
if("7".equals(area)){
wcsTask.setToLocationCode(taskHeader.getToLocation());
}
//平台
wcsTask.setPlatform(QuantityConstant.PLATFORM_WMS);
//优先级
wcsTask.setPriority(1000);
//任务状态
wcsTask.setTaskStatus(taskHeader.getStatus());
//去向站台
wcsTask.setToPort(port);
//设置任务类型码
wcsTask = taskAssignService.switchTaskTypeToWcs(wcsTask);
return AjaxResult.success(wcsTask);
}
//将集合删除
containerList.removeAll(removeContainerList);
if(!(containerList != null && containerList.size() > 0)) {
return AjaxResult.error("没有找到合适的空托盘组!");
}
String containerCode = containerList.get(0).getCode();
//根据容器编码和仓库编码获得容器
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
if(container == null){
throw new ServiceException("没有找到托盘“");
}
//调用创建空托组出库的任务(容器编码,仓库编码,站台)
if("7".equals(area)){
return workTaskService.createManyEmptyOut(containerCode, warehouseCode, port, area);
}
return workTaskService.createManyEmptyOut(containerCode, warehouseCode, port);
}
/**
* 生成空托出库任务
* @return
*/
@PostMapping("/wcsCallEmptyOut")
@Log(title = "任务-任务管理", operating = "生成空托出库任务", action = BusinessType.INSERT)
@ResponseBody
@ApiLogger(apiName = "生成空托出库任务", from="WCS")
public AjaxResult wcsCallEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerWcsCallEmptyOut(manyEmptyDomain);
return ajaxResult;
}
});
return ajaxResult;
}
private AjaxResult innerWcsCallEmptyOut(ManyEmptyDomain manyEmptyDomain) {
//获得仓库编码
String warehouseCode = manyEmptyDomain.getWarehouseCode();
//获得区域
String area = manyEmptyDomain.getArea();
//获得站台
String port = manyEmptyDomain.getPort();
if(warehouseCode == null) {
return AjaxResult.error("warehouseCode 不能为空");
}
if(area == null) {
return AjaxResult.error("area 不能为空");
}
if(port == null) {
return AjaxResult.error("port 不能为空");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据 仓库编码和区域筛选
zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
if(zone == null) {
return AjaxResult.error("area不正确,没有找到对应区域");
}
String zoneCode = zone.getCode();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
//根据任务状态,任务类型,出库口,库区编码
taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, port);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, zone.getCode());
if("7".equals(area)){
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getUserDef2, "1");
}else{
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_EMPTYSHIPMENT);
}
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
if(taskHeader != null) {
//给WcsTask实体类设置值
WcsTask wcsTask = new WcsTask();
//任务类型
wcsTask.setTaskType(taskHeader.getTaskType());
//任务编号
wcsTask.setTaskNo(String.valueOf(taskHeader.getId()));
//容器编号
wcsTask.setContainerCode(taskHeader.getContainerCode());
//仓库编码
wcsTask.setWarehouseCode(warehouseCode);
//原库位
wcsTask.setFromLocationCode(taskHeader.getFromLocation());
if("7".equals(area)){
wcsTask.setToLocationCode(taskHeader.getToLocation());
}
//平台
wcsTask.setPlatform(QuantityConstant.PLATFORM_WMS);
//优先级
wcsTask.setPriority(1000);
//任务状态
wcsTask.setTaskStatus(taskHeader.getStatus());
//去向站台
wcsTask.setToPort(port);
//设置任务类型码
wcsTask = taskAssignService.switchTaskTypeToWcs(wcsTask);
return AjaxResult.success(wcsTask);
}
//调用 已入空容器展示
List<Location> list = containerService.getEmptyContainerInLocation(zoneCode,
"","", warehouseCode);
if(list == null || list.size() <= 0) {
return AjaxResult.error("没有找到空托盘");
}
Location location = list.get(0);
String containerCode = location.getContainerCode();
String locationCode = location.getCode();
if("7".equals(area)){
return workTaskService.createEmptyOut(containerCode,locationCode,port, warehouseCode, area);
}
//创建空托出库
return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
}
/**
* 回转呼叫空托盘出库
* @return
*/
@PostMapping("/callEmptyContainerShipment")
@Log(title = "任务-任务管理", operating = "回转呼叫空托盘组出库", action = BusinessType.INSERT)
@ResponseBody
@Transactional
@ApiLogger(apiName = "回转呼叫空托盘出库", from="WCS")
public AjaxResult callEmptyContainerShipment(@RequestBody ManyEmptyDomain manyEmptyDomain) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerWcsCallEmptyOut(manyEmptyDomain);
return ajaxResult;
}
});
return ajaxResult;
}
}