ReceiptTaskService.java
32.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
package com.huaheng.pc.task.taskHeader.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.huaheng.api.wcs.domain.TaskReceiptCompleteDomain;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.warecellAllocation.WarecellAllocationService;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DataUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
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;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.materialMultiple.domain.MaterialMultiple;
import com.huaheng.pc.config.materialMultiple.service.MaterialMultipleServiceImpl;
import com.huaheng.pc.config.materialUnit.domain.MaterialUnit;
import com.huaheng.pc.config.materialWarnning.domain.MaterialWarning;
import com.huaheng.pc.config.materialWarnning.service.IMaterialWarningService;
import com.huaheng.pc.config.materialWarnning.service.impl.MaterialWarningServiceImpl;
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.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
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;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.system.config.domain.Config;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.mapper.TaskHeaderMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.*;
/**
* 入库任务创建和完成
* @author mahua
* @date 2020/7/6
*/
@Service
public class ReceiptTaskService {
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryTransactionService inventoryTransactionService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private TaskHeaderMapper taskHeaderMapper;
@Resource
private ContainerService containerService;
@Resource
private LocationService locationService;
@Resource
private MaterialService materialService;
@Resource
private MaterialMultipleServiceImpl materialMultipleService;
@Resource
private IMaterialWarningService materialWarningService;
@Resource
private WarecellAllocationService warecellAllocationService;
/**
* 创建入库任务(整盘入库、补充入库)
*
* @param ids 入库组盘头表id
* @return AjaxResult 创建结果
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult createReceiptTask(List<Integer> ids) {
List<String> taskIds = new ArrayList<>();
for (Integer id : ids) {
ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(id);
//检查组盘信息,托盘是否锁定,锁定容器,检查组盘明细
checkReceiptTask(receiptContainerHeader,id);
//查询入库组盘明细
LambdaQueryWrapper<ReceiptContainerDetail> lam = Wrappers.lambdaQuery();
lam.eq(ReceiptContainerDetail::getReceiptContainerId,id);
lam.lt(ReceiptContainerDetail::getStatus,QuantityConstant.RECEIPT_CONTAINER_TASK);
List<ReceiptContainerDetail> list = receiptContainerDetailService.list(lam);
// List<ReceiptContainerDetail> list = receiptContainerDetailService.getReceiptContainerDetailByHeaderId(id);
if (list.isEmpty()) {
throw new ServiceException("id:" + id + "的入库组盘,没有组盘明细,请先组盘!");
}
String containerCode = receiptContainerHeader.getContainerCode();
Container container = containerService.getContainerByCode(containerCode);
if(StringUtils.isNotNull(container) && "D".equals(container.getContainerType())){
receiptContainerHeader.setToLocation(container.getLocationCode());
receiptContainerHeader.setFromLocation(container.getLocationCode());
receiptContainerHeader.setTaskType(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
receiptContainerHeaderService.updateById(receiptContainerHeader);
for (ReceiptContainerDetail receiptContainerDetail : list) {
receiptContainerDetail.setLocationCode(container.getLocationCode());
receiptContainerDetail.setTaskType(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
}
receiptContainerDetailService.updateBatchById(list);
}
//检查库位容器,修改状态
checkLocationContainer(receiptContainerHeader);
if (receiptContainerHeader.getStatus() <= QuantityConstant.RECEIPT_CONTAINER_TASK.intValue()) {
if (receiptContainerHeader.getStatus() < QuantityConstant.RECEIPT_CONTAINER_TASK) {
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK);
receiptContainerHeaderService.updateById(receiptContainerHeader);
}
//添加任务主表
TaskHeader task=taskHeaderService.createTaskByReceipt(receiptContainerHeader);
LambdaQueryWrapper<TaskHeader> lambdaQuery = Wrappers.lambdaQuery();
lambdaQuery.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
lambdaQuery.eq(TaskHeader::getContainerCode,containerCode);
lambdaQuery.eq(TaskHeader::getInternalTaskType,100);
lambdaQuery.last("limit 1");
lambdaQuery.orderByDesc(TaskHeader::getId);
TaskHeader taskHeader=taskHeaderService.getOne(lambdaQuery);
if(taskHeader!=null){
task=taskHeader;
}
task.setGoodsShelfNo(container.getGoodsShelfNo());
if (taskHeaderService.saveOrUpdate(task)) {
//添加任务明细表
for (ReceiptContainerDetail item : list) {
// 保存任务详情
taskDetailService.createTaskDetailByReceipt(task,item);
//更新入库组盘明细状态
item.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK);
if (!receiptContainerDetailService.updateById(item)) {
throw new ServiceException("更新入库组盘明细状态出错");
}
/* 修改明细状态为上架*/
ReceiptDetail receiptDetail = receiptDetailService.getById(item.getReceiptDetailId());
receiptDetail.setProcessStamp(String.valueOf(QuantityConstant.RECEIPT_HEADER_SHELF));
if (!receiptDetailService.updateById(receiptDetail)) {
throw new ServiceException("更新入库单详情失败");
}
//更新头表状态
receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
}
String taskId = String.valueOf(task.getId());
taskIds.add(taskId);
//昆山pk库区和xn库区直接完成任务
if(task.getWarehouseCode().equals(QuantityConstant.WAREHOUSE_KS)){
if(task.getZoneCode().equals("PK") || task.getZoneCode().equals("XN")){
taskHeaderService.completeTask(task);
}
}
} else {
throw new ServiceException("任务生成失败");
}
}
}
return AjaxResult.success("生成上架任务成功").setData(taskIds);
}
/**检查组盘信息,托盘是否锁定,锁定容器,检查组盘明细*/
public void checkReceiptTask(ReceiptContainerHeader receiptContainerHeader,Integer id){
if (receiptContainerHeader == null) {
throw new ServiceException("id:" + id + "的入库组盘不存在!");
}
if (!receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode())) {
throw new ServiceException("id:" + id + "的入库组盘不能在" + ShiroUtils.getWarehouseCode() + "仓库操作");
}
Container container = containerService.getContainerByCode(receiptContainerHeader.getContainerCode());
if(container.getStatus().equals(QuantityConstant.STATUS_CONTAINER_LOCK)) {
// throw new ServiceException("托盘已经锁定,不能生成任务,托盘号:"+receiptContainerHeader.getContainerCode());
}
//锁定容器
containerService.updateStatus(receiptContainerHeader.getContainerCode(),
QuantityConstant.STATUS_CONTAINER_LOCK, container.getWarehouseCode());
}
/**检查库位容器,修改状态*/
public void checkLocationContainer(ReceiptContainerHeader receiptContainerHeader){
if(StringUtils.isNotEmpty(receiptContainerHeader.getFromLocation())) {
locationService.updateStatus(receiptContainerHeader.getFromLocation(),
QuantityConstant.STATUS_LOCATION_LOCK);
}
String locationCode = receiptContainerHeader.getToLocation();
if(StringUtils.isNotEmpty(locationCode)) {
locationService.updateStatus(locationCode, QuantityConstant.STATUS_LOCATION_LOCK);
Location desLocation = locationService.getLocationByCode(locationCode);
String loginWarehouse = ShiroUtils.getWarehouseCode();
if(!desLocation.getWarehouseCode().equals(loginWarehouse)) {
throw new ServiceException("库位对应仓库不对");
}
/*if (taskHeaderService.getUncompleteTaskInNear(desLocation) > 0) {
throw new ServiceException("目标库位:" + desLocation + "旁边存在任务,请完成任务以后再分配");
}*/
}
}
/**
* 自动生成容器编码
* @return 容器编码
*/
@Transactional
public String createContainer(){
String code = MessageFormat.format("{0}{1}",
"LS",
String.format("%d", Calendar.getInstance().getTimeInMillis()));
Container container = new Container();
container.setCode(code);
container.setWarehouseCode(ShiroUtils.getWarehouseCode());
container.setCompanyCode(ShiroUtils.getCompanyCodeList().get(0));
container.setContainerType("LS");
container.setCreatedBy(ShiroUtils.getLoginName());
container.setLastUpdated(new Date());
container.setLastUpdatedBy(ShiroUtils.getLoginName());
container.setEnable(true);
container.setStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
if (!containerService.save(container)){
throw new ServiceException("新增容器失败");
}
return code;
}
/**
* 完成入库任务
* @param task 任务
* @return AjaxResult 完成入库任务结果
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult completeReceiptTask(TaskHeader task) {
/* 判断任务状态*/
if (task.getStatus().equals(QuantityConstant.TASK_STATUS_COMPLETED)) {
return AjaxResult.error("任务已完成");
}
if (StringUtils.isEmpty(task.getToLocation())) {
throw new ServiceException("任务" + task.getId() + "没有目的库位,执行中止");
}
String warehouseCode = task.getWarehouseCode();
BigDecimal totalQty = BigDecimal.ZERO;
List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(task.getId());
if (taskDetailList.isEmpty()) {
throw new ServiceException("任务明细为空");
}
InventoryHeader inventoryHeader = null;
//补充入库把原来库存详情库位换成最新的库位
inventoryHeader=checkSUPPLEMENTRECEIPT(task,inventoryHeader,warehouseCode);
if (StringUtils.isNull(inventoryHeader)) {
inventoryHeader = inventoryHeaderService.getByContainerLocation(task.getToLocation(),task.getContainerCode(),warehouseCode);
}
/* 如果库存 头明细不存在则新增库存头表记录*/
if (StringUtils.isNull(inventoryHeader)) {
inventoryHeader=this.saveInventeryByTask(task,warehouseCode);
}
if (StringUtils.isNull(inventoryHeader)) {
throw new ServiceException("库存添加失败");
}
/* 遍历任务明细,修改关联的入库组盘、入库单状态、添加库存*/
TaskReceiptCompleteDomain taskReceiptCompleteDomain=new TaskReceiptCompleteDomain();
taskReceiptCompleteDomain.setTotalQty(inventoryHeader.getTotalQty());
taskReceiptCompleteDomain.setInventoryHeader(inventoryHeader);
List<ReceiptContainerDetail> receiptContainerDetails=new ArrayList<>();
List<ReceiptDetail> receiptDetails=new ArrayList<>();
List<TaskDetail> taskDetails=new ArrayList<>();
Set<Integer> receiptHeaderIdSet=new HashSet<>();
for (TaskDetail taskDetail : taskDetailList) {
if (taskDetail.getStatus() < QuantityConstant.TASK_STATUS_COMPLETED) {
// totalQty = totalQty.add(taskDetail.getQty());
/*查询入库单明细*/
ReceiptDetail receiptDetail = receiptDetailService.getById(taskDetail.getBillDetailId());
if (StringUtils.isNotNull(receiptDetail)) {
taskReceiptCompleteDomain = this.addInventoryDetail(taskDetail, receiptDetail, inventoryHeader,taskReceiptCompleteDomain);
//修改组盘表状态为完成
ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
receiptContainerDetail.setId(taskDetail.getAllocationId());
receiptContainerDetail.setStatus(QuantityConstant.RECEIPT_CONTAINER_FINISHED);
receiptContainerDetail.setLastUpdatedBy(receiptDetail.getCreatedBy());
receiptContainerDetails.add(receiptContainerDetail);
} else {
throw new ServiceException("未找到id:" + taskDetail.getBillDetailId() + "入库单明细");
}
receiptDetail.setProcessStamp(String.valueOf(QuantityConstant.RECEIPT_HEADER_POSTING));
if(StringUtils.isNull(receiptDetail.getBackQty())){
receiptDetail.setBackQty(BigDecimal.ZERO.add(taskDetail.getQty()));
}else{
receiptDetail.setBackQty(receiptDetail.getBackQty().add(taskDetail.getQty()));
}
receiptDetails.add(receiptDetail);
// receiptDetailService.updateById(receiptDetail);
receiptHeaderIdSet.add(receiptDetail.getReceiptId());
// receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
materialWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getCompanyCode());
taskDetail.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
taskDetails.add(taskDetail);
// taskDetailService.updateById(taskDetail);
}
}
taskReceiptCompleteDomain.setReceiptDetailList(receiptDetails);
taskReceiptCompleteDomain.setTaskDetailList(taskDetails);
taskReceiptCompleteDomain.setReceiptHeaderIdSet(receiptHeaderIdSet);
taskReceiptCompleteDomain.setReceiptContainerDetailList(receiptContainerDetails);
//save批量提交数据
saveOrUpdateTaskCompleteTable(taskReceiptCompleteDomain);
//修改库位状态和对应的容器
locationService.updateContainerCodeAndStatus(task.getToLocation(),task.getContainerCode(),QuantityConstant.STATUS_LOCATION_EMPTY,warehouseCode);
//修改任务主表状态,因为立库任务表单头只对应一个货箱,表单详情的任务会同时完成
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
task.setCompleteStatus(1);
LambdaUpdateWrapper<TaskHeader> taskHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
taskHeaderLambdaUpdateWrapper.eq(TaskHeader::getId, task.getId());
if (!taskHeaderService.update(task, taskHeaderLambdaUpdateWrapper)){
throw new ServiceException("更新任务主表失败");
}
//修改容器状态和对应的库位
Container container = new Container();
container.setLocationCode(task.getToLocation());
container.setStatus(QuantityConstant.STATUS_CONTAINER_SOME);
LambdaUpdateWrapper<Container> containerLambdaUpdateWrapper = Wrappers.lambdaUpdate();
containerLambdaUpdateWrapper.eq(Container::getCode, task.getContainerCode());
containerLambdaUpdateWrapper.eq(Container::getWarehouseCode,task.getWarehouseCode());
if (!containerService.update(container, containerLambdaUpdateWrapper)) {
throw new ServiceException("更新容器失败");
}
//修改入库组盘头表状态
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(task.getAllocationHeadId());
receiptContainerHeader.setLastUpdatedBy(task.getCreatedBy());
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_FINISHED);
if (!receiptContainerHeaderService.updateById(receiptContainerHeader)) {
throw new ServiceException("更新入库组盘头表状态失败");
}
return AjaxResult.success();
}
public InventoryHeader checkSUPPLEMENTRECEIPT(TaskHeader task,InventoryHeader inventoryHeader,String warehouseCode){
if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)) {
LambdaQueryWrapper<InventoryHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, warehouseCode)
.eq(InventoryHeader::getLocationCode, task.getFromLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
lambdaQueryWrapper.last("limit 1");
inventoryHeader= inventoryHeaderService.getOne(lambdaQueryWrapper);
if(inventoryHeader != null) {
String locationCode = inventoryHeader.getLocationCode();
Location location = locationService.getLocationByCode(locationCode, warehouseCode);
location.setContainerCode("");
location.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
locationService.updateById(location);
inventoryHeader.setLocationCode(task.getToLocation());
inventoryHeaderService.updateById(inventoryHeader);
LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper2 = Wrappers.lambdaQuery();
lambdaQueryWrapper2.eq(InventoryDetail::getWarehouseCode, warehouseCode)
.eq(InventoryDetail::getInventoryHeaderId, inventoryHeader.getId());
List<InventoryDetail> inventoryDetails = inventoryDetailService.list(lambdaQueryWrapper2);
if(inventoryDetails != null && inventoryDetails.size() > 0) {
for(InventoryDetail inventoryDetail : inventoryDetails) {
inventoryDetail.setLocationCode(task.getToLocation());
inventoryDetail.setZoneCode(location.getZoneCode());
inventoryDetailService.updateById(inventoryDetail);
}
}
}
}
return inventoryHeader;
}
/**
* 添加库存明细与库存交易记录
* @param taskDetail 任务明细
* @param receiptDetail 入库单明细
* @param inventoryHeader 库存头表
* @return 任务数量
*/
private TaskReceiptCompleteDomain addInventoryDetail(TaskDetail taskDetail, ReceiptDetail receiptDetail,
InventoryHeader inventoryHeader, TaskReceiptCompleteDomain taskReceiptCompleteDomain) {
List<InventoryDetail> inventoryDetailList=taskReceiptCompleteDomain.getInventoryDetailList();
List<InventoryTransaction> inventoryTransactionList=taskReceiptCompleteDomain.getInventoryTransactionList();
String warehouseCode = inventoryHeader.getWarehouseCode();
/*该入库明细是否已存在库存明细记录,已存在更新数量、不存在新增记录*/
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
inventory.eq(InventoryDetail::getContainerCode, inventoryHeader.getContainerCode())
.eq(InventoryDetail::getWarehouseCode, warehouseCode)
.eq(InventoryDetail::getLocationCode, inventoryHeader.getLocationCode())
.eq(InventoryDetail::getMaterialCode, taskDetail.getMaterialCode())
.eq(InventoryDetail::getCompanyCode, taskDetail.getCompanyCode())
.eq(InventoryDetail::getBatch,taskDetail.getBatch())
.eq(InventoryDetail::getReceiptDetailId, taskDetail.getBillDetailId());
InventoryDetail inventoryDetail = inventoryDetailService.getOne(inventory);
Material material = materialService.getMaterialByCode(receiptDetail.getMaterialCode(), warehouseCode);
/*单位换算*/
BigDecimal receiptQty = taskDetail.getQty();
if (StringUtils.isNotEmpty(receiptDetail.getMaterialUnit()) &&
StringUtils.isNotEmpty(material.getUnit()) &&
!receiptDetail.getMaterialUnit().equals(material.getUnit())) {
LambdaQueryWrapper<MaterialMultiple> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(MaterialMultiple::getMaterialCode, receiptDetail.getMaterialCode())
.eq(MaterialMultiple::getUnitId1, receiptDetail.getMaterialUnit())
.eq(MaterialMultiple::getUnitId2, material.getUnit());
MaterialMultiple materialMultiple = materialMultipleService.getOne(queryWrapper);
if (StringUtils.isNull(materialMultiple)) {
throw new ServiceException("入库单单位与物料绑定主单位不一致且单位换算不存在");
} else {
receiptQty = receiptQty.multiply(materialMultiple.getMultiple());
}
}
if (StringUtils.isNotNull(inventoryDetail)) {
inventoryDetail.setQty(inventoryDetail.getQty().add(taskDetail.getQty()));
}
else {
// ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId());
inventoryDetail = new InventoryDetail();
inventoryDetail.setInventoryHeaderId(inventoryHeader.getId());
inventoryDetail.setWarehouseCode(taskDetail.getWarehouseCode());
inventoryDetail.setZoneCode(inventoryHeader.getZoneCode());
inventoryDetail.setCompanyCode(taskDetail.getCompanyCode());
inventoryDetail.setLocationCode(taskDetail.getToLocation());
inventoryDetail.setContainerCode(taskDetail.getContainerCode());
inventoryDetail.setMaterialCode(taskDetail.getMaterialCode());
inventoryDetail.setMaterialName(taskDetail.getMaterialName());
inventoryDetail.setMaterialSpec(taskDetail.getMaterialSpec());
inventoryDetail.setMaterialUnit(material.getUnit());
inventoryDetail.setQty(receiptQty);
inventoryDetail.setTaskQty(new BigDecimal(0));
inventoryDetail.setInventorySts(QuantityConstant.GOOD);
inventoryDetail.setSupplierCode(receiptDetail.getSupplierCode());
inventoryDetail.setReferCode(receiptDetail.getReferCode());
inventoryDetail.setReferDetailId(receiptDetail.getReferLineNum());
inventoryDetail.setBatch(receiptDetail.getBatch());
inventoryDetail.setLot(receiptDetail.getLot());
inventoryDetail.setProjectNo(receiptDetail.getProjectNo());
inventoryDetail.setMoCode(receiptDetail.getMoCode());
inventoryDetail.setGoodsShelfNo(taskDetail.getGoodsShelfNo());
inventoryDetail.setUWarehouseCode(receiptDetail.getUWarehouseCode());
inventoryDetail.setManufactureDate(receiptDetail.getManufactureDate());
inventoryDetail.setExpirationDate(receiptDetail.getExpirationDate());
inventoryDetail.setAgingDate(receiptDetail.getAgingDate());
inventoryDetail.setAttribute1(receiptDetail.getAttribute1());
inventoryDetail.setAttribute2(receiptDetail.getAttribute2());
inventoryDetail.setAttribute3(receiptDetail.getAttribute3());
inventoryDetail.setReceiptCode(receiptDetail.getReceiptCode());
inventoryDetail.setReceiptDetailId(receiptDetail.getId());
inventoryHeader.setTotalLines(inventoryHeader.getTotalLines()+1);
}
if (!inventoryDetailService.saveOrUpdate(inventoryDetail)) {
throw new ServiceException("保存库存明细失败");
}
// inventoryHeader.setTotalQty(inventoryHeader.getTotalQty().add(taskDetail.getQty()));
// inventoryHeaderService.updateById(inventoryHeader);
//记录库存交易记录
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
inventoryTransaction.setWarehouseCode(taskDetail.getWarehouseCode());
inventoryTransaction.setCompanyCode(taskDetail.getCompanyCode());
inventoryTransaction.setLocationCode(inventoryHeader.getLocationCode());
inventoryTransaction.setContainerCode(inventoryHeader.getContainerCode());
inventoryTransaction.setMaterialCode(taskDetail.getMaterialCode());
inventoryTransaction.setMaterialName(taskDetail.getMaterialName());
inventoryTransaction.setMaterialSpec(taskDetail.getMaterialSpec());
inventoryTransaction.setMaterialUnit(material.getUnit());
inventoryTransaction.setBillCode(taskDetail.getBillCode());
inventoryTransaction.setBillDetailId(taskDetail.getBillDetailId());
inventoryTransaction.setBatch(receiptDetail.getBatch());
inventoryTransaction.setLot(receiptDetail.getLot());
inventoryTransaction.setInventorySts(receiptDetail.getInventorySts());
inventoryTransaction.setTaskQty(receiptQty);
inventoryTransaction.setInventoryDetailId(inventoryDetail.getId());
inventoryTransaction.setMoCode(inventoryDetail.getMoCode());
inventoryTransaction.setUWarehouseCode(inventoryDetail.getUWarehouseCode());
inventoryTransaction.setGoodsShelfNo(inventoryDetail.getGoodsShelfNo());
inventoryTransaction.setZoneCode(inventoryDetail.getZoneCode());
inventoryDetailList.add(inventoryDetail);
inventoryTransactionList.add(inventoryTransaction);
taskReceiptCompleteDomain.setInventoryDetailList(inventoryDetailList);
taskReceiptCompleteDomain.setInventoryTransactionList(inventoryTransactionList);
taskReceiptCompleteDomain.setTotalQty(taskReceiptCompleteDomain.getTotalQty().add(taskDetail.getQty()));
return taskReceiptCompleteDomain;
}
/**
* 根据保存库存
* @param task
* @param warehouseCode
* @return
*/
public InventoryHeader saveInventeryByTask(TaskHeader task,String warehouseCode){
InventoryHeader inventoryHeader = new InventoryHeader();
inventoryHeader.setWarehouseCode(warehouseCode);
inventoryHeader.setLocationCode(task.getToLocation());
Location location = locationService.getLocationByCode(task.getToLocation(), warehouseCode);
inventoryHeader.setZoneCode(location.getZoneCode());
inventoryHeader.setTotalWeight(task.getWeight());
inventoryHeader.setContainerCode(task.getContainerCode());
inventoryHeader.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
inventoryHeader.setTotalQty(new BigDecimal(0));
inventoryHeader.setTotalLines(0);
inventoryHeader.setLocking(1);
inventoryHeader.setEnable(1);
inventoryHeader.setCompanyCode(task.getCompanyCode());
inventoryHeader.setCreated(new Date());
inventoryHeader.setCreatedBy("");
inventoryHeader.setLastUpdated(new Date());
inventoryHeader.setLastUpdatedBy("");
if (!inventoryHeaderService.save(inventoryHeader)) {
throw new ServiceException("添加库存单失败");
}
return inventoryHeader;
}
public void saveOrUpdateTaskCompleteTable(TaskReceiptCompleteDomain taskReceiptCompleteDomain){
List<InventoryTransaction> inventoryTransactionList=taskReceiptCompleteDomain.getInventoryTransactionList();
List<InventoryDetail> inventoryDetailList=taskReceiptCompleteDomain.getInventoryDetailList();
List<ReceiptDetail> receiptDetailList=taskReceiptCompleteDomain.getReceiptDetailList();
List<TaskDetail> taskDetails=taskReceiptCompleteDomain.getTaskDetailList();
List<ReceiptContainerDetail> receiptContainerDetailList=taskReceiptCompleteDomain.getReceiptContainerDetailList();
InventoryHeader inventoryHeader=taskReceiptCompleteDomain.getInventoryHeader();
Set<Integer> receiptHeaderIdSet=taskReceiptCompleteDomain.getReceiptHeaderIdSet();
BigDecimal totalQty=taskReceiptCompleteDomain.getTotalQty();
if(inventoryDetailList!=null&&inventoryDetailList.size()>0){
inventoryDetailService.saveOrUpdateBatch(inventoryDetailList);
}
inventoryHeader.setTotalQty(totalQty);
inventoryHeaderService.saveOrUpdate(inventoryHeader);
if(inventoryTransactionList!=null&&inventoryTransactionList.size()>0){
inventoryTransactionService.saveBatch(inventoryTransactionList);
}
if(receiptDetailList!=null&&receiptDetailList.size()>0){
receiptDetailService.updateBatchById(receiptDetailList);
}
if(taskDetails!=null&&taskDetails.size()>0){
taskDetailService.updateBatchById(taskDetails);
}
if(receiptContainerDetailList!=null&&receiptContainerDetailList.size()>0){
receiptContainerDetailService.updateBatchById(receiptContainerDetailList);
}
receiptDetailService.updateReceiptHeaderLastStatusV2(receiptHeaderIdSet);
}
}