|
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.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
周鸿
authored
|
6
7
8
|
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.acs.service.AcsCSService;
import com.huaheng.api.acs.service.AgvTaskCSService;
|
|
9
10
11
|
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
|
|
12
|
import com.huaheng.common.utils.Wrappers;
|
|
13
14
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
15
|
import com.huaheng.framework.web.service.ConfigService;
|
|
16
17
18
19
|
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;
|
|
20
|
import com.huaheng.pc.config.materialWarnning.service.IMaterialWarningService;
|
|
21
|
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
|
|
22
23
|
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
|
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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;
|
|
38
|
import com.huaheng.pc.system.dict.service.IDictDataService;
|
周鸿
authored
|
39
|
import com.huaheng.pc.task.agvTask.domain.AgvTask;
|
|
40
41
42
43
44
45
46
47
48
|
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;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
|
周鸿
authored
|
49
|
import java.util.*;
|
|
50
51
52
|
/**
* 入库任务创建和完成
|
|
53
|
*
|
|
54
|
* @author mahua
|
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
* @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;
|
|
82
83
|
@Resource
private IMaterialWarningService materialWarningService;
|
|
84
85
|
@Resource
private ShipmentPreferenceService shipmentPreferenceService;
|
|
86
87
|
@Resource
private ConfigService configService;
|
|
88
89
|
@Resource
private StationService stationService;
|
|
90
91
|
@Resource
private IDictDataService dictDataService;
|
周鸿
authored
|
92
93
|
@Resource
private AgvTaskCSService agvTaskCSService;
|
|
94
|
|
|
95
96
|
/**
* 创建出库任务
|
|
97
|
*
|
|
98
99
100
101
|
* @param shipmentTaskCreateModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
|
|
102
|
public AjaxResult createTaskFromShipmentContainers(ShipmentTaskCreateModel shipmentTaskCreateModel) {
|
|
103
|
Integer taskId;
|
|
104
|
Integer preTaskNo = 0;
|
|
105
106
107
|
Integer shipmentContainerHeaderId = shipmentTaskCreateModel.getShipmentContainerHeaderIds();
//获取表头
ShipmentContainerHeader shipmentContainerHeader = containerHeaderService.getById(shipmentContainerHeaderId);
|
|
108
|
String zoneCode = shipmentContainerHeader.getZoneCode();
|
|
109
110
111
112
|
if (shipmentContainerHeader == null) {
return AjaxResult.error("出库货箱" + shipmentContainerHeaderId + "未找到,操作中止");
}
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
|
|
113
|
// return AjaxResult.error("出库货箱" + shipmentContainerHeader.getContainerCode() + "已经生成任务,请不要重复生成,操作中止");
|
|
114
|
}
|
|
115
|
//获取所有该组盘头下的组盘子表
|
|
116
|
List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.selectByShippingContainerIdUnComplete(shipmentContainerHeader.getId());
|
|
117
118
119
|
if (shipmentContainerDetails.isEmpty()) {
return AjaxResult.error("货箱" + shipmentContainerHeader.getContainerCode() + "没有子任务,操作中止");
}
|
|
120
|
List<ShipmentContainerDetail> shipmentContainerDetails2 = shipmentContainerDetailService.selectByShippingContainerId(shipmentContainerHeader.getId());
|
|
121
122
123
124
125
|
List<TaskHeader> taskHeaders = taskHeaderService.list(new LambdaQueryWrapper<TaskHeader>()
.eq(TaskHeader::getContainerCode, shipmentContainerHeader.getContainerCode())
.eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
);
|
|
126
|
if (CollectionUtils.isNotEmpty(taskHeaders)) {
|
|
127
|
String createdBy = taskHeaders.get(0).getCreatedBy();
|
|
128
129
|
if (!createdBy.equals(ShiroUtils.getUserName())) {
return AjaxResult.error(shipmentContainerHeader.getContainerCode() + ":有其他人生成了任务");
|
|
130
131
|
}
}
|
|
132
133
134
135
136
137
138
139
140
|
//检测库位
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("库位禁用或不存在!");
}
|
|
141
|
if (location.getRowFlag() == QuantityConstant.ROW_OUT) {
|
|
142
|
Location location1 = locationService.getNear(location);
|
|
143
|
if (location1 != null) {
|
|
144
145
146
147
148
|
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);
|
|
149
|
if (taskHeaderList != null && taskHeaderList.size() > 0) {
|
|
150
151
152
153
|
preTaskNo = taskHeaderList.get(0).getPreTaskNo();
}
}
}
|
|
154
155
156
157
158
159
160
|
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("托盘不存在!");
}
|
|
161
|
if (container.getStatus().equals(QuantityConstant.STATUS_CONTAINER_LOCK)) {
|
|
162
|
// return AjaxResult.error("托盘已经锁定!");
|
|
163
|
}
|
|
164
|
container.setStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
|
|
165
|
containerService.update(container, containerLambdaQueryWrapper);
|
|
166
|
locationService.updateStatus(location.getCode(), QuantityConstant.STATUS_LOCATION_LOCK);
|
|
167
|
//创建任务头
|
|
168
169
|
|
|
170
|
TaskHeader task = new TaskHeader();
|
|
171
172
|
LambdaQueryWrapper<TaskHeader> lambdaQuery = Wrappers.lambdaQuery();
|
|
173
|
lambdaQuery.eq(TaskHeader::getWarehouseCode, shipmentContainerHeader.getWarehouseCode());
|
|
174
|
lambdaQuery.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
|
|
175
176
|
lambdaQuery.eq(TaskHeader::getContainerCode, shipmentContainerHeader.getContainerCode());
lambdaQuery.eq(TaskHeader::getInternalTaskType, 200);
|
|
177
178
|
lambdaQuery.last("limit 1");
lambdaQuery.orderByDesc(TaskHeader::getId);
|
|
179
180
181
182
183
|
TaskHeader taskHeader = taskHeaderService.getOne(lambdaQuery);
int taskIdCheck = 0;
if (taskHeader != null) {
task = taskHeader;
taskIdCheck = task.getId();
|
|
184
|
}
|
|
185
186
187
188
189
190
191
192
193
194
|
task.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
task.setFromLocation(shipmentContainerHeader.getLocationCode());
//判断是否整出任务,钱柜和AGV不能整出
//表示整出优先
//判断当前子货箱所有数量是否等于该托盘对应的所有库存的数量,
//这里必须与库存的在库数量对比,后期可能存在一个配盘在执行任务,后一个配盘又在配这个的情况(这个时候不能整出)
//如果相等,则说明这个货箱包含了所有的数量,则可以整出,否则,创建拣选任务;
//查询所有库存
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
195
196
|
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, shipmentContainerHeader.getContainerCode())
.eq(InventoryDetail::getWarehouseCode, shipmentContainerHeader.getWarehouseCode());
|
|
197
198
199
|
List<InventoryDetail> inventories = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
BigDecimal inventoryTotal = new BigDecimal("0");
for (InventoryDetail item : inventories) {
|
|
200
201
|
BigDecimal lastQty = item.getQty().subtract(item.getTaskQty());
inventoryTotal = inventoryTotal.add(lastQty);
|
|
202
203
|
}
BigDecimal containerTotal = new BigDecimal("0");
|
|
204
|
for (ShipmentContainerDetail item : shipmentContainerDetails) {
|
|
205
206
|
containerTotal = containerTotal.add(item.getQty());
}
|
|
207
|
String value = dictDataService.getDictValueByLabel(QuantityConstant.RULE_SHIPMENT_TASK, zoneCode, ShiroUtils.getWarehouseCode());
|
|
208
|
int shipmentTaskRule = Integer.parseInt(value);
|
|
209
|
// 当onlyPicking为1,只允许分拣出库
|
|
210
|
//组盘头下的明细数量=该容器库存下的明细数量
|
|
211
|
//剩余库存小于等于0
|
周鸿
authored
|
212
213
|
// if (inventoryTotal.compareTo(new BigDecimal(0)) <= 0 && !container.getContainerType().equals(QuantityConstant.AGV_CONTAINER_TYPE)) {
if (inventoryTotal.compareTo(new BigDecimal(0)) <= 0){
|
|
214
|
//整盘出库
|
周鸿
authored
|
215
216
|
if(shipmentTaskRule == QuantityConstant.RULE_TASK_WHOLE_SHIPMENT) {
task.setTaskType(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
|
周鸿
authored
|
217
218
219
220
221
222
|
}else{
value = dictDataService.getDictValueByLabel(QuantityConstant.RULE_TASK_LOCATION, zoneCode, ShiroUtils.getWarehouseCode());
int taskLocationRule = Integer.parseInt(value);
if (taskLocationRule == QuantityConstant.RULE_TASK_SET_LOCATION) {
task.setToLocation(shipmentContainerHeader.getLocationCode());
}
|
周鸿
authored
|
223
|
}
|
|
224
|
} else {
|
|
225
|
value = dictDataService.getDictValueByLabel(QuantityConstant.RULE_TASK_LOCATION, zoneCode, ShiroUtils.getWarehouseCode());
|
|
226
|
int taskLocationRule = Integer.parseInt(value);
|
|
227
|
if (taskLocationRule == QuantityConstant.RULE_TASK_SET_LOCATION) {
|
|
228
229
|
task.setToLocation(shipmentContainerHeader.getLocationCode());
}
|
|
230
|
}
|
|
231
|
|
|
232
|
task.setZoneCode(location.getZoneCode());
|
|
233
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
|
|
234
235
236
237
|
task.setAllocationHeadId(shipmentContainerHeader.getId());
task.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
task.setAssignedUser(ShiroUtils.getLoginName());
task.setConfirmedBy(ShiroUtils.getLoginName());
|
|
238
|
task.setCreatedBy(ShiroUtils.getUserName());
|
|
239
|
//东厂默认分配站台 KS0001 LK
|
|
240
|
if (location.getWarehouseCode().equals("KS0001") && location.getZoneCode().equals(QuantityConstant.ZONE_CODE_TYPE_LK)) {
|
|
241
242
243
|
Station station = stationService.getOne(
new LambdaQueryWrapper<Station>()
.eq(Station::getWarehouseCode, "KS0001")
|
|
244
|
.eq(Station::getArea, 5)
|
|
245
|
.eq(Station::getRoadway, 1)
|
|
246
247
248
249
|
.last("limit 1"));
if (station != null) {
task.setPort(station.getCode());
}
|
|
250
|
} else {
|
|
251
252
|
task.setPort(shipmentContainerHeader.getPort());
}
|
|
253
254
|
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
task.setContainerCode(shipmentContainerHeader.getContainerCode());
|
|
255
|
task.setGoodsShelfNo(container.getGoodsShelfNo());
|
|
256
|
task.setCompanyCode(shipmentContainerHeader.getCompanyCode());
|
|
257
|
task.setPreTaskNo(preTaskNo);
|
|
258
|
if (!taskHeaderService.saveOrUpdate(task)) {
|
|
259
260
|
throw new ServiceException("生成任务失败");
}
|
|
261
|
taskId = task.getId();
|
|
262
|
for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetails) {
|
|
263
|
if (taskIdCheck != 0) {
|
|
264
|
//任务存在时,判断该组盘明细有无,有则修改明细状态
|
|
265
266
267
|
LambdaQueryWrapper<TaskDetail> lambdaQuerydetail = Wrappers.lambdaQuery();
lambdaQuerydetail.eq(TaskDetail::getWarehouseCode, shipmentContainerHeader.getWarehouseCode());
lambdaQuerydetail.eq(TaskDetail::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
|
|
268
269
|
lambdaQuerydetail.eq(TaskDetail::getTaskId, taskIdCheck);
lambdaQuerydetail.eq(TaskDetail::getAllocationId, shipmentContainerDetail.getId());
|
|
270
|
lambdaQuerydetail.last("limit 1");
|
|
271
272
|
TaskDetail detail = taskDetailService.getOne(lambdaQuerydetail);
if (detail != null) {
|
|
273
274
|
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
shipmentContainerDetailService.updateById(shipmentContainerDetail);
|
|
275
276
277
|
continue;
}
}
|
|
278
279
280
281
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
taskDetail.setInternalTaskType(task.getInternalTaskType());
taskDetail.setWarehouseCode(task.getWarehouseCode());
|
|
282
|
taskDetail.setUWarehouseCode(shipmentContainerDetail.getUWarehouseCode());
|
|
283
284
285
286
287
288
289
290
291
292
293
294
295
|
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());
|
|
296
|
taskDetail.setGoodsShelfNo(container.getGoodsShelfNo());
|
|
297
|
taskDetail.setFromLocation(task.getFromLocation());
|
|
298
|
|
|
299
|
String shipmentCode = shipmentContainerDetail.getShipmentCode();
|
|
300
301
|
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
.eq(ShipmentHeader::getCode, shipmentCode)
|
|
302
|
.eq(ShipmentHeader::getWarehouseCode, shipmentContainerHeader.getWarehouseCode())
|
|
303
304
|
);
// ShipmentHeader shipmentHeader=shipmentHeaderService.getOne(shipmentId);
|
|
305
306
|
taskDetail.setReferenceCode(shipmentHeader.getReferCode());
|
|
307
|
// taskDetail.setToLocation(task.getToLocation());
|
|
308
309
310
311
312
313
|
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());
|
|
314
315
|
taskDetail.setCreatedBy(shipmentContainerDetail.getCreatedBy());
|
|
316
317
318
319
320
321
322
323
324
325
326
327
328
|
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报错");
}
|
周鸿
authored
|
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
//判断长沙agv库则添加agv任务
// String warehouseCode=task.getWarehouseCode();
// String containerType=container.getContainerType();
// if(warehouseCode.equals(QuantityConstant.WAREHOUSE_CS)&&containerType.contains("V")){
// AgvTaskCS agvTask=agvTaskCSService.saveAGVTaskByTask(task);
// //分拣任务回库指令
// if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)){
// AgvTaskCS agvTask1=agvTaskCSService.saveAGVTaskByTaskReturn(task,agvTask);
// }else{
// //当整盘出库时,判断有没有生成回库任务,有则删除
// AgvTaskCS agvTaskPre=agvTaskCSService.getAgvTaskByHeaderId(task,QuantityConstant.AGV_TYPE_TAKE);
// if(agvTaskPre!=null){
// agvTaskCSService.removeById(agvTaskPre.getId());
// }
// }
// }
|
|
345
|
return AjaxResult.success(taskId);
|
|
346
347
348
349
|
}
/**
* 完成出库任务
|
|
350
|
*
|
|
351
352
353
|
* @param task
*/
@Transactional(rollbackFor = Exception.class)
|
|
354
|
public AjaxResult completeShipmentTask(TaskHeader task) {
|
|
355
356
357
|
//获取任务明细
List<TaskDetail> taskDetails = taskDetailService.findByTaskId(task.getId());
|
|
358
|
if (task.getStatus().intValue() == QuantityConstant.TASK_STATUS_COMPLETED) {
|
|
359
360
|
throw new ServiceException("任务已完成");
}
|
|
361
|
|
|
362
363
364
365
|
if (StringUtils.isEmpty(task.getFromLocation())) {
throw new ServiceException("任务" + task.getId() + "没有起始库位,执行中止");
}
|
|
366
367
|
if (StringUtils.isEmpty(task.getToLocation())
&& task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)) {
|
|
368
369
|
throw new ServiceException("任务" + task.getId() + "没有目的库位,执行中止");
}
|
|
370
|
String warehouseCode = task.getWarehouseCode();
|
|
371
|
InventoryHeader inventoryHeader = null;
|
|
372
|
if (task.getTaskType().equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)) {
|
|
373
|
LambdaQueryWrapper<InventoryHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
374
|
lambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, warehouseCode)
|
|
375
376
|
.eq(InventoryHeader::getLocationCode, task.getFromLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
|
|
377
|
inventoryHeader = inventoryHeaderService.getOne(lambdaQueryWrapper);
|
|
378
|
if (inventoryHeader != null) {
|
|
379
|
String locationCode = inventoryHeader.getLocationCode();
|
|
380
|
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
|
|
381
|
location.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
382
383
384
385
|
locationService.updateById(location);
inventoryHeader.setLocationCode(task.getToLocation());
inventoryHeaderService.updateById(inventoryHeader);
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
|
|
386
|
lambdaQueryWrapper2.eq(InventoryDetail::getWarehouseCode, warehouseCode)
|
|
387
388
|
.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader.getId());
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(lambdaQueryWrapper2);
|
|
389
390
|
if (inventoryDetails != null && inventoryDetails.size() > 0) {
for (InventoryDetail inventoryDetail : inventoryDetails) {
|
|
391
392
393
394
395
396
|
inventoryDetail.setLocationCode(task.getToLocation());
inventoryDetailService.updateById(inventoryDetail);
}
}
}
}
|
|
397
398
399
400
401
402
403
404
405
406
407
|
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() + "】不存在!");
}
//减扣库存单
|
|
408
|
inventoryHeader = inventoryHeaderService.getById(inventoryDetail.getInventoryHeaderId());
|
|
409
410
411
412
413
414
415
416
417
|
//扣减库存明细
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
|
|
418
|
&& inventoryDetail.getTaskQty().signum() == 0) {
|
|
419
420
421
422
|
//如果库存没有了,就删除这个库存
inventoryDetailService.removeById(inventoryDetail.getId());
inventoryHeader.setTotalQty(inventoryHeader.getTotalQty().subtract(taskDetail.getQty()));
inventoryHeader.setTotalLines(inventoryHeader.getTotalLines() - 1);
|
|
423
|
if (inventoryHeader.getTotalQty().signum() == 0) {
|
|
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
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();
|
|
442
|
inventoryTransaction.setWarehouseCode(warehouseCode);
|
|
443
|
inventoryTransaction.setCompanyCode(inventoryDetail.getCompanyCode());
|
|
444
445
446
|
inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode());
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
|
|
447
448
449
450
|
inventoryTransaction.setMaterialCode(inventoryDetail.getMaterialCode());
inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit());
|
|
451
|
inventoryTransaction.setReferCode(taskDetail.getReferenceCode());
|
|
452
|
inventoryTransaction.setBillCode(taskDetail.getBillCode());
|
|
453
|
inventoryTransaction.setInventoryDetailId(inventoryDetail.getId());
|
|
454
455
456
457
|
inventoryTransaction.setMoCode(inventoryDetail.getMoCode());
inventoryTransaction.setUWarehouseCode(inventoryDetail.getUWarehouseCode());
inventoryTransaction.setGoodsShelfNo(inventoryDetail.getGoodsShelfNo());
inventoryTransaction.setZoneCode(inventoryDetail.getZoneCode());
|
|
458
459
|
//取出子单据
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
|
|
460
|
if (shipmentDetail != null) {
|
|
461
462
463
464
465
|
inventoryTransaction.setBillDetailId(shipmentDetail.getId());
}
inventoryTransaction.setBatch(inventoryDetail.getBatch());
inventoryTransaction.setLot(inventoryDetail.getLot());
inventoryTransaction.setProjectNo(inventoryDetail.getProjectNo());
|
|
466
467
|
inventoryTransaction.setQcCheck(inventoryDetail.getQcCheck());
inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode());
|
|
468
469
|
inventoryTransaction.setManufactureDate(inventoryDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(inventoryDetail.getExpirationDate());
|
|
470
471
472
473
|
inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
//这里取反,更符合出库的语义,同时方便对记录进行统计
inventoryTransaction.setTaskQty(taskDetail.getQty());
inventoryTransactionService.save(inventoryTransaction);
|
|
474
|
// materialWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getCompanyCode());
|
|
475
476
477
478
|
}
}
//设置主任务为已执行
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
479
|
task.setCompleteStatus(1);
|
|
480
|
taskHeaderService.updateById(task);
|
|
481
|
/* 更新库位和容器*/
|
|
482
483
|
updateShipmentLocationContainer(task.getFromLocation(), task.getToLocation(),
task.getContainerCode(), task.getTaskType(), warehouseCode);
|
|
484
485
486
487
|
//设置出库货箱表头状态为拣货任务完成
LambdaUpdateWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
shipmentContainerHeaderLambdaUpdateWrapper.eq(ShipmentContainerHeader::getId, task.getAllocationHeadId())
|
|
488
|
.set(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
|
|
489
490
491
492
493
494
495
496
497
|
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());
|
|
498
|
|
|
499
|
if (StringUtils.isNotNull(shipmentDetail)) {
|
xcq
authored
|
500
|
if (shipmentDetail.getBackQty() == null || shipmentDetail.getBackQty().compareTo(BigDecimal.ZERO) == 0) {
|
|
501
|
shipmentDetail.setBackQty(BigDecimal.ZERO.add(taskDetail.getQty()));
|
|
502
|
} else {
|
|
503
504
|
shipmentDetail.setBackQty(shipmentDetail.getBackQty().add(taskDetail.getQty()));
}
|
|
505
|
if (shipmentDetail.getQty().compareTo(shipmentDetail.getTaskQty()) == 0) {
|
|
506
507
|
shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
shipmentDetailService.updateById(shipmentDetail);
|
|
508
|
} else {
|
|
509
|
shipmentDetailService.updateById(shipmentDetail);
|
|
510
511
|
}
ids.add(shipmentDetail.getShipmentId());
|
|
512
|
}
|
|
513
|
|
|
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
}
/*更新出库单状态*/
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);
}
|
|
529
|
shipmentHeader.setLastUpdatedBy(task.getLastUpdatedBy());
|
|
530
531
532
533
|
shipmentHeader.setLastUpdated(new Date());
shipmentHeaderService.updateById(shipmentHeader);
}
}
|
|
534
535
|
return AjaxResult.success("完成出库任务成功");
|
|
536
537
538
539
|
}
/**
* 出库任务完成时更新库位和容器状态
|
|
540
541
542
|
*
* @param fromLocation 源库位
* @param toLocation 目标库位
|
|
543
|
* @param containerCode 容器编码
|
|
544
|
* @param taskType 任务类型
|
|
545
|
*/
|
|
546
|
public void updateShipmentLocationContainer(String fromLocation, String toLocation,
|
|
547
|
String containerCode, Integer taskType, String warehouseCode) {
|
|
548
|
//将库位状态改为空闲,如果是整出的对应的容器也清空
|
|
549
|
Location fromLocationRecord = locationService.getLocationByCode(fromLocation, warehouseCode);
|
|
550
551
552
|
if (StringUtils.isNull(fromLocationRecord)) {
throw new ServiceException("系统没有" + fromLocation + "库位");
}
|
|
553
554
|
if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
fromLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
555
556
557
|
if (!fromLocationRecord.getZoneCode().equals("XN")) {
fromLocationRecord.setContainerCode("");
}
|
|
558
|
locationService.updateById(fromLocationRecord);
|
|
559
|
} else {
|
|
560
|
Location toLocationRecord = locationService.getLocationByCode(toLocation, warehouseCode);
|
|
561
562
563
|
if (StringUtils.isNull(fromLocationRecord)) {
throw new ServiceException("系统没有" + toLocation + "库位");
}
|
|
564
|
toLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
|
|
565
|
toLocationRecord.setContainerCode(containerCode);
|
|
566
567
|
locationService.updateById(toLocationRecord);
}
|
周鸿
authored
|
568
569
570
571
572
|
//昆山立库出库不需要删除原库位,昆山有个提前解锁库位接口
if (warehouseCode.equals(QuantityConstant.WAREHOUSE_KS) &&fromLocationRecord.getZoneCode().equals("LK")){
}else{
//分拣出库,原库位和目的库位不同则解绑原库位
if (taskType.equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)&&!fromLocation.equals(toLocation)) {
|
周鸿
authored
|
573
574
575
576
|
fromLocationRecord.setContainerCode("");
fromLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
locationService.updateById(fromLocationRecord);
}
|
周鸿
authored
|
577
|
}
|
周鸿
authored
|
578
579
580
581
582
583
584
585
|
// if (warehouseCode.equals(QuantityConstant.WAREHOUSE_XZ) && (taskType.equals(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) || taskType.equals(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT))) {
// if (fromLocationRecord.getZoneCode().equals("LK")) {
// fromLocationRecord.setContainerCode("");
// fromLocationRecord.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
// locationService.updateById(fromLocationRecord);
// }
// }
|
|
586
|
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
|
|
587
|
if (StringUtils.isEmpty(containerCode)) {
|
|
588
|
throw new ServiceException("系统无" + container + "容器");
|
|
589
590
591
592
593
594
595
596
|
}
if (taskType.equals(QuantityConstant.TASK_TYPE_WHOLESHIPMENT)) {
if ("LS".equals(container.getContainerType())) {
if (!containerService.removeById(container.getId())) {
throw new ServiceException("删除临时容器失败");
}
} else {
|
|
597
598
599
600
601
602
603
|
if (!container.getZoneCode().equals("XN")) {
containerService.updateLocationCodeAndStatus(containerCode, "",
QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
} else {
containerService.updateLocationCodeAndStatus(containerCode, container.getLocationCode(),
QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
}
|
|
604
605
606
607
608
|
}
} else {
//查询是否存在关联的库存,入如果没有就修改容器状态为empty
LambdaQueryWrapper<InventoryDetail> inventoryDetaillambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetaillambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
|
|
609
|
List<InventoryDetail> detailList = inventoryDetailService.list(inventoryDetaillambdaQueryWrapper);
|
|
610
611
|
//库存查询不到该容器就把容器状态改为可用
if (detailList.isEmpty()) {
|
|
612
613
|
containerService.updateLocationCodeAndStatus(containerCode, toLocation,
QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
|
|
614
|
} else {
|
|
615
616
|
containerService.updateLocationCodeAndStatus(containerCode, toLocation,
QuantityConstant.STATUS_CONTAINER_SOME, warehouseCode);
|
|
617
618
619
620
|
}
}
}
}
|