|
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.BusinessException;
|
|
10
|
import com.huaheng.common.exception.service.ServiceException;
|
|
11
|
import com.huaheng.common.support.Convert;
|
|
12
|
import com.huaheng.common.utils.DataUtils;
|
|
13
|
import com.huaheng.common.utils.StringUtils;
|
|
14
15
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
16
|
import com.huaheng.mobile.download.Constant;
|
|
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
21
|
import com.huaheng.pc.config.containerCapacity.domain.ContainerCapacity;
import com.huaheng.pc.config.containerCapacity.service.ContainerCapacityService;
|
|
22
23
|
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
24
25
|
import com.huaheng.pc.config.sendMail.service.MailService;
import com.huaheng.pc.config.sendMail.service.SendMailService;
|
|
26
27
|
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
|
|
28
|
import com.huaheng.pc.inventory.cycleCountHeader.service.CycleCountHeaderService;
|
|
29
30
|
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
|
|
31
32
|
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
|
|
33
|
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
|
|
34
|
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
|
|
35
|
import com.huaheng.pc.monitor.message.service.BrokerMessageLogService;
|
|
36
37
|
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
|
|
38
39
40
41
|
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
|
|
42
43
|
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
|
|
44
|
import com.huaheng.pc.receipt.receiving.service.ReceivingService;
|
|
45
46
47
48
|
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
|
|
49
|
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
|
|
50
|
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
|
|
51
|
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
|
|
52
|
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
|
|
53
54
|
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
|
|
55
|
import com.huaheng.pc.task.taskHeader.domain.MobileTask;
|
|
56
|
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
|
|
57
58
|
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
|
|
59
|
import io.swagger.models.auth.In;
|
|
60
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
61
|
import org.springframework.stereotype.Service;
|
|
62
63
64
|
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
|
|
65
|
import java.math.BigDecimal;
|
|
66
|
import java.util.*;
|
|
67
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
68
|
import java.util.stream.Collectors;
|
|
69
|
|
|
70
|
@Service
|
|
71
|
public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHeader> implements TaskHeaderService {
|
|
72
|
|
|
73
|
@Resource
|
|
74
|
private ShipmentContainerHeaderService shipmentContainerHeaderService;
|
|
75
|
@Resource
|
|
76
|
private ShipmentContainerDetailService shipmentContainerDetailService;
|
|
77
|
@Resource
|
|
78
|
private LocationService locationService;
|
|
79
|
@Resource
|
|
80
81
|
private ContainerService containerService;
@Resource
|
|
82
|
private TaskDetailService taskDetailService;
|
|
83
|
@Resource
|
|
84
|
private TaskHeaderService taskHeaderService;
|
|
85
|
@Resource
|
|
86
|
private InventoryHeaderService inventoryHeaderService;
|
|
87
88
89
|
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
|
|
90
|
private InventoryTransactionService inventoryTransactionService;
|
|
91
|
@Resource
|
|
92
|
private ReceiptHeaderService receiptHeaderService;
|
|
93
94
|
@Resource
private ReceiptDetailService receiptDetailService;
|
|
95
|
@Resource
|
|
96
|
private ReceiptContainerDetailService receiptContainerDetailService;
|
|
97
98
99
100
|
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
|
|
101
102
|
@Resource
private CycleCountDetailService cycleCountDetailService;
|
|
103
|
@Resource
|
|
104
105
|
private CycleCountHeaderService cycleCountHeaderService;
@Resource
|
|
106
|
private ReceiptContainerHeaderService receiptContainerHeaderService;
|
|
107
|
@Resource
|
|
108
|
private TaskHeaderMapper taskHeaderMapper;
|
|
109
110
|
@Autowired
private TaskAssignService taskAssignService;
|
|
111
112
|
@Resource
private ContainerCapacityService containerCapacityService;
|
|
113
114
115
|
@Resource
private ConfigWarningService configWarningService;
@Resource
|
|
116
|
private ReceivingService receivingService;
|
|
117
|
|
|
118
119
120
|
@Resource
private CreateTaskMessage createTaskMessage;
|
|
121
122
|
/**
* 盘点任务首选项
|
|
123
|
*
|
|
124
125
126
127
128
|
* @param taskHeaderList
* @return
*/
@Override
public List<TaskHeader> preferenceRealize(List<TaskHeader> taskHeaderList) {
|
|
129
|
//盘点任务头,默认不显示库位,容器。
|
|
130
|
List<TaskHeader> taskHeaders = new ArrayList<>();
|
|
131
|
for (TaskHeader item : taskHeaderList) {
|
|
132
133
134
135
136
137
138
|
item.setFromLocation("");
item.setToLocation("");
item.setContainerCode("");
taskHeaders.add(item);
}
return taskHeaders;
}
|
|
139
|
|
|
140
141
142
143
144
|
@Override
public List<TaskHeader> getTasksStatus(Short lastStatus) {
return taskHeaderMapper.getTasksStatus(lastStatus);
}
|
|
145
|
/**
|
|
146
147
148
149
150
151
152
|
* 根据库位完成任务
*
* @param locationCode
* @return
* @throws Exception
*/
@Override
|
|
153
154
|
@Transactional(rollbackFor = Exception.class)
public AjaxResult completeTask(String locationCode) {
|
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
LambdaQueryWrapper<TaskHeader> taskQueryWrapper = Wrappers.lambdaQuery();
taskQueryWrapper.eq(TaskHeader::getToLocation, locationCode);
List<TaskHeader> list = this.list(taskQueryWrapper);
if (list.size() < 1) {
throw new ServiceException("库位(" + locationCode + ")没有任务!");
} else if(list.get(0).getStatus() == 100) {
//如果已完成则不管
throw new ServiceException("库位(" + locationCode + ")任务已经完成!");
}
if(list.get(0).getTaskType()==100 || list.get(0).getTaskType()==200){
//入库任务
return completeReceiptTask((list.get(0)));
} else {
throw new ServiceException("库位(" + locationCode + ")的任务不是上架,不能完成!");
}
}
@Override
|
|
173
|
@Transactional(rollbackFor = Exception.class)
|
|
174
|
public AjaxResult createReplenishTask(String containerCode, Integer taskStatus) {
|
|
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
|
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("该容器存在多条任务");
}
if (receiptContainerHeaderList.get(0).getWarehouseCode() != ShiroUtils.getWarehouseCode()) {
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());
|
|
204
205
|
this.createReceiptTask(ids);
return AjaxResult.success("成功!");
|
|
206
207
208
209
210
211
212
213
|
}
/**
* 移动端根据容器编码获取盘点任务
* @param containerCode 容器编码
* @return
*/
@Override
|
|
214
|
@Transactional(rollbackFor = Exception.class)
|
|
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
|
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;
}
/**
|
|
243
|
* 查询容器有无任务
|
|
244
|
*/
|
|
245
246
247
248
|
@Override
public Integer UncompleteCount(String ContainerCode) {
return taskHeaderMapper.UncompleteCount(ContainerCode, ShiroUtils.getWarehouseCode());
}
|
|
249
|
|
|
250
251
|
/**
* 取消任务
|
|
252
|
*/
|
|
253
|
@Override
|
|
254
|
@Transactional(rollbackFor = Exception.class)
|
|
255
|
public AjaxResult cancelTask(Integer[] taskIds) {
|
|
256
|
for (int taskId : taskIds) {
|
|
257
|
TaskHeader taskHeader = taskHeaderService.getById(taskId);
|
|
258
259
|
if (taskHeader == null) {
return AjaxResult.error("任务" + taskId + "未找到,操作中止");
|
|
260
|
}
|
|
261
262
|
if (taskHeader.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
return AjaxResult.error("存在任务" + taskHeader.getId() + "已下发或执行,操作中止");
|
|
263
|
}
|
|
264
265
266
267
268
269
270
271
|
//查出任务明细
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);
TaskDetail taskDetail = taskDetailList.get(0);
|
|
272
|
if (taskDetail == null) {
|
|
273
274
|
throw new ServiceException("任务明细条目错误");
}
|
|
275
276
|
//删除子任务
LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
277
|
lambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
|
|
278
279
280
281
|
taskDetailService.remove(lambdaQueryWrapper);
//删除主任务
taskHeaderService.removeById(taskHeader.getId());
// 更改库位状态(整盘入库任务除外)
|
|
282
|
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHELF)) {
|
|
283
|
receiptContainerHeaderService.cancelReceipt(taskHeader.getAllocationHeadId());
|
|
284
285
286
|
}
//根据任务类型来更新货箱状态
//修改关联的货箱状态
|
|
287
|
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_PICKING)) {
|
|
288
289
|
ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
shipmentContainerHeader.setId(taskHeader.getAllocationHeadId());
|
|
290
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
|
|
291
292
|
shipmentContainerHeaderService.updateById(shipmentContainerHeader);
}
|
|
293
|
//盘点取消任务,恢复明细状态为1
|
|
294
|
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_CYCLECOUNT)) {
|
|
295
296
297
298
299
300
301
302
303
304
|
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);//
|
|
305
|
for (CycleCountDetail item : cycleCountDetailList) {
|
|
306
307
308
309
310
311
312
313
314
|
item.setTaskHeaderId(null);
item.setTaskHeaderId(null);
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setEnableStatus(1);
cycleCountDetailService.saveOrUpdate(item);
}
}
|
|
315
|
if (taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHELF) || taskHeader.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_PICKING)) {
|
|
316
|
if (taskHeader.getToLocation() != null) {
|
|
317
318
319
|
//更新托盘、库位状态
locationService.updateStatus(taskHeader.getToLocation(), "empty");
}
|
|
320
321
322
323
324
|
Container container = new Container();
container.setStatus("empty");
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, taskHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
|
|
325
326
327
328
329
330
331
332
333
|
}
// if(task.getType()==900){
// //出库查看任务没有关联的货箱,不做处理
// }
}
return AjaxResult.success("取消任务成功!");
}
|
|
334
|
/**
|
|
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
* 创建空托入库
*
* @param containerCode 容器编码
* @param destinationLocation 目的库位
* @param companyCode 货主编码
* @return
*/
@Override
public AjaxResult createEmptyIn(String containerCode, String destinationLocation, String companyCode) {
return inventoryHeaderService.createEmptyIn(containerCode, destinationLocation);
}
/**
* 容器收货上架
*
* @param containerCode
* @return
*/
@Override
|
|
354
|
@Transactional(rollbackFor = Exception.class)
|
|
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
public AjaxResult createQuickTask(String containerCode) {
LambdaQueryWrapper<ReceiptContainerHeader> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ReceiptContainerHeader::getContainerCode, containerCode)
.eq(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_BUILD)
.eq(ReceiptContainerHeader::getWarehouseCode, ShiroUtils.getWarehouseCode());
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("没有组盘明细,请先组盘");
}
|
|
373
|
if (receiptContainerHeader.getStatus() == QuantityConstant.RECEIPT_HEADER_BUILD.shortValue()) {
|
|
374
375
376
377
378
|
String ids = String.valueOf(receiptContainerHeader.getId());
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id不能为空");
}
List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
|
|
379
380
381
382
383
384
385
386
387
|
// for (int i = 0; i<idList.size(); i++){
// LambdaQueryWrapper<ReceiptContainerDetail> lambda = Wrappers.lambdaQuery();
// lambda.eq(ReceiptContainerDetail::getReceiptContainerId, idList.get(i));
// List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(lambda);
// for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetails){
// receivingService.position(receiptContainerDetail);
// }
//
// }
|
|
388
389
390
|
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id不能为空");
}
|
|
391
392
393
394
395
396
397
398
399
|
// for (int i = 0; i<idList.size(); i++){
// LambdaQueryWrapper<ReceiptContainerDetail> lambda = Wrappers.lambdaQuery();
// lambda.eq(ReceiptContainerDetail::getReceiptContainerId, idList.get(i));
// List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(lambda);
// for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetails){
// receivingService.position(receiptContainerDetail);
// }
//
// }
|
|
400
401
402
403
404
405
406
407
408
|
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 taskHeaderService.createReceiptTask(idList);
}
|
|
409
|
return AjaxResult.error("生成入库任务失败");
|
|
410
411
412
|
}
/**
|
|
413
|
* 生成出库任务
|
|
414
|
*
|
|
415
416
417
418
|
* @param shipmentTaskCreateModel
* @return
*/
@Override
|
|
419
|
@Transactional(rollbackFor = Exception.class)
|
|
420
|
public AjaxResult createTaskFromShipmentContainers(ShipmentTaskCreateModel shipmentTaskCreateModel) {
|
|
421
|
Boolean flag = true;
|
|
422
423
424
|
Integer shipmentContainerHeaderId = shipmentTaskCreateModel.getShipmentContainerHeaderIds();
//获取表头
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerHeaderId);
|
|
425
|
if (shipmentContainerHeader == null) {
|
|
426
427
|
return AjaxResult.error("出库货箱" + shipmentContainerHeaderId + "未找到,操作中止");
}
|
|
428
|
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
|
|
429
430
431
|
return AjaxResult.error("出库货箱" + shipmentContainerHeader.getContainerCode() + "已经生成任务,请不要重复生成,操作中止");
}
//获取所有子货箱
|
|
432
433
|
LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId, shipmentContainerHeader.getId());
|
|
434
|
List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(lambdaQueryWrapper);
|
|
435
|
if (shipmentContainerDetails == null || shipmentContainerDetails.size() == 0) {
|
|
436
437
438
|
return AjaxResult.error("货箱" + shipmentContainerHeader.getContainerCode() + "没有子任务,操作中止");
}
//检测库位
|
|
439
440
441
442
|
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getCode, shipmentContainerHeader.getLocationCode())
.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(Location::getDeleted, false);
|
|
443
|
Location location = locationService.getOne(locationLambdaQueryWrapper);
|
|
444
|
if (location == null) {
|
|
445
446
447
448
449
|
return AjaxResult.error("库位禁用或不存在!");
}
//创建任务头
TaskHeader task = new TaskHeader();
//分拣出库
|
|
450
|
task.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
|
|
451
|
task.setFromLocation(shipmentContainerHeader.getLocationCode());
|
|
452
|
task.setToLocation(shipmentContainerHeader.getLocationCode());
|
|
453
|
//判断是否整出任务,钱柜和AGV不能整出
|
|
454
|
|
|
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
//表示整出优先
//判断当前子货箱所有数量是否等于该托盘对应的所有库存的数量,
//这里必须与库存的在库数量对比,后期可能存在一个配盘在执行任务,后一个配盘又在配这个的情况(这个时候不能整出)
// 如果相等,则说明这个货箱包含了所有的数量,则可以整出,否则,创建拣选任务;
//查询所有库存
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getLocationCode, shipmentContainerHeader.getLocationCode())
.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<InventoryDetail> inventories = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
BigDecimal inventoryTotal = new BigDecimal("0");
for (InventoryDetail item : inventories) {
inventoryTotal = inventoryTotal.add(item.getQty());
}
BigDecimal containerTotal = new BigDecimal("0");
for (ShipmentContainerDetail item : shipmentContainerDetails) {
containerTotal = containerTotal.add(item.getQty());
}
if (inventoryTotal.compareTo(containerTotal) == 0) {
task.setTaskType(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);//整盘出库
task.setToLocation("");
}
|
|
476
|
|
|
477
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_PICKING);
|
|
478
|
task.setAllocationHeadId(shipmentContainerHeader.getId());
|
|
479
480
481
482
|
task.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
task.setCompanyCode(shipmentContainerHeader.getCompanyCode());
task.setAssignedUser(ShiroUtils.getLoginName());
task.setConfirmedBy(ShiroUtils.getLoginName());
|
|
483
|
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
484
485
486
487
488
489
490
|
task.setContainerCode(shipmentContainerHeader.getContainerCode());
task.setCreatedBy(ShiroUtils.getLoginName());
task.setCreated(new Date());
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(null);
this.save(task);
//遍历子货箱创建子任务
|
|
491
|
for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetails) {
|
|
492
493
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
|
|
494
|
taskDetail.setInternalTaskType(task.getInternalTaskType());
|
|
495
496
|
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setCompanyCode(task.getCompanyCode());
|
|
497
|
taskDetail.setTaskType(task.getTaskType());
|
|
498
|
taskDetail.setToInventoryId(shipmentContainerDetail.getInventoryId());
|
|
499
|
taskDetail.setAllocationId(shipmentContainerDetail.getId());
|
|
500
501
502
503
|
taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
taskDetail.setMaterialCode(shipmentContainerDetail.getMaterialCode());
taskDetail.setMaterialName(shipmentContainerDetail.getMaterialName());
|
|
504
505
|
taskDetail.setMaterialSpec(shipmentContainerDetail.getMaterialSpec());
taskDetail.setMaterialUnit(shipmentContainerDetail.getMaterialUnit());
|
|
506
507
508
|
taskDetail.setFromInventoryId(shipmentContainerDetail.getInventoryId());
taskDetail.setQty(shipmentContainerDetail.getQty());
taskDetail.setContainerCode(task.getContainerCode());
|
|
509
510
|
taskDetail.setFromLocation(task.getFromLocation());
taskDetail.setToLocation(task.getToLocation());
|
|
511
512
513
|
taskDetail.setLot(shipmentContainerDetail.getLot());
taskDetail.setBatch(shipmentContainerDetail.getBatch());
taskDetail.setProjectNo(shipmentContainerDetail.getProjectNo());
|
|
514
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
515
|
taskDetail.setWaveId(shipmentContainerDetail.getWaveId());
|
|
516
|
taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
|
|
517
|
taskDetail.setCreatedBy(ShiroUtils.getLoginName());
|
|
518
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
519
520
|
flag = taskDetailService.save(taskDetail);
if (flag == false) {
|
|
521
522
|
throw new ServiceException("新建任务明细失败,sql报错");
}
|
|
523
|
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
|
|
524
525
|
}
//更新货位状态
|
|
526
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
|
|
527
|
flag = shipmentContainerHeaderService.updateById(shipmentContainerHeader);
|
|
528
|
if (flag == false) {
|
|
529
530
531
532
|
throw new ServiceException("修改组盘头状态失败,sql报错");
}
flag = shipmentContainerDetailService.updateBatchById(shipmentContainerDetails);
|
|
533
|
if (flag == false) {
|
|
534
535
|
throw new ServiceException("修改组盘明细状态明细失败,sql报错");
}
|
|
536
537
|
return AjaxResult.success(task.getId());
}
|
|
538
|
|
|
539
|
/**
|
|
540
|
* 下发WCS执行任务
|
|
541
|
* 执行任务
|
|
542
|
*/
|
|
543
|
@Override
|
|
544
|
@Transactional(rollbackFor = Exception.class)
|
|
545
|
public AjaxResult<TaskHeader> sendTaskToWcs(Integer[] taskIds) {
|
|
546
547
|
TaskHeader task = null;
for (Integer taskId : taskIds) {
|
|
548
|
task = taskHeaderService.getById(taskId);
|
|
549
|
|
|
550
|
if (task.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
|
|
551
552
|
return AjaxResult.error("任务" + taskId + "已经下发,请不要重复下发,操作中止");
}
|
|
553
|
// 给wcs传递任务
|
|
554
555
556
557
558
|
try {
createTaskMessage.createTask(task);
} catch (Exception e) {
e.printStackTrace();
}
|
|
559
|
|
|
560
|
//修改任务头表
|
|
561
|
task.setId(taskId);
|
|
562
|
task.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
563
564
565
|
task.setStartPickDateTime(new Date()); //生成时间
task.setLastUpdated(new Date());
task.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
566
|
taskHeaderService.saveOrUpdate(task);
|
|
567
|
//修改任务明细状态
|
|
568
569
570
571
|
LambdaQueryWrapper<TaskDetail> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskDetail::getTaskId, task.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaWrapper);
List<TaskDetail> taskDetails = new ArrayList<>();
|
|
572
|
for (TaskDetail item : taskDetailList) {
|
|
573
|
item.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
574
575
576
577
578
|
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setProcessStamp("100");
taskDetails.add(item);
//盘点执行修改盘点单据状态为10
|
|
579
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_CYCLECOUNT)) {
|
|
580
|
cycleCountDetailService.updataDetailStatus(item.getBillDetailId(), QuantityConstant.CYCLECOUNT_STATUS_EXECUTING);
|
|
581
|
}
|
|
582
|
}
|
|
583
584
585
586
|
if(taskDetails != null && taskDetails.size() > 0) {
if (!taskDetailService.saveOrUpdateBatch(taskDetails)) {
throw new ServiceException("更新任务明细失败");
}
|
|
587
|
}
|
|
588
|
|
|
589
590
591
592
593
594
595
596
597
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
|
// //修改入库明细
// if (task.getInternalTaskType()==100){
// ReceiptDetail receiptDetail = receiptDetailService.queryflow(receiptDetailService.getById(record.getId()));
// if (!receiptDetailService.updateById(receiptDetail)){
// throw new ServiceException("更新状态失败");
// }
// receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
//
// //修改组盘表状态为20
// ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
// receiptContainerDetail.setStatus(20);
// receiptContainerDetail.setLastUpdated(new Date());
// receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
// LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
// receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getReceiptId,receiptDetail.getReceiptId());
// if (! receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper))
// throw new ServiceException("更新组盘状态失败");
// }
//
// //修改出库单状态
// if (task.getInternalTaskType()==200){
// LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
// taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId,task.getId());
// List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
//
// for (TaskDetail taskDeatails: taskDetailList) {
// LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
// shipmentDetailLambdaQueryWrapper.eq(ShipmentDetail::getId,taskDeatails.getBillDetailId());
//
// ShipmentHeader shipmentHeader =new ShipmentHeader();
// shipmentHeader.setId(shipmentDetailService.getOne(shipmentDetailLambdaQueryWrapper).getShipmentId());
// shipmentHeader.setFirstStatus(100);
// shipmentHeader.setLastStatus(100);
// shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
// shipmentHeader.setLastUpdated(new Date());
// shipmentHeaderService.updateById(shipmentHeader);
// }
// }
|
|
628
|
}
|
|
629
|
return AjaxResult.success("执行下发任务成功", task);
|
|
630
631
632
|
}
@Override
|
|
633
|
public AjaxResult completeTaskByWMS(Integer[] taskIds, String[] weightConvert) {
|
|
634
635
|
for (int i = 0;i<taskIds.length;i++) {
TaskHeader task = taskHeaderService.getById(taskIds[i]);
|
|
636
|
|
|
637
|
if (task == null) {
|
|
638
|
throw new ServiceException("任务" + taskIds[i] + "未找到,执行中止");
|
|
639
|
}
|
|
640
641
642
643
644
645
|
//任务写入重量
String weight = "";
if (StringUtils.isNotNull(weightConvert)) {
weight = weightConvert[i];
}
task.setWeight(weight);
|
|
646
|
//如果已完成则不管
|
|
647
648
649
|
if (task.getStatus().equals(QuantityConstant.TASK_STATUS_COMPLETED)) {
return AjaxResult.success("任务(" + taskIds[i] + ")任务已经是完成的!");
|
|
650
|
}
|
|
651
652
|
//整盘入库,空托入库库位自动分配
//整盘入库手动完成分配库位,已分配则略过
|
|
653
|
if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLERECEIPT) || task.getTaskType().equals(QuantityConstant.TASK_TYPE_EMPTYRECEIPT)){
|
|
654
655
|
if(StringUtils.isEmpty(task.getToLocation())){
//自动分配库位
|
|
656
657
|
AjaxResult ajaxResult = this.setLocationCode(task.getId(),0 );
task.setToLocation((String)ajaxResult.getData());
|
|
658
659
|
}
}
|
|
660
|
//如果没有库位不能完成
|
|
661
662
|
if (StringUtils.isEmpty(task.getFromLocation()) && StringUtils.isEmpty(task.getToLocation())) {
throw new ServiceException("任务" + task.getId() + "没有库位,执行中止");
|
|
663
|
}
|
|
664
|
|
|
665
|
this.completeTask(task);
|
|
666
667
668
669
670
671
672
673
674
|
}
return AjaxResult.success("完成任务成功!");
}
/**
* 完成任务
*
* @param task
*/
|
|
675
|
public void completeTask(TaskHeader task) {
|
|
676
|
//区分任务类型
|
|
677
|
if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHELF) ) {
|
|
678
|
//入库任务
|
|
679
|
this.completeReceiptTask(task);
|
|
680
|
combineInventory(task);
|
|
681
|
}
|
|
682
683
684
685
|
if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_PICKING) &&
(task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT) || task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT))) {
//出库任务
this.completeShipmentTask(task);
|
|
686
|
}
|
|
687
|
// 900 出库查看,空托出库查看
|
|
688
689
|
if (task.getTaskType().equals( QuantityConstant.TASK_TYPE_VIEW)) {
this.completeSeeOutTask(task);
|
|
690
|
}
|
|
691
|
// 700 盘点
|
|
692
693
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_CYCLECOUNT)) {
this.completeCycleCountTask(task);
|
|
694
|
}
|
|
695
|
if (task.getTaskType().equals( QuantityConstant.TASK_TYPE_TRANSFER)) {
|
|
696
|
// //移库
|
|
697
|
this.completeTransferTask(task);
|
|
698
|
}
|
|
699
|
if (task.getTaskType().equals( QuantityConstant.TASK_TYPE_EMPTYRECEIPT)) {
|
|
700
|
//空托盘入库
|
|
701
|
this.completeEmptyIn(task);
|
|
702
|
}
|
|
703
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_EMPTYSHIPMENT) ) {
|
|
704
|
//空托盘出库
|
|
705
|
this.completeEmptyOut(task);
|
|
706
707
708
|
}
}
|
|
709
710
|
/**
|
|
711
|
* 完成入库任务
|
|
712
|
*/
|
|
713
|
@Override
|
|
714
|
@Transactional(rollbackFor = Exception.class)
|
|
715
|
public AjaxResult completeReceiptTask(TaskHeader task) {
|
|
716
717
|
List<Map<String, Object>> taskReceiptContainerDetail = taskHeaderMapper.getReceiptTask(task.getId());
if (taskReceiptContainerDetail.size() < 1) {
|
|
718
719
|
return AjaxResult.success("未找到对应任务的入库单号!!!");
}
|
|
720
721
|
LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
|
|
722
|
.eq(InventoryHeader::getLocationCode, task.getToLocation())
|
|
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
if(header == null) {
//添加库存单
header = new InventoryHeader();
header.setWarehouseCode(task.getWarehouseCode());
header.setCompanyCode(task.getCompanyCode());//货主
header.setContainerCode(task.getContainerCode());
header.setContainerStatus("some");
header.setLocationCode(task.getToLocation());
header.setLocking(1);
header.setEnable(1);
header.setTotalQty(new BigDecimal(0));
header.setTotalWeight(task.getWeight());
header.setCreatedBy(ShiroUtils.getLoginName());
header.setCreated(new Date());
header.setLastUpdatedBy(ShiroUtils.getLoginName());
header.setLastUpdated(new Date());
if (!inventoryHeaderService.save(header)) {
throw new ServiceException("添加库存单失败");
}
}
|
|
746
747
|
for (Map<String, Object> map : taskReceiptContainerDetail) {
//将未完成的任务数量更新到库存表
|
|
748
|
if (DataUtils.getInteger(map.get("status")) < QuantityConstant.TASK_STATUS_COMPLETED) {
|
|
749
|
|
|
750
751
|
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
|
|
752
|
.eq(InventoryDetail::getLocationCode, task.getToLocation())
|
|
753
|
.eq(InventoryDetail::getMaterialCode, DataUtils.getString(map.get("materialCode")))
|
|
754
|
.eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")))
|
|
755
756
757
758
|
.eq(InventoryDetail::getBatch, DataUtils.getString(map.get("batch")))
.eq(InventoryDetail::getLot, DataUtils.getString(map.get("lot")))
.eq(InventoryDetail::getProjectNo, DataUtils.getString(map.get("projectNo")))
.eq(InventoryDetail::getCompanyCode, DataUtils.getString(map.get("companyCode")));
|
|
759
760
|
InventoryDetail detail = inventoryDetailService.getOne(inventory);
if (detail == null) {
|
|
761
762
763
764
765
|
//库存明细添加
detail = new InventoryDetail();
detail.setInventoryHeaderId(header.getId());//库存头ID
detail.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));//仓库
detail.setCompanyCode(task.getCompanyCode());//货主
|
|
766
|
detail.setLocationCode(task.getToLocation());//库位号
|
|
767
768
769
770
|
detail.setContainerCode(DataUtils.getString(map.get("containerCode")));//容器号
detail.setMaterialCode(DataUtils.getString(map.get("materialCode")));//物料号
detail.setMaterialName(DataUtils.getString(map.get("materialName")));//物料名称
detail.setMaterialSpec(DataUtils.getString(map.get("materialSpec")));//物料规格
|
|
771
|
detail.setMaterialUnit(DataUtils.getString(map.get("materialUnit")));//物料单位
|
|
772
|
detail.setReceiptCode(DataUtils.getString(map.get("receiptCode")));//入库单编码
|
|
773
|
detail.setReceiptDetailId(DataUtils.getInteger(map.get("receiptDetailId")));//入库单明细ID
|
|
774
775
|
detail.setBatch(DataUtils.getString(map.get("batch")));//批次
detail.setLot(DataUtils.getString(map.get("lot")));//批号
|
|
776
|
detail.setProjectNo(DataUtils.getString(map.get("projectNo")));//项目号
|
|
777
|
detail.setInventorySts(DataUtils.getString(map.get("inventorySts")));//库存状态
|
|
778
|
// detail.setManufactureDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("manufactureDate").toString()));//生产日期
|
|
779
|
// detail.setExpirationDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("expirationDate").toString()));//失效日期
|
|
780
|
detail.setQty(DataUtils.getBigDecimal(map.get("qty")));//数量
|
|
781
|
detail.setLockedQty(DataUtils.getBigDecimal(0));
|
|
782
|
detail.setTaskQty(DataUtils.getBigDecimal(0));
|
|
783
784
|
detail.setCreatedBy(ShiroUtils.getLoginName());//创建人
detail.setLastUpdatedBy(ShiroUtils.getLoginName());//创建时间
|
|
785
|
if (!inventoryDetailService.save(detail)) {
|
|
786
|
throw new ServiceException("添加库存明细失败");
|
|
787
|
}
|
|
788
|
} else {
|
|
789
790
791
|
detail.setQty(detail.getQty().add(DataUtils.getBigDecimal(map.get("qty"))));
detail.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<InventoryDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
792
|
lambdaUpdateWrapper.eq(InventoryDetail::getId, detail.getId());
|
|
793
|
if (!inventoryDetailService.update(detail, lambdaUpdateWrapper)){
|
|
794
|
throw new ServiceException("更新库存明细失败");
|
|
795
|
}
|
|
796
797
798
|
}
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
|
|
799
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
|
|
800
801
|
inventoryTransaction.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));
inventoryTransaction.setCompanyCode(task.getCompanyCode());
|
|
802
|
inventoryTransaction.setLocationCode(task.getToLocation());
|
|
803
804
805
|
inventoryTransaction.setContainerCode(DataUtils.getString(map.get("containerCode")));
inventoryTransaction.setMaterialCode(DataUtils.getString(map.get("materialCode")));
inventoryTransaction.setMaterialName(DataUtils.getString(map.get("materialName")));
|
|
806
807
|
inventoryTransaction.setMaterialSpec(DataUtils.getString(map.get("materialSpec")));//物料规格
inventoryTransaction.setMaterialUnit(DataUtils.getString(map.get("materialUnit")));//物料单位
|
|
808
|
inventoryTransaction.setBillCode(DataUtils.getString(map.get("receiptCode")));
|
|
809
|
inventoryTransaction.setBillDetailId(DataUtils.getInteger(map.get("receiptDetailId")));
|
|
810
811
812
|
inventoryTransaction.setBatch(DataUtils.getString(map.get("batch")));
inventoryTransaction.setLot(DataUtils.getString(map.get("lot")));
inventoryTransaction.setInventorySts(DataUtils.getString((map.get("inventorySts"))));
|
|
813
|
inventoryTransaction.setTaskQty(DataUtils.getBigDecimal(map.get("qty")));
|
|
814
815
|
inventoryTransaction.setCreated(new Date());
inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
|
|
816
|
if (!inventoryTransactionService.save(inventoryTransaction)) {
|
|
817
|
throw new ServiceException("新增库存记录失败");
|
|
818
819
|
}
|
|
820
821
|
//修改任务明细的状态为完成
TaskDetail taskDetail = new TaskDetail();
|
|
822
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
823
824
825
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setAgingDate(new Date()); //入库时间
LambdaUpdateWrapper<TaskDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
826
|
lambdaUpdateWrapper.eq(TaskDetail::getTaskId, task.getId());
|
|
827
|
taskDetailService.update(taskDetail, lambdaUpdateWrapper);
|
|
828
|
if (!taskDetailService.update(taskDetail, lambdaUpdateWrapper)) {
|
|
829
830
|
throw new ServiceException("修改入库单明细失败");
}
|
|
831
|
|
|
832
833
|
}
|
|
834
|
}
|
|
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
|
//修改任务主表状态,因为立库任务表单头只对应一个货箱,表单详情的任务会同时完成
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
LambdaUpdateWrapper<TaskHeader> taskHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
taskHeaderLambdaUpdateWrapper.eq(TaskHeader::getId, task.getId());
if (!taskHeaderService.update(task, taskHeaderLambdaUpdateWrapper)){
throw new ServiceException("更新任务主表失败");
}
//修改库位状态和对应的容器
Location location = new Location();
location.setContainerCode(task.getContainerCode());
location.setStatus("empty");
LambdaUpdateWrapper<Location> locationLambdaUpdateWrapper = Wrappers.lambdaUpdate();
locationLambdaUpdateWrapper.eq(Location::getCode, task.getToLocation());
if (!locationService.update(location, locationLambdaUpdateWrapper)){
throw new ServiceException("更新库位失败");
}
//修改容器状态和对应的库位
Container container = new Container();
container.setLocationCode(task.getToLocation());
container.setStatus("some");
LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
containerLambdaUpdateWrapper.eq(Container::getCode, task.getContainerCode());
if (!containerService.update(container, containerLambdaUpdateWrapper)) {
throw new ServiceException("更新容器失败");
}
//修改组盘表状态为20
ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
receiptContainerDetail.setStatus(QuantityConstant.RECEIPT_CONTAINER_REVIEWSUCCESS);
receiptContainerDetail.setProcessStamp("0");
receiptContainerDetail.setLastUpdated(new Date());
receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getReceiptId, DataUtils.getInteger(taskReceiptContainerDetail.get(0).get("receiptId")));
if (!receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper)){
throw new ServiceException("更新组盘状态失败");
}
//修改入库组盘头表状态
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(task.getAllocationHeadId());
receiptContainerHeader.setLastUpdated(new Date());
receiptContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
880
|
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_FINISHED.intValue());
|
|
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
if (!receiptContainerHeaderService.updateById(receiptContainerHeader)) {
throw new ServiceException("更新入库组盘头表状态失败");
}
//修改入库单状态
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setLastUpdated(new Date());
LambdaUpdateWrapper<ReceiptHeader> receiptHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
receiptHeaderLambdaUpdateWrapper.eq(ReceiptHeader::getId, DataUtils.getInteger(taskReceiptContainerDetail.get(0).get("receiptId")));
if (!receiptHeaderService.update(receiptHeader, receiptHeaderLambdaUpdateWrapper)) {
throw new ServiceException("更新入库头表状态失败");
}
|
|
896
|
return AjaxResult.success("完成入库任务");
|
|
897
|
}
|
|
898
|
|
|
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
|
@Transactional(rollbackFor = Exception.class)
public void combineInventory(TaskHeader task) {
LambdaQueryWrapper<InventoryHeader> inventoryHeaderErapper = Wrappers.lambdaQuery();
inventoryHeaderErapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(InventoryHeader::getLocationCode, task.getToLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
InventoryHeader header = inventoryHeaderService.getOne(inventoryHeaderErapper);
if(header != null) {
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(InventoryDetail::getLocationCode, task.getFromLocation())
.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--) {
|
|
914
915
916
917
918
919
|
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())) {
|
|
920
921
922
923
924
|
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);
|
|
925
926
927
928
|
LambdaQueryWrapper<InventoryDetail> wrapper2 = Wrappers.lambdaQuery();
wrapper2.eq(InventoryDetail::getId, inventoryDetailList.get(j).getId());
inventoryDetailService.remove(wrapper2);
inventoryDetailList.remove(j);
|
|
929
930
931
932
|
}
}
}
BigDecimal totalQty = new BigDecimal(0);
|
|
933
|
int totalLines = 0;
|
|
934
935
|
for(InventoryDetail inventoryDetail : inventoryDetailList) {
totalQty = totalQty.add(inventoryDetail.getQty());
|
|
936
|
totalLines++;
|
|
937
938
|
}
header.setTotalQty(totalQty);
|
|
939
940
|
header.setTotalLines(totalLines);
header.setContainerStatus("some");
|
|
941
942
943
944
945
|
LambdaQueryWrapper<InventoryHeader> wrapper = Wrappers.lambdaQuery();
wrapper.eq(InventoryHeader::getId, header.getId());
inventoryHeaderService.update(header, wrapper);
}
}
|
|
946
|
|
|
947
948
949
950
951
952
953
954
|
/**
* 移动端创建入库任务
*
* @param containerCode 容器编码
* @param sourceLocation 目的库位
* @return
*/
@Override
|
|
955
|
@Transactional(rollbackFor = Exception.class)
|
|
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
|
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("该容器没有任务!");
}
if (receiptContainerHeader.getWarehouseCode() != ShiroUtils.getWarehouseCode()) {
throw new ServiceException("容器不在当前仓库!");
}
List<Integer> idList = new ArrayList<>();
idList.add(receiptContainerHeader.getId());
createReceiptTask(idList);
return AjaxResult.success(receiptContainerHeader);
}
|
|
974
975
976
977
978
|
// @Override
// public List<Map<String, Object>> getReceiptTask(Integer taskId) {
// return taskHeaderMapper.getReceiptTask(taskId) ;
// }
|
|
979
|
/**
|
|
980
|
* 生成
|
|
981
|
* 立库移库
|
|
982
|
*/
|
|
983
|
@Override
|
|
984
|
@Transactional(rollbackFor = Exception.class)
|
|
985
|
public AjaxResult createTransferTask(String sourceLocation, String destinationLocation) {
|
|
986
|
|
|
987
988
|
//源库位校验
Location temp1 = new Location();
|
|
989
|
temp1.setCode(sourceLocation);
|
|
990
|
temp1.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
991
|
temp1.setStatus("empty");
|
|
992
|
LambdaQueryWrapper<Location> lambda1 = Wrappers.lambdaQuery(temp1);
|
|
993
|
Location loc1 = locationService.getOne(lambda1);
|
|
994
995
|
if (loc1 == null) {
return AjaxResult.error("源库位:" + sourceLocation + "未找到");
|
|
996
|
}
|
|
997
|
if (!"empty".equals(loc1.getStatus())) {
|
|
998
|
return AjaxResult.error("源库位:" + sourceLocation + "状态非空闲");
|
|
999
|
}
|
|
1000
1001
|
if (StringUtils.isEmpty(loc1.getContainerCode())) {
return AjaxResult.error("源库位:" + sourceLocation + "不存在托盘");
|
|
1002
1003
1004
|
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
|
|
1005
1006
1007
|
int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation, ShiroUtils.getWarehouseCode());
if (count1 > 0) {
return AjaxResult.error("源库位:" + sourceLocation + "存在入库组盘,不能移库");
|
|
1008
|
}
|
|
1009
1010
1011
|
int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation, ShiroUtils.getWarehouseCode());
if (count2 > 0) {
return AjaxResult.error("源库位:" + sourceLocation + "存在出库组盘,不能移库");
|
|
1012
|
}
|
|
1013
|
//目的库位校验
|
|
1014
|
Location temp2 = new Location();
|
|
1015
|
temp2.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
1016
|
temp2.setCode(destinationLocation);
|
|
1017
1018
|
LambdaQueryWrapper<Location> lambdaQueryWrapper2 = Wrappers.lambdaQuery(temp2);
Location loc2 = locationService.getOne(lambdaQueryWrapper2);
|
|
1019
1020
|
if (loc2 == null) {
return AjaxResult.error("目标库位:" + destinationLocation + "未找到");
|
|
1021
|
}
|
|
1022
|
if (!"empty".equals(loc2.getStatus())) {
|
|
1023
|
return AjaxResult.error("目标库位:" + destinationLocation + "状态非空闲");
|
|
1024
|
}
|
|
1025
1026
|
if (StringUtils.isNotEmpty(loc2.getContainerCode())) {
return AjaxResult.error("目标库位:" + destinationLocation + "已存在托盘");
|
|
1027
|
}
|
|
1028
1029
1030
|
int count3 = inventoryHeaderService.getUncompleteReceiptContainer(destinationLocation, ShiroUtils.getWarehouseCode());
if (count3 > 0) {
return AjaxResult.error("目标库位:" + sourceLocation + "存在入库组盘,不能移库");
|
|
1031
|
}
|
|
1032
1033
1034
1035
|
//写入任务主表和明细表
TaskHeader taskHeader = new TaskHeader();
taskHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
taskHeader.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));//获取第一个货主
|
|
1036
|
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_TRANSFER);
|
|
1037
|
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
1038
|
taskHeader.setContainerCode(loc1.getContainerCode());
|
|
1039
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
|
taskHeader.setFromLocation(sourceLocation);
taskHeader.setToLocation(destinationLocation);
taskHeader.setCreated(new Date());
taskHeader.setCreatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdated(new Date());
taskHeaderMapper.insert(taskHeader);
//写入明细表
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(taskHeader.getId());//主单ID
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setInternalTaskType(taskHeader.getTaskType());
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
|
|
1054
|
taskDetail.setCompanyCode(taskHeader.getCompanyCode());
|
|
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
taskDetail.setFromLocation(sourceLocation);
taskDetail.setToLocation(destinationLocation);
taskDetail.setContainerCode(taskHeader.getContainerCode());
taskDetail.setCreated(new Date());
taskDetail.setCreatedBy(ShiroUtils.getLoginName());
taskDetail.setLastUpdated(new Date());
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetailService.save(taskDetail);
|
|
1064
1065
1066
|
//更新货位状态为预定
loc1.setStatus("lock");
loc2.setStatus("lock");
|
|
1067
1068
1069
1070
1071
1072
1073
1074
|
locationService.saveOrUpdate(loc1);
locationService.saveOrUpdate(loc2);
return AjaxResult.success(taskHeader.getId());
}
/**
* 完成移库任务
|
|
1075
|
*
|
|
1076
1077
|
* @param task
*/
|
|
1078
|
@Transactional(rollbackFor = Exception.class)
|
|
1079
|
public void completeTransferTask(TaskHeader task) {
|
|
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
|
//找到任务明细
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setContainerCode(task.getContainerCode());
LambdaQueryWrapper<TaskDetail> taskDetailLW = Wrappers.lambdaQuery(taskDetail);
taskDetail = taskDetailService.getOne(taskDetailLW);
//更新库存主表和明细的库位,更改更新用户和时间
InventoryHeader inventoryHeader = new InventoryHeader();
//主表
inventoryHeader.setWarehouseCode(taskDetail.getWarehouseCode());
inventoryHeader.setCompanyCode(taskDetail.getCompanyCode());
inventoryHeader.setContainerCode(taskDetail.getContainerCode());
inventoryHeader.setLocationCode(taskDetail.getFromLocation());//通过源库位查找库存
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryHeader);
inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
|
|
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
|
if (StringUtils.isNotNull(inventoryHeader)){
inventoryHeader.setLocationCode(taskDetail.getToLocation());//把目的库位写入库存
inventoryHeader.setLastUpdated(new Date());
inventoryHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
inventoryHeaderService.saveOrUpdate(inventoryHeader);//修改主表库位
//明细表
List<InventoryDetail> inventoryDetails = new ArrayList<>();
InventoryDetail inventoryDetail = new InventoryDetail();
inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryDetail);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
/*同时写入库存交易表*/
List<InventoryTransaction> inventoryTransactionList = new ArrayList<>();
for (InventoryDetail item : inventoryDetailList) {
item.setLocationCode(inventoryHeader.getLocationCode());//修改明细表库位
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
inventoryDetails.add(item);
/*----------*/
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
inventoryTransaction.setLocationCode(taskDetail.getToLocation());
inventoryTransaction.setContainerCode(taskDetail.getContainerCode());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_ADJUSTPROPERTIES);
inventoryTransaction.setMaterialCode(item.getMaterialCode());
inventoryTransaction.setManufactureDate(item.getManufactureDate());
inventoryTransaction.setMaterialName(item.getMaterialName());
inventoryTransaction.setMaterialSpec(item.getMaterialSpec());
inventoryTransaction.setMaterialUnit(item.getMaterialUnit());
inventoryTransaction.setTaskQty(BigDecimal.ZERO);
inventoryTransaction.setInventorySts(item.getInventorySts());
inventoryTransaction.setCompanyCode(item.getCompanyCode());
inventoryTransaction.setReferDetailId(item.getId().toString());
inventoryTransaction.setBatch(item.getBatch());
inventoryTransaction.setLot(item.getLot());
inventoryTransaction.setProjectNo(item.getProjectNo());
inventoryTransaction.setWeight(item.getWeight());
inventoryTransaction.setManufactureDate(item.getManufactureDate());
inventoryTransaction.setExpirationDate(item.getExpirationDate());
inventoryTransaction.setAgingDate(item.getCreated());
inventoryTransaction.setAttributeId(item.getAttributeId());
inventoryTransaction.setAttribute1(item.getAttribute1());
inventoryTransaction.setAttribute2(item.getAttribute2());
inventoryTransaction.setAttribute3(item.getAttribute3());
inventoryTransaction.setCreated(new Date());
inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
//inventoryTransaction.setLockCode();
inventoryTransaction.setBillCode(item.getInventoryHeaderId().toString());
inventoryTransaction.setBillDetailId(item.getId());
inventoryTransaction.setSupplierCode(item.getSupplierCode());
inventoryTransactionList.add(inventoryTransaction);
}
|
|
1152
1153
1154
1155
1156
1157
1158
|
if(inventoryDetails != null && inventoryDetails.size() > 0) {
if (inventoryDetailService.saveOrUpdateBatch(inventoryDetails)) {
//更新库存明细成功后,写入库存交易
inventoryTransactionService.saveBatch(inventoryTransactionList);
} else {
throw new ServiceException("库存明细更新错误!");
}
|
|
1159
|
}
|
|
1160
|
|
|
1161
|
}
|
|
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
|
//更新托盘、库位状态
Location temp1 = new Location(); //源库位
temp1.setCode(taskDetail.getFromLocation());
temp1.setWarehouseCode(ShiroUtils.getWarehouseCode());
LambdaQueryWrapper<Location> lambdaQueryWrapper1 = Wrappers.lambdaQuery(temp1);
Location loc1 = locationService.getOne(lambdaQueryWrapper1);
Location temp2 = new Location();//目的库位
temp2.setCode(taskDetail.getToLocation());
temp2.setWarehouseCode(ShiroUtils.getWarehouseCode());
LambdaQueryWrapper<Location> lambdaQueryWrapper2 = Wrappers.lambdaQuery(temp2);
Location loc2 = locationService.getOne(lambdaQueryWrapper2);
loc2.setContainerCode(loc1.getContainerCode());
loc2.setStatus("empty");
loc1.setContainerCode("");
loc1.setStatus("empty");
locationService.saveOrUpdate(loc1);
locationService.saveOrUpdate(loc2);
|
|
1180
1181
1182
1183
1184
1185
1186
|
Container container = containerService.findAllByCode(task.getContainerCode());
container.setLocationCode(task.getToLocation());
if (!containerService.updateById(container)){
throw new ServiceException("更新容器失败");
}
|
|
1187
|
//更新taskHeader状态
|
|
1188
|
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1189
1190
1191
1192
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
taskHeaderService.saveOrUpdate(task);
//更新taskDetail状态
|
|
1193
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1194
1195
1196
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setLastUpdated(new Date());
taskDetailService.saveOrUpdate(taskDetail);
|
|
1197
1198
|
}
|
|
1199
|
/**
|
|
1200
1201
|
* 生成
* 出库查看
|
|
1202
|
* 任务
|
|
1203
|
*/
|
|
1204
|
@Override
|
|
1205
|
@Transactional(rollbackFor = Exception.class)
|
|
1206
1207
|
public AjaxResult createCheckOutTask(String[] ids) {
|
|
1208
1209
|
for (String id : ids) {
InventoryHeader inventoryHeader = inventoryHeaderService.getById(Integer.parseInt(id));
|
|
1210
|
//校验库位是否锁定
|
|
1211
1212
1213
1214
1215
1216
|
//检查库位容器
Location temp = new Location();
temp.setCode(inventoryHeader.getLocationCode());
temp.setWarehouseCode(inventoryHeader.getWarehouseCode());
LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery(temp);
Location loc = locationService.getOne(lambdaQueryWrapper);
|
|
1217
|
if (loc == null) {
|
|
1218
1219
|
throw new ServiceException("库存没有库位!");
}
|
|
1220
|
if (!"empty".equals(loc.getStatus())) {
|
|
1221
|
throw new ServiceException(inventoryHeader.getLocationCode() + "状态非空闲,操作失败");
|
|
1222
|
}
|
|
1223
1224
|
if (StringUtils.isEmpty(loc.getContainerCode())) {
throw new ServiceException(inventoryHeader.getLocationCode() + "没有容器,操作失败");
|
|
1225
1226
1227
1228
1229
1230
1231
|
}
//通过库存头,找到库存明细
InventoryDetail inventoryDetail = new InventoryDetail();
inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryDetail);
|
|
1232
|
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
|
|
1233
1234
1235
1236
1237
|
//写入任务主表
TaskHeader taskHeader = new TaskHeader();
taskHeader.setWarehouseCode(inventoryHeader.getWarehouseCode());
taskHeader.setCompanyCode(inventoryHeader.getCompanyCode());//货主
|
|
1238
1239
|
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_WORK);
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_VIEW);
|
|
1240
|
taskHeader.setContainerCode(inventoryHeader.getContainerCode());
|
|
1241
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
1242
1243
1244
1245
1246
1247
1248
1249
1250
|
taskHeader.setFromLocation(inventoryHeader.getLocationCode());
taskHeader.setToLocation(inventoryHeader.getLocationCode());
taskHeader.setCreated(new Date());
taskHeader.setCreatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdated(new Date());
taskHeaderMapper.insert(taskHeader);
//分拆库存明细,并写入任务细表
List<TaskDetail> taskDetails = new ArrayList<>();
|
|
1251
|
for (InventoryDetail item : inventoryDetailList) {
|
|
1252
|
item.setLockedQty(item.getQty());
|
|
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(taskHeader.getId());//主单ID
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setInternalTaskType(taskHeader.getTaskType());
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setCompanyCode(item.getCompanyCode());
taskDetail.setFromLocation(taskHeader.getFromLocation());
taskDetail.setToLocation(taskHeader.getToLocation());
taskDetail.setContainerCode(taskHeader.getContainerCode());
taskDetail.setCreated(new Date());
taskDetail.setCreatedBy(ShiroUtils.getLoginName());
taskDetail.setLastUpdated(new Date());
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetails.add(taskDetail);
|
|
1267
|
if (!inventoryDetailService.updateById(item)) {throw new BusinessException("锁定库存失败");}
|
|
1268
1269
1270
|
}
if (taskDetailService.saveBatch(taskDetails)) {
//锁定库位状态
|
|
1271
|
locationService.updateStatus(inventoryHeader.getLocationCode(), "lock");
|
|
1272
1273
1274
|
} else {
throw new ServiceException("出库查看任务明细生成失败!");
}
|
|
1275
|
|
|
1276
1277
1278
|
}
return AjaxResult.success("出库查看任务生成成功!");
}
|
|
1279
|
|
|
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
|
/**库存监控出库查看*/
@Override
@Transactional
public AjaxResult checkLocationCode(String locationCode){
Location location = new Location();
location.setCode(locationCode);
location.setWarehouseCode(ShiroUtils.getWarehouseCode());
location.setDeleted(false);
LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery(location);
Location loc = locationService.getOne(lambdaQueryWrapper);
if(!loc.getStatus().equals("empty")){
return AjaxResult.error(locationCode+"状态非空闲,操作失败");
}
if(StringUtils.isEmpty(loc.getContainerCode())){
return AjaxResult.error(locationCode+"没有托盘,操作失败");
}
//生成出库查看任务
TaskHeader task = new TaskHeader();
task.setWarehouseCode(ShiroUtils.getWarehouseCode());
task.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
//这里默认一个0
task.setTaskType(900);
// task.setStation(1);
// task.setPort(1003);
// if(loc.getType().equals("L")){
// task.setZoneCode("LK");
// }
// task.setRoadway(loc.getRoadway());
// task.setContainerCode(loc.getContainerCode());
// task.setFirstStatus((short)1);
// task.setLastStatus((short)1);
// task.setSourceLocation(loc.getCode());
// task.setDestinationLocation(loc.getCode());
// task.setCreated(new Date());
// task.setCreatedBy(ShiroUtils.getLoginName());
// task.setBeginTime(new Date());
// insert(task);
// //出库时先锁库位状态
// loc.setStatus("lock");
// locationService.updateByModel(loc);
return AjaxResult.success(task.getId());
}
|
|
1326
|
/**
|
|
1327
|
* 完成
|
|
1328
|
* 出库查看
|
|
1329
|
* 更新状态,解锁库存
|
|
1330
|
*/
|
|
1331
|
@Override
|
|
1332
|
@Transactional(rollbackFor = Exception.class)
|
|
1333
|
public AjaxResult completeSeeOutTask(TaskHeader taskHeader) {
|
|
1334
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1335
1336
1337
1338
1339
1340
1341
1342
1343
|
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
taskHeader.setLastUpdated(new Date()); //更新时间
//task更新明细单总的状态
TaskDetail taskDetail = new TaskDetail();
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setTaskId(taskHeader.getId());
LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(taskDetail);
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaQueryWrapper);//查询子单
|
|
1344
|
List<TaskDetail> list = new CopyOnWriteArrayList<>();
|
|
1345
|
for (TaskDetail item : taskDetailList) {
|
|
1346
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1347
1348
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
|
|
1349
|
list.add(item);
|
|
1350
|
}
|
|
1351
1352
|
if (taskDetailService.saveOrUpdateBatch(list) == false ||
taskHeaderService.saveOrUpdate(taskHeader) == false) {
|
|
1353
1354
|
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1355
|
//释放库位状态
|
|
1356
|
locationService.updateStatus(taskHeader.getFromLocation(), "empty");
|
|
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
|
LambdaQueryWrapper<InventoryDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(InventoryDetail::getLocationCode, taskHeader.getFromLocation())
.eq(InventoryDetail::getContainerCode, taskHeader.getContainerCode());
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(queryWrapper);
if (!inventoryDetailList.isEmpty()) {
for (InventoryDetail inventoryDetail : inventoryDetailList) {
inventoryDetail.setLockedQty(new BigDecimal(0));
if (!inventoryDetailService.updateById(inventoryDetail)) {throw new BusinessException("解锁库存失败");}
}
}
|
|
1367
1368
1369
1370
|
return AjaxResult.success("完成出库查看任务");
}
/**
|
|
1371
|
* 盘点完成
|
|
1372
|
*
|
|
1373
1374
1375
1376
|
* @param taskHeader
* @return
*/
@Override
|
|
1377
|
@Transactional(rollbackFor = Exception.class)
|
|
1378
|
public AjaxResult completeCycleCountTask(TaskHeader taskHeader) {
|
|
1379
1380
1381
|
/*盘点完成,传入任务主单,查出任务明细,通过任务明细查找盘点的明细单,
完成任务同时,修改盘点细单和主单的状态,完成后库存锁复位*/
//修改任务主单状态
|
|
1382
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
|
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
taskHeader.setLastUpdated(new Date()); //更新时间
//task更新明细单状态
TaskDetail taskDetail = new TaskDetail();
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setTaskId(taskHeader.getId());
LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(taskDetail);
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaQueryWrapper);//查询子单
List<TaskDetail> list = new CopyOnWriteArrayList<>();
//修改任务明细状态的同时查找到盘点明细的条目并修改状态,最后修改主单状态
List<CycleCountDetail> cycleCountDetailList = new CopyOnWriteArrayList<>();
|
|
1395
|
for (TaskDetail item : taskDetailList) {
|
|
1396
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1397
1398
1399
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
list.add(item);
|
|
1400
|
|
|
1401
|
CycleCountDetail cycleCountDetail = cycleCountDetailService.getById(item.getBillDetailId());//盘点明细
|
|
1402
|
cycleCountDetail.setEnableStatus(QuantityConstant.CYCLECOUNT_STATUS_COMPLETED);
|
|
1403
1404
1405
1406
1407
1408
1409
1410
|
cycleCountDetail.setCompletedBy(ShiroUtils.getLoginName());
cycleCountDetail.setCompletedAt(new Date());
cycleCountDetailList.add(cycleCountDetail);
//取消库存盘点锁
InventoryDetail inventoryDetail = inventoryDetailService.getById(cycleCountDetail.getInventoryDetailId());
inventoryDetail.setLockCode("");
inventoryDetailService.saveOrUpdate(inventoryDetail);
}
|
|
1411
|
if (taskHeaderService.saveOrUpdate(taskHeader) == false ||
|
|
1412
1413
1414
1415
1416
1417
1418
1419
1420
|
taskDetailService.saveOrUpdateBatch(list) == false ||
cycleCountDetailService.saveOrUpdateBatch(cycleCountDetailList) == false) {
throw new ServiceException("盘点任务单据状态更新失败!");
}
//更新主单状态
cycleCountHeaderService.updataHeaderStatus(cycleCountDetailList.get(0).getCycleCountHeadCode());
//释放库位
locationService.updateStatus(cycleCountDetailList.get(0).getLocationCode(), "empty");
return AjaxResult.success("完成盘点任务");
|
|
1421
1422
1423
1424
|
}
/**
|
|
1425
|
* 完成空托盘入库任务
|
|
1426
|
*
|
|
1427
1428
|
* @param taskHeader
*/
|
|
1429
|
@Transactional(rollbackFor = Exception.class)
|
|
1430
1431
1432
|
public void completeEmptyIn(TaskHeader taskHeader) {
//完成任务,修改主单和明细状态
|
|
1433
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
|
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdated(new Date());
//taskHeaderService.saveOrUpdate(taskHeader);
//taskDetail更新明细单总的状态
TaskDetail taskDetail = new TaskDetail();
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setTaskId(taskHeader.getId());
LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(taskDetail);
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaQueryWrapper);//查询子单
for (TaskDetail item : taskDetailList) {
|
|
1445
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1446
1447
1448
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
}
|
|
1449
1450
|
if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false ||
taskHeaderService.saveOrUpdate(taskHeader) == false) {
|
|
1451
1452
|
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1453
|
//解锁容器,更新库位
|
|
1454
|
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), taskHeader.getToLocation(), "empty");
|
|
1455
|
//解锁库位,更新容器
|
|
1456
|
locationService.updateContainerCodeAndStatus(taskHeader.getToLocation(), taskHeader.getContainerCode(), "empty");
|
|
1457
|
|
|
1458
1459
1460
1461
1462
1463
1464
1465
1466
|
//写入库存头表
InventoryHeader inventoryHeader = new InventoryHeader();
inventoryHeader.setWarehouseCode(taskHeader.getWarehouseCode());
inventoryHeader.setLocationCode(taskHeader.getToLocation());
inventoryHeader.setContainerCode(taskHeader.getContainerCode());
inventoryHeader.setContainerStatus("empty");
inventoryHeader.setCompanyCode(taskHeader.getCompanyCode());
inventoryHeader.setMaterialSkuQty("0");
inventoryHeader.setTotalWeight("0");
|
|
1467
|
inventoryHeader.setTotalQty(new BigDecimal(0));
|
|
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
|
inventoryHeader.setTotalLines(0);
inventoryHeader.setProjectNos("");
inventoryHeader.setBatchs("");
inventoryHeader.setLots("");
inventoryHeader.setLockRemark("");
inventoryHeader.setCreated(new Date());
inventoryHeader.setCreatedBy(ShiroUtils.getLoginName());
inventoryHeader.setLastUpdated(new Date());
inventoryHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
Boolean j = inventoryHeaderService.save(inventoryHeader);
if(!j){
throw new ServiceException("新增空托库存头失败!");
}
|
|
1482
1483
1484
1485
|
}
/**
* 完成空托盘出库任务
|
|
1486
|
*
|
|
1487
1488
|
* @param taskHeader
*/
|
|
1489
|
@Override
|
|
1490
|
@Transactional(rollbackFor = Exception.class)
|
|
1491
|
public AjaxResult completeEmptyOut(TaskHeader taskHeader) {
|
|
1492
|
|
|
1493
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
|
taskHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
taskHeader.setLastUpdated(new Date());
//taskHeaderService.saveOrUpdate(taskHeader);
//taskDetail更新明细单总的状态
TaskDetail taskDetail = new TaskDetail();
taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
taskDetail.setTaskType(taskHeader.getTaskType());
taskDetail.setTaskId(taskHeader.getId());
LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(taskDetail);
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaQueryWrapper);//查询子单
for (TaskDetail item : taskDetailList) {
|
|
1505
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1506
1507
1508
1509
1510
1511
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
}
if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false || taskHeaderService.saveOrUpdate(taskHeader) == false) {
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1512
1513
1514
1515
|
//更新货位
locationService.updateContainerCodeAndStatus(taskHeader.getFromLocation(), "", "empty");
//更新容器信息
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), "", "empty");
|
|
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
|
//删除库存头表
InventoryHeader tmp = new InventoryHeader();
tmp.setContainerStatus("empty");
tmp.setContainerCode(taskHeader.getContainerCode());
tmp.setLocationCode(taskHeader.getFromLocation());
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(tmp);
Boolean j = inventoryHeaderService.remove(inventoryHeaderLambdaQueryWrapper);
if(!j){
throw new ServiceException("空库位记录删除失败!");
}
return AjaxResult.success("空托出库完成");
|
|
1527
1528
|
}
|
|
1529
1530
|
/**
* 创建上架任务
|
|
1531
|
*
|
|
1532
1533
1534
1535
|
* @param ids
* @return
*/
@Override
|
|
1536
|
@Transactional(rollbackFor = Exception.class)
|
|
1537
|
public AjaxResult createReceiptTask(List<Integer> ids) {
|
|
1538
|
for (Integer id : ids) {
|
|
1539
|
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(id);
|
|
1540
|
if (receiptContainerHeader == null) {
|
|
1541
|
throw new ServiceException("任务不存在!");
|
|
1542
1543
1544
|
}
if (!receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode())) {
|
|
1545
|
throw new ServiceException("任务不在当前仓库!");
|
|
1546
1547
|
}
|
|
1548
1549
1550
1551
1552
1553
1554
1555
|
//锁定容器
Container container = new Container();
container.setStatus("lock");
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, receiptContainerHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
//查询入库组盘明细
|
|
1556
|
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
|
|
1557
|
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptContainerId, id);
|
|
1558
|
List<ReceiptContainerDetail> list = receiptContainerDetailService.list(containerDetailLambda);
|
|
1559
|
|
|
1560
|
if (list.size() < 1) {
|
|
1561
|
throw new ServiceException("没有组盘明细,请先组盘!");
|
|
1562
|
}
|
|
1563
1564
|
if (receiptContainerHeader.getStatus() == QuantityConstant.RECEIPT_CONTAINER_BUILD.intValue()) {
if (receiptContainerHeader.getStatus().intValue() < QuantityConstant.RECEIPT_CONTAINER_TASK) {
|
|
1565
|
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK.intValue());
|
|
1566
1567
1568
1569
|
receiptContainerHeaderService.updateById(receiptContainerHeader);
}
//添加任务主表
TaskHeader task = new TaskHeader();
|
|
1570
|
task.setAllocationHeadId(receiptContainerHeader.getId());
|
|
1571
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHELF);
|
|
1572
1573
1574
1575
1576
1577
|
task.setWarehouseCode(receiptContainerHeader.getWarehouseCode());
task.setCompanyCode(receiptContainerHeader.getCompanyCode());
task.setTaskType(Integer.valueOf(receiptContainerHeader.getTaskType()));
task.setFromLocation(receiptContainerHeader.getFromLocation());
task.setToLocation(receiptContainerHeader.getToLocation());
task.setContainerCode(receiptContainerHeader.getContainerCode());
|
|
1578
|
task.setRecvDock(receiptContainerHeader.getRecvDock());
|
|
1579
1580
|
task.setCreated(new Date());
task.setCreatedBy(ShiroUtils.getLoginName());
|
|
1581
|
if (this.save(task)) {
|
|
1582
|
//添加任务明细表
|
|
1583
|
int conatinQty = 0;
|
|
1584
|
for (ReceiptContainerDetail item : list) {
|
|
1585
1586
1587
1588
1589
1590
|
LambdaQueryWrapper<ContainerCapacity> lambdaQueryWrapper = Wrappers.lambdaQuery();
String[] containCodeSplit = task.getContainerCode().split("\\D");
String containType = containCodeSplit[0];
lambdaQueryWrapper.eq(ContainerCapacity::getContainerType, task.getContainerCode())
.eq(ContainerCapacity::getMaterialCode, item.getMaterialCode())
.eq(ContainerCapacity::getWarehouseCode, ShiroUtils.getWarehouseCode())
|
|
1591
|
.eq(ContainerCapacity::getEnable, 0);
|
|
1592
1593
|
ContainerCapacity containerCapacity = containerCapacityService.getOne(lambdaQueryWrapper);
|
|
1594
1595
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
|
|
1596
|
taskDetail.setTaskType(Integer.valueOf(receiptContainerHeaderService.getById(item.getReceiptContainerId()).getTaskType()));
|
|
1597
|
taskDetail.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHELF);
|
|
1598
|
taskDetail.setWarehouseCode(task.getWarehouseCode());
|
|
1599
|
taskDetail.setAllocationId(item.getReceiptId());
|
|
1600
1601
1602
1603
|
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setMaterialCode(item.getMaterialCode());
taskDetail.setMaterialName(item.getMaterialName());
|
|
1604
1605
|
taskDetail.setMaterialSpec(item.getMaterialSpec());
taskDetail.setMaterialUnit(item.getMaterialUnit());
|
|
1606
1607
1608
|
taskDetail.setBillCode(item.getReceiptCode());
taskDetail.setBillDetailId(item.getReceiptDetailId());
taskDetail.setBillCode(item.getReceiptCode());
|
|
1609
|
taskDetail.setQty(item.getQty());
|
|
1610
1611
1612
1613
|
taskDetail.setContainerCode(task.getContainerCode());
taskDetail.setFromLocation(task.getFromLocation());
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setBatch(item.getBatch());
|
|
1614
|
taskDetail.setProjectNo(item.getProjectNo());
|
|
1615
|
if (containerCapacity != null) {
|
|
1616
1617
1618
|
conatinQty += (int) Math.floor(item.getQty().intValue() / containerCapacity.getQty().intValue());
taskDetail.setContainQty((int) Math.floor(item.getQty().intValue() / containerCapacity.getQty().intValue()));
}
|
|
1619
|
if (!taskDetailService.save(taskDetail)) {
|
|
1620
1621
1622
|
throw new ServiceException("生成任务明细失败");
}
|
|
1623
|
//更新入库组盘明细状态
|
|
1624
|
item.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK);
|
|
1625
|
if (!receiptContainerDetailService.updateById(item)) {
|
|
1626
1627
|
throw new ServiceException("更新入库组盘明细状态出错");
}
|
|
1628
|
|
|
1629
1630
1631
|
/**
* 修改明细状态为上架
*/
|
|
1632
|
ReceiptDetail receiptDetail = receiptDetailService.getById(item.getReceiptDetailId());
|
|
1633
1634
|
receiptDetail.setProcessStamp(String.valueOf(QuantityConstant.RECEIPT_HEADER_SHELF));
if (!receiptDetailService.updateById(receiptDetail)) {
|
|
1635
|
throw new ServiceException("更新入库单详情失败");
|
|
1636
|
}
|
|
1637
1638
1639
|
//更新头表状态
receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
|
|
1640
|
}
|
|
1641
1642
|
task.setContainQty(conatinQty);
|
|
1643
|
if (!taskHeaderService.updateById(task)) {
|
|
1644
1645
|
throw new ServiceException("更新任务头表容器数量失败");
}
|
|
1646
1647
|
} else {
throw new ServiceException("生成任务头表失败");
|
|
1648
1649
1650
|
}
}
}
|
|
1651
|
return AjaxResult.success("生成上架任务成功");
|
|
1652
|
}
|
|
1653
|
|
|
1654
1655
|
/**
* 完成出库任务
|
|
1656
|
*/
|
|
1657
|
@Override
|
|
1658
|
@Transactional(rollbackFor = Exception.class)
|
|
1659
1660
1661
1662
1663
1664
1665
|
public void completeShipmentTask(TaskHeader task) {
//获取所有子任务
TaskDetail condition = new TaskDetail();
condition.setTaskId(task.getId());
LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery(condition);
List<TaskDetail> taskDetails = taskDetailService.list(lambdaQueryWrapper);
List<Integer> shipmentHeadIds = new ArrayList<>();
|
|
1666
1667
|
for (TaskDetail taskDetail : taskDetails) {
if (taskDetail.getStatus() < QuantityConstant.TASK_STATUS_RUNNING) {
|
|
1668
1669
1670
1671
1672
1673
1674
1675
|
//获取出库子货箱
ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getById(taskDetail.getAllocationId());
//取出子单据
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
//暂存id,为更新单据状态准备
shipmentHeadIds.add(shipmentDetail.getShipmentId());
//获取对应库存记录
InventoryDetail inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
|
|
1676
|
if (inventoryDetail == null) {
|
|
1677
1678
1679
|
throw new ServiceException("任务明细对应的库存ID【" + taskDetail.getToInventoryId().toString() + "】不存在!");
}
BigDecimal orignalQty = inventoryDetail.getQty();
|
|
1680
1681
|
//减扣库存单
InventoryHeader inventoryHeader = inventoryHeaderService.getById(inventoryDetail.getInventoryHeaderId());
|
|
1682
|
inventoryHeader.setTotalQty(inventoryDetail.getQty().subtract(taskDetail.getQty()));
|
|
1683
|
//扣减库存明细
|
|
1684
1685
|
inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(taskDetail.getQty()));
inventoryDetail.setQty(inventoryDetail.getQty().subtract(taskDetail.getQty()));
|
|
1686
|
if (inventoryDetail.getQty().compareTo(new BigDecimal("0")) == 0 && inventoryDetail.getTaskQty().compareTo(new BigDecimal("0")) == 0) {
|
|
1687
1688
|
//如果库存没有了,就删除这个库存
inventoryDetailService.removeById(inventoryDetail.getId());
|
|
1689
|
inventoryHeaderService.removeById(inventoryHeader.getId());
|
|
1690
|
} else {
|
|
1691
1692
|
//否则更新这个库存
inventoryDetailService.updateById(inventoryDetail);
|
|
1693
|
inventoryHeaderService.updateById(inventoryHeader);
|
|
1694
1695
|
}
//设置子任务状态为已执行
|
|
1696
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1697
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
1698
|
taskDetail.setLastUpdated(new Date());//完成时间
|
|
1699
1700
1701
1702
1703
1704
1705
|
taskDetailService.updateById(taskDetail);
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
inventoryTransaction.setCompanyCode(shipmentDetail.getCompanyCode());
inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode());
|
|
1706
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
|
|
1707
|
inventoryTransaction.setMaterialCode(shipmentDetail.getMaterialCode());
|
|
1708
1709
1710
|
inventoryTransaction.setMaterialName(shipmentDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(shipmentDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(shipmentDetail.getMaterialUnit());
|
|
1711
1712
1713
1714
|
inventoryTransaction.setBillCode(taskDetail.getBillCode());
inventoryTransaction.setBillDetailId(shipmentDetail.getId());
inventoryTransaction.setBatch(shipmentDetail.getBatch());
inventoryTransaction.setLot(shipmentDetail.getLot());
|
|
1715
1716
1717
|
inventoryTransaction.setProjectNo(shipmentDetail.getProjectNo());
inventoryTransaction.setQcCheck(inventoryDetail.getQcCheck());
inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode());
|
|
1718
1719
1720
1721
|
inventoryTransaction.setManufactureDate(shipmentDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(shipmentDetail.getExpirationDate());
inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
//这里取反,更符合出库的语义,同时方便对记录进行统计
|
|
1722
|
inventoryTransaction.setTaskQty(taskDetail.getQty());
|
|
1723
1724
1725
1726
1727
1728
1729
|
// inventoryTransaction.setCostPrice(shipmentDetail.);
inventoryTransaction.setCreated(null);
inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
inventoryTransactionService.save(inventoryTransaction);
// //更新单据状态
// shipmentHeaderService.updateShipmentStatus(shipmentHeader.getId());
}
|
|
1730
|
/* 物料预警*/
|
|
1731
1732
1733
|
// configWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getMaterialName());
// /* 空库位剩余数量预警*/
// configWarningService.emptyLocationWarning();
|
|
1734
1735
|
}
//设置主任务为已执行
|
|
1736
|
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1737
1738
1739
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
taskHeaderService.updateById(task);
|
|
1740
1741
|
|
|
1742
|
//将库位状态改为空闲,如果是整出的对应的容器也清空
|
|
1743
1744
|
LambdaQueryWrapper<Location> lam = Wrappers.lambdaQuery();
lam.eq(Location::getCode, task.getFromLocation());
|
|
1745
|
Location locationRecord = locationService.getOne(lam);
|
|
1746
1747
|
if (lam == null) {
throw new ServiceException("系统没有" + task.getToLocation() + "库位");
|
|
1748
|
}
|
|
1749
|
locationRecord.setStatus("empty");
|
|
1750
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
|
|
1751
1752
|
locationRecord.setContainerCode("");
}
|
|
1753
|
locationService.updateById(locationRecord);
|
|
1754
|
//如果是整出,删掉这个库位上的这个托盘,否则更改托盘状态
|
|
1755
|
LambdaQueryWrapper<Container> containerLam = Wrappers.lambdaQuery();
|
|
1756
|
containerLam.eq(Container::getCode, task.getContainerCode());
|
|
1757
|
Container ctn = containerService.getOne(containerLam);
|
|
1758
|
if (ctn == null) {
|
|
1759
1760
|
throw new ServiceException("系统无此容器");
}
|
|
1761
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
|
|
1762
|
if ("LS".equals(ctn.getContainerType())) {
|
|
1763
|
Boolean flag = containerService.removeById(ctn.getId());
|
|
1764
|
if (flag == false) {
|
|
1765
1766
|
throw new ServiceException("删除临时容器失败");
}
|
|
1767
|
} else {
|
|
1768
1769
|
containerService.updateLocationCodeAndStatus(task.getContainerCode(), "", "empty");
}
|
|
1770
|
} else {
|
|
1771
1772
1773
1774
|
//查询是否存在关联的库存,入如果没有就修改容器状态为empty
InventoryDetail inventoryCondition = new InventoryDetail();
inventoryCondition.setLocationCode(task.getToLocation());
LambdaQueryWrapper<InventoryDetail> inventoryDetaillambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
1775
1776
|
inventoryDetaillambdaQueryWrapper.eq(InventoryDetail::getLocationCode, task.getToLocation());
List<InventoryDetail> detailList = inventoryDetailService.list();
|
|
1777
|
//库存查询不到该容器就把容器状态改为可用
|
|
1778
1779
|
if (detailList.size() < 1) {
Container container = new Container();
|
|
1780
|
container.setCode(task.getContainerCode());
|
|
1781
|
condition.setToLocation("");
|
|
1782
|
LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
1783
1784
|
containerLambdaUpdateWrapper.eq(Container::getCode, task.getContainerCode());
containerService.update(container, containerLambdaUpdateWrapper);
|
|
1785
1786
|
}
}
|
|
1787
|
//设置出库货箱状态为拣货任务完成
|
|
1788
|
for (TaskDetail taskDetail : taskDetails) {
|
|
1789
|
ShipmentContainerDetail shipmentContainerDetail = new ShipmentContainerDetail();
|
|
1790
|
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS);
|
|
1791
1792
1793
1794
1795
1796
1797
|
shipmentContainerDetail.setLastUpdated(new Date());
shipmentContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<ShipmentContainerDetail> shipmentContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
shipmentContainerDetailLambdaUpdateWrapper.eq(ShipmentContainerDetail::getId, taskDetail.getAllocationId());
if (!shipmentContainerDetailService.update(shipmentContainerDetail, shipmentContainerDetailLambdaUpdateWrapper)) {
throw new ServiceException("更新组盘明细状态失败");
}
|
|
1798
|
}
|
|
1799
|
//设置出库货箱表头状态为拣货任务完成
|
|
1800
|
ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
|
|
1801
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS);
|
|
1802
1803
1804
|
shipmentContainerHeader.setLastUpdated(new Date());
shipmentContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
1805
1806
|
shipmentContainerHeaderLambdaUpdateWrapper.eq(ShipmentContainerHeader::getId, task.getAllocationHeadId());
if (!shipmentContainerHeaderService.update(shipmentContainerHeader, shipmentContainerHeaderLambdaUpdateWrapper)) {
|
|
1807
|
throw new ServiceException("更新组盘头状态失败");
|
|
1808
1809
|
}
//修改出库单状态
|
|
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
|
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, task.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
HashSet<Integer> ids = new HashSet<>();
for (TaskDetail taskDeatails : taskDetailList) {
LambdaQueryWrapper<ShipmentDetail> shipmentDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentDetailLambdaQueryWrapper.eq(ShipmentDetail::getId, taskDeatails.getBillDetailId());
ShipmentDetail shipmentDetail = shipmentDetailService.getOne(shipmentDetailLambdaQueryWrapper);
if (shipmentDetail == null) {
throw new ServiceException("查找出库单明细失败");
}
if (shipmentDetail.getShipQty().compareTo(shipmentDetail.getRequestQty()) == 0) {
shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
shipmentDetailService.updateById(shipmentDetail);
}
ids.add(shipmentDetail.getShipmentId());
}
|
|
1828
|
|
|
1829
1830
1831
1832
1833
1834
|
for (Integer id : ids) {
ShipmentHeader shipmentHeader = shipmentHeaderService.getById(id);
if (shipmentHeader != null) {
Map<String, Integer> status = shipmentDetailService.selectStatus(shipmentHeader.getId());
Integer maxStatus = status.get("maxStatus");
Integer minStatus = status.get("minStatus");
|
|
1835
|
if (maxStatus.equals(QuantityConstant.SHIPMENT_HEADER_COMPLETED)) {
|
|
1836
1837
|
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
|
|
1838
|
if (minStatus.equals(QuantityConstant.SHIPMENT_HEADER_COMPLETED)) {
|
|
1839
1840
1841
1842
1843
1844
1845
|
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
shipmentHeader.setLastUpdated(new Date());
shipmentHeaderService.updateById(shipmentHeader);
}
}
|
|
1846
|
}
|
|
1847
|
|
|
1848
1849
1850
1851
|
/**
* 自动空托出库
* */
@Override
|
|
1852
|
@Transactional(rollbackFor = Exception.class)
|
|
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
|
public AjaxResult createAutoEmptyOut(String warehouseCode){
/*先查询容器表,选中空托盘,再查询库存核实*/
//该容器中有库位信息,并且状态是空
List<Location> locationsList = locationService.selectContainerEmpty(warehouseCode);
if(locationsList.size() == 0){
throw new ServiceException("立库中没有空容器!");
}
//根据入库顺序正序排列取第一个
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("选中的库位容器错误,请确认库位和容器!");
}
//生成空容器出库任务
inventoryHeaderService.createEmptyOut(container.getCode(), location.getCode());
return AjaxResult.success("空容器出库任务已下发!",container.getCode());
|
|
1874
|
}
|
|
1875
|
|
|
1876
|
/**
|
|
1877
|
* 任务自动分配库位
|
|
1878
1879
1880
1881
|
*
* */
@Override
@Transactional(rollbackFor = Exception.class)
|
|
1882
1883
|
public String getLocationCode(Integer taskId, String weight){
String warehouseCode = ShiroUtils.getWarehouseCode();
|
|
1884
1885
1886
1887
|
TaskHeader task = this.getById(taskId);
if (task == null) {
throw new ServiceException("找不到id为"+ taskId +"的任务");
}
|
|
1888
|
if (StringUtils.isNotEmpty(task.getToLocation())) {
|
|
1889
|
throw new ServiceException("任务已经有目的库位");
|
|
1890
|
}
|
|
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
|
if(!warehouseCode.equals(task.getWarehouseCode())){
throw new ServiceException("仓库错误!");
}
/*if(task.getIsDoubleIn() != 1 ){
if(StringUtils.isNotEmpty(task.getToLocation())){
return AjaxResult.success("已经存在目的库位不再分配!");
}
}*/
//查询容器,根据容器类型分配库位
Container tmp = new Container();
tmp.setCode(task.getContainerCode());
tmp.setWarehouseCode(warehouseCode);
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(tmp);
Container container = containerService.getOne(containerLambdaQueryWrapper);
//库位筛选
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getWarehouseCode,task.getWarehouseCode())
.eq(Location::getContainerCode,"")
.eq(Location::getStatus,"empty")
.eq(Location::getDeleted,false);
/*if(container.getContainerType().equals("L")){
locationLambdaQueryWrapper.eq(Location::getRoadway,"2")
.le(Location::getIColumn,8); //小于等于
}
else if(container.getContainerType().equals("M")) {
locationLambdaQueryWrapper.eq(Location::getRoadway,"2")
.gt(Location::getIColumn,8);//大于
}
else if(container.getContainerType().equals("S")){
locationLambdaQueryWrapper.eq(Location::getRoadway,"1");
}
else if(container.getContainerType().equals("D")){
return AjaxResult.success("地面库区不自动分配库位");
}*/
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
if (locations.size() == 0) {
throw new ServiceException("没有空闲库位!");
}
//随机取库位
Random rand = new Random();
Location location = locations.get(rand.nextInt(locations.size()));
if (location == null) {
throw new ServiceException("库位分配错误!");
}
//锁定库位
locationService.updateStatus(location.getCode(),"lock");
//给组盘分配库位
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(task.getAllocationHeadId());
receiptContainerHeader.setToLocation(location.getCode());
|
|
1942
1943
1944
1945
|
receiptContainerHeader.setContainerCode(container.getCode());
receiptContainerHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
receiptContainerHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
|
//LambdaQueryWrapper<ReceiptContainerHeader> rchlqw = Wrappers.lambdaQuery(receiptContainerHeader);
receiptContainerHeaderService.saveOrUpdate(receiptContainerHeader);
//组盘明细分配库位
ReceiptContainerDetail tmpe = new ReceiptContainerDetail();
tmpe.setReceiptContainerId(task.getAllocationHeadId());
tmpe.setWarehouseCode(task.getWarehouseCode());
LambdaQueryWrapper<ReceiptContainerDetail> receiptContainerDetailLambda = Wrappers.lambdaQuery(tmpe);
List<ReceiptContainerDetail> receiptContainerDetailList = receiptContainerDetailService.list(receiptContainerDetailLambda);
//stream修改库位
receiptContainerDetailList
.stream()
.forEach(r -> r.setLocationCode(receiptContainerHeader.getToLocation()));
receiptContainerDetailService.updateBatchById(receiptContainerDetailList);
//给子任务分配库位
TaskDetail tdtmp = new TaskDetail();
tdtmp.setTaskId(task.getId());
tdtmp.setWarehouseCode(task.getWarehouseCode());
tdtmp.setTaskType(task.getTaskType());
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery(tdtmp);
List<TaskDetail> taskDetails = taskDetailService.list(taskDetailLambdaQueryWrapper);
taskDetails.stream().forEach(t -> t.setToLocation(task.getToLocation()));
taskDetailService.updateBatchById(taskDetails);
//给任务分配库位
task.setToLocation(location.getCode());
task.setWeight(weight);
//task.setFromLocation(location.getCode());
//LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(task);
this.saveOrUpdate(task);
|
|
1974
|
return location.getCode();
|
|
1975
1976
1977
|
}
|
|
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
|
/**
* 自动分配库位
* @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("任务已经有目的库位,不需要再分配");
}
|
|
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
|
// Location location = new Location();
// location.setWarehouseCode(ShiroUtils.getWarehouseCode());
//
// location.setContainerCode("");
// location.setStatus("empty");
// location.setDeleted(false);
// if("M".equals(taskHeader.getContainerCode().substring(0,1))){
// if (high.intValue() == 1) {
// location.setILayer(5);
// }
// }
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getWarehouseCode,ShiroUtils.getWarehouseCode())
.eq(Location::getContainerCode,"")
.eq(Location::getStatus,"empty")
.eq(Location::getDeleted,false);
// location = locationService.getOne(locationLambdaQueryWrapper);
// if (location == null) {
// throw new ServiceException("没有对应库位可以分配给容器了!");
// }
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
if (locations.size() == 0) {
throw new ServiceException("没有空闲库位!");
|
|
2017
|
}
|
|
2018
2019
2020
|
//随机取库位
Random rand = new Random();
Location location = locations.get(rand.nextInt(locations.size()));
|
|
2021
|
if (location == null) {
|
|
2022
|
throw new ServiceException("库位分配错误!");
|
|
2023
2024
|
}
//锁定库位
|
|
2025
|
locationService.updateStatus(location.getCode(),"lock");
|
|
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
|
//给组盘分配库位
int internalTaskType = taskHeader.getInternalTaskType();
if(internalTaskType == QuantityConstant.TASK_TYPE_WHOLERECEIPT.intValue() || internalTaskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT.intValue() ) {
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();
condition.setWarehouseCode(ShiroUtils.getWarehouseCode());
condition.setTaskId(taskHeader.getId());
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery(condition);
TaskDetail taskDetail = taskDetailService.getOne(taskDetailLambdaQueryWrapper);
if (taskDetail != null) {
taskDetail.setToLocation(location.getCode());
taskDetailService.update(taskDetail, taskDetailLambdaQueryWrapper);
}
}
//给任务分配库位
taskHeader.setToLocation(location.getCode());
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(taskHeader);
this.update(taskHeader, taskHeaderLambdaQueryWrapper);
return AjaxResult.success("生成库位成功",location.getCode());
|
|
2051
|
|
|
2052
|
}
|
|
2053
2054
2055
2056
2057
|
|
|
2058
|
|
|
2059
|
}
|