Browse Source

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

sucheng 3 months ago
parent
commit
c85b326dc9

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

@@ -513,68 +513,8 @@ public class ApsProductionOrderServiceImpl extends ServiceImpl<ApsProductionOrde
                 }
 
                 //根据订单和产品明细,及其合并订单,重新赋值 坯料计划和输出成品的冗余字段
-                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);
-                }
+                List<ApsProductDetailDo> apsProductDetailDos = BeanUtil.copyToList(apsProductDetailVoList, ApsProductDetailDo.class);
+                setBlankColumn(apsProductionOrderDo, apsBlankOrderDoList, apsProductDetailDos, apsProductionMergeOrderDoList);
             }
 
             if (req.getIsNeedPublish()) {
@@ -1201,6 +1141,15 @@ public class ApsProductionOrderServiceImpl extends ServiceImpl<ApsProductionOrde
             } catch (Exception e) {
                 throw new RuntimeException("更新订单信息错误,请刷新页面后重试");
             }
+            //订单更新完后,更新坯料计划对应的字段
+            //查询坯料计划
+            List<ApsBlankOrderDo> apsBlankOrderDoList = apsBlankOrderService.list(new LambdaQueryWrapper<ApsBlankOrderDo>().eq(ApsBlankOrderDo::getProductionorderid, id));
+            //查询产品明细
+            List<ApsProductDetailDo> apsProductDetailVoList = apsProductDetailService.list(new LambdaQueryWrapper<ApsProductDetailDo>().eq(ApsProductDetailDo::getMainid, id));
+            //查询合并订单
+            List<ApsProductionMergeOrderDo> apsProductionMergeOrderDoList = apsProductionMergeOrderService.list(new LambdaQueryWrapper<ApsProductionMergeOrderDo>().eq(ApsProductionMergeOrderDo::getMainid, id));
+            setBlankColumn(oldOrder, apsBlankOrderDoList, apsProductDetailVoList, apsProductionMergeOrderDoList);
+
             //提交流程
             if (req.getIsSubmitWf()) {
                 String processinstid = nowApsProductionOrderDo.getProcessinstid();
@@ -1261,6 +1210,74 @@ public class ApsProductionOrderServiceImpl extends ServiceImpl<ApsProductionOrde
         return R.ok();
     }
 
+    private void setBlankColumn(ApsProductionOrderDo orderDo, List<ApsBlankOrderDo> apsBlankOrderDoList, List<ApsProductDetailDo> apsProductDetailVoList, List<ApsProductionMergeOrderDo> apsProductionMergeOrderDoList) {
+        //根据订单和产品明细,及其合并订单,重新赋值 坯料计划和输出成品的冗余字段
+        String orderno = orderDo.getOrderno();
+        String customorderno = orderDo.getCustomorderno();
+        String customname = orderDo.getCustomname();
+        List<String> blankIdList = apsBlankOrderDoList.stream().map(ApsBlankOrderDo::getId).collect(Collectors.toList());
+        if (!blankIdList.isEmpty()) {
+            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();
+                //查询对应的产品明细
+                ApsProductDetailDo 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.setOrderno(apsProductionMergeOrderDo.getOrderno());
+                            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);
+            }
+        }
+    }
+
     @Override
     public R removeBatchNumberByOrderId(String orderId) {
         //查询所有的坯料计划