Bläddra i källkod

aps-订单提交后,更新坯料计划及其输出成品对应的冗余字段

sucheng 3 månader sedan
förälder
incheckning
7d36689070

+ 64 - 0
cx-aps/cx-aps-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ApsProductionOrderServiceImpl.java

@@ -511,6 +511,70 @@ public class ApsProductionOrderServiceImpl extends ServiceImpl<ApsProductionOrde
                     }
                     apsProductionMergeOrderService.saveOrUpdateBatch(apsProductionMergeOrderDoList);
                 }
+
+                //根据订单和产品明细,及其合并订单,重新赋值 坯料计划和输出成品的冗余字段
+                String orderno = apsProductionOrderDo.getOrderno();
+                String customorderno = apsProductionOrderDo.getCustomorderno();
+                String customname = apsProductionOrderDo.getCustomname();
+                List<String> blankIdList = apsBlankOrderDoList.stream().map(ApsBlankOrderDo::getId).collect(Collectors.toList());
+                List<ApsProcessOutputProductDo> apsProcessOutputProductDoList = apsProcessOutputProductService.list(new LambdaQueryWrapper<ApsProcessOutputProductDo>().in(ApsProcessOutputProductDo::getBlankid, blankIdList));
+                List<ApsProcessOutputProductDo> needUpdateOutProductList = new LinkedList<>();
+                //先更新输出成品
+                for (ApsProcessOutputProductDo apsProcessOutputProductDo : apsProcessOutputProductDoList) {
+                    //产品明细ID
+                    String productid = apsProcessOutputProductDo.getProductid();
+                    //查询对应的产品明细
+                    ApsProductDetailVo apsProductDetailVo = apsProductDetailVoList.stream().filter(item -> item.getId().equals(productid) && item.getDeleted().equals("0")).findFirst().orElse(null);
+                    ApsProcessOutputProductDo needUpdateOutProduct = new ApsProcessOutputProductDo();
+                    needUpdateOutProduct.setId(apsProcessOutputProductDo.getId());
+                    needUpdateOutProduct.setBlankid(apsProcessOutputProductDo.getBlankid());
+                    if (apsProductDetailVo == null) {
+                        needUpdateOutProduct.setOrderno(orderno);
+                        needUpdateOutProduct.setCustomorderno(customorderno);
+                        needUpdateOutProduct.setCustomname(customname);
+                    } else {
+                        if (StringUtils.isNotBlank(apsProductDetailVo.getCustomorderno())) {
+                            needUpdateOutProduct.setCustomorderno(apsProductDetailVo.getCustomorderno());
+                            //查询对应合并订单的详情
+                            ApsProductionMergeOrderDo apsProductionMergeOrderDo = apsProductionMergeOrderDoList.stream().filter(item -> item.getCustomorderno().equals(apsProductDetailVo.getCustomorderno()) && item.getDeleted().equals("0")).findFirst().orElse(null);
+                            if (apsProductionMergeOrderDo == null) {
+                                needUpdateOutProduct.setOrderno(orderno);
+                                needUpdateOutProduct.setCustomname(customname);
+                            } else {
+                                needUpdateOutProduct.setCustomorderno(apsProductionMergeOrderDo.getCustomorderno());
+                                needUpdateOutProduct.setCustomname(apsProductionMergeOrderDo.getCustomname());
+                            }
+                        } else {
+                            needUpdateOutProduct.setCustomorderno(customorderno);
+                            needUpdateOutProduct.setOrderno(orderno);
+                            needUpdateOutProduct.setCustomname(customname);
+                        }
+
+                    }
+                    needUpdateOutProductList.add(needUpdateOutProduct);
+                }
+                Map<String, List<ApsProcessOutputProductDo>> blankIdAndOutputMap = needUpdateOutProductList.stream().collect(Collectors.groupingBy(ApsProcessOutputProductDo::getBlankid));
+                //遍历循环,计算坯料计划的需要更新的字段值
+                List<ApsBlankOrderDo> needUpdateBlankList = new LinkedList<>();
+                for (String key : blankIdAndOutputMap.keySet()) {
+                    List<ApsProcessOutputProductDo> apsProcessOutputProductDos = blankIdAndOutputMap.get(key);
+                    String orderNos = apsProcessOutputProductDos.stream().map(ApsProcessOutputProductDo::getOrderno).distinct().collect(Collectors.joining(","));
+                    String customOrderNos = apsProcessOutputProductDos.stream().map(ApsProcessOutputProductDo::getCustomorderno).distinct().collect(Collectors.joining(","));
+                    String customNames = apsProcessOutputProductDos.stream().map(ApsProcessOutputProductDo::getCustomname).distinct().collect(Collectors.joining(","));
+                    ApsBlankOrderDo needUpdateBlank = new ApsBlankOrderDo();
+                    needUpdateBlank.setId(key);
+                    needUpdateBlank.setOrderno(orderNos);
+                    needUpdateBlank.setCustomorderno(customOrderNos);
+                    needUpdateBlank.setCustomname(customNames);
+                    needUpdateBlankList.add(needUpdateBlank);
+                }
+                //更新输出成品集合和坯料计划集合
+                if (!needUpdateOutProductList.isEmpty()) {
+                    apsProcessOutputProductService.updateBatchById(needUpdateOutProductList);
+                }
+                if (!needUpdateBlankList.isEmpty()) {
+                    apsBlankOrderService.updateBatchById(needUpdateBlankList);
+                }
             }
 
             if (req.getIsNeedPublish()) {