ReceiptTaskService.java
26.7 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
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.baomidou.mybatisplus.core.toolkit.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.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 入库任务创建和完成
* @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;
/**
* 创建入库任务(整盘入库、补充入库)
*
* @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);
if (receiptContainerHeader == null) {
throw new ServiceException("id:" + id + "的入库组盘不存在!");
}
if (!receiptContainerHeader.getWarehouseCode().equals(ShiroUtils.getWarehouseCode())) {
throw new ServiceException("id:" + id + "的入库组盘不能在" + ShiroUtils.getWarehouseCode() + "仓库操作");
}
//锁定容器
Container container = new Container();
container.setStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
LambdaUpdateWrapper<Container> containerUpdateWrapper = Wrappers.lambdaUpdate();
containerUpdateWrapper.eq(Container::getCode, receiptContainerHeader.getContainerCode());
containerService.update(container, containerUpdateWrapper);
//查询入库组盘明细
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptContainerId, id);
List<ReceiptContainerDetail> list = receiptContainerDetailService.list(containerDetailLambda);
if (list.isEmpty()) {
throw new ServiceException("id:" + id + "的入库组盘,没有组盘明细,请先组盘!");
}
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)) {
return AjaxResult.error("库位对应仓库不对");
}
if (taskHeaderService.getUncompleteTaskInNear(desLocation) > 0) {
return AjaxResult.error("目标库位:" + desLocation + "旁边存在任务,请完成任务以后再分配");
}
}
if (receiptContainerHeader.getStatus() == QuantityConstant.RECEIPT_CONTAINER_BUILD.intValue()) {
if (receiptContainerHeader.getStatus() < QuantityConstant.RECEIPT_CONTAINER_TASK) {
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_TASK);
receiptContainerHeaderService.updateById(receiptContainerHeader);
}
//添加任务主表
TaskHeader task = new TaskHeader();
task.setAllocationHeadId(receiptContainerHeader.getId());
task.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
task.setWarehouseCode(receiptContainerHeader.getWarehouseCode());
task.setCompanyCode(receiptContainerHeader.getCompanyCode());
task.setStatus(QuantityConstant.TASK_STATUS_BUILD);
task.setTaskType(receiptContainerHeader.getTaskType());
task.setFromLocation(receiptContainerHeader.getFromLocation());
if(receiptContainerHeader.getToLocation() != null){
task.setToLocation(receiptContainerHeader.getToLocation());
}
Location location = locationService.getLocationByCode(
task.getToLocation(), ShiroUtils.getWarehouseCode());
if(location != null) {
task.setZoneCode(location.getZoneCode());
}
task.setContainerCode(receiptContainerHeader.getContainerCode());
task.setRecvDock(receiptContainerHeader.getRecvDock());
task.setPort(receiptContainerHeader.getPort());
if (taskHeaderService.save(task)) {
//添加任务明细表
for (ReceiptContainerDetail item : list) {
TaskDetail taskDetail = new TaskDetail();
taskDetail.setTaskId(task.getId());
taskDetail.setTaskType(task.getTaskType());
taskDetail.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
taskDetail.setWarehouseCode(task.getWarehouseCode());
taskDetail.setAllocationId(item.getId());
taskDetail.setCompanyCode(task.getCompanyCode());
taskDetail.setMaterialCode(item.getMaterialCode());
taskDetail.setMaterialName(item.getMaterialName());
taskDetail.setMaterialSpec(item.getMaterialSpec());
taskDetail.setMaterialUnit(item.getMaterialUnit());
taskDetail.setInventorySts(item.getInventorySts());
taskDetail.setBillCode(item.getReceiptCode());
taskDetail.setBillDetailId(item.getReceiptDetailId());
taskDetail.setQty(item.getQty());
taskDetail.setContainerCode(task.getContainerCode());
taskDetail.setFromLocation(task.getFromLocation());
if(task.getToLocation() != null) {
taskDetail.setToLocation(task.getToLocation());
}
taskDetail.setBatch(item.getBatch());
taskDetail.setProjectNo(item.getProjectNo());
if (!taskDetailService.save(taskDetail)) {
throw new ServiceException("生成任务明细失败");
}
//更新入库组盘明细状态
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);
} else {
throw new ServiceException("任务生成失败");
}
}
}
return AjaxResult.success("生成上架任务成功").setData(taskIds);
}
/**
* 完成入库任务
* @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() + "没有目的库位,执行中止");
}
BigDecimal totalQty = BigDecimal.ZERO;
List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(task.getId());
if (taskDetailList.isEmpty()) {
throw new ServiceException("任务明细为空");
}
InventoryHeader inventoryHeader = null;
if(task.getTaskType().equals(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)) {
LambdaQueryWrapper<InventoryHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(InventoryHeader::getLocationCode, task.getFromLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
inventoryHeader= inventoryHeaderService.getOne(lambdaQueryWrapper);
if(inventoryHeader != null) {
String locationCode = inventoryHeader.getLocationCode();
Location location = locationService.getLocationByCode(locationCode, ShiroUtils.getWarehouseCode());
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, ShiroUtils.getWarehouseCode())
.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);
}
}
}
}
if (StringUtils.isNull(inventoryHeader)) {
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(InventoryHeader::getLocationCode, task.getToLocation())
.eq(InventoryHeader::getContainerCode, task.getContainerCode());
inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
}
/* 如果库存 头明细不存在则新增库存头表记录*/
if (StringUtils.isNull(inventoryHeader)) {
inventoryHeader = new InventoryHeader();
inventoryHeader.setWarehouseCode(task.getWarehouseCode());
inventoryHeader.setLocationCode(task.getToLocation());
Location location = locationService.getLocationByCode(task.getToLocation(), ShiroUtils.getWarehouseCode());
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("添加库存单失败");
}
}
/* 遍历任务明细,修改关联的入库组盘、入库单状态、添加库存*/
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)) {
totalQty = this.addInventoryDetail(taskDetail, receiptDetail, inventoryHeader);
//修改组盘表状态为完成
ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
receiptContainerDetail.setStatus(QuantityConstant.RECEIPT_CONTAINER_FINISHED);
LambdaUpdateWrapper<ReceiptContainerDetail> receiptContainerDetailLambdaUpdateWrapper = Wrappers.lambdaUpdate();
receiptContainerDetailLambdaUpdateWrapper.eq(ReceiptContainerDetail::getId, taskDetail.getAllocationId());
if (!receiptContainerDetailService.update(receiptContainerDetail, receiptContainerDetailLambdaUpdateWrapper)){
throw new ServiceException("更新组盘状态失败");
}
} else {
throw new ServiceException("未找到id:" + taskDetail.getBillDetailId() + "入库单明细");
}
receiptDetail.setProcessStamp(String.valueOf(QuantityConstant.RECEIPT_HEADER_POSTING));
receiptDetailService.updateById(receiptDetail);
receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
materialWarningService.materialWarning(taskDetail.getMaterialCode(), taskDetail.getCompanyCode());
}
}
if (StringUtils.isNull(inventoryHeader)) {
throw new ServiceException("库存添加失败");
}
//修改任务主表状态,因为立库任务表单头只对应一个货箱,表单详情的任务会同时完成
task.setStatus(QuantityConstant.TASK_STATUS_COMPLETED);
LambdaUpdateWrapper<TaskHeader> taskHeaderLambdaUpdateWrapper = Wrappers.lambdaUpdate();
taskHeaderLambdaUpdateWrapper.eq(TaskHeader::getId, task.getId());
if (!taskHeaderService.update(task, taskHeaderLambdaUpdateWrapper)){
throw new ServiceException("更新任务主表失败");
}
//修改库位状态和对应的容器
Location location = new Location();
location.setContainerCode(task.getContainerCode());
location.setWarehouseCode(ShiroUtils.getWarehouseCode());
location.setStatus(QuantityConstant.STATUS_LOCATION_EMPTY);
LambdaUpdateWrapper<Location> locationLambdaUpdateWrapper = Wrappers.lambdaUpdate();
locationLambdaUpdateWrapper.eq(Location::getCode, task.getToLocation());
locationLambdaUpdateWrapper.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
if (!locationService.update(location, locationLambdaUpdateWrapper)){
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());
if (!containerService.update(container, containerLambdaUpdateWrapper)) {
throw new ServiceException("更新容器失败");
}
//修改入库组盘头表状态
ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
receiptContainerHeader.setId(task.getAllocationHeadId());
receiptContainerHeader.setStatus(QuantityConstant.RECEIPT_CONTAINER_FINISHED);
if (!receiptContainerHeaderService.updateById(receiptContainerHeader)) {
throw new ServiceException("更新入库组盘头表状态失败");
}
return AjaxResult.success();
}
/**
* 添加库存明细与库存交易记录
* @param taskDetail 任务明细
* @param receiptDetail 入库单明细
* @param inventoryHeader 库存头表
* @return 任务数量
*/
private BigDecimal addInventoryDetail(TaskDetail taskDetail, ReceiptDetail receiptDetail, InventoryHeader inventoryHeader) {
/*该入库明细是否已存在库存明细记录,已存在更新数量、不存在新增记录*/
LambdaQueryWrapper<InventoryDetail> inventory = Wrappers.lambdaQuery();
inventory.eq(InventoryDetail::getWarehouseCode, taskDetail.getWarehouseCode())
.eq(InventoryDetail::getLocationCode, inventoryHeader.getLocationCode())
.eq(InventoryDetail::getMaterialCode, taskDetail.getMaterialCode())
.eq(InventoryDetail::getContainerCode, inventoryHeader.getContainerCode())
.eq(InventoryDetail::getCompanyCode, taskDetail.getCompanyCode())
.eq(InventoryDetail::getBatch,taskDetail.getBatch())
.eq(InventoryDetail::getReceiptDetailId, taskDetail.getBillDetailId());
InventoryDetail inventoryDetail = inventoryDetailService.getOne(inventory);
Material material = materialService.findAllByCode(receiptDetail.getMaterialCode());
/*单位换算*/
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(taskDetail.getInventorySts());
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.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(receiptHeader.getCode());
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);
if (!inventoryTransactionService.save(inventoryTransaction)) {
throw new ServiceException("新增库存记录失败");
}
return receiptQty;
}
}