|
1
2
|
package com.huaheng.pc.task.taskHeader.service;
|
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
5
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
6
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
7
|
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
|
|
8
|
import com.huaheng.common.constant.QuantityConstant;
|
|
9
|
import com.huaheng.common.exception.service.ServiceException;
|
|
10
|
import com.huaheng.common.support.Convert;
|
|
11
|
import com.huaheng.common.utils.StringUtils;
|
|
12
13
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
14
15
16
|
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
|
|
17
|
import com.huaheng.pc.config.configWarning.service.ConfigWarningService;
|
|
18
|
import com.huaheng.pc.config.container.domain.Container;
|
|
19
|
import com.huaheng.pc.config.container.service.ContainerService;
|
|
20
|
import com.huaheng.pc.config.containerCapacity.service.ContainerCapacityService;
|
|
21
22
|
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.service.CycleCountPreferenceService;
|
|
23
24
|
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
25
26
|
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
|
|
27
|
import com.huaheng.pc.inventory.cycleCountHeader.service.CycleCountHeaderService;
|
|
28
29
|
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
|
|
30
31
32
|
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
|
|
33
34
|
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
|
|
35
36
37
|
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
|
|
38
|
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
|
|
39
|
import com.huaheng.pc.receipt.receiving.service.ReceivingService;
|
|
40
41
42
|
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
|
|
43
44
|
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
|
|
45
46
|
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
|
|
47
|
import com.huaheng.pc.task.taskHeader.domain.MobileTask;
|
|
48
49
|
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
|
|
50
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
51
|
import org.springframework.stereotype.Service;
|
|
52
53
54
|
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
|
|
55
|
import java.math.BigDecimal;
|
|
56
|
import java.util.*;
|
|
57
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
58
|
import java.util.stream.Collectors;
|
|
59
|
|
|
60
|
@Service
|
|
61
|
public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHeader> implements TaskHeaderService {
|
|
62
|
|
|
63
|
@Resource
|
|
64
|
private ShipmentContainerHeaderService shipmentContainerHeaderService;
|
|
65
|
@Resource
|
|
66
|
private LocationService locationService;
|
|
67
|
@Resource
|
|
68
69
|
private ContainerService containerService;
@Resource
|
|
70
|
private TaskDetailService taskDetailService;
|
|
71
|
@Resource
|
|
72
|
private TaskHeaderService taskHeaderService;
|
|
73
|
@Resource
|
|
74
|
private InventoryHeaderService inventoryHeaderService;
|
|
75
76
|
@Resource
private InventoryDetailService inventoryDetailService;
|
|
77
|
@Resource
|
|
78
|
private ReceiptContainerDetailService receiptContainerDetailService;
|
|
79
|
@Resource
|
|
80
|
private CycleCountDetailService cycleCountDetailService;
|
|
81
|
@Resource
|
|
82
83
84
|
private CycleCountPreferenceService cycleCountPreferenceService;
@Resource
private CycleCountTaskService cycleCountTaskService;
|
|
85
|
@Resource
|
|
86
|
private ReceiptContainerHeaderService receiptContainerHeaderService;
|
|
87
|
@Resource
|
|
88
|
private TaskHeaderMapper taskHeaderMapper;
|
|
89
|
@Autowired
|
|
90
|
private TaskAssignService taskAssignService;
|
|
91
|
@Resource
|
|
92
|
private ReceiptTaskService receiptTaskService;
|
|
93
94
|
@Resource
private ShipmentTaskService shipmentTaskService;
|
|
95
96
|
@Resource
private WorkTaskService workTaskService;
|
|
97
98
|
@Resource
private TransferTaskService transferTaskService;
|
|
99
100
|
@Resource
private ReceivingService receivingService;
|
|
101
102
|
@Resource
private ConfigService configService;
|
|
103
104
|
|
|
105
|
|
|
106
107
108
109
110
|
@Override
public List<TaskHeader> getTasksStatus(Short lastStatus) {
return taskHeaderMapper.getTasksStatus(lastStatus);
}
|
|
111
|
|
|
112
|
/**
|
|
113
|
* 查询容器有无任务
|
|
114
115
|
*/
@Override
|
|
116
|
public Integer UncompleteCount(String ContainerCode) {
|
|
117
|
return taskHeaderMapper.UncompleteCount(ContainerCode, ShiroUtils.getWarehouseCode());
|
|
118
119
120
121
|
}
/**
|
|
122
123
124
|
* 盘点任务首选项
*
* @param taskHeaderList
|
|
125
126
127
|
* @return
*/
@Override
|
|
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
|
public List<TaskHeader> preferenceRealize(List<TaskHeader> taskHeaderList) {
//盘点任务头,默认不显示库位,容器。
List<TaskHeader> taskHeaders = new ArrayList<>();
for (TaskHeader item:taskHeaderList){
//盘点明细
CycleCountDetail cycleCountDetailtemp = new CycleCountDetail();
cycleCountDetailtemp.setWarehouseCode(item.getWarehouseCode());
cycleCountDetailtemp.setCycleCountHeadCode(item.getReferenceCode());
cycleCountDetailtemp.setId(item.getAllocationHeadId()); //明细ID
LambdaQueryWrapper<CycleCountDetail> detailLambdaQueryWrapper = Wrappers.lambdaQuery(cycleCountDetailtemp);
CycleCountDetail cycleCountDetail = cycleCountDetailService.getOne(detailLambdaQueryWrapper);
if(StringUtils.isNull(cycleCountDetail)){
throw new SecurityException("没有找到子任务对应的盘点明细!");
}
//找盘点首选项
CycleCountPreference cycleCountPreferenceTemp = new CycleCountPreference();
cycleCountPreferenceTemp.setCode(cycleCountDetail.getPreferenceCode());
cycleCountPreferenceTemp.setWarehouseCode(cycleCountDetail.getWarehouseCode());
LambdaQueryWrapper<CycleCountPreference> preferenceLambdaQueryWrapper = Wrappers.lambdaQuery(cycleCountPreferenceTemp);
CycleCountPreference cycleCountPreference = cycleCountPreferenceService.getOne(preferenceLambdaQueryWrapper);
if(StringUtils.isNull(cycleCountPreference)){
throw new SecurityException("没有找到盘点首选项!");
}
//根据首选项判断数据
if(!cycleCountPreference.getPromptLocation()){
//库位
item.setFromLocation("");
item.setToLocation("");
}
if(!cycleCountPreference.getPromptLpn()){
//容器
item.setContainerCode("");
}
taskHeaders.add(item);
|
|
162
|
}
|
|
163
|
return taskHeaders;
|
|
164
|
}
|
|
165
|
|
|
166
167
|
/**
* 取消任务
|
|
168
|
*/
|
|
169
|
@Override
|
|
170
|
@Transactional(rollbackFor = Exception.class)
|
|
171
|
public AjaxResult cancelTask(Integer[] taskIds) {
|
|
172
|
for (int taskId : taskIds) {
|
|
173
|
TaskHeader taskHeader = taskHeaderService.getById(taskId);
|
|
174
175
|
if (taskHeader == null) {
return AjaxResult.error("任务" + taskId + "未找到,操作中止");
|
|
176
|
}
|
|
177
|
if (taskHeader.getStatus() > QuantityConstant.TASK_STATUS_RELEASE) {
|
|
178
|
return AjaxResult.error("存在任务" + taskHeader.getId() + "已下发或执行,操作中止");
|
|
179
|
}
|
|
180
181
182
183
184
185
186
|
//查出任务明细
TaskDetail taskDetail1 = new TaskDetail();
taskDetail1.setTaskId(taskHeader.getId());
taskDetail1.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail1.setCompanyCode(taskHeader.getCompanyCode());
LambdaQueryWrapper<TaskDetail> td = Wrappers.lambdaQuery(taskDetail1);
List<TaskDetail> taskDetailList = taskDetailService.list(td);
|
|
187
188
189
190
191
192
|
TaskDetail taskDetail = null;
if(taskDetailList != null && taskDetailList.size() > 0) {
taskDetail = taskDetailList.get(0);
if (taskDetail == null) {
throw new ServiceException("任务明细条目错误");
}
|
|
193
|
}
|
|
194
195
|
//删除子任务
LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
196
|
lambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
|
|
197
198
199
200
|
taskDetailService.remove(lambdaQueryWrapper);
//删除主任务
taskHeaderService.removeById(taskHeader.getId());
// 更改库位状态(整盘入库任务除外)
|
|
201
202
|
if (taskHeader.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLERECEIPT) ||
taskHeader.getTaskType().equals(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)) {
|
|
203
|
receiptContainerHeaderService.cancelReceipt(taskHeader.getAllocationHeadId());
|
|
204
205
206
|
}
//根据任务类型来更新货箱状态
//修改关联的货箱状态
|
|
207
|
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHIPMENT)) {
|
|
208
209
|
ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
shipmentContainerHeader.setId(taskHeader.getAllocationHeadId());
|
|
210
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
|
|
211
212
|
shipmentContainerHeaderService.updateById(shipmentContainerHeader);
}
|
|
213
|
//盘点取消任务,恢复明细状态为1
|
|
214
215
216
217
|
int taskType = taskHeader.getTaskType().intValue();
switch (taskType) {
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
|
|
218
219
220
221
222
|
LambdaQueryWrapper<ReceiptContainerHeader> lambda = Wrappers.lambdaQuery();
lambda.eq(ReceiptContainerHeader::getContainerCode, taskHeader.getContainerCode())
.ne(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_FINISHED)
.eq(ReceiptContainerHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getOne(lambda);
|
|
223
224
225
226
227
228
|
String value = configService.getKey(QuantityConstant.RULE_TASK_LOCATION);
int taskLocationRule = Integer.parseInt(value);
if (taskLocationRule == QuantityConstant.RULE_TASK_NOT_LOCATION) {
receiptContainerHeader.setToLocation("");
receiptContainerHeaderService.update(receiptContainerHeader, lambda);
}
|
|
229
230
231
232
233
234
235
236
|
LambdaQueryWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
receiptContainerDetailLambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerHeader.getId());
List<ReceiptContainerDetail> receiptContainerDetailList = receiptContainerDetailService.list(receiptContainerDetailLambdaQueryWrapper);
for(ReceiptContainerDetail receiptContainerDetail : receiptContainerDetailList) {
LambdaQueryWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaQueryWrapper1 = Wrappers.lambdaQuery();
receiptContainerDetailLambdaQueryWrapper1.eq(ReceiptContainerDetail::getId, receiptContainerDetail.getId());
receiptContainerDetail.setLocationCode("");
receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaQueryWrapper1);
|
|
237
|
}
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
break;
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
break;
case QuantityConstant.TASK_TYPE_CYCLECOUNT:
CycleCountDetail cycleCountDetail = new CycleCountDetail();
cycleCountDetail.setCompanyCode(taskDetail.getCompanyCode());
cycleCountDetail.setWarehouseCode(taskDetail.getWarehouseCode());
cycleCountDetail.setLocationCode(taskDetail.getFromLocation());
cycleCountDetail.setContainerCode(taskDetail.getContainerCode());
cycleCountDetail.setCycleCountHeadCode(taskDetail.getBillCode());//盘点单Code
cycleCountDetail.setId(taskDetail.getBillDetailId());//盘点细单ID
LambdaQueryWrapper<CycleCountDetail> lam = Wrappers.lambdaQuery(cycleCountDetail);
List<CycleCountDetail> cycleCountDetailList = cycleCountDetailService.list(lam);//
for (CycleCountDetail item : cycleCountDetailList) {
item.setTaskHeaderId(null);
item.setTaskHeaderId(null);
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setEnableStatus(1);
cycleCountDetailService.saveOrUpdate(item);
|
|
260
|
}
|
|
261
262
263
|
break;
default:
break;
|
|
264
|
}
|
|
265
|
cancelLocationAndContainerStatus(taskHeader);
|
|
266
267
268
269
|
}
return AjaxResult.success("取消任务成功!");
}
|
|
270
271
272
|
private void cancelLocationAndContainerStatus(TaskHeader taskHeader) {
if (taskHeader.getFromLocation() != null) {
//更新托盘、库位状态
|
|
273
|
locationService.updateStatus(taskHeader.getFromLocation(), QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
274
275
276
|
}
if (taskHeader.getToLocation() != null) {
//更新托盘、库位状态
|
|
277
|
locationService.updateStatus(taskHeader.getToLocation(), QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
278
279
280
281
282
|
}
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getContainerCode, taskHeader.getContainerCode());
InventoryHeader inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
Container container = new Container();
|
|
283
|
container.setStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
|
|
284
|
if(inventoryHeader != null) {
|
|
285
286
|
if(QuantityConstant.STATUS_CONTAINER_SOME.equals(inventoryHeader.getContainerStatus())) {
container.setStatus(QuantityConstant.STATUS_CONTAINER_SOME);
|
|
287
288
289
290
291
292
293
294
|
}
}
container.setLocationCode(taskHeader.getFromLocation());
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, taskHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
}
|
|
295
|
/**
|
|
296
|
* 下发WCS执行任务
|
|
297
|
* 执行任务
|
|
298
|
*/
|
|
299
|
@Override
|
|
300
|
@Transactional(rollbackFor = Exception.class)
|
|
301
|
public AjaxResult<TaskHeader> sendTaskToWcs(Integer[] taskIds) {
|
|
302
303
|
TaskHeader task = null;
for (Integer taskId : taskIds) {
|
|
304
|
task = taskHeaderService.getById(taskId);
|
|
305
|
|
|
306
|
if (task.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
|
|
307
308
|
return AjaxResult.error("任务" + taskId + "已经下发,请不要重复下发,操作中止");
}
|
|
309
|
|
|
310
311
312
313
314
315
316
317
318
|
String value = configService.getKey(QuantityConstant.RULE_CONNECT_WCS);
int connectWCS = Integer.parseInt(value);
if(connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
// 给wcs传递任务
AjaxResult ajaxResult = taskAssignService.wcsTaskAssign(task);
if (ajaxResult != null && ajaxResult.hasErr()) {
return AjaxResult.error(ajaxResult.getMsg());
}
}
|
|
319
|
//修改任务头表
|
|
320
|
task.setId(taskId);
|
|
321
|
task.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
322
323
324
|
task.setStartPickDateTime(new Date()); //生成时间
task.setLastUpdated(new Date());
task.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
325
|
taskHeaderService.saveOrUpdate(task);
|
|
326
|
//修改任务明细状态
|
|
327
328
329
330
|
LambdaQueryWrapper<TaskDetail> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskDetail::getTaskId, task.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaWrapper);
List<TaskDetail> taskDetails = new ArrayList<>();
|
|
331
|
for (TaskDetail item : taskDetailList) {
|
|
332
|
item.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
333
334
335
336
337
|
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setProcessStamp("100");
taskDetails.add(item);
//盘点执行修改盘点单据状态为10
|
|
338
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_CYCLECOUNT)) {
|
|
339
|
cycleCountDetailService.updataDetailStatus(item.getBillDetailId(), QuantityConstant.CYCLECOUNT_STATUS_EXECUTING);
|
|
340
|
}
|
|
341
|
}
|
|
342
343
344
345
|
if(taskDetails != null && taskDetails.size() > 0) {
if (!taskDetailService.saveOrUpdateBatch(taskDetails)) {
throw new ServiceException("更新任务明细失败");
}
|
|
346
|
}
|
|
347
|
}
|
|
348
|
return AjaxResult.success("执行下发任务成功", task);
|
|
349
350
|
}
|
|
351
352
353
|
/**
* WMS完成任务
*/
|
|
354
|
@Override
|
|
355
|
@Transactional(rollbackFor = Exception.class)
|
|
356
|
public AjaxResult completeTaskByWMS(Integer[] taskIds, String[] weightConvert) {
|
|
357
358
|
for (int i = 0;i<taskIds.length;i++) {
TaskHeader task = taskHeaderService.getById(taskIds[i]);
|
|
359
|
|
|
360
|
if (task == null) {
|
|
361
|
throw new ServiceException("任务" + taskIds[i] + "未找到,执行中止");
|
|
362
|
}
|
|
363
|
//任务写入重量
|
|
364
365
366
367
368
|
// String weight = "";
// if (StringUtils.isNotNull(weightConvert)) {
// weight = weightConvert[i];
// }
// task.setWeight(weight);
|
|
369
|
//如果已完成则不管
|
|
370
371
|
if (task.getStatus().equals(QuantityConstant.TASK_STATUS_COMPLETED)) {
return AjaxResult.success("任务(" + taskIds[i] + ")任务已经是完成的!");
|
|
372
|
|
|
373
|
}
|
|
374
375
|
//整盘入库,空托入库库位自动分配
//整盘入库手动完成分配库位,已分配则略过
|
|
376
|
if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLERECEIPT) || task.getTaskType().equals(QuantityConstant.TASK_TYPE_EMPTYRECEIPT)){
|
|
377
378
|
if(StringUtils.isEmpty(task.getToLocation())){
//自动分配库位
|
|
379
380
|
AjaxResult ajaxResult = this.setLocationCode(task.getId(),0 );
task.setToLocation((String)ajaxResult.getData());
|
|
381
382
|
}
}
|
|
383
|
//如果没有库位不能完成
|
|
384
385
|
if (StringUtils.isEmpty(task.getFromLocation()) && StringUtils.isEmpty(task.getToLocation())) {
throw new ServiceException("任务" + task.getId() + "没有库位,执行中止");
|
|
386
|
}
|
|
387
|
|
|
388
|
this.completeTask(task);
|
|
389
390
391
392
393
394
395
396
397
|
}
return AjaxResult.success("完成任务成功!");
}
/**
* 完成任务
*
* @param task
*/
|
|
398
|
public void completeTask(TaskHeader task) {
|
|
399
|
int taskType = task.getTaskType().intValue();
|
|
400
|
//区分任务类型
|
|
401
402
403
404
405
406
407
408
409
410
411
|
switch(taskType) {
//整盘入库、补充入库
case QuantityConstant.TASK_TYPE_WHOLERECEIPT:
case QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT:
receiptTaskService.completeReceiptTask(task);
combineInventory(task);
break;
//整盘出库、分拣出库
case QuantityConstant.TASK_TYPE_WHOLESHIPMENT:
case QuantityConstant.TASK_TYPE_SORTINGSHIPMENT:
shipmentTaskService.completeShipmentTask(task);
|
|
412
|
combineInventory(task);
|
|
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
break;
//空托入库
case QuantityConstant.TASK_TYPE_EMPTYRECEIPT:
workTaskService.completeEmptyIn(task);
break;
//空托出库
case QuantityConstant.TASK_TYPE_EMPTYSHIPMENT:
workTaskService.completeEmptyOut(task);
break;
case QuantityConstant.TASK_TYPE_CYCLECOUNT:
cycleCountTaskService.completeCycleCountTask(task);
break;
case QuantityConstant.TASK_TYPE_TRANSFER:
transferTaskService.completeTransferTask(task);
break;
case QuantityConstant.TASK_TYPE_VIEW:
workTaskService.completeCheckOutTask(task);
break;
default:
throw new ServiceException("不支持的任务类型");
|
|
433
434
435
|
}
}
|
|
436
437
438
439
440
441
442
443
444
445
446
|
/**
* 根据库位完成任务
*
* @param locationCode
* @return
* @throws Exception
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult completeTask(String locationCode) {
LambdaQueryWrapper<TaskHeader> taskQueryWrapper = Wrappers.lambdaQuery();
|
|
447
448
|
taskQueryWrapper.eq(TaskHeader::getToLocation, locationCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
|
|
449
450
451
452
453
454
455
|
List<TaskHeader> list = this.list(taskQueryWrapper);
if (list.isEmpty()) {
throw new ServiceException("库位(" + locationCode + ")没有任务!");
} else if(list.get(0).getStatus().equals(QuantityConstant.TASK_STATUS_COMPLETED)) {
//如果已完成则不管
throw new ServiceException("库位(" + locationCode + ")任务已经完成!");
}
|
|
456
457
458
459
|
TaskHeader taskHeader = list.get(0);
int taskType = taskHeader.getTaskType().intValue();
if(taskType == QuantityConstant.TASK_TYPE_WHOLERECEIPT
|| taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT){
|
|
460
|
//入库任务
|
|
461
|
return receiptTaskService.completeReceiptTask(taskHeader);
|
|
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
} else {
throw new ServiceException("库位(" + locationCode + ")的任务不是上架,不能完成!");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult createReplenishTask(String containerCode, Integer taskStatus) {
LambdaQueryWrapper<ReceiptContainerHeader> headerQueryWrapper = Wrappers.lambdaQuery();
headerQueryWrapper.eq(ReceiptContainerHeader::getContainerCode, containerCode)
.eq(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_BUILD);
List<ReceiptContainerHeader> receiptContainerHeaderList = receiptContainerHeaderService.list(headerQueryWrapper);
if (receiptContainerHeaderList.isEmpty()) {
throw new ServiceException("该容器没有任务!");
}
if (receiptContainerHeaderList.size() > 1){
throw new ServiceException("该容器存在多条任务");
}
|
|
481
|
if (receiptContainerHeaderList.get(0).getWarehouseCode() != ShiroUtils.getWarehouseCode()) {
|
|
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
throw new ServiceException("容器不在当前仓库!");
}
LambdaQueryWrapper<ReceiptContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerHeaderList.get(0).getId());
List<ReceiptContainerDetail> containerDetailList = receiptContainerDetailService.list(lambdaQueryWrapper);
ReceiptContainerHeader containerHeader = receiptContainerHeaderList.get(0);
if (containerDetailList.isEmpty()){
throw new ServiceException("没有组盘明细,请先组盘!");
}
if (containerHeader.getStatus().equals(QuantityConstant.TASK_STATUS_BUILD)) {
if (containerHeader.getStatus().intValue() != taskStatus.intValue()) {
containerHeader.setStatus(taskStatus);
receiptContainerHeaderService.updateById(containerHeader);
}
}
List<Integer> ids = new ArrayList<>();
ids.add(containerHeader.getId());
receiptTaskService.createReceiptTask(ids);
return AjaxResult.success("成功!");
}
/**
* 移动端根据容器编码获取盘点任务
* @param containerCode 容器编码
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public List<MobileTask> mobileFindTransferTask(String containerCode) {
/* 查询该容器未完成的盘点任务明细*/
LambdaQueryWrapper<TaskDetail> detailLambdaQueryWrapper = Wrappers.lambdaQuery();
detailLambdaQueryWrapper.eq(TaskDetail::getContainerCode, containerCode)
.eq(TaskDetail::getTaskType, QuantityConstant.TASK_TYPE_CYCLECOUNT)
.ne(TaskDetail::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskDetail> taskDetailList = taskDetailService.list(detailLambdaQueryWrapper);
/* 获取任务明细中的任务头id*/
List<Integer> headerIdList = taskDetailList.stream().map(TaskDetail::getTaskId).collect(Collectors.toList());
List<MobileTask> mobileTasks = new ArrayList<>();
/* 遍历id查询出盘点任务*/
for (Integer id : headerIdList) {
TaskHeader taskHeader = taskHeaderService.getById(id);
MobileTask mobileTask = new MobileTask();
mobileTask.setTaskHeader(taskHeader);
LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(TaskDetail::getTaskId, id)
.eq(TaskDetail::getContainerCode, containerCode);
List<TaskDetail> taskDetails = taskDetailService.list(queryWrapper);
mobileTask.setTaskDetail(taskDetails);
mobileTasks.add(mobileTask);
}
return mobileTasks;
}
/**
* 容器收货上架
*
* @param containerCode
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult createQuickTask(String containerCode) {
LambdaQueryWrapper<ReceiptContainerHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ReceiptContainerHeader::getContainerCode, containerCode)
.eq(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_BUILD)
|
|
549
|
.eq(ReceiptContainerHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
|
|
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getOne(queryWrapper);
if (receiptContainerHeader == null) {
throw new ServiceException("该容器没有任务!");
}
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailQueryWrapper = Wrappers.lambdaQuery();
containerDetailQueryWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerHeader.getId())
.eq(ReceiptContainerDetail::getStatus, QuantityConstant.RECEIPT_CONTAINER_BUILD)
.eq(ReceiptContainerDetail::getContainerCode, containerCode);
List<ReceiptContainerDetail> containerDetailList = receiptContainerDetailService.list(containerDetailQueryWrapper);
if (containerDetailList.isEmpty()) {
throw new SecurityException("没有组盘明细,请先组盘");
}
if (receiptContainerHeader.getStatus() == QuantityConstant.RECEIPT_HEADER_BUILD.shortValue()) {
String ids = String.valueOf(receiptContainerHeader.getId());
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id不能为空");
}
List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id不能为空");
}
Integer maxId = idList.stream().max(Comparator.comparing(Integer::intValue)).orElse(null);
LambdaQueryWrapper<ReceiptContainerHeader> lambda = Wrappers.lambdaQuery();
lambda.select(ReceiptContainerHeader::getId)
.lt(ReceiptContainerHeader::getStatus, 10)
.le(ReceiptContainerHeader::getId, maxId);
return receiptTaskService.createReceiptTask(idList);
}
return AjaxResult.error("生成入库任务失败");
}
|
|
586
587
588
589
|
@Transactional(rollbackFor = Exception.class)
public void combineInventory(TaskHeader task) {
LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
|
|
590
|
inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
|
|
591
592
593
594
595
|
.eq(InventoryHeader::getLocationCode, task.getToLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
if(header != null) {
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
|
|
596
|
inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
|
|
597
|
.eq(InventoryDetail::getLocationCode, task.getToLocation())
|
|
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
.eq(InventoryDetail::getContainerCode, task.getContainerCode());
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventory);
for(int i=0; i < inventoryDetailList.size() -1; i++) {
for(int j = inventoryDetailList.size() - 1; j > i; j--) {
InventoryDetail inventoryDetail = inventoryDetailList.get(i);
InventoryDetail inventoryDetail2 = inventoryDetailList.get(j);
if(inventoryDetail.getMaterialCode().equals(inventoryDetail2.getMaterialCode())
&& inventoryDetail.getBatch().equals(inventoryDetail2.getBatch())
&& inventoryDetail.getLot().equals(inventoryDetail2.getLot())
&& inventoryDetail.getProjectNo().equals(inventoryDetail2.getProjectNo())) {
BigDecimal totalQty = inventoryDetailList.get(i).getQty().add(inventoryDetailList.get(j).getQty());
inventoryDetailList.get(i).setQty(totalQty);
LambdaQueryWrapper<InventoryDetail> wrapper = Wrappers.lambdaQuery();
wrapper.eq(InventoryDetail::getId, inventoryDetailList.get(i).getId());
inventoryDetailService.update(inventoryDetailList.get(i), wrapper);
LambdaQueryWrapper<InventoryDetail> wrapper2 = Wrappers.lambdaQuery();
wrapper2.eq(InventoryDetail::getId, inventoryDetailList.get(j).getId());
inventoryDetailService.remove(wrapper2);
inventoryDetailList.remove(j);
}
}
}
BigDecimal totalQty = new BigDecimal(0);
int totalLines = 0;
for(InventoryDetail inventoryDetail : inventoryDetailList) {
totalQty = totalQty.add(inventoryDetail.getQty());
totalLines++;
}
header.setTotalQty(totalQty);
header.setTotalLines(totalLines);
|
|
628
|
header.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
|
|
629
630
631
632
633
634
|
LambdaQueryWrapper<InventoryHeader> wrapper = Wrappers.lambdaQuery();
wrapper.eq(InventoryHeader::getId, header.getId());
inventoryHeaderService.update(header, wrapper);
}
}
|
|
635
636
637
638
639
640
641
642
|
/**
* 移动端创建入库任务
*
* @param containerCode 容器编码
* @param sourceLocation 目的库位
* @return
*/
@Override
|
|
643
|
@Transactional(rollbackFor = Exception.class)
|
|
644
645
646
647
648
649
650
651
|
public AjaxResult mobileCreateReceiptTask(String containerCode, String sourceLocation) {
LambdaQueryWrapper<ReceiptContainerHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ReceiptContainerHeader::getContainerCode, containerCode)
.eq(ReceiptContainerHeader::getStatus, 0);
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getOne(queryWrapper);
if (receiptContainerHeader == null) {
throw new ServiceException("该容器没有任务!");
}
|
|
652
|
if (receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode())) {
|
|
653
654
655
656
|
throw new ServiceException("容器不在当前仓库!");
}
List<Integer> idList = new ArrayList<>();
idList.add(receiptContainerHeader.getId());
|
|
657
|
receiptTaskService.createReceiptTask(idList);
|
|
658
659
660
661
|
return AjaxResult.success(receiptContainerHeader);
}
|
|
662
|
/**
|
|
663
664
|
* 自动空托出库
* */
|
|
665
|
@Override
|
|
666
|
@Transactional(rollbackFor = Exception.class)
|
|
667
668
669
670
671
672
|
public AjaxResult createAutoEmptyOut(String warehouseCode){
/*先查询容器表,选中空托盘,再查询库存核实*/
//该容器中有库位信息,并且状态是空
List<Location> locationsList = locationService.selectContainerEmpty(warehouseCode);
if(locationsList.size() == 0){
throw new ServiceException("立库中没有空容器!");
|
|
673
|
}
|
|
674
675
676
677
678
679
680
681
682
683
|
//根据入库顺序正序排列取第一个
Location location = locationsList.get(0);
//反查库位
Container containerTmp = new Container();
containerTmp.setWarehouseCode(location.getWarehouseCode());
containerTmp.setCode(location.getContainerCode());
LambdaQueryWrapper<Container> containerLambda = Wrappers.lambdaQuery(containerTmp);
Container container = containerService.getOne(containerLambda);
if(container == null){
throw new ServiceException("选中的库位容器错误,请确认库位和容器!");
|
|
684
|
}
|
|
685
686
687
|
//生成空容器出库任务
inventoryHeaderService.createEmptyOut(container.getCode(), location.getCode());
return AjaxResult.success("空容器出库任务已下发!",container.getCode());
|
|
688
689
690
|
}
/**
|
|
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
|
* 自动分配库位
* @param taskId 任务号
* @param high 1是高库位,否则低库位
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult setLocationCode(Integer taskId, Integer high) {
TaskHeader taskHeader = this.getById(taskId);
if (taskHeader == null) {
throw new ServiceException("找不到id为"+ taskId +"的任务!");
}
if (StringUtils.isNotEmpty(taskHeader.getToLocation())) {
return AjaxResult.success("任务已经有目的库位,不需要再分配");
}
|
|
706
|
|
|
707
|
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
708
|
locationLambdaQueryWrapper.eq(Location::getWarehouseCode,ShiroUtils.getWarehouseCode())
|
|
709
|
.eq(Location::getContainerCode,"")
|
|
710
|
.eq(Location::getStatus,QuantityConstant.STATUS_LOCATION_EMPTY)
|
|
711
|
.eq(Location::getDeleted,false);
|
|
712
|
|
|
713
714
715
|
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
if (locations.size() == 0) {
throw new ServiceException("没有空闲库位!");
|
|
716
|
}
|
|
717
718
719
|
//随机取库位
Random rand = new Random();
Location location = locations.get(rand.nextInt(locations.size()));
|
|
720
|
if (location == null) {
|
|
721
|
throw new ServiceException("库位分配错误!");
|
|
722
723
|
}
//锁定库位
|
|
724
|
locationService.updateStatus(location.getCode(), QuantityConstant.STATUS_LOCATION_LOCK);
|
|
725
|
//给组盘分配库位
|
|
726
|
|
|
727
|
int internalTaskType = taskHeader.getInternalTaskType();
|
|
728
|
if(internalTaskType == QuantityConstant.TASK_TYPE_WHOLERECEIPT || internalTaskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) {
|
|
729
730
731
732
733
734
735
|
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(taskHeader.getAllocationHeadId());
receiptContainerHeader.setToLocation(location.getCode());
LambdaQueryWrapper<ReceiptContainerHeader> receiptContainerHeaderlLambdaQueryWrapper = Wrappers.lambdaQuery(receiptContainerHeader);
receiptContainerHeaderService.update(receiptContainerHeader, receiptContainerHeaderlLambdaQueryWrapper);
//给子任务分配库位
TaskDetail condition = new TaskDetail();
|
|
736
|
condition.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
737
738
|
condition.setTaskId(taskHeader.getId());
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery(condition);
|
|
739
740
741
742
743
744
745
746
|
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
if(taskDetailList != null && taskDetailList.size() > 0) {
for(TaskDetail taskDetail : taskDetailList) {
if (taskDetail != null) {
taskDetail.setToLocation(location.getCode());
taskDetailService.update(taskDetail, taskDetailLambdaQueryWrapper);
}
}
|
|
747
748
749
750
751
752
753
|
}
}
//给任务分配库位
taskHeader.setToLocation(location.getCode());
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(taskHeader);
this.update(taskHeader, taskHeaderLambdaQueryWrapper);
return AjaxResult.success("生成库位成功",location.getCode());
|
|
754
|
|
|
755
|
}
|
|
756
|
|
|
757
758
759
|
@Override
public int getUncompleteTaskInNear(Location location) {
Location location1 = locationService.getNear(location);
|
|
760
761
762
|
if(location1 == null) {
return 0;
}
|
|
763
764
765
|
String locationCode = location1.getCode();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getToLocation, locationCode)
|
|
766
|
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
|
|
767
|
List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
|
|
768
769
770
771
772
773
774
775
|
if(taskHeaderList == null || taskHeaderList.size() == 0) {
taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getFromLocation, locationCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
if(taskHeaderList == null || taskHeaderList.size() == 0) {
return 0;
}
|
|
776
777
778
|
}
return taskHeaderList.size();
}
|
|
779
|
|
|
780
781
782
|
@Override
public List<TaskHeader> remoteList(){
LambdaQueryWrapper<TaskHeader> wrapper = Wrappers.lambdaQuery();
|
|
783
784
|
wrapper.ge(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_RELEASE)
.lt(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED);
|
|
785
786
|
return list(wrapper);
}
|
|
787
|
}
|