|
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.conditions.update.UpdateWrapper;
|
|
6
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
7
|
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
|
|
8
|
import com.huaheng.common.constant.QuantityConstant;
|
|
9
|
import com.huaheng.common.exception.service.ServiceException;
|
|
10
|
import com.huaheng.common.utils.DataUtils;
|
|
11
|
import com.huaheng.common.utils.StringUtils;
|
|
12
13
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
14
15
|
import com.huaheng.pc.config.configWarning.domain.ConfigWarning;
import com.huaheng.pc.config.configWarning.service.ConfigWarningService;
|
|
16
|
import com.huaheng.pc.config.container.domain.Container;
|
|
17
|
import com.huaheng.pc.config.container.service.ContainerService;
|
|
18
19
|
import com.huaheng.pc.config.containerCapacity.domain.ContainerCapacity;
import com.huaheng.pc.config.containerCapacity.service.ContainerCapacityService;
|
|
20
21
|
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
|
|
22
23
24
|
import com.huaheng.pc.config.sendMail.domain.SendMail;
import com.huaheng.pc.config.sendMail.service.MailService;
import com.huaheng.pc.config.sendMail.service.SendMailService;
|
|
25
26
|
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.inventory.cycleCountDetail.service.CycleCountDetailService;
|
|
27
|
import com.huaheng.pc.inventory.cycleCountHeader.domain.CycleCountHeader;
|
|
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
36
|
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
|
|
37
38
39
40
|
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;
|
|
41
42
|
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
|
|
43
44
45
46
|
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;
|
|
47
|
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
|
|
48
|
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
|
|
49
|
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
|
|
50
|
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
|
|
51
52
53
|
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
|
|
54
|
import org.apache.poi.ss.formula.functions.T;
|
|
55
|
import org.jsoup.helper.DataUtil;
|
|
56
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
57
|
import org.springframework.stereotype.Service;
|
|
58
|
import java.math.BigDecimal;
|
|
59
|
import java.text.SimpleDateFormat;
|
|
60
|
import java.time.temporal.TemporalAdjuster;
|
|
61
|
import java.util.ArrayList;
|
|
62
|
import java.util.Date;
|
|
63
|
import java.util.List;
|
|
64
|
import java.util.Map;
|
|
65
|
import java.util.*;
|
|
66
67
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
68
69
70
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
|
|
71
72
|
import org.springframework.transaction.annotation.Transactional;
|
|
73
74
|
import javax.annotation.Resource;
|
|
75
|
@Service
|
|
76
|
public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHeader> implements TaskHeaderService {
|
|
77
|
|
|
78
|
@Resource
|
|
79
|
private ShipmentContainerHeaderService shipmentContainerHeaderService;
|
|
80
|
@Resource
|
|
81
|
private ShipmentContainerDetailService shipmentContainerDetailService;
|
|
82
|
@Resource
|
|
83
|
private LocationService locationService;
|
|
84
|
@Resource
|
|
85
86
|
private ContainerService containerService;
@Resource
|
|
87
|
private TaskDetailService taskDetailService;
|
|
88
|
@Resource
|
|
89
|
private TaskHeaderService taskHeaderService;
|
|
90
|
@Resource
|
|
91
|
private InventoryHeaderService inventoryHeaderService;
|
|
92
93
94
|
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
|
|
95
|
private InventoryTransactionService inventoryTransactionService;
|
|
96
|
@Resource
|
|
97
|
private ReceiptHeaderService receiptHeaderService;
|
|
98
99
|
@Resource
private ReceiptDetailService receiptDetailService;
|
|
100
|
@Resource
|
|
101
|
private ReceiptContainerDetailService receiptContainerDetailService;
|
|
102
103
104
105
|
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
|
|
106
107
|
@Resource
private CycleCountDetailService cycleCountDetailService;
|
|
108
|
@Resource
|
|
109
110
|
private CycleCountHeaderService cycleCountHeaderService;
@Resource
|
|
111
|
private ReceiptContainerHeaderService receiptContainerHeaderService;
|
|
112
|
@Resource
|
|
113
|
private TaskHeaderMapper taskHeaderMapper;
|
|
114
115
|
@Autowired
private TaskAssignService taskAssignService;
|
|
116
117
|
@Resource
private ContainerCapacityService containerCapacityService;
|
|
118
119
120
121
122
123
|
@Resource
private ConfigWarningService configWarningService;
@Resource
private MailService mailService;
@Resource
private SendMailService sendMailService;
|
|
124
|
|
|
125
126
|
/**
* 盘点任务首选项
|
|
127
|
*
|
|
128
129
130
131
132
133
|
* @param taskHeaderList
* @return
*/
@Transactional
@Override
public List<TaskHeader> preferenceRealize(List<TaskHeader> taskHeaderList) {
|
|
134
|
//盘点任务头,默认不显示库位,容器。
|
|
135
|
List<TaskHeader> taskHeaders = new ArrayList<>();
|
|
136
|
for (TaskHeader item : taskHeaderList) {
|
|
137
138
139
140
141
142
143
|
item.setFromLocation("");
item.setToLocation("");
item.setContainerCode("");
taskHeaders.add(item);
}
return taskHeaders;
}
|
|
144
|
|
|
145
146
147
148
149
|
@Override
public List<TaskHeader> getTasksStatus(Short lastStatus) {
return taskHeaderMapper.getTasksStatus(lastStatus);
}
|
|
150
|
/**
|
|
151
|
* 查询容器有无任务
|
|
152
|
*/
|
|
153
154
155
156
|
@Override
public Integer UncompleteCount(String ContainerCode) {
return taskHeaderMapper.UncompleteCount(ContainerCode, ShiroUtils.getWarehouseCode());
}
|
|
157
|
|
|
158
159
|
/**
* 取消任务
|
|
160
|
*/
|
|
161
|
@Override
|
|
162
|
@Transactional
|
|
163
|
public AjaxResult cancelTask(Integer[] taskIds) {
|
|
164
|
for (int taskId : taskIds) {
|
|
165
|
TaskHeader taskHeader = taskHeaderService.getById(taskId);
|
|
166
167
|
if (taskHeader == null) {
return AjaxResult.error("任务" + taskId + "未找到,操作中止");
|
|
168
|
}
|
|
169
170
|
if (taskHeader.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
return AjaxResult.error("存在任务" + taskHeader.getId() + "已下发或执行,操作中止");
|
|
171
|
}
|
|
172
173
174
175
176
177
178
179
|
//查出任务明细
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);
|
|
180
|
if (taskDetail == null) {
|
|
181
182
|
throw new ServiceException("任务明细条目错误");
}
|
|
183
184
|
//删除子任务
LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
185
|
lambdaQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
|
|
186
187
188
189
|
taskDetailService.remove(lambdaQueryWrapper);
//删除主任务
taskHeaderService.removeById(taskHeader.getId());
// 更改库位状态(整盘入库任务除外)
|
|
190
191
192
|
if (taskHeader.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_SHELF) {
ReceiptContainerHeader record = new ReceiptContainerHeader();
record.setStatus((short) QuantityConstant.RECEIPT_CONTAINER_BUILD.intValue());
|
|
193
|
record.setId(taskHeader.getAllocationHeadId());
|
|
194
195
196
|
if (!receiptContainerHeaderService.updateById(record)) {
throw new ServiceException("回滚组盘明细失败");
}
|
|
197
198
199
|
}
//根据任务类型来更新货箱状态
//修改关联的货箱状态
|
|
200
|
if (taskHeader.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_PICKING) {
|
|
201
202
|
ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
shipmentContainerHeader.setId(taskHeader.getAllocationHeadId());
|
|
203
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
|
|
204
205
|
shipmentContainerHeaderService.updateById(shipmentContainerHeader);
}
|
|
206
|
//盘点取消任务,恢复明细状态为1
|
|
207
|
if (taskHeader.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_CYCLECOUNT) {
|
|
208
209
210
211
212
213
214
215
216
217
|
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);//
|
|
218
|
for (CycleCountDetail item : cycleCountDetailList) {
|
|
219
220
221
222
223
224
225
226
227
|
item.setTaskHeaderId(null);
item.setTaskHeaderId(null);
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setEnableStatus(1);
cycleCountDetailService.saveOrUpdate(item);
}
}
|
|
228
229
|
if (taskHeader.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_SHELF || taskHeader.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_PICKING) {
if (taskHeader.getToLocation() != null) {
|
|
230
231
232
233
234
235
236
237
238
239
240
241
|
//更新托盘、库位状态
locationService.updateStatus(taskHeader.getToLocation(), "empty");
}
}
// if(task.getType()==900){
// //出库查看任务没有关联的货箱,不做处理
// }
}
return AjaxResult.success("取消任务成功!");
}
|
|
242
243
|
/**
* 生成出库任务
|
|
244
|
*
|
|
245
246
247
248
249
|
* @param shipmentTaskCreateModel
* @return
*/
@Override
@Transactional
|
|
250
|
public AjaxResult createTaskFromShipmentContainers(ShipmentTaskCreateModel shipmentTaskCreateModel) {
|
|
251
|
Boolean flag = true;
|
|
252
253
254
|
Integer shipmentContainerHeaderId = shipmentTaskCreateModel.getShipmentContainerHeaderIds();
//获取表头
ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerHeaderId);
|
|
255
|
if (shipmentContainerHeader == null) {
|
|
256
257
|
return AjaxResult.error("出库货箱" + shipmentContainerHeaderId + "未找到,操作中止");
}
|
|
258
|
if (shipmentContainerHeader.getStatus() >= QuantityConstant.SHIPMENT_CONTAINER_TASK) {
|
|
259
260
261
|
return AjaxResult.error("出库货箱" + shipmentContainerHeader.getContainerCode() + "已经生成任务,请不要重复生成,操作中止");
}
//获取所有子货箱
|
|
262
263
|
LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId, shipmentContainerHeader.getId());
|
|
264
|
List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(lambdaQueryWrapper);
|
|
265
|
if (shipmentContainerDetails == null || shipmentContainerDetails.size() == 0) {
|
|
266
267
268
|
return AjaxResult.error("货箱" + shipmentContainerHeader.getContainerCode() + "没有子任务,操作中止");
}
//检测库位
|
|
269
270
271
272
|
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getCode, shipmentContainerHeader.getLocationCode())
.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(Location::getDeleted, false);
|
|
273
|
Location location = locationService.getOne(locationLambdaQueryWrapper);
|
|
274
|
if (location == null) {
|
|
275
276
277
278
279
|
return AjaxResult.error("库位禁用或不存在!");
}
//创建任务头
TaskHeader task = new TaskHeader();
//分拣出库
|
|
280
|
task.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
|
|
281
|
task.setFromLocation(shipmentContainerHeader.getLocationCode());
|
|
282
|
task.setToLocation(shipmentContainerHeader.getLocationCode());
|
|
283
|
//判断是否整出任务,钱柜和AGV不能整出
|
|
284
|
|
|
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
//表示整出优先
//判断当前子货箱所有数量是否等于该托盘对应的所有库存的数量,
//这里必须与库存的在库数量对比,后期可能存在一个配盘在执行任务,后一个配盘又在配这个的情况(这个时候不能整出)
// 如果相等,则说明这个货箱包含了所有的数量,则可以整出,否则,创建拣选任务;
//查询所有库存
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("");
}
|
|
306
|
|
|
307
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_PICKING);
|
|
308
|
task.setAllocationHeadId(shipmentContainerHeader.getId());
|
|
309
310
311
312
|
task.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
task.setCompanyCode(shipmentContainerHeader.getCompanyCode());
task.setAssignedUser(ShiroUtils.getLoginName());
task.setConfirmedBy(ShiroUtils.getLoginName());
|
|
313
|
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
314
315
316
317
318
319
320
|
task.setContainerCode(shipmentContainerHeader.getContainerCode());
task.setCreatedBy(ShiroUtils.getLoginName());
task.setCreated(new Date());
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(null);
this.save(task);
//遍历子货箱创建子任务
|
|
321
|
for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetails) {
|
|
322
323
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
|
|
324
|
taskDetail.setInternalTaskType(task.getInternalTaskType());
|
|
325
326
|
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setCompanyCode(task.getCompanyCode());
|
|
327
|
taskDetail.setTaskType(task.getTaskType());
|
|
328
|
taskDetail.setToInventoryId(shipmentContainerDetail.getInventoryId());
|
|
329
|
taskDetail.setAllocationId(shipmentContainerDetail.getId());
|
|
330
331
332
333
|
taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
taskDetail.setMaterialCode(shipmentContainerDetail.getMaterialCode());
taskDetail.setMaterialName(shipmentContainerDetail.getMaterialName());
|
|
334
335
|
taskDetail.setMaterialSpec(shipmentContainerDetail.getMaterialSpec());
taskDetail.setMaterialUnit(shipmentContainerDetail.getMaterialUnit());
|
|
336
337
338
|
taskDetail.setFromInventoryId(shipmentContainerDetail.getInventoryId());
taskDetail.setQty(shipmentContainerDetail.getQty());
taskDetail.setContainerCode(task.getContainerCode());
|
|
339
340
|
taskDetail.setFromLocation(task.getFromLocation());
taskDetail.setToLocation(task.getToLocation());
|
|
341
342
343
|
taskDetail.setLot(shipmentContainerDetail.getLot());
taskDetail.setBatch(shipmentContainerDetail.getBatch());
taskDetail.setProjectNo(shipmentContainerDetail.getProjectNo());
|
|
344
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
345
|
taskDetail.setWaveId(shipmentContainerDetail.getWaveId());
|
|
346
|
taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
|
|
347
|
taskDetail.setCreatedBy(ShiroUtils.getLoginName());
|
|
348
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
349
350
|
flag = taskDetailService.save(taskDetail);
if (flag == false) {
|
|
351
352
353
|
throw new ServiceException("新建任务明细失败,sql报错");
}
|
|
354
|
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
|
|
355
356
|
}
//更新货位状态
|
|
357
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
|
|
358
|
flag = shipmentContainerHeaderService.updateById(shipmentContainerHeader);
|
|
359
|
if (flag == false) {
|
|
360
361
362
363
|
throw new ServiceException("修改组盘头状态失败,sql报错");
}
flag = shipmentContainerDetailService.updateBatchById(shipmentContainerDetails);
|
|
364
|
if (flag == false) {
|
|
365
366
|
throw new ServiceException("修改组盘明细状态明细失败,sql报错");
}
|
|
367
368
369
|
return AjaxResult.success(task.getId());
}
|
|
370
|
|
|
371
|
/**
|
|
372
|
* 下发WCS执行任务
|
|
373
|
* 执行任务
|
|
374
|
*/
|
|
375
|
@Override
|
|
376
|
@Transactional
|
|
377
|
public AjaxResult<TaskHeader> sendTaskToWcs(Integer[] taskIds) {
|
|
378
379
|
TaskHeader task = null;
for (Integer taskId : taskIds) {
|
|
380
|
task = taskHeaderService.getById(taskId);
|
|
381
|
|
|
382
|
if (task.getStatus() >= QuantityConstant.TASK_STATUS_RELEASE) {
|
|
383
384
|
return AjaxResult.error("任务" + taskId + "已经下发,请不要重复下发,操作中止");
}
|
|
385
386
|
// 给wcs传递任务
taskAssignService.wcsTaskAssign(task);
|
|
387
|
|
|
388
|
//修改任务头表
|
|
389
|
task.setId(taskId);
|
|
390
|
task.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
391
392
393
|
task.setStartPickDateTime(new Date()); //生成时间
task.setLastUpdated(new Date());
task.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
394
|
taskHeaderService.saveOrUpdate(task);
|
|
395
|
//修改任务明细状态
|
|
396
397
398
399
|
LambdaQueryWrapper<TaskDetail> lambdaWrapper = Wrappers.lambdaQuery();
lambdaWrapper.eq(TaskDetail::getTaskId, task.getId());
List<TaskDetail> taskDetailList = taskDetailService.list(lambdaWrapper);
List<TaskDetail> taskDetails = new ArrayList<>();
|
|
400
|
for (TaskDetail item : taskDetailList) {
|
|
401
|
item.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
|
|
402
403
404
405
406
|
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
item.setProcessStamp("100");
taskDetails.add(item);
//盘点执行修改盘点单据状态为10
|
|
407
408
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
cycleCountDetailService.updataDetailStatus(item.getBillDetailId(), QuantityConstant.CYCLECOUNT_STATUS_EXECUTING);
|
|
409
|
}
|
|
410
|
}
|
|
411
|
if (!taskDetailService.saveOrUpdateBatch(taskDetails)) {
|
|
412
413
|
throw new ServiceException("更新任务明细失败");
}
|
|
414
|
|
|
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
// //修改入库明细
// 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);
// }
// }
|
|
454
|
}
|
|
455
|
return AjaxResult.success("执行下发任务成功", task);
|
|
456
457
458
|
}
@Override
|
|
459
|
@Transactional
|
|
460
|
public AjaxResult completeTaskByWMS(Integer[] taskIds) {
|
|
461
462
463
464
465
466
|
for (int taskId : taskIds) {
TaskHeader task = taskHeaderService.getById(taskId);
if (task == null) {
throw new ServiceException("任务" + taskId + "未找到,执行中止");
}
//如果已完成则不管
|
|
467
|
if (task.getStatus() == QuantityConstant.TASK_STATUS_COMPLETED) {
|
|
468
469
470
|
throw new ServiceException("任务(" + taskId + ")任务已经是完成的!");
}
//如果没有库位不能完成
|
|
471
472
473
|
// if (StringUtils.isEmpty(task.getFromLocation())) {
// throw new ServiceException("任务" + taskId + "没有库位,执行中止");
// }
|
|
474
|
this.completeTask(task);
|
|
475
|
|
|
476
477
478
479
480
481
482
483
484
485
|
}
return AjaxResult.success("完成任务成功!");
}
/**
* 完成任务
*
* @param task
*/
|
|
486
487
|
@Transactional
public void completeTask(TaskHeader task) {
|
|
488
|
//区分任务类型
|
|
489
|
if (task.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_SHELF) {
|
|
490
491
492
|
//入库任务
completeReceiptTask(task);
}
|
|
493
|
if (task.getInternalTaskType() == QuantityConstant.TASK_INTENERTYPE_PICKING) {
|
|
494
495
|
// 出库任务
completeShipmentTask(task);
|
|
496
|
}
|
|
497
|
// 900 出库查看,空托出库查看
|
|
498
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_VIEW) {
|
|
499
|
completeSeeOutTask(task);
|
|
500
|
}
|
|
501
|
// 700 盘点
|
|
502
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
|
|
503
504
|
completeCycleCountTask(task);
}
|
|
505
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_TRANSFER) {
|
|
506
|
// //移库
|
|
507
|
completeTransferTask(task);
|
|
508
|
}
|
|
509
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_EMPTYRECEIPT) {
|
|
510
|
//空托盘入库
|
|
511
|
completeEmptyIn(task);
|
|
512
|
}
|
|
513
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT) {
|
|
514
|
//空托盘出库
|
|
515
|
completeEmptyOut(task);
|
|
516
517
518
|
}
}
|
|
519
520
|
/**
|
|
521
|
* 完成入库任务
|
|
522
|
*/
|
|
523
|
@Override
|
|
524
|
@Transactional
|
|
525
|
public AjaxResult completeReceiptTask(TaskHeader task) {
|
|
526
527
|
List<Map<String, Object>> taskReceiptContainerDetail = taskHeaderMapper.getReceiptTask(task.getId());
if (taskReceiptContainerDetail.size() < 1) {
|
|
528
529
|
return AjaxResult.success("未找到对应任务的入库单号!!!");
}
|
|
530
531
|
for (Map<String, Object> map : taskReceiptContainerDetail) {
//将未完成的任务数量更新到库存表
|
|
532
|
if (DataUtils.getInteger(map.get("status")) < QuantityConstant.TASK_STATUS_COMPLETED) {
|
|
533
534
535
536
537
538
539
|
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
inventory.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(InventoryDetail::getLocationCode, task.getFromLocation())
.eq(InventoryDetail::getReceiptDetailId, DataUtils.getString(map.get("receiptDetailId")))
.eq(InventoryDetail::getContainerCode, DataUtils.getString(map.get("containerCode")));
InventoryDetail detail = inventoryDetailService.getOne(inventory);
if (detail == null) {
|
|
540
541
542
543
544
|
//添加库存单
InventoryHeader header = new InventoryHeader();
header.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));//仓库
header.setCompanyCode(task.getCompanyCode());//货主
header.setContainerCode(DataUtils.getString(map.get("containerCode")));//容器号
|
|
545
|
header.setLocationCode(task.getToLocation());
|
|
546
547
548
549
550
551
|
header.setTotalQty(DataUtils.getInteger(map.get("totalQty")));//总数量
header.setLocking(1);
header.setEnable(1);
header.setCreatedBy(ShiroUtils.getLoginName());
header.setCreated(new Date());
header.setLastUpdated(new Date());
|
|
552
553
554
|
if (!inventoryHeaderService.save(header))
throw new ServiceException("添加库存单失败");
|
|
555
556
557
558
559
|
//库存明细添加
detail = new InventoryDetail();
detail.setInventoryHeaderId(header.getId());//库存头ID
detail.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));//仓库
detail.setCompanyCode(task.getCompanyCode());//货主
|
|
560
|
detail.setLocationCode(task.getToLocation());//库位号
|
|
561
562
563
564
|
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")));//物料规格
|
|
565
|
detail.setMaterialUnit(DataUtils.getString(map.get("materialUnit")));//物料单位
|
|
566
|
detail.setReceiptCode(DataUtils.getString(map.get("receiptCode")));//入库单编码
|
|
567
|
detail.setReceiptDetailId(DataUtils.getInteger(map.get("receiptDetailId")));//入库单明细ID
|
|
568
569
570
|
detail.setBatch(DataUtils.getString(map.get("batch")));//批次
detail.setLot(DataUtils.getString(map.get("lot")));//批号
detail.setInventorySts(DataUtils.getString(map.get("inventorySts")));//库存状态
|
|
571
|
// detail.setManufactureDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("manufactureDate").toString()));//生产日期
|
|
572
|
// detail.setExpirationDate(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("expirationDate").toString()));//失效日期
|
|
573
|
detail.setQty(DataUtils.getBigDecimal(map.get("qty")));//数量
|
|
574
|
detail.setTaskQty(DataUtils.getBigDecimal(0));
|
|
575
576
|
detail.setCreatedBy(ShiroUtils.getLoginName());//创建人
detail.setLastUpdatedBy(ShiroUtils.getLoginName());//创建时间
|
|
577
578
|
if (!inventoryDetailService.save(detail))
throw new ServiceException("添加库存明细失败");
|
|
579
|
} else {
|
|
580
581
582
|
detail.setQty(detail.getQty().add(DataUtils.getBigDecimal(map.get("qty"))));
detail.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<InventoryDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
583
|
lambdaUpdateWrapper.eq(InventoryDetail::getId, DataUtils.getInteger(map.get("receiptDetailId")));
|
|
584
|
if (!inventoryDetailService.update(detail, lambdaUpdateWrapper))
|
|
585
|
throw new ServiceException("更新入库单明细失败");
|
|
586
|
|
|
587
588
589
|
}
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
|
|
590
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
|
|
591
592
|
inventoryTransaction.setWarehouseCode(DataUtils.getString(map.get("warehouseCode")));
inventoryTransaction.setCompanyCode(task.getCompanyCode());
|
|
593
|
inventoryTransaction.setLocationCode(task.getToLocation());
|
|
594
595
596
|
inventoryTransaction.setContainerCode(DataUtils.getString(map.get("containerCode")));
inventoryTransaction.setMaterialCode(DataUtils.getString(map.get("materialCode")));
inventoryTransaction.setMaterialName(DataUtils.getString(map.get("materialName")));
|
|
597
598
|
inventoryTransaction.setMaterialSpec(DataUtils.getString(map.get("materialSpec")));//物料规格
inventoryTransaction.setMaterialUnit(DataUtils.getString(map.get("materialUnit")));//物料单位
|
|
599
|
inventoryTransaction.setBillCode(DataUtils.getString(map.get("receiptCode")));
|
|
600
|
inventoryTransaction.setBillDetailId(DataUtils.getInteger(map.get("receiptDetailId")));
|
|
601
602
603
|
inventoryTransaction.setBatch(DataUtils.getString(map.get("batch")));
inventoryTransaction.setLot(DataUtils.getString(map.get("lot")));
inventoryTransaction.setInventorySts(DataUtils.getString((map.get("inventorySts"))));
|
|
604
|
inventoryTransaction.setTaskQty(DataUtils.getBigDecimal(map.get("qty")));
|
|
605
606
|
inventoryTransaction.setCreated(new Date());
inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
|
|
607
608
|
if (!inventoryTransactionService.save(inventoryTransaction))
throw new ServiceException("新增库存记录失败");
|
|
609
610
|
//修改任务明细的状态为完成
TaskDetail taskDetail = new TaskDetail();
|
|
611
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
612
613
614
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setAgingDate(new Date()); //入库时间
LambdaUpdateWrapper<TaskDetail> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
615
|
lambdaUpdateWrapper.eq(TaskDetail::getTaskId, task.getId());
|
|
616
|
taskDetailService.update(taskDetail, lambdaUpdateWrapper);
|
|
617
|
if (!taskDetailService.update(taskDetail, lambdaUpdateWrapper)) {
|
|
618
619
|
throw new ServiceException("修改入库单明细失败");
}
|
|
620
|
|
|
621
|
//修改任务主表状态,因为立库任务表单头只对应一个货箱,表单详情的任务会同时完成
|
|
622
|
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
623
624
625
626
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
LambdaUpdateWrapper<TaskHeader> taskHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
taskHeaderLambdaUpdateWrapper.eq(TaskHeader::getId, task.getId());
|
|
627
628
|
if (!taskHeaderService.update(task, taskHeaderLambdaUpdateWrapper))
throw new ServiceException("更新任务主表失败");
|
|
629
630
631
|
//修改库位状态和对应的容器
Location location = new Location();
|
|
632
633
|
location.setContainerCode(task.getContainerCode());
location.setStatus("empty");
|
|
634
|
LambdaUpdateWrapper<Location> locationLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
635
|
locationLambdaUpdateWrapper.eq(Location::getCode, task.getToLocation());
|
|
636
|
if (!locationService.update(location, locationLambdaUpdateWrapper))
|
|
637
|
throw new ServiceException("更新库位失败");
|
|
638
639
640
|
//修改容器状态和对应的库位
Container container = new Container();
|
|
641
|
container.setLocationCode(task.getToLocation());
|
|
642
|
container.setStatus("some");
|
|
643
|
LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
644
|
containerLambdaUpdateWrapper.eq(Container::getCode, task.getContainerCode());
|
|
645
|
if (!containerService.update(container, containerLambdaUpdateWrapper)) {
|
|
646
|
throw new ServiceException("更新容器失败");
|
|
647
|
}
|
|
648
|
//修改组盘表状态为20
|
|
649
|
ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
|
|
650
|
receiptContainerDetail.setStatus(QuantityConstant.RECEIPT_CONTAINER_REVIEWSUCCESS);
|
|
651
652
653
|
receiptContainerDetail.setProcessStamp("0");
receiptContainerDetail.setLastUpdated(new Date());
receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
654
|
LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
655
|
receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getReceiptId, DataUtils.getInteger(map.get("receiptId")));
|
|
656
|
if (!receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper))
|
|
657
|
throw new ServiceException("更新组盘状态失败");
|
|
658
|
|
|
659
660
661
662
663
664
665
|
//修改入库组盘头表状态
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(task.getAllocationHeadId());
receiptContainerHeader.setLastUpdated(new Date());
receiptContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
666
|
receiptContainerHeader.setStatus((short) QuantityConstant.RECEIPT_CONTAINER_FINISHED.intValue());
|
|
667
|
if (!receiptContainerHeaderService.updateById(receiptContainerHeader)) {
|
|
668
669
670
|
throw new ServiceException("更新入库组盘头表状态失败");
}
|
|
671
672
|
//修改入库单状态
ReceiptHeader receiptHeader = new ReceiptHeader();
|
|
673
674
|
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
|
|
675
676
677
|
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setLastUpdated(new Date());
LambdaUpdateWrapper<ReceiptHeader> receiptHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
678
679
|
receiptHeaderLambdaUpdateWrapper.eq(ReceiptHeader::getId, DataUtils.getInteger(map.get("receiptId")));
if (!receiptHeaderService.update(receiptHeader, receiptHeaderLambdaUpdateWrapper)) {
|
|
680
|
throw new ServiceException("更新入库头表状态失败");
|
|
681
|
}
|
|
682
|
|
|
683
684
685
686
|
/* 物料预警*/
configWarningService.materialWarning(String.valueOf(map.get("materialCode")), String.valueOf(map.get("materialName")));
/* 空库位剩余数量预警*/
configWarningService.emptyLocationWarning();
|
|
687
688
|
}
|
|
689
|
}
|
|
690
|
return AjaxResult.success("完成入库任务");
|
|
691
|
}
|
|
692
693
694
695
696
697
|
// @Override
// public List<Map<String, Object>> getReceiptTask(Integer taskId) {
// return taskHeaderMapper.getReceiptTask(taskId) ;
// }
|
|
698
|
/**
|
|
699
|
* 生成
|
|
700
|
* 立库移库
|
|
701
|
*/
|
|
702
|
@Transactional
|
|
703
|
public AjaxResult createTransferTask(String sourceLocation, String destinationLocation) {
|
|
704
|
|
|
705
706
|
//源库位校验
Location temp1 = new Location();
|
|
707
|
temp1.setCode(sourceLocation);
|
|
708
|
temp1.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
709
|
LambdaQueryWrapper<Location> lambda1 = Wrappers.lambdaQuery(temp1);
|
|
710
|
Location loc1 = locationService.getOne(lambda1);
|
|
711
712
|
if (loc1 == null) {
return AjaxResult.error("源库位:" + sourceLocation + "未找到");
|
|
713
|
}
|
|
714
715
|
if (!loc1.getStatus().equals("empty")) {
return AjaxResult.error("源库位:" + sourceLocation + "状态非空闲");
|
|
716
|
}
|
|
717
718
|
if (StringUtils.isEmpty(loc1.getContainerCode())) {
return AjaxResult.error("源库位:" + sourceLocation + "不存在托盘");
|
|
719
720
721
|
}
//这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库
//校验入库组盘
|
|
722
723
724
|
int count1 = inventoryHeaderService.getUncompleteReceiptContainer(sourceLocation, ShiroUtils.getWarehouseCode());
if (count1 > 0) {
return AjaxResult.error("源库位:" + sourceLocation + "存在入库组盘,不能移库");
|
|
725
|
}
|
|
726
727
728
|
int count2 = inventoryHeaderService.getUncompleteShipmentContainer(sourceLocation, ShiroUtils.getWarehouseCode());
if (count2 > 0) {
return AjaxResult.error("源库位:" + sourceLocation + "存在出库组盘,不能移库");
|
|
729
|
}
|
|
730
|
//目的库位校验
|
|
731
|
Location temp2 = new Location();
|
|
732
|
temp2.setWarehouseCode(ShiroUtils.getWarehouseCode());
|
|
733
|
temp2.setCode(destinationLocation);
|
|
734
735
|
LambdaQueryWrapper<Location> lambdaQueryWrapper2 = Wrappers.lambdaQuery(temp2);
Location loc2 = locationService.getOne(lambdaQueryWrapper2);
|
|
736
737
|
if (loc2 == null) {
return AjaxResult.error("目标库位:" + destinationLocation + "未找到");
|
|
738
|
}
|
|
739
740
|
if (!loc2.getStatus().equals("empty")) {
return AjaxResult.error("目标库位:" + destinationLocation + "状态非空闲");
|
|
741
|
}
|
|
742
743
|
if (StringUtils.isNotEmpty(loc2.getContainerCode())) {
return AjaxResult.error("目标库位:" + destinationLocation + "已存在托盘");
|
|
744
|
}
|
|
745
746
747
|
int count3 = inventoryHeaderService.getUncompleteReceiptContainer(destinationLocation, ShiroUtils.getWarehouseCode());
if (count3 > 0) {
return AjaxResult.error("目标库位:" + sourceLocation + "存在入库组盘,不能移库");
|
|
748
|
}
|
|
749
750
751
752
|
//写入任务主表和明细表
TaskHeader taskHeader = new TaskHeader();
taskHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
taskHeader.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));//获取第一个货主
|
|
753
|
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_TRANSFER);
|
|
754
|
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_TRANSFER);
|
|
755
|
taskHeader.setContainerCode(loc1.getContainerCode());
|
|
756
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
|
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());
taskDetail.setCompanyCode(taskDetail.getCompanyCode());
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);
|
|
781
782
783
|
//更新货位状态为预定
loc1.setStatus("lock");
loc2.setStatus("lock");
|
|
784
785
786
787
788
789
790
791
|
locationService.saveOrUpdate(loc1);
locationService.saveOrUpdate(loc2);
return AjaxResult.success(taskHeader.getId());
}
/**
* 完成移库任务
|
|
792
|
*
|
|
793
794
|
* @param task
*/
|
|
795
|
@Transactional
|
|
796
|
public void completeTransferTask(TaskHeader task) {
|
|
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
|
//找到任务明细
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);
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);
|
|
826
|
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
|
|
827
828
|
/*同时写入库存交易表*/
List<InventoryTransaction> inventoryTransactionList = new ArrayList<>();
|
|
829
|
for (InventoryDetail item : inventoryDetailList) {
|
|
830
831
832
833
|
item.setLocationCode(inventoryHeader.getLocationCode());//修改明细表库位
item.setLastUpdated(new Date());
item.setLastUpdatedBy(ShiroUtils.getLoginName());
inventoryDetails.add(item);
|
|
834
|
/*----------*/
|
|
835
836
837
838
|
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
inventoryTransaction.setLocationCode(taskDetail.getToLocation());
inventoryTransaction.setContainerCode(taskDetail.getContainerCode());
|
|
839
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_ADJUSTPROPERTIES);
|
|
840
841
842
843
844
|
inventoryTransaction.setMaterialCode(item.getMaterialCode());
inventoryTransaction.setManufactureDate(item.getManufactureDate());
inventoryTransaction.setMaterialName(item.getMaterialName());
inventoryTransaction.setMaterialSpec(item.getMaterialSpec());
inventoryTransaction.setMaterialUnit(item.getMaterialUnit());
|
|
845
|
inventoryTransaction.setTaskQty(BigDecimal.ZERO);
|
|
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
|
inventoryTransaction.setInventorySts(item.getInventorySts());
//inventoryTransaction.setReferCode();
//inventoryTransaction.setQcCheck();
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());
inventoryDetailList.add(inventoryDetail);
}
|
|
869
|
if (inventoryDetailService.saveOrUpdateBatch(inventoryDetails)) {
|
|
870
871
|
//更新库存明细成功后,写入库存交易
inventoryTransactionService.saveBatch(inventoryTransactionList);
|
|
872
|
} else {
|
|
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
|
throw new ServiceException("库存明细更新错误!");
}
//更新托盘、库位状态
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);
//更新taskHeader状态
|
|
895
|
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
896
897
898
899
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
taskHeaderService.saveOrUpdate(task);
//更新taskDetail状态
|
|
900
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
901
902
903
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setLastUpdated(new Date());
taskDetailService.saveOrUpdate(taskDetail);
|
|
904
905
|
}
|
|
906
|
/**
|
|
907
908
|
* 生成
* 出库查看
|
|
909
|
* 任务
|
|
910
|
*/
|
|
911
912
913
914
|
@Override
@Transactional
public AjaxResult createCheckOutTask(String[] ids) {
|
|
915
916
|
for (String id : ids) {
InventoryHeader inventoryHeader = inventoryHeaderService.getById(Integer.parseInt(id));
|
|
917
|
//校验库位是否锁定
|
|
918
919
920
921
922
923
|
//检查库位容器
Location temp = new Location();
temp.setCode(inventoryHeader.getLocationCode());
temp.setWarehouseCode(inventoryHeader.getWarehouseCode());
LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery(temp);
Location loc = locationService.getOne(lambdaQueryWrapper);
|
|
924
|
if (loc == null) {
|
|
925
926
|
throw new ServiceException("库存没有库位!");
}
|
|
927
928
|
if (!loc.getStatus().equals("empty")) {
throw new ServiceException(inventoryHeader.getLocationCode() + "状态非空闲,操作失败");
|
|
929
|
}
|
|
930
931
|
if (StringUtils.isEmpty(loc.getContainerCode())) {
throw new ServiceException(inventoryHeader.getLocationCode() + "没有容器,操作失败");
|
|
932
933
934
935
936
937
938
|
}
//通过库存头,找到库存明细
InventoryDetail inventoryDetail = new InventoryDetail();
inventoryDetail.setWarehouseCode(inventoryHeader.getWarehouseCode());
inventoryDetail.setCompanyCode(inventoryHeader.getCompanyCode());
inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery(inventoryDetail);
|
|
939
|
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
|
|
940
941
942
943
944
|
//写入任务主表
TaskHeader taskHeader = new TaskHeader();
taskHeader.setWarehouseCode(inventoryHeader.getWarehouseCode());
taskHeader.setCompanyCode(inventoryHeader.getCompanyCode());//货主
|
|
945
946
|
taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_WORK);
taskHeader.setTaskType(QuantityConstant.TASK_TYPE_VIEW);
|
|
947
|
taskHeader.setContainerCode(inventoryHeader.getContainerCode());
|
|
948
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
|
|
949
950
951
952
953
954
955
956
957
|
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<>();
|
|
958
|
for (InventoryDetail item : inventoryDetailList) {
|
|
959
|
|
|
960
961
962
963
964
965
966
967
968
969
970
971
972
973
|
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);
|
|
974
975
976
|
}
if (taskDetailService.saveBatch(taskDetails)) {
//锁定库位状态
|
|
977
|
locationService.updateStatus(inventoryHeader.getLocationCode(), "lock");
|
|
978
979
980
|
} else {
throw new ServiceException("出库查看任务明细生成失败!");
}
|
|
981
|
|
|
982
983
984
|
}
return AjaxResult.success("出库查看任务生成成功!");
}
|
|
985
|
|
|
986
|
/**
|
|
987
|
* 完成
|
|
988
|
* 出库查看
|
|
989
|
* 更新状态即可
|
|
990
|
*/
|
|
991
992
|
@Transactional
@Override
|
|
993
|
public AjaxResult completeSeeOutTask(TaskHeader taskHeader) {
|
|
994
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
995
996
997
998
999
1000
1001
1002
1003
|
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);//查询子单
|
|
1004
|
List<TaskDetail> list = new CopyOnWriteArrayList<>();
|
|
1005
|
for (TaskDetail item : taskDetailList) {
|
|
1006
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1007
1008
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
|
|
1009
|
list.add(item);
|
|
1010
|
}
|
|
1011
1012
|
if (taskDetailService.saveOrUpdateBatch(list) == false ||
taskHeaderService.saveOrUpdate(taskHeader) == false) {
|
|
1013
1014
|
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1015
|
//释放库位状态
|
|
1016
|
locationService.updateStatus(taskHeader.getFromLocation(), "empty");
|
|
1017
1018
1019
1020
|
return AjaxResult.success("完成出库查看任务");
}
/**
|
|
1021
|
* 盘点完成
|
|
1022
|
*
|
|
1023
1024
1025
1026
1027
|
* @param taskHeader
* @return
*/
@Transactional
@Override
|
|
1028
|
public AjaxResult completeCycleCountTask(TaskHeader taskHeader) {
|
|
1029
1030
1031
|
/*盘点完成,传入任务主单,查出任务明细,通过任务明细查找盘点的明细单,
完成任务同时,修改盘点细单和主单的状态,完成后库存锁复位*/
//修改任务主单状态
|
|
1032
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
|
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<>();
|
|
1045
|
for (TaskDetail item : taskDetailList) {
|
|
1046
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1047
1048
1049
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
list.add(item);
|
|
1050
|
|
|
1051
|
CycleCountDetail cycleCountDetail = cycleCountDetailService.getById(item.getBillDetailId());//盘点明细
|
|
1052
|
cycleCountDetail.setEnableStatus(QuantityConstant.CYCLECOUNT_STATUS_COMPLETED);
|
|
1053
1054
1055
1056
1057
1058
1059
1060
|
cycleCountDetail.setCompletedBy(ShiroUtils.getLoginName());
cycleCountDetail.setCompletedAt(new Date());
cycleCountDetailList.add(cycleCountDetail);
//取消库存盘点锁
InventoryDetail inventoryDetail = inventoryDetailService.getById(cycleCountDetail.getInventoryDetailId());
inventoryDetail.setLockCode("");
inventoryDetailService.saveOrUpdate(inventoryDetail);
}
|
|
1061
|
if (taskHeaderService.saveOrUpdate(taskHeader) == false ||
|
|
1062
1063
1064
1065
1066
1067
1068
1069
1070
|
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("完成盘点任务");
|
|
1071
1072
1073
1074
|
}
/**
|
|
1075
|
* 完成空托盘入库任务
|
|
1076
|
*
|
|
1077
1078
1079
1080
1081
1082
|
* @param taskHeader
*/
@Transactional
public void completeEmptyIn(TaskHeader taskHeader) {
//完成任务,修改主单和明细状态
|
|
1083
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
|
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) {
|
|
1095
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1096
1097
1098
1099
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
taskDetailList.add(item);
}
|
|
1100
1101
|
if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false ||
taskHeaderService.saveOrUpdate(taskHeader) == false) {
|
|
1102
1103
|
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1104
|
//解锁容器,更新库位
|
|
1105
|
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), taskHeader.getToLocation(), "empty");
|
|
1106
|
//解锁库位,更新容器
|
|
1107
|
locationService.updateContainerCodeAndStatus(taskHeader.getToLocation(), taskHeader.getContainerCode(), "empty");
|
|
1108
1109
1110
1111
1112
|
}
/**
* 完成空托盘出库任务
|
|
1113
|
*
|
|
1114
1115
1116
1117
1118
|
* @param taskHeader
*/
@Transactional
public void completeEmptyOut(TaskHeader taskHeader) {
|
|
1119
|
taskHeader.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
|
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) {
|
|
1131
|
item.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1132
1133
1134
1135
1136
1137
1138
|
item.setLastUpdatedBy(ShiroUtils.getLoginName()); //更新用户
item.setLastUpdated(new Date()); //更新时间
taskDetailList.add(item);
}
if (taskDetailService.saveOrUpdateBatch(taskDetailList) == false || taskHeaderService.saveOrUpdate(taskHeader) == false) {
throw new ServiceException("任务单据状态更新失败!");
}
|
|
1139
1140
1141
1142
1143
|
//更新货位
locationService.updateContainerCodeAndStatus(taskHeader.getFromLocation(), "", "empty");
//更新容器信息
containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), "", "empty");
|
|
1144
1145
|
}
|
|
1146
1147
|
/**
* 创建上架任务
|
|
1148
|
*
|
|
1149
1150
1151
1152
|
* @param ids
* @return
*/
@Override
|
|
1153
|
@Transactional
|
|
1154
|
public AjaxResult createReceiptTask(List<Integer> ids) {
|
|
1155
|
for (Integer id : ids) {
|
|
1156
1157
1158
|
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(id);
if (receiptContainerHeader == null)
throw new ServiceException("任务不存在!");
|
|
1159
|
if (!receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode()))
|
|
1160
|
throw new ServiceException("任务不在当前仓库!");
|
|
1161
1162
1163
1164
1165
1166
1167
1168
1169
|
//锁定容器
Container container = new Container();
container.setStatus("lock");
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, receiptContainerHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
//查询入库组盘明细
|
|
1170
|
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
|
|
1171
|
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptContainerId, id);
|
|
1172
|
List<ReceiptContainerDetail> list = receiptContainerDetailService.list(containerDetailLambda);
|
|
1173
|
|
|
1174
1175
|
if (list.size() < 1)
throw new ServiceException("没有组盘明细,请先组盘!");
|
|
1176
1177
1178
|
if (receiptContainerHeader.getStatus() == QuantityConstant.RECEIPT_CONTAINER_BUILD.intValue()) {
if (receiptContainerHeader.getStatus().intValue() < QuantityConstant.RECEIPT_CONTAINER_TASK) {
receiptContainerHeader.setStatus((short) QuantityConstant.RECEIPT_CONTAINER_TASK.intValue());
|
|
1179
1180
1181
1182
|
receiptContainerHeaderService.updateById(receiptContainerHeader);
}
//添加任务主表
TaskHeader task = new TaskHeader();
|
|
1183
|
task.setAllocationHeadId(receiptContainerHeader.getId());
|
|
1184
|
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHELF);
|
|
1185
1186
1187
1188
1189
1190
1191
|
task.setWarehouseCode(receiptContainerHeader.getWarehouseCode());
task.setCompanyCode(receiptContainerHeader.getCompanyCode());
task.setFromLocation(receiptContainerHeader.getFromLocation());
task.setTaskType(Integer.valueOf(receiptContainerHeader.getTaskType()));
task.setFromLocation(receiptContainerHeader.getFromLocation());
task.setToLocation(receiptContainerHeader.getToLocation());
task.setContainerCode(receiptContainerHeader.getContainerCode());
|
|
1192
|
task.setRecvDock(receiptContainerHeader.getRecvDock());
|
|
1193
1194
|
task.setCreated(new Date());
task.setCreatedBy(ShiroUtils.getLoginName());
|
|
1195
|
if (this.save(task)) {
|
|
1196
|
//添加任务明细表
|
|
1197
|
int conatinQty = 0;
|
|
1198
|
for (ReceiptContainerDetail item : list) {
|
|
1199
1200
1201
1202
1203
1204
|
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())
|
|
1205
|
.eq(ContainerCapacity::getEnable, 0);
|
|
1206
1207
|
ContainerCapacity containerCapacity = containerCapacityService.getOne(lambdaQueryWrapper);
|
|
1208
1209
|
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
|
|
1210
|
taskDetail.setTaskType(Integer.valueOf(receiptContainerHeaderService.getById(item.getReceiptContainerId()).getTaskType()));
|
|
1211
|
taskDetail.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_SHELF);
|
|
1212
|
taskDetail.setWarehouseCode(task.getWarehouseCode());
|
|
1213
|
taskDetail.setAllocationId(item.getReceiptId());
|
|
1214
1215
1216
1217
|
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setMaterialCode(item.getMaterialCode());
taskDetail.setMaterialName(item.getMaterialName());
|
|
1218
1219
|
taskDetail.setMaterialSpec(item.getMaterialSpec());
taskDetail.setMaterialUnit(item.getMaterialUnit());
|
|
1220
1221
1222
|
taskDetail.setBillCode(item.getReceiptCode());
taskDetail.setBillDetailId(item.getReceiptDetailId());
taskDetail.setBillCode(item.getReceiptCode());
|
|
1223
|
taskDetail.setQty(item.getQty());
|
|
1224
1225
1226
1227
|
taskDetail.setContainerCode(task.getContainerCode());
taskDetail.setFromLocation(task.getFromLocation());
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
taskDetail.setBatch(item.getBatch());
|
|
1228
|
if (containerCapacity != null) {
|
|
1229
1230
1231
|
conatinQty += (int) Math.floor(item.getQty().intValue() / containerCapacity.getQty().intValue());
taskDetail.setContainQty((int) Math.floor(item.getQty().intValue() / containerCapacity.getQty().intValue()));
}
|
|
1232
|
if (!taskDetailService.save(taskDetail)) {
|
|
1233
1234
1235
|
throw new ServiceException("生成任务明细失败");
}
|
|
1236
|
//更新入库组盘明细状态
|
|
1237
|
item.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK);
|
|
1238
|
if (!receiptContainerDetailService.updateById(item)) {
|
|
1239
1240
|
throw new ServiceException("更新入库组盘明细状态出错");
}
|
|
1241
|
|
|
1242
|
ReceiptDetail receiptDetail = receiptDetailService.getById(item.getReceiptDetailId());
|
|
1243
1244
|
ReceiptDetail detail = receiptDetailService.queryflow(receiptDetail);
|
|
1245
|
if (!receiptDetailService.updateById(detail)) {
|
|
1246
|
throw new ServiceException("更新入库单详情失败");
|
|
1247
|
}
|
|
1248
1249
1250
|
//更新头表状态
receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
|
|
1251
|
}
|
|
1252
1253
|
task.setContainQty(conatinQty);
|
|
1254
|
if (!taskHeaderService.updateById(task)) {
|
|
1255
1256
|
throw new ServiceException("更新任务头表容器数量失败");
}
|
|
1257
1258
|
} else {
throw new ServiceException("生成任务头表失败");
|
|
1259
1260
1261
|
}
}
}
|
|
1262
|
return AjaxResult.success("生成上架任务成功!");
|
|
1263
|
}
|
|
1264
|
|
|
1265
1266
|
/**
* 完成出库任务
|
|
1267
|
*/
|
|
1268
|
@Override
|
|
1269
|
@Transactional
|
|
1270
1271
1272
1273
1274
1275
1276
|
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<>();
|
|
1277
1278
|
for (TaskDetail taskDetail : taskDetails) {
if (taskDetail.getStatus() < QuantityConstant.TASK_STATUS_RUNNING) {
|
|
1279
1280
1281
1282
1283
1284
1285
1286
|
//获取出库子货箱
ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getById(taskDetail.getAllocationId());
//取出子单据
ShipmentDetail shipmentDetail = shipmentDetailService.getById(taskDetail.getBillDetailId());
//暂存id,为更新单据状态准备
shipmentHeadIds.add(shipmentDetail.getShipmentId());
//获取对应库存记录
InventoryDetail inventoryDetail = inventoryDetailService.getById(taskDetail.getToInventoryId());
|
|
1287
|
if (inventoryDetail == null) {
|
|
1288
1289
1290
|
throw new ServiceException("任务明细对应的库存ID【" + taskDetail.getToInventoryId().toString() + "】不存在!");
}
BigDecimal orignalQty = inventoryDetail.getQty();
|
|
1291
1292
1293
1294
|
//减扣库存单
InventoryHeader inventoryHeader = inventoryHeaderService.getById(inventoryDetail.getInventoryHeaderId());
inventoryHeader.setTotalQty(inventoryDetail.getQty().subtract(taskDetail.getQty()).intValue());
//扣减库存明细
|
|
1295
1296
|
inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(taskDetail.getQty()));
inventoryDetail.setQty(inventoryDetail.getQty().subtract(taskDetail.getQty()));
|
|
1297
|
if (inventoryDetail.getQty().compareTo(new BigDecimal("0")) == 0 && inventoryDetail.getTaskQty().compareTo(new BigDecimal("0")) == 0) {
|
|
1298
1299
|
//如果库存没有了,就删除这个库存
inventoryDetailService.removeById(inventoryDetail.getId());
|
|
1300
|
inventoryHeaderService.removeById(inventoryHeader.getId());
|
|
1301
|
} else {
|
|
1302
1303
|
//否则更新这个库存
inventoryDetailService.updateById(inventoryDetail);
|
|
1304
|
inventoryHeaderService.updateById(inventoryHeader);
|
|
1305
1306
|
}
//设置子任务状态为已执行
|
|
1307
|
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1308
|
taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
|
|
1309
|
taskDetail.setLastUpdated(new Date());//完成时间
|
|
1310
1311
1312
1313
1314
1315
1316
|
taskDetailService.updateById(taskDetail);
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setWarehouseCode(task.getWarehouseCode());
inventoryTransaction.setCompanyCode(shipmentDetail.getCompanyCode());
inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode());
|
|
1317
|
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
|
|
1318
|
inventoryTransaction.setMaterialCode(shipmentDetail.getMaterialCode());
|
|
1319
1320
1321
|
inventoryTransaction.setMaterialName(shipmentDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(shipmentDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(shipmentDetail.getMaterialUnit());
|
|
1322
1323
1324
1325
|
inventoryTransaction.setBillCode(taskDetail.getBillCode());
inventoryTransaction.setBillDetailId(shipmentDetail.getId());
inventoryTransaction.setBatch(shipmentDetail.getBatch());
inventoryTransaction.setLot(shipmentDetail.getLot());
|
|
1326
1327
1328
|
inventoryTransaction.setProjectNo(shipmentDetail.getProjectNo());
inventoryTransaction.setQcCheck(inventoryDetail.getQcCheck());
inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode());
|
|
1329
1330
1331
1332
|
inventoryTransaction.setManufactureDate(shipmentDetail.getManufactureDate());
inventoryTransaction.setExpirationDate(shipmentDetail.getExpirationDate());
inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
//这里取反,更符合出库的语义,同时方便对记录进行统计
|
|
1333
|
inventoryTransaction.setTaskQty(taskDetail.getQty());
|
|
1334
1335
1336
1337
1338
1339
1340
|
// inventoryTransaction.setCostPrice(shipmentDetail.);
inventoryTransaction.setCreated(null);
inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName());
inventoryTransactionService.save(inventoryTransaction);
// //更新单据状态
// shipmentHeaderService.updateShipmentStatus(shipmentHeader.getId());
}
|
|
1341
1342
1343
1344
|
/* 物料预警*/
configWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getMaterialName());
/* 空库位剩余数量预警*/
configWarningService.emptyLocationWarning();
|
|
1345
1346
|
}
//设置主任务为已执行
|
|
1347
|
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
|
|
1348
1349
1350
|
task.setLastUpdatedBy(ShiroUtils.getLoginName());
task.setLastUpdated(new Date());
taskHeaderService.updateById(task);
|
|
1351
1352
|
|
|
1353
|
//将库位状态改为空闲,如果是整出的对应的容器也清空
|
|
1354
|
|
|
1355
1356
|
LambdaQueryWrapper<Location> lam = Wrappers.lambdaQuery();
lam.eq(Location::getCode, task.getFromLocation());
|
|
1357
|
Location locationRecord = locationService.getOne(lam);
|
|
1358
1359
|
if (lam == null) {
throw new ServiceException("系统没有" + task.getToLocation() + "库位");
|
|
1360
|
}
|
|
1361
|
locationRecord.setStatus("empty");
|
|
1362
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_WHOLESHIPMENT) {
|
|
1363
1364
|
locationRecord.setContainerCode("");
}
|
|
1365
|
locationService.updateById(locationRecord);
|
|
1366
|
//如果是整出,删掉这个库位上的这个托盘,否则更改托盘状态
|
|
1367
|
LambdaQueryWrapper<Container> containerLam = Wrappers.lambdaQuery();
|
|
1368
|
containerLam.eq(Container::getCode, task.getContainerCode());
|
|
1369
|
Container ctn = containerService.getOne(containerLam);
|
|
1370
|
if (ctn == null) {
|
|
1371
1372
|
throw new ServiceException("系统无此容器");
}
|
|
1373
1374
|
if (task.getTaskType() == QuantityConstant.TASK_TYPE_WHOLESHIPMENT) {
if (ctn.getContainerType().equals("LS")) {
|
|
1375
|
Boolean flag = containerService.removeById(ctn.getId());
|
|
1376
|
if (flag == false) {
|
|
1377
1378
|
throw new ServiceException("删除临时容器失败");
}
|
|
1379
|
} else {
|
|
1380
1381
|
containerService.updateLocationCodeAndStatus(task.getContainerCode(), "", "empty");
}
|
|
1382
|
} else {
|
|
1383
1384
1385
1386
|
//查询是否存在关联的库存,入如果没有就修改容器状态为empty
InventoryDetail inventoryCondition = new InventoryDetail();
inventoryCondition.setLocationCode(task.getToLocation());
LambdaQueryWrapper<InventoryDetail> inventoryDetaillambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
1387
1388
|
inventoryDetaillambdaQueryWrapper.eq(InventoryDetail::getLocationCode, task.getToLocation());
List<InventoryDetail> detailList = inventoryDetailService.list();
|
|
1389
|
//库存查询不到该容器就把容器状态改为可用
|
|
1390
1391
|
if (detailList.size() < 1) {
Container container = new Container();
|
|
1392
1393
|
container.setCode(task.getToLocation());
condition.setToLocation("");
|
|
1394
1395
1396
|
LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
containerLambdaUpdateWrapper.eq(Container::getCode, task.getToLocation());
containerService.update(containerLambdaUpdateWrapper);
|
|
1397
1398
|
}
}
|
|
1399
|
//设置出库货箱状态为拣货任务完成
|
|
1400
|
for (TaskDetail taskDetail : taskDetails) {
|
|
1401
|
ShipmentContainerDetail shipmentContainerDetail = new ShipmentContainerDetail();
|
|
1402
|
shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS);
|
|
1403
1404
1405
1406
1407
1408
1409
|
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("更新组盘明细状态失败");
}
|
|
1410
|
}
|
|
1411
|
//设置出库货箱表头状态为拣货任务完成
|
|
1412
|
ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
|
|
1413
|
shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS);
|
|
1414
1415
1416
|
shipmentContainerHeader.setLastUpdated(new Date());
shipmentContainerHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaUpdateWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
|
|
1417
1418
|
shipmentContainerHeaderLambdaUpdateWrapper.eq(ShipmentContainerHeader::getId, task.getAllocationHeadId());
if (!shipmentContainerHeaderService.update(shipmentContainerHeader, shipmentContainerHeaderLambdaUpdateWrapper)) {
|
|
1419
|
throw new ServiceException("更新组盘头状态失败");
|
|
1420
1421
|
}
//修改出库单状态
|
|
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
|
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());
}
|
|
1440
|
|
|
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
|
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 == QuantityConstant.SHIPMENT_HEADER_COMPLETED) {
shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
if (minStatus == QuantityConstant.SHIPMENT_HEADER_COMPLETED) {
shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
}
shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
shipmentHeader.setLastUpdated(new Date());
shipmentHeaderService.updateById(shipmentHeader);
}
}
|
|
1458
|
|
|
1459
|
}
|
|
1460
|
}
|