TaskAssignServiceImpl.java
14.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
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.TaskDetails;
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.HttpUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.address.service.AddressService;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 任务下发接口ServiceImpl层
* @author ricard
* @date 2019/10/11
*
*/
@Service
public class TaskAssignServiceImpl implements TaskAssignService {
@Autowired
private AddressService addressService;
@Autowired
private TaskDetailService taskDetailService;
@Resource
private LocationService locationService;
@Resource
private TransferTaskService transferTaskService;
@Resource
private TaskHeaderService taskHeaderService;
public static String platform = "wms";
//wms下发任务给wcs
/**
* 1、判断taskHeader是否为空
* 2、判断必填字段是否满足
* 3、转换实体
* 4、发送数据
*
* @param taskHeader
* @return
*/
@Override
@Transactional
public AjaxResult wcsTaskAssign(TaskHeader taskHeader) {
//1、判断taskHeader是否为空
Integer 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任务类型为空");
}
if(StringUtils.isEmpty(taskHeader.getContainerCode())){
return AjaxResult.error("wms任务中容器为空");
}
int taskType = taskHeader.getTaskType().intValue();
//入库性质的任务源库位不能为空
if(taskType == QuantityConstant.TASK_TYPE_WHOLERECEIPT || taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT
|| taskType == QuantityConstant.TASK_TYPE_EMPTYRECEIPT || taskType == QuantityConstant.TASK_TYPE_TRANSFER) {
if (taskHeader.getFromLocation() == null) {
return AjaxResult.error("源库位为空");
}
}
// 出库性质的任务目的库位不能为空
if(taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT || 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 (taskHeader.getToLocation() == null) {
return AjaxResult.error("目的库位为空");
}
}
//3、转换实体,初始化wcs任务实体
WcsTask wcsTask = new WcsTask();
wcsTask.setTaskNo(taskHeader.getId().toString());
wcsTask.setWarehouseCode(ShiroUtils.getWarehouseCode());
wcsTask.setTaskType(taskType);
wcsTask.setFromPort("");
wcsTask.setToPort(taskHeader.getPort());
wcsTask.setContainerCode(taskHeader.getContainerCode());
Location location;
switch(wcsTask.getTaskType().intValue()) {
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:
location = locationService.getLocationByCode(taskHeader.getFromLocation());
break;
case QuantityConstant.TASK_TYPE_TRANSFER:
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
location = locationService.getLocationByCode(taskHeader.getToLocation());
break;
default:
location = locationService.getLocationByCode(taskHeader.getToLocation());
break;
}
if (taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT
|| taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT
|| taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT
|| taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT
|| taskType == QuantityConstant.TASK_TYPE_VIEW ) {
int rowFlag = location.getRowFlag().intValue();
if(rowFlag == QuantityConstant.ROW_OUT) {
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());
preTaskNo = (Integer) ajaxResult.getData();
if (ajaxResult.hasErr()) {
return AjaxResult.error("创建移库任务失败");
}
taskHeaderService.sendTaskToWcs(Convert.toIntArray(String.valueOf(preTaskNo)));
}
} 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);
LambdaQueryWrapper<TaskHeader> lambdaWrapper2 = Wrappers.lambdaQuery();
lambdaWrapper2.eq(TaskHeader::getId, taskHeader.getId());
taskHeaderService.update(taskHeader, lambdaWrapper2);
}
if(location != null) {
Location insideLocation = locationService.getNear(location);
if (insideLocation != null) {
String nearLocationCode = insideLocation.getCode();
LambdaQueryWrapper<TaskHeader> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskHeader::getFromLocation, nearLocationCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
.in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
QuantityConstant.TASK_TYPE_SORTINGSHIPMENT, QuantityConstant.TASK_TYPE_VIEW)
.ge(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_RELEASE);
List<TaskHeader> taskHeader2 = taskHeaderService.list(lambdaWrapper);
if (taskHeader2 != null && taskHeader2.size() > 0) {
return AjaxResult.error("执行任务出库时,相应的旁边库位有分拣出库或者补充入库任务,请先执行完旁边库位任务");
}
}
Location insideNear = locationService.getInsideNear(location);
if (location.getRowFlag().intValue() == QuantityConstant.ROW_OUT) {
String locationCode = location.getCode();
LambdaQueryWrapper<TaskHeader> lambdaWrapper3 = Wrappers.lambdaQuery();
lambdaWrapper3.eq(TaskHeader::getFromLocation, locationCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
.in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT,
QuantityConstant.TASK_TYPE_SORTINGSHIPMENT, QuantityConstant.TASK_TYPE_VIEW)
.ge(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD);
List<TaskHeader> taskHeader3 = taskHeaderService.list(lambdaWrapper3);
if (taskHeader3 != null && taskHeader3.size() > 0) {
String insideNearCode = insideNear.getCode();
LambdaQueryWrapper<TaskHeader> lambdaWrapper4 = Wrappers.lambdaQuery();
lambdaWrapper4.eq(TaskHeader::getFromLocation, insideNearCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
.ge(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD);
List<TaskHeader> taskHeader4 = taskHeaderService.list(lambdaWrapper4);
if (taskHeader4 != null && taskHeader4.size() > 0) {
return AjaxResult.error("执行任务出库时,请先执行完旁边库位任务");
}
}
}
}
if (0 != preTaskNo) {
wcsTask.setPreTaskNo(String.valueOf(preTaskNo));
}
if(location != null) {
wcsTask.setStation(location.getRoadway());
wcsTask.setDestination(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);
//找到任务明细
LambdaQueryWrapper<TaskDetail> taskDetailLam = Wrappers.lambdaQuery();
taskDetailLam.eq(TaskDetail::getTaskId,taskHeader.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLam);
if(taskDetailList == null){
return AjaxResult.error("没有子任务");
}
List<TaskDetails> taskDetails =new ArrayList<>();
for(TaskDetail item : taskDetailList) {
TaskDetails details = new TaskDetails();
details.setMaterialCode(item.getMaterialCode());
details.setMaterialName(item.getMaterialName());
if(StringUtils.isEmpty(item.getMaterialUnit())){
details.setUnit("PCS");
}else {
details.setUnit(item.getMaterialUnit());
}
details.setQty(item.getQty());
details.setReferLineNo(item.getId().toString());
taskDetails.add(details);
}
wcsTask.setTaskDetails(taskDetails);
//4、发送数据
String url = addressService.selectAddress(QuantityConstant.ADDRESS_WCS_TASK_ASSIGN);
wcsTask = switchTaskTypeToWcs(wcsTask);
String JsonParam = JSON.toJSONString(wcsTask);
System.out.println(JsonParam);
String result = HttpUtils.bodypost(url, JsonParam);
if(StringUtils.isEmpty(result)) {
throw new ServiceException("接口地址错误或返回为空");
}
AjaxResult ajaxResult = JSON.parseObject(result, AjaxResult.class);
if(ajaxResult.getCode()!= HttpConstant.OK) {
return AjaxResult.error(ajaxResult.getMsg());
}
return AjaxResult.success("");
}
// wcs任务类型 入库 = 100 , 出库 = 300,分拣出库 = 400 ,移库 = 800,换站=1000
private WcsTask switchTaskTypeToWcs(WcsTask wcsTask) {
int taskType = wcsTask.getTaskType().intValue();
switch (taskType) {
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
wcsTask.setTaskType(100);
break;
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_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;
}
}