TaskAssignServiceImpl.java
15 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
package com.huaheng.api.wcs.service.taskAssignService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.HttpConstant;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.AjaxResultWCS;
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.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.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.TransferTaskService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* 任务下发接口ServiceImpl层
*
* @author ricard
* @date 2019/10/11
*/
@Service
public class TaskAssignServiceImpl implements TaskAssignService {
@Resource
private AddressService addressService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private LocationService locationService;
@Resource
private TransferTaskService transferTaskService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ContainerService containerService;
@Resource
private ContainerTypeService containerTypeService;
@Resource
private ConfigService configService;
public static String platform = "wms";
//wms下发任务给wcs
/**
* 1、判断taskHeader是否为空
* 2、判断必填字段是否满足
* 3、转换实体
* 4、发送数据
*
* @param taskHeader
* @return
*/
@Override
@Transactional
public AjaxResult wcsTaskAssign(TaskHeader taskHeader) {
//1、判断taskHeader是否为空
int preTaskNo = 0;
if (taskHeader == null) {
return AjaxResult.error("wms任务为空");
}
//2、判断必填字段是否满足
if (taskHeader.getId() == null) {
return AjaxResult.error("wms任务号Id为空");
}
if (taskHeader.getTaskType() == null) {
return AjaxResult.error("wms任务类型为空");
}
String containerCode = taskHeader.getContainerCode();
if (StringUtils.isEmpty(containerCode)) {
return AjaxResult.error("wms任务中容器为空");
}
int taskType = taskHeader.getTaskType().intValue();
// 出库性质的任务圆库位不能为空
if (taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT || taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT
|| taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT
|| taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT || taskType == QuantityConstant.TASK_TYPE_CYCLECOUNT
|| taskType == QuantityConstant.TASK_TYPE_TRANSFER || taskType == QuantityConstant.TASK_TYPE_VIEW) {
if (StringUtils.isEmpty(taskHeader.getFromLocation())) {
return AjaxResult.error("源库位为空");
}
}
/*if(taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT || taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT){
taskHeader.setToLocation("");
}*/
String warehouseCode = taskHeader.getWarehouseCode();
//3、转换实体,初始化wcs任务实体
Location location;
boolean direction = true; // true 执行时是入库动作, false 执行时是出库动作
switch (taskType) {
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
case QuantityConstant.TASK_TYPE_VIEW:
case QuantityConstant.TASK_TYPE_CYCLECOUNT:
case QuantityConstant.TASK_TYPE_TRANSFER:
location = locationService.getLocationByCode(taskHeader.getFromLocation(), warehouseCode);
direction = false;
break;
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
location = locationService.getLocationByCode(taskHeader.getToLocation(), warehouseCode);
direction = true;
break;
default:
location = locationService.getLocationByCode(taskHeader.getToLocation(), warehouseCode);
break;
}
// 出库动作 补充入库 移库
if (!direction) {
int rowFlag = location.getRowFlag().intValue();
if (rowFlag == QuantityConstant.ROW_OUT) {
if (warehouseCode.equalsIgnoreCase("KS0001") && location.getIRow() == 1) {
} else {
Location insideLocation = locationService.getInsideNear(location);
String insideLocationCode = insideLocation.getCode();
if (StringUtils.isNotEmpty(insideLocation.getContainerCode())) {
LambdaQueryWrapper<TaskHeader> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskHeader::getFromLocation, insideLocationCode);
lambdaWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader2 = taskHeaderService.getOne(lambdaWrapper);
if (taskHeader2 != null) {
preTaskNo = taskHeader2.getId();
} else {
Location destinationLocation = locationService.getEmptyLocation(insideLocation);
if (destinationLocation == null) {
return AjaxResult.error("移库没有剩余库位");
}
AjaxResult ajaxResult = transferTaskService.createTransferTask(
insideLocation.getCode(), destinationLocation.getCode(), warehouseCode);
preTaskNo = (Integer) ajaxResult.getData();
if (ajaxResult.hasErr()) {
return AjaxResult.error("创建移库任务失败");
}
// TaskHeader transferTaskHeader = taskHeaderService.getById(preTaskNo);
// sendToWcs(transferTaskHeader, 0, location);
if (warehouseCode.equals("XZ0001")) {
taskHeader.setPreTaskNo(preTaskNo);
taskHeaderService.updateById(taskHeader);
TaskHeader transferTaskHeader = taskHeaderService.getById(preTaskNo);
sendToWcs(transferTaskHeader, 0, location);
}
return AjaxResult.error("先执行移库任务");
}
taskHeader.setPreTaskNo(preTaskNo);
taskHeaderService.updateById(taskHeader);
return AjaxResult.error("先执行移库任务");
} else {
LambdaQueryWrapper<TaskHeader> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskHeader::getToLocation, insideLocationCode);
lambdaWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
TaskHeader taskHeader1 = taskHeaderService.getOne(lambdaWrapper);
if (taskHeader1 != null) {
return AjaxResult.error("执行外侧库位出库时,相应的内侧库位有任务,请先执行完内侧库位任务");
}
// taskHeader.setPreTaskNo(preTaskNo);
taskHeaderService.updateById(taskHeader);
}
}
}
}
AjaxResult ajaxResult = sendToWcs(taskHeader, preTaskNo, location);
return ajaxResult;
}
@Override
@Transactional
public AjaxResult sendToWcs(TaskHeader taskHeader, int preTaskNo, Location location) {
int taskType = taskHeader.getTaskType();
String warehouseCode = taskHeader.getWarehouseCode();
String containerCode = taskHeader.getContainerCode();
WcsTask wcsTask = new WcsTask();
wcsTask.setTaskNo(taskHeader.getId().toString());
wcsTask.setWarehouseCode(warehouseCode);
wcsTask.setTaskType(taskType);
wcsTask.setFromPort("");
wcsTask.setToPort(taskHeader.getPort());
wcsTask.setContainerCode(taskHeader.getContainerCode());
if (preTaskNo != 0) {
wcsTask.setPreTaskNo(String.valueOf(preTaskNo));
}
if (location != null) {
wcsTask.setStation(location.getRoadway());
wcsTask.setRoadWay(location.getRoadway());
if (StringUtils.isEmpty(taskHeader.getFromLocation())) {
wcsTask.setFromLocationCode("");
} else {
wcsTask.setFromLocationCode(taskHeader.getFromLocation());
}
if (StringUtils.isEmpty(taskHeader.getToLocation())) {
wcsTask.setToLocationCode("");
} else {
wcsTask.setToLocationCode(taskHeader.getToLocation());
}
}
wcsTask.setPriority(10);
if (QuantityConstant.TASK_TYPE_TRANSFER == taskType) {
wcsTask.setPriority(100);
}
wcsTask.setRemark("0");
wcsTask.setPlatform(platform);
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
String area = container.getArea();
if (StringUtils.isEmpty(area)) {
return AjaxResult.error("容器未配置库区 area");
}
//4、发送数据
String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS, warehouseCode);
String val = configService.getKey(QuantityConstant.ZONE_MUTLI_ROADWAY, warehouseCode);
int connectWCS = Integer.parseInt(value);
if (connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
String url = "";
//是否有一个库区多个巷道的 堆垛机
//有,需要不同巷道的URL
if (StringUtils.isEmpty(val)) {
url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN, warehouseCode, area);
} else {
String[] strs = Convert.toStrArray(val);
List<String> strings = Arrays.asList(strs);
if (strings.contains(container.getArea())) {
ContainerType containerType = containerTypeService.getContainerTypeByCode(container.getContainerType(), container.getWarehouseCode());
Integer roadway = containerType.getRoadway();
url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN, warehouseCode, area, roadway);
}
}
wcsTask = switchTaskTypeToWcs(wcsTask);
String jsonParam = JSON.toJSONString(wcsTask);
System.out.println(jsonParam);
url = url + "TaskAssign";
String result = OkHttpUtils.bodypost(url, jsonParam, warehouseCode);
if (StringUtils.isNull(result) || StringUtils.isEmpty(result)) {
throw new ServiceException("WCS:接口地址错误或返回为空");
}
// AjaxResultWCS ajaxResult = new AjaxResultWCS();
// ajaxResult.setCode(200);
AjaxResultWCS ajaxResult = JSON.parseObject(result, AjaxResultWCS.class);
if (ajaxResult.getCode() != HttpConstant.OK) {
return AjaxResult.error("源库位:" + wcsTask.getFromLocationCode() + "目标库位:" + wcsTask.getToLocationCode() + "," + ajaxResult.getMessage());
}
taskHeader.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
taskHeaderService.updateById(taskHeader);
//总有个别数据任务详情没有修改状态
LambdaQueryWrapper<TaskDetail> lambdaWrapper = com.huaheng.common.utils.Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
// List<TaskDetail> taskDetailList = taskDetailService.list(lambdaWrapper);
TaskDetail item = new TaskDetail();
item.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setProcessStamp("100");
taskDetailService.update(item, lambdaWrapper);
}
return AjaxResult.success("");
}
// wcs任务类型 入库 = 100 , 出库 = 300,分拣出库 = 400 ,移库 = 800,换站=1000
@Override
public WcsTask switchTaskTypeToWcs(WcsTask wcsTask) {
int taskType = wcsTask.getTaskType().intValue();
switch (taskType) {
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
case QuantityConstant.TASK_TYPE_MANY_EMPTYRECEIPT:
wcsTask.setTaskType(100);
break;
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
case QuantityConstant.TASK_TYPE_MANY_EMPTYSHIPMENT:
wcsTask.setTaskType(300);
break;
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
case QuantityConstant.TASK_TYPE_CYCLECOUNT:
case QuantityConstant.TASK_TYPE_VIEW:
wcsTask.setTaskType(400);
break;
case QuantityConstant.TASK_TYPE_TRANSFER:
wcsTask.setTaskType(800);
break;
case QuantityConstant.TASK_TYPE_OVER_STATION:
wcsTask.setTaskType(1000);
break;
default:
throw new ServiceException("不支持的任务类型");
}
return wcsTask;
}
}