Commit d2b794c157e50e4e4fa9e7b0f843cb3d7816e368
1 parent
a979db47
feat:MOM下发出库单据,当前出库单与WMS每一个状态是新建的单据比对,通知单号、仓库、车间都相同都的出库单进行合并。
Showing
4 changed files
with
148 additions
and
127 deletions
src/main/java/com/huaheng/api/mes/service/MesServiceImpl.java
... | ... | @@ -297,7 +297,6 @@ public class MesServiceImpl implements IMesService { |
297 | 297 | if (detail.getLMPKID() != null) { |
298 | 298 | shipmentDetail.setLMPKID(detail.getLMPKID()); |
299 | 299 | } |
300 | - | |
301 | 300 | shipmentDetail.setShipmentId(shipmentHeader.getId()); |
302 | 301 | shipmentDetail.setShipmentCode(shipmentHeader.getCode()); |
303 | 302 | shipmentDetail.setCompanyCode("BHF"); |
... | ... | @@ -313,12 +312,31 @@ public class MesServiceImpl implements IMesService { |
313 | 312 | throw new ServiceException("生成出库单详情失败"); |
314 | 313 | } |
315 | 314 | |
316 | - | |
317 | 315 | //如果通知单号和车间、仓库相同,自动合并单据 |
318 | - | |
316 | + String warehouse = shipmentHeader.getWarehouse(); | |
317 | + String workshop = shipmentHeader.getWorkshop(); | |
318 | + String noticeNo = shipmentHeader.getNoticeNo(); | |
319 | + if (StringUtils.isNotEmpty(noticeNo) && StringUtils.isNotEmpty(warehouse) && StringUtils.isNotEmpty(workshop)) { | |
320 | + List<ShipmentHeader> automaticMergeCount = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>() | |
321 | + .ne(ShipmentHeader::getCode, shipmentHeader.getCode()) | |
322 | + .eq(ShipmentHeader::getFirstStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD) | |
323 | + .eq(ShipmentHeader::getLastStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD) | |
324 | + .eq(ShipmentHeader::getDeleted, 0) | |
325 | + .eq(ShipmentHeader::getWarehouse, warehouse) | |
326 | + .eq(ShipmentHeader::getWorkshop, workshop) | |
327 | + .eq(ShipmentHeader::getNoticeNo, noticeNo)); | |
328 | + if (!automaticMergeCount.isEmpty()) { | |
329 | + String ids = automaticMergeCount.get(0).getId() + "," + shipmentHeader.getId(); | |
330 | + AjaxResult analysis = shipmentHeaderService.analysis(ids); | |
331 | + if (analysis.hasErr()) { | |
332 | + throw new ServiceException("合并单据失败," + analysis.getMsg()); | |
333 | + } | |
334 | + } | |
335 | + } | |
319 | 336 | return AjaxResult.success(receiptDTO); |
320 | 337 | } |
321 | 338 | |
339 | + | |
322 | 340 | /** |
323 | 341 | * 取消入库 |
324 | 342 | */ |
... | ... |
src/main/java/com/huaheng/pc/shipment/shipmentHeader/controller/ShipmentHeaderController.java
... | ... | @@ -498,125 +498,8 @@ public class ShipmentHeaderController extends BaseController { |
498 | 498 | @Log(title = "出库-出库单", operating = "单据合并", action = BusinessType.OTHER) |
499 | 499 | @PostMapping("/addWave") |
500 | 500 | @ResponseBody |
501 | - @Transactional | |
502 | 501 | public AjaxResult analysis(String ids, String codeNull) { |
503 | - BigDecimal totalQty = BigDecimal.ZERO; | |
504 | - int totalLines = 0; | |
505 | - if (StringUtils.isEmpty(ids)) { | |
506 | - throw new ServiceException("id不能为空"); | |
507 | - } | |
508 | - // 查询需要合并的头表 | |
509 | - String[] headerIdArr = ids.split(","); | |
510 | - LambdaQueryWrapper<ShipmentHeader> headerWrapper = Wrappers.lambdaQuery(); | |
511 | - headerWrapper.in(ShipmentHeader::getId, headerIdArr); | |
512 | - List<ShipmentHeader> shipmentHeaderList = shipmentHeaderService.list(headerWrapper); | |
513 | - if (shipmentHeaderList.isEmpty()) { | |
514 | - throw new ServiceException("单据主表不存在!!!"); | |
515 | - } | |
516 | - shipmentHeaderList.forEach(shipmentHeader -> { | |
517 | - //新增出库单历史 | |
518 | - shipmentHeaderHistoryService.saveById(shipmentHeader.getId().toString(), "合并前单据"); | |
519 | - if (!"MOM".equals(shipmentHeader.getCreatedBy())) { | |
520 | - throw new ServiceException("手动创建的单据,不允许合并!!!"); | |
521 | - } | |
522 | - if ("merge".equals(shipmentHeader.getShipmentType())) { | |
523 | - throw new ServiceException("单据类型为合并单据,不允许合并!!!"); | |
524 | - } | |
525 | - if (shipmentHeader.getLastStatus() > QuantityConstant.RECEIPT_HEADER_POOL || shipmentHeader.getFirstStatus() > QuantityConstant.RECEIPT_HEADER_POOL) { | |
526 | - throw new ServiceException("单据已被使用,不能合并,必须是新建状态或订单池!"); | |
527 | - } | |
528 | - | |
529 | - }); | |
530 | - // 创建合并后的头表 | |
531 | - ShipmentHeader shipmentHeader = new ShipmentHeader(); | |
532 | - shipmentHeader.setShipmentType("merge"); | |
533 | - String code = shipmentHeaderServiceImpl.createCode(shipmentHeader.getShipmentType()); | |
534 | - shipmentHeader.setCode(code); | |
535 | - shipmentHeader.setWarehouseCode("CS0001"); | |
536 | - shipmentHeader.setCompanyCode("BHF"); | |
537 | - shipmentHeader.setCreatedBy("MOM"); | |
538 | - shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_BUILD); | |
539 | - shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_BUILD); | |
540 | - StringBuilder recordID = new StringBuilder(); | |
541 | - StringBuilder workShops = new StringBuilder(); | |
542 | - Set<String> uniqueWorkshops = new HashSet<>(); | |
543 | - for (ShipmentHeader header : shipmentHeaderList) { | |
544 | - uniqueWorkshops.add(header.getWorkshop()); | |
545 | - } | |
546 | - for (String workshop : uniqueWorkshops) { | |
547 | - workShops.append(workshop).append(","); | |
548 | - } | |
549 | - // 移除最后一个逗号 | |
550 | - if (workShops.length() > 0) { | |
551 | - workShops.setLength(workShops.length() - 1); | |
552 | - } | |
553 | - shipmentHeaderList.forEach(header -> recordID.append(header.getId()).append(",")); | |
554 | - shipmentHeader.setWorkshop(workShops.toString()); | |
555 | - shipmentHeader.setRecordID(recordID.toString()); | |
556 | - shipmentHeaderService.save(shipmentHeader); | |
557 | - | |
558 | - // 修改合并子表 | |
559 | - List<ShipmentDetail> headerListData = new ArrayList<>(); | |
560 | - for (ShipmentHeader header : shipmentHeaderList) { | |
561 | - totalQty = totalQty.add(header.getTotalQty()); | |
562 | - totalLines = totalLines + header.getTotalLines(); | |
563 | - LambdaQueryWrapper<ShipmentDetail> detailWrapper = Wrappers.lambdaQuery(); | |
564 | - detailWrapper.eq(ShipmentDetail::getShipmentId, header.getId()); | |
565 | - List<ShipmentDetail> headerList = shipmentDetailService.list(detailWrapper); | |
566 | - headerList.forEach(shipmentDetail -> { | |
567 | - shipmentDetail.setRecordID(header.getId()); | |
568 | - shipmentDetail.setRecordCode(header.getCode()); | |
569 | - shipmentDetail.setPreMergerWorkshop(header.getWorkshop()); | |
570 | - shipmentDetail.setShipmentId(shipmentHeader.getId()); | |
571 | - shipmentDetail.setShipmentCode(shipmentHeader.getCode()); | |
572 | - shipmentDetail.setCreatedBy("MOM"); | |
573 | - shipmentDetail.setLastUpdatedBy("MOM"); | |
574 | - shipmentDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD); | |
575 | - }); | |
576 | - headerListData.addAll(headerList); | |
577 | - } | |
578 | - // 保存合并后的子表 | |
579 | - shipmentDetailService.saveBatch(headerListData); | |
580 | - | |
581 | - //保存总数量 总行数 | |
582 | - shipmentHeader.setTotalLines(totalLines); | |
583 | - shipmentHeader.setTotalQty(totalQty); | |
584 | - shipmentHeaderService.updateById(shipmentHeader); | |
585 | - | |
586 | - //// 把合并完的头表置为删除状态 | |
587 | - //shipmentHeaderList.forEach(header -> { | |
588 | - // header.setDeleted(true); | |
589 | - //}); | |
590 | - //// 保存置为删除状态的头表 | |
591 | - //shipmentHeaderService.updateBatchById(shipmentHeaderList); | |
592 | - | |
593 | - // shipmentDetailService.saveWave(ids,code); | |
594 | - | |
595 | - | |
596 | - List<ShipmentHeader> source = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>().in(ShipmentHeader::getId, headerIdArr)); | |
597 | - List<Integer> shipmentHeaderIds = new ArrayList<>(); | |
598 | - for (ShipmentHeader header : source) { | |
599 | - shipmentHeaderIds.add(header.getId()); | |
600 | - } | |
601 | - if (!shipmentHeaderService.removeByIds(shipmentHeaderIds)) { | |
602 | - throw new ServiceException("删除头表失败"); | |
603 | - } | |
604 | - | |
605 | - List<Integer> shipmentDetailIds = new ArrayList<>(); | |
606 | - | |
607 | - for (ShipmentHeader header : source) { | |
608 | - List<ShipmentDetail> details = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentId, header.getId())); | |
609 | - for (ShipmentDetail shipmentDetail : details) { | |
610 | - shipmentDetailIds.add(shipmentDetail.getId()); | |
611 | - } | |
612 | - } | |
613 | - | |
614 | - if (shipmentDetailIds.size() > 0) { | |
615 | - if (!shipmentDetailService.removeByIds(shipmentDetailIds)) { | |
616 | - throw new ServiceException("删除明细表失败"); | |
617 | - } | |
618 | - } | |
619 | - return AjaxResult.success("合并成功!"); | |
502 | + return shipmentHeaderService.analysis(ids); | |
620 | 503 | } |
621 | 504 | |
622 | 505 | /** |
... | ... |
src/main/java/com/huaheng/pc/shipment/shipmentHeader/service/ShipmentHeaderService.java
... | ... | @@ -7,10 +7,10 @@ import com.baomidou.mybatisplus.extension.service.IService; |
7 | 7 | import java.lang.reflect.InvocationTargetException; |
8 | 8 | import java.util.List; |
9 | 9 | |
10 | -public interface ShipmentHeaderService extends IService<ShipmentHeader>{ | |
10 | +public interface ShipmentHeaderService extends IService<ShipmentHeader> { | |
11 | 11 | |
12 | 12 | //新增出库主单 |
13 | - AjaxResult<Boolean> saveHeader(ShipmentHeader shipmentHeader) ; | |
13 | + AjaxResult<Boolean> saveHeader(ShipmentHeader shipmentHeader); | |
14 | 14 | |
15 | 15 | //根据单据类型建单据号 |
16 | 16 | String createCode(String shipmentType); |
... | ... | @@ -26,4 +26,6 @@ public interface ShipmentHeaderService extends IService<ShipmentHeader>{ |
26 | 26 | List<ShipmentHeader> selectListByCreated(); |
27 | 27 | |
28 | 28 | List<ShipmentHeader> getLatestShipment(); |
29 | + | |
30 | + AjaxResult analysis(String ids); | |
29 | 31 | } |
... | ... |
src/main/java/com/huaheng/pc/shipment/shipmentHeader/service/ShipmentHeaderServiceImpl.java
... | ... | @@ -32,11 +32,9 @@ import org.springframework.transaction.annotation.Transactional; |
32 | 32 | |
33 | 33 | import javax.annotation.Resource; |
34 | 34 | import java.lang.reflect.InvocationTargetException; |
35 | +import java.math.BigDecimal; | |
35 | 36 | import java.text.SimpleDateFormat; |
36 | -import java.util.ArrayList; | |
37 | -import java.util.Date; | |
38 | -import java.util.List; | |
39 | -import java.util.Map; | |
37 | +import java.util.*; | |
40 | 38 | |
41 | 39 | @Service |
42 | 40 | public class ShipmentHeaderServiceImpl extends ServiceImpl<ShipmentHeaderMapper, ShipmentHeader> implements ShipmentHeaderService { |
... | ... | @@ -297,4 +295,124 @@ public class ShipmentHeaderServiceImpl extends ServiceImpl<ShipmentHeaderMapper, |
297 | 295 | return shipmentHeaderMapper.getLatestShipment(); |
298 | 296 | } |
299 | 297 | |
298 | + @Override | |
299 | + @Transactional(rollbackFor = Exception.class) | |
300 | + public AjaxResult analysis(String ids) { | |
301 | + BigDecimal totalQty = BigDecimal.ZERO; | |
302 | + int totalLines = 0; | |
303 | + if (StringUtils.isEmpty(ids)) { | |
304 | + throw new ServiceException("id不能为空"); | |
305 | + } | |
306 | + // 查询需要合并的头表 | |
307 | + String[] headerIdArr = ids.split(","); | |
308 | + LambdaQueryWrapper<ShipmentHeader> headerWrapper = Wrappers.lambdaQuery(); | |
309 | + headerWrapper.in(ShipmentHeader::getId, headerIdArr); | |
310 | + List<ShipmentHeader> shipmentHeaderList = list(headerWrapper); | |
311 | + if (shipmentHeaderList.isEmpty()) { | |
312 | + throw new ServiceException("单据主表不存在!!!"); | |
313 | + } | |
314 | + shipmentHeaderList.forEach(shipmentHeader -> { | |
315 | + //新增出库单历史 | |
316 | + shipmentHeaderHistoryService.saveById(shipmentHeader.getId().toString(), "合并前单据"); | |
317 | + if (!"MOM".equals(shipmentHeader.getCreatedBy())) { | |
318 | + throw new ServiceException("手动创建的单据,不允许合并!!!"); | |
319 | + } | |
320 | + if ("merge".equals(shipmentHeader.getShipmentType())) { | |
321 | + throw new ServiceException("单据类型为合并单据,不允许合并!!!"); | |
322 | + } | |
323 | + if (shipmentHeader.getLastStatus() > QuantityConstant.RECEIPT_HEADER_POOL || shipmentHeader.getFirstStatus() > QuantityConstant.RECEIPT_HEADER_POOL) { | |
324 | + throw new ServiceException("单据已被使用,不能合并,必须是新建状态或订单池!"); | |
325 | + } | |
326 | + | |
327 | + }); | |
328 | + // 创建合并后的头表 | |
329 | + ShipmentHeader shipmentHeader = new ShipmentHeader(); | |
330 | + shipmentHeader.setShipmentType("merge"); | |
331 | + String code = createCode(shipmentHeader.getShipmentType()); | |
332 | + shipmentHeader.setCode(code); | |
333 | + shipmentHeader.setWarehouseCode("CS0001"); | |
334 | + shipmentHeader.setCompanyCode("BHF"); | |
335 | + shipmentHeader.setCreatedBy("MOM"); | |
336 | + shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_BUILD); | |
337 | + shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_BUILD); | |
338 | + StringBuilder recordID = new StringBuilder(); | |
339 | + StringBuilder workShops = new StringBuilder(); | |
340 | + Set<String> uniqueWorkshops = new HashSet<>(); | |
341 | + for (ShipmentHeader header : shipmentHeaderList) { | |
342 | + uniqueWorkshops.add(header.getWorkshop()); | |
343 | + } | |
344 | + for (String workshop : uniqueWorkshops) { | |
345 | + workShops.append(workshop).append(","); | |
346 | + } | |
347 | + // 移除最后一个逗号 | |
348 | + if (workShops.length() > 0) { | |
349 | + workShops.setLength(workShops.length() - 1); | |
350 | + } | |
351 | + shipmentHeaderList.forEach(header -> recordID.append(header.getId()).append(",")); | |
352 | + shipmentHeader.setWorkshop(workShops.toString()); | |
353 | + shipmentHeader.setRecordID(recordID.toString()); | |
354 | + save(shipmentHeader); | |
355 | + | |
356 | + // 修改合并子表 | |
357 | + List<ShipmentDetail> headerListData = new ArrayList<>(); | |
358 | + for (ShipmentHeader header : shipmentHeaderList) { | |
359 | + totalQty = totalQty.add(header.getTotalQty()); | |
360 | + totalLines = totalLines + header.getTotalLines(); | |
361 | + LambdaQueryWrapper<ShipmentDetail> detailWrapper = Wrappers.lambdaQuery(); | |
362 | + detailWrapper.eq(ShipmentDetail::getShipmentId, header.getId()); | |
363 | + List<ShipmentDetail> headerList = shipmentDetailService.list(detailWrapper); | |
364 | + headerList.forEach(shipmentDetail -> { | |
365 | + shipmentDetail.setRecordID(header.getId()); | |
366 | + shipmentDetail.setRecordCode(header.getCode()); | |
367 | + shipmentDetail.setPreMergerWorkshop(header.getWorkshop()); | |
368 | + shipmentDetail.setShipmentId(shipmentHeader.getId()); | |
369 | + shipmentDetail.setShipmentCode(shipmentHeader.getCode()); | |
370 | + shipmentDetail.setCreatedBy("MOM"); | |
371 | + shipmentDetail.setLastUpdatedBy("MOM"); | |
372 | + shipmentDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD); | |
373 | + }); | |
374 | + headerListData.addAll(headerList); | |
375 | + } | |
376 | + // 保存合并后的子表 | |
377 | + shipmentDetailService.saveBatch(headerListData); | |
378 | + | |
379 | + //保存总数量 总行数 | |
380 | + shipmentHeader.setTotalLines(totalLines); | |
381 | + shipmentHeader.setTotalQty(totalQty); | |
382 | + updateById(shipmentHeader); | |
383 | + | |
384 | + //// 把合并完的头表置为删除状态 | |
385 | + //shipmentHeaderList.forEach(header -> { | |
386 | + // header.setDeleted(true); | |
387 | + //}); | |
388 | + //// 保存置为删除状态的头表 | |
389 | + //shipmentHeaderService.updateBatchById(shipmentHeaderList); | |
390 | + // shipmentDetailService.saveWave(ids,code); | |
391 | + | |
392 | + | |
393 | + List<ShipmentHeader> source = list(new LambdaQueryWrapper<ShipmentHeader>().in(ShipmentHeader::getId, headerIdArr)); | |
394 | + List<Integer> shipmentHeaderIds = new ArrayList<>(); | |
395 | + for (ShipmentHeader header : source) { | |
396 | + shipmentHeaderIds.add(header.getId()); | |
397 | + } | |
398 | + if (!removeByIds(shipmentHeaderIds)) { | |
399 | + throw new ServiceException("删除头表失败"); | |
400 | + } | |
401 | + | |
402 | + List<Integer> shipmentDetailIds = new ArrayList<>(); | |
403 | + for (ShipmentHeader header : source) { | |
404 | + List<ShipmentDetail> details = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentId, header.getId())); | |
405 | + for (ShipmentDetail shipmentDetail : details) { | |
406 | + shipmentDetailIds.add(shipmentDetail.getId()); | |
407 | + } | |
408 | + } | |
409 | + | |
410 | + if (!shipmentDetailIds.isEmpty()) { | |
411 | + if (!shipmentDetailService.removeByIds(shipmentDetailIds)) { | |
412 | + throw new ServiceException("删除明细表失败"); | |
413 | + } | |
414 | + } | |
415 | + return AjaxResult.success("合并成功"); | |
416 | + } | |
417 | + | |
300 | 418 | } |
... | ... |