|
1
2
3
4
|
package com.huaheng.pc.task.taskHeader.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
5
|
import com.huaheng.common.utils.Wrappers;
|
|
6
7
8
9
10
|
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
11
12
13
|
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
|
|
14
15
16
17
|
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
18
19
20
|
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.materialWarnning.domain.MaterialWarning;
import com.huaheng.pc.config.materialWarnning.service.IMaterialWarningService;
|
|
21
22
|
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
|
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
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;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
|
|
41
|
import org.aspectj.weaver.loadtime.Aj;
|
|
42
43
44
45
46
47
48
49
50
|
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
/**
* 入库任务创建和完成
|
|
51
|
* @author mahua
|
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
* @date 2020/7/14
*/
@Service
public class ShipmentTaskService {
@Resource
private ShipmentContainerHeaderService containerHeaderService;
@Resource
private ShipmentContainerDetailService shipmentContainerDetailService;
@Resource
private LocationService locationService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryTransactionService inventoryTransactionService;
@Resource
private ContainerService containerService;
|
|
79
80
|
@Resource
private IMaterialWarningService materialWarningService;
|
|
81
82
|
@Resource
private ShipmentPreferenceService shipmentPreferenceService;
|
|
83
84
|
@Resource
private ConfigService configService;
|
|
85
86
87
88
89
90
91
|
/**
* 创建出库任务
* @param shipmentTaskCreateModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult createTaskFromShipmentContainers(ShipmentTaskCreateModel shipmentTaskCreateModel){
|
|
92
|
Integer taskId;
|
|
93
|
Integer preTaskNo = 0;
|
|
94
95
96
97
98
99
100
101
102
|
Integer shipmentContainerHeaderId = shipmentTaskCreateModel.getShipmentContainerHeaderIds();
//获取表头
ShipmentContainerHeader shipmentContainerHeader = containerHeaderService.getById(shipmentContainerHeaderId);
if (shipmentContainerHeader == null) {
return AjaxResult.error("出库货箱" + shipmentContainerHeaderId + "未找到,操作中止");
}
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
return AjaxResult.error("出库货箱" + shipmentContainerHeader.getContainerCode() + "已经生成任务,请不要重复生成,操作中止");
}
|
|
103
|
//获取所有该组盘头下的组盘子表
|
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.selectByShippingContainerId(shipmentContainerHeader.getId());
if (shipmentContainerDetails.isEmpty()) {
return AjaxResult.error("货箱" + shipmentContainerHeader.getContainerCode() + "没有子任务,操作中止");
}
//检测库位
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getCode, shipmentContainerHeader.getLocationCode())
.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(Location::getDeleted, false);
Location location = locationService.getOne(locationLambdaQueryWrapper);
if (StringUtils.isNull(location)) {
return AjaxResult.error("库位禁用或不存在!");
}
|
|
118
|
if(location.getRowFlag() == QuantityConstant.ROW_OUT) {
|
|
119
120
121
122
123
124
125
|
Location location1 = locationService.getNear(location);
if(location1 != null) {
String locationCode = location1.getCode();
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getToLocation, locationCode)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
|
|
126
|
if(taskHeaderList != null && taskHeaderList.size() > 0) {
|
|
127
128
129
130
|
preTaskNo = taskHeaderList.get(0).getPreTaskNo();
}
}
}
|
|
131
132
133
134
135
136
137
|
LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
containerLambdaQueryWrapper.eq(Container::getCode, shipmentContainerHeader.getContainerCode())
.eq(Container::getWarehouseCode, ShiroUtils.getWarehouseCode());
Container container = containerService.getOne(containerLambdaQueryWrapper);
if (StringUtils.isNull(container)) {
return AjaxResult.error("托盘不存在!");
}
|
|
138
|
if(container.getStatus().equals(QuantityConstant.STATUS_CONTAINER_LOCK)) {
|
|
139
140
|
return AjaxResult.error("托盘已经锁定!");
}
|
|
141
|
container.setStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
|
|
142
|
containerService.update(container, containerLambdaQueryWrapper);
|
|
143
|
locationService.updateStatus(location.getCode(), QuantityConstant.STATUS_LOCATION_LOCK);
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
//创建任务头
TaskHeader task = new TaskHeader();
task.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
task.setFromLocation(shipmentContainerHeader.getLocationCode());
//判断是否整出任务,钱柜和AGV不能整出
//表示整出优先
//判断当前子货箱所有数量是否等于该托盘对应的所有库存的数量,
//这里必须与库存的在库数量对比,后期可能存在一个配盘在执行任务,后一个配盘又在配这个的情况(这个时候不能整出)
//如果相等,则说明这个货箱包含了所有的数量,则可以整出,否则,创建拣选任务;
//查询所有库存
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());
}
|
|
167
168
|
String value = configService.getKey(QuantityConstant.RULE_SHIPMENT_TASK);
int shipmentTaskRule = Integer.parseInt(value);
|
|
169
|
// 当onlyPicking为1,只允许分拣出库
|
|
170
171
|
if (inventoryTotal.compareTo(containerTotal) == 0 &&
(shipmentTaskRule == QuantityConstant.RULE_TASK_WHOLE_SHIPMENT)) {
|
|
172
173
|
//整盘出库
task.setTaskType(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
|
|
174
175
176
177
178
179
|
} else {
value = configService.getKey(QuantityConstant.RULE_TASK_LOCATION);
int taskLocationRule = Integer.parseInt(value);
if (taskLocationRule == QuantityConstant.RULE_TASK_SET_LOCATION) {
task.setToLocation(shipmentContainerHeader.getLocationCode());
}
|
|
180
181
|
}
|
|
182
|
task.setZoneCode(location.getZoneCode());
|
|
183
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
|
|
184
185
186
187
|
task.setAllocationHeadId(shipmentContainerHeader.getId());
task.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
task.setAssignedUser(ShiroUtils.getLoginName());
task.setConfirmedBy(ShiroUtils.getLoginName());
|
|
188
|
task.setPort(shipmentContainerHeader.getPort());
|
|
189
190
|
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
task.setContainerCode(shipmentContainerHeader.getContainerCode());
|
|
191
|
task.setCompanyCode(shipmentContainerHeader.getCompanyCode());
|
|
192
|
task.setPreTaskNo(preTaskNo);
|
|
193
194
195
|
if (!taskHeaderService.save(task)){
throw new ServiceException("生成任务失败");
}
|
|
196
|
taskId = task.getId();
|
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetails) {
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
taskDetail.setInternalTaskType(task.getInternalTaskType());
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setTaskType(task.getTaskType());
taskDetail.setToInventoryId(shipmentContainerDetail.getInventoryId());
taskDetail.setAllocationId(shipmentContainerDetail.getId());
taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
taskDetail.setMaterialCode(shipmentContainerDetail.getMaterialCode());
taskDetail.setMaterialName(shipmentContainerDetail.getMaterialName());
taskDetail.setMaterialSpec(shipmentContainerDetail.getMaterialSpec());
taskDetail.setMaterialUnit(shipmentContainerDetail.getMaterialUnit());
taskDetail.setFromInventoryId(shipmentContainerDetail.getInventoryId());
taskDetail.setQty(shipmentContainerDetail.getQty());
taskDetail.setContainerCode(task.getContainerCode());
taskDetail.setFromLocation(task.getFromLocation());
|
|
216
|
// taskDetail.setToLocation(task.getToLocation());
|
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
taskDetail.setLot(shipmentContainerDetail.getLot());
taskDetail.setBatch(shipmentContainerDetail.getBatch());
taskDetail.setProjectNo(shipmentContainerDetail.getProjectNo());
taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
taskDetail.setWaveId(shipmentContainerDetail.getWaveId());
taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
if (!taskDetailService.save(taskDetail)) {
throw new ServiceException("新建任务明细失败,sql报错");
}
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
if (!shipmentContainerDetailService.updateById(shipmentContainerDetail)) {
throw new ServiceException("修改组盘明细状态失败");
}
}
//更新货位状态
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
if (!containerHeaderService.updateById(shipmentContainerHeader)) {
throw new ServiceException("修改组盘头状态失败,sql报错");
}
|
|
237
|
return AjaxResult.success(taskId);
|
|
238
239
240
241
242
243
244
|
}
/**
* 完成出库任务
* @param task
*/
@Transactional(rollbackFor = Exception.class)
|
|
245
|
public AjaxResult completeShipmentTask(TaskHeader task) {
|
|
246
247
248
|
//获取任务明细
List<TaskDetail> taskDetails = taskDetailService.findByTaskId(task.getId());
|
|
249
|
if (task.getStatus().intValue() == QuantityConstant.TASK_STATUS_COMPLETED) {
|
|
250
251
|
throw new ServiceException("任务已完成");
}
|
|
252
|
|
|
253
254
255
256
|
if (StringUtils.isEmpty(task.getFromLocation())) {
throw new ServiceException("任务" + task.getId() + "没有起始库位,执行中止");
}
|
|
257
258
|
if (StringUtils.isEmpty(task.getToLocation())
&& task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)) {
|
|
259
260
|
throw new ServiceException("任务" + task.getId() + "没有目的库位,执行中止");
}
|
|
261
|
String warehouseCode = task.getWarehouseCode();
|
|
262
263
264
|
InventoryHeader inventoryHeader = null;
if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)) {
LambdaQueryWrapper<InventoryHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
265
|
lambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, warehouseCode)
|
|
266
267
|
.eq(InventoryHeader::getLocationCode, task.getFromLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
|
|
268
|
inventoryHeader = inventoryHeaderService.getOne(lambdaQueryWrapper);
|
|
269
270
|
if(inventoryHeader != null) {
String locationCode = inventoryHeader.getLocationCode();
|
|
271
|
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
|
|
272
|
location.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
273
274
275
276
|
locationService.updateById(location);
inventoryHeader.setLocationCode(task.getToLocation());
inventoryHeaderService.updateById(inventoryHeader);
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
|
|
277
|
lambdaQueryWrapper2.eq(InventoryDetail::getWarehouseCode, warehouseCode)
|
|
278
279
280
281
282
283
284
285
286
287
|
.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader.getId());
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(lambdaQueryWrapper2);
if(inventoryDetails != null && inventoryDetails.size() > 0) {
for(InventoryDetail inventoryDetail : inventoryDetails) {
inventoryDetail.setLocationCode(task.getToLocation());
inventoryDetailService.updateById(inventoryDetail);
}
}
}
}
|
|
288
289
290
291
292
293
294
295
296
297
298
|
for (TaskDetail taskDetail : taskDetails) {
if (taskDetail.getStatus() < QuantityConstant.TASK_STATUS_RUNNING) {
//获取出库子货箱
ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getById(taskDetail.getAllocationId());
//获取对应库存记录
InventoryDetail inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
if (inventoryDetail == null) {
throw new ServiceException("任务明细对应的库存ID【" + taskDetail.getToInventoryId().toString() + "】不存在!");
}
//减扣库存单
|
|
299
|
inventoryHeader = inventoryHeaderService.getById(inventoryDetail.getInventoryHeaderId());
|
|
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
//扣减库存明细
inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(taskDetail.getQty()));
inventoryDetail.setQty(inventoryDetail.getQty().subtract(taskDetail.getQty()));
if (inventoryDetail.getQty().signum() == -1) {
throw new ServiceException("扣减库存大于wms库存");
}
if (inventoryDetail.getQty().signum() == 0
&& inventoryDetail.getTaskQty().signum() == 0) {
//如果库存没有了,就删除这个库存
inventoryDetailService.removeById(inventoryDetail.getId());
inventoryHeader.setTotalQty(inventoryHeader.getTotalQty().subtract(taskDetail.getQty()));
inventoryHeader.setTotalLines(inventoryHeader.getTotalLines() - 1);
|
|
314
|
if (inventoryHeader.getTotalQty().signum() == 0) {
|
|
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
inventoryHeaderService.removeById(inventoryHeader.getId());
} else {
inventoryHeaderService.updateById(inventoryHeader);
}
} else {
//否则更新这个库存
inventoryDetailService.updateById(inventoryDetail);
inventoryHeader.setTotalQty(inventoryHeader.getTotalQty().subtract(taskDetail.getQty()));
inventoryHeaderService.updateById(inventoryHeader);
}
//设置子任务状态为已执行
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
taskDetailService.updateById(taskDetail);
//修改出库组盘明细状态
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
shipmentContainerDetailService.updateById(shipmentContainerDetail);
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
|
|
333
|
inventoryTransaction.setWarehouseCode(warehouseCode);
|
|
334
|
inventoryTransaction.setCompanyCode(inventoryDetail.getCompanyCode());
|
|
335
336
337
|
inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
|
|
338
339
340
341
|
inventoryTransaction.setMaterialCode(inventoryDetail.getMaterialCode());
inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit());
|
|
342
|
inventoryTransaction.setBillCode(taskDetail.getBillCode());
|
|
343
344
345
346
347
348
349
350
|
//取出子单据
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
if(shipmentDetail != null) {
inventoryTransaction.setBillDetailId(shipmentDetail.getId());
}
inventoryTransaction.setBatch(inventoryDetail.getBatch());
inventoryTransaction.setLot(inventoryDetail.getLot());
inventoryTransaction.setProjectNo(inventoryDetail.getProjectNo());
|
|
351
352
|
inventoryTransaction.setQcCheck(inventoryDetail.getQcCheck());
inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode());
|
|
353
354
|
inventoryTransaction.setManufactureDate(inventoryDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(inventoryDetail.getExpirationDate());
|
|
355
356
357
358
|
inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
//这里取反,更符合出库的语义,同时方便对记录进行统计
inventoryTransaction.setTaskQty(taskDetail.getQty());
inventoryTransactionService.save(inventoryTransaction);
|
|
359
|
materialWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getCompanyCode());
|
|
360
361
362
363
364
|
}
}
//设置主任务为已执行
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
taskHeaderService.updateById(task);
|
|
365
|
/* 更新库位和容器*/
|
|
366
367
|
updateShipmentLocationContainer(task.getFromLocation(), task.getToLocation(),
task.getContainerCode(), task.getTaskType(), warehouseCode);
|
|
368
369
370
371
|
//设置出库货箱表头状态为拣货任务完成
LambdaUpdateWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
shipmentContainerHeaderLambdaUpdateWrapper.eq(ShipmentContainerHeader::getId, task.getAllocationHeadId())
|
|
372
|
.set(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
|
|
373
374
375
376
377
378
379
380
381
|
if (!containerHeaderService.update(shipmentContainerHeaderLambdaUpdateWrapper)) {
throw new ServiceException("更新组盘头状态失败");
}
//修改出库单状态
List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(task.getId());
HashSet<Integer> ids = new HashSet<>();
for (TaskDetail taskDetail : taskDetailList) {
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
|
|
382
|
|
|
383
|
if (StringUtils.isNotNull(shipmentDetail)) {
|
|
384
|
if (shipmentDetail.getQty().compareTo(shipmentDetail.getTaskQty()) == 0) {
|
|
385
386
387
388
|
shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
shipmentDetailService.updateById(shipmentDetail);
}
ids.add(shipmentDetail.getShipmentId());
|
|
389
|
}
|
|
390
|
|
|
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
}
/*更新出库单状态*/
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");
if (maxStatus.equals(QuantityConstant.SHIPMENT_HEADER_COMPLETED)) {
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
if (minStatus.equals(QuantityConstant.SHIPMENT_HEADER_COMPLETED)) {
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
|
|
406
|
shipmentHeader.setLastUpdatedBy("wcs");
|
|
407
408
409
410
|
shipmentHeader.setLastUpdated(new Date());
shipmentHeaderService.updateById(shipmentHeader);
}
}
|
|
411
412
|
return AjaxResult.success("完成出库任务成功");
|
|
413
414
415
416
417
418
419
420
421
|
}
/**
* 出库任务完成时更新库位和容器状态
* @param fromLocation 源库位
* @param toLocation 目标库位
* @param containerCode 容器编码
* @param taskType 任务类型
*/
|
|
422
423
|
public void updateShipmentLocationContainer(String fromLocation, String toLocation,
String containerCode, Integer taskType, String warehouseCode){
|
|
424
|
//将库位状态改为空闲,如果是整出的对应的容器也清空
|
|
425
|
Location fromLocationRecord = locationService.getLocationByCode(fromLocation, warehouseCode);
|
|
426
427
428
429
430
431
|
if (StringUtils.isNull(fromLocationRecord)) {
throw new ServiceException("系统没有" + fromLocation + "库位");
}
/* 如果目标库位与源库位不一样时,需要更新两个库位*/
if (StringUtils.isNotEmpty(toLocation)
&& !fromLocation.equals(toLocation)) {
|
|
432
|
Location toLocationRecord = locationService.getLocationByCode(toLocation, warehouseCode);
|
|
433
434
435
|
if (StringUtils.isNull(fromLocationRecord)) {
throw new ServiceException("系统没有" + toLocation + "库位");
}
|
|
436
|
toLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
437
438
|
if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
toLocationRecord.setContainerCode("");
|
|
439
440
|
} else {
toLocationRecord.setContainerCode(containerCode);
|
|
441
442
443
444
|
}
locationService.updateById(toLocationRecord);
fromLocationRecord.setContainerCode("");
}
|
|
445
|
fromLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
446
447
448
449
450
|
if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
fromLocationRecord.setContainerCode("");
}
locationService.updateById(fromLocationRecord);
|
|
451
|
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
|
|
452
453
454
455
456
457
458
459
460
461
|
if (StringUtils.isEmpty(containerCode)) {
throw new ServiceException("系统无"+container+"容器");
}
if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
if ("LS".equals(container.getContainerType())) {
if (!containerService.removeById(container.getId())) {
throw new ServiceException("删除临时容器失败");
}
} else {
|
|
462
|
containerService.updateLocationCodeAndStatus(containerCode, "",
|
|
463
|
QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
|
|
464
465
466
467
468
|
}
} else {
//查询是否存在关联的库存,入如果没有就修改容器状态为empty
LambdaQueryWrapper<InventoryDetail> inventoryDetaillambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetaillambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
|
|
469
|
List<InventoryDetail> detailList = inventoryDetailService.list(inventoryDetaillambdaQueryWrapper);
|
|
470
471
|
//库存查询不到该容器就把容器状态改为可用
if (detailList.isEmpty()) {
|
|
472
473
|
containerService.updateLocationCodeAndStatus(containerCode, toLocation,
QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
|
|
474
|
} else {
|
|
475
476
|
containerService.updateLocationCodeAndStatus(containerCode, toLocation,
QuantityConstant.STATUS_CONTAINER_SOME, warehouseCode);
|
|
477
478
479
480
|
}
}
}
}
|