|
1
2
3
4
5
6
|
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;
|
|
7
8
|
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
|
|
9
10
11
12
|
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;
|
|
13
|
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
|
|
14
15
16
17
18
|
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;
|
|
19
|
import com.huaheng.pc.config.address.service.AddressService;
|
|
20
21
|
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
|
|
22
|
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
|
|
23
24
|
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
25
26
27
28
29
30
31
|
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;
|
|
32
33
|
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
|
|
34
|
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
|
|
35
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
36
37
38
39
|
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
|
|
40
|
import java.util.ArrayList;
|
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import java.util.Arrays;
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
|
|
58
59
|
private LocationService locationService;
@Resource
|
|
60
61
62
63
64
|
private LocationTypeService locationTypeService;
@Resource
private LocationHighService locationHighService;
@Resource
private ContainerService containerService;
|
|
65
66
|
@Resource
private ContainerTypeService containerTypeService;
|
|
67
68
69
70
|
@Autowired
private AddressService addressService;
@Resource
private TaskHeaderService taskHeaderService;
|
|
71
72
|
@Resource
private TaskAssignService taskAssignService;
|
|
73
74
75
|
@Resource
private InventoryHeaderService inventoryHeaderService;
|
|
76
|
/**
|
|
77
|
* 生成空托盘组入库任务
|
|
78
|
*
|
|
79
80
81
82
83
84
|
* @return
*/
@PostMapping("/manyEmptyIn")
@Log(title = "任务-任务管理", operating = "生成空托盘组入库任务", action = BusinessType.INSERT)
@ResponseBody
@Transactional
|
|
85
|
@ApiLogger(apiName = "manyEmptyIn", from = "ROBOT")
|
|
86
|
public AjaxResult manyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
|
|
87
88
89
90
91
92
93
94
95
96
97
98
99
|
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = innerManyEmptyIn(manyEmptyDomain);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 生成空托盘组出库任务
|
|
100
|
*
|
|
101
102
103
104
105
106
|
* @return
*/
@PostMapping("/manyEmptyOut")
@Log(title = "任务-任务管理", operating = "生成空托盘组出库任务", action = BusinessType.INSERT)
@ResponseBody
@Transactional
|
|
107
|
@ApiLogger(apiName = "manyEmptyOut", from = "ROBOT")
|
|
108
109
110
111
112
113
114
115
116
117
118
119
|
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) {
|
|
120
|
if (manyEmptyDomain == null) {
|
|
121
122
123
|
throw new ServiceException("空托盘组参数不对!");
}
String containerCode = manyEmptyDomain.getContainerCode();
|
|
124
|
String warehouseCode = manyEmptyDomain.getWarehouseCode();
|
|
125
126
|
String area = manyEmptyDomain.getArea();
String roadWay = manyEmptyDomain.getRoadWay();
|
|
127
|
List<String> roadWays = new ArrayList<>();
|
|
128
|
String[] str = roadWay.split(",");
|
|
129
|
roadWays = Arrays.asList(str);
|
|
130
131
132
133
134
135
136
137
138
|
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);
|
|
139
|
if (zone == null) {
|
|
140
141
|
return AjaxResult.error("分配库位时,没有找到库区");
}
|
|
142
143
144
145
146
|
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);
|
|
147
|
if (taskHeader != null) {
|
|
148
149
|
return AjaxResult.success("已经生成空托盘组任务");
}
|
|
150
151
152
153
154
|
//查询满足条件的库位类型
LambdaQueryWrapper<LocationType> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(LocationType::getZoneCode, zone.getCode())
.eq(LocationType::getWarehouseCode, warehouseCode);
List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper);
|
|
155
|
if (locationTypeList == null) {
|
|
156
157
158
159
|
return AjaxResult.error("分配库位时,没有找到库位类型");
}
List<String> locationTypeCodeList = locationTypeList.stream().
map(t -> t.getCode()).collect(Collectors.toList());
|
|
160
|
int highHeight = Float.valueOf(height).intValue();
|
|
161
|
LambdaQueryWrapper<LocationHigh> locationHighLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
162
|
locationHighLambdaQueryWrapper.eq(LocationHigh::getHighLevel, highHeight)
|
|
163
164
165
|
.in(LocationHigh::getLocationTypeCode, locationTypeCodeList);
LocationHigh locationHigh = locationHighService.getOne(locationHighLambdaQueryWrapper);
int high = locationHigh.getHigh();
|
|
166
|
String locationCode = allocationService.allocation(allocationRule, locationTypeCodeList, area,
|
|
167
|
roadWays, warehouseCode, containerCode, null, null);
|
|
168
|
if (locationCode == null) {
|
|
169
170
171
172
173
|
return AjaxResult.error("分配库位时,没有找到库位");
}
return workTaskService.createManyEmptyIn(containerCode, locationCode, warehouseCode);
}
|
|
174
175
|
private AjaxResult innerManyEmptyOut(ManyEmptyDomain manyEmptyDomain) {
|
|
176
|
if (manyEmptyDomain == null) {
|
|
177
178
|
throw new ServiceException("空托盘组参数不对!");
}
|
|
179
|
String warehouseCode = manyEmptyDomain.getWarehouseCode();
|
|
180
|
String area = manyEmptyDomain.getArea();
|
|
181
|
String port = manyEmptyDomain.getPort();
|
|
182
183
184
185
186
|
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<>();
|
|
187
188
|
if (containerList != null && containerList.size() > 0) {
for (Container container : containerList) {
|
|
189
190
|
String locationCode = container.getLocationCode();
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
|
|
191
|
if (!location.getArea().equals(area)) {
|
|
192
193
194
195
196
197
198
199
200
201
|
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)
.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_MANY_EMPTYSHIPMENT)
|
|
202
|
.eq(TaskHeader::getPort, port)
|
|
203
204
|
.eq(TaskHeader::getZoneCode, zone.getCode());
TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
|
|
205
|
if (taskHeader != null) {
|
|
206
207
208
209
210
211
212
213
214
|
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());
wcsTask.setPlatform(QuantityConstant.PLATFORM_WMS);
wcsTask.setPriority(1000);
wcsTask.setTaskStatus(taskHeader.getStatus());
|
|
215
|
wcsTask.setToPort(port);
|
|
216
217
218
219
|
wcsTask = taskAssignService.switchTaskTypeToWcs(wcsTask);
return AjaxResult.success(wcsTask);
}
containerList.removeAll(removeContainerList);
|
|
220
|
if (!(containerList != null && containerList.size() > 0)) {
|
|
221
|
return AjaxResult.error("没有找到合适的空托盘组!");
|
|
222
|
}
|
|
223
|
String containerCode = containerList.get(0).getCode();
|
|
224
|
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
|
|
225
|
if (container == null) {
|
|
226
227
|
throw new ServiceException("没有找到托盘“");
}
|
|
228
|
return workTaskService.createManyEmptyOut(containerCode, warehouseCode, port);
|
|
229
|
}
|
|
230
231
232
|
/**
* 生成空托出库任务
|
|
233
|
*
|
|
234
235
236
237
238
|
* @return
*/
@PostMapping("/wcsCallEmptyOut")
@Log(title = "任务-任务管理", operating = "生成空托出库任务", action = BusinessType.INSERT)
@ResponseBody
|
|
239
|
@ApiLogger(apiName = "生成空托出库任务", from = "WCS")
|
|
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
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();
|
|
255
|
if (warehouseCode == null) {
|
|
256
257
|
return AjaxResult.error("warehouseCode 不能为空");
}
|
|
258
|
if (area == null) {
|
|
259
260
|
return AjaxResult.error("area 不能为空");
}
|
|
261
|
if (port == null) {
|
|
262
263
264
265
266
267
|
return AjaxResult.error("port 不能为空");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
|
|
268
|
if (zone == null) {
|
|
269
270
271
272
|
return AjaxResult.error("area不正确,没有找到对应区域");
}
String zoneCode = zone.getCode();
List<Location> list = containerService.getEmptyContainerInLocation(zoneCode,
|
|
273
274
|
"", "", warehouseCode);
if (list == null || list.size() <= 0) {
|
|
275
276
277
278
279
280
281
|
return AjaxResult.error("没有找到空托盘");
}
Location location = list.get(0);
String containerCode = location.getContainerCode();
String locationCode = location.getCode();
return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
}
|
|
282
|
}
|