From 1513b84f9d700f54c4caa28fb553ddb9aea21eb4 Mon Sep 17 00:00:00 2001
From: 廖井涛 <2265517004@qq.com>
Date: 星期二, 13 五月 2025 09:10:14 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/ERP_override

---
 north-glass-erp/src/main/java/com/example/erp/service/pp/FlowCardService.java |  145 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 97 insertions(+), 48 deletions(-)

diff --git a/north-glass-erp/src/main/java/com/example/erp/service/pp/FlowCardService.java b/north-glass-erp/src/main/java/com/example/erp/service/pp/FlowCardService.java
index 057678f..ed590ab 100644
--- a/north-glass-erp/src/main/java/com/example/erp/service/pp/FlowCardService.java
+++ b/north-glass-erp/src/main/java/com/example/erp/service/pp/FlowCardService.java
@@ -19,6 +19,7 @@
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDate;
 import java.util.List;
 import java.util.Map;
 
@@ -29,6 +30,7 @@
 import java.sql.Date;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 import static com.example.erp.service.sd.OrderService.getOrderProcessDetails;
 
@@ -52,11 +54,25 @@
     }
 
     //娴佺▼鍗$鐞嗘煡璇�
-    public Map<String, Object> selectProcessCard(Integer pageNum, Integer pageSize, Date selectTime1, Date selectTime2, FlowCard flowCard) {
+    public Map<String, Object> selectProcessCard(Integer pageNum, Integer pageSize,List<String> selectDate, FlowCard flowCard) {
         Integer offset = (pageNum - 1) * pageSize;
+        String endDate = LocalDate.now().toString();
+        String startDate = LocalDate.now().minusDays(15).toString();
+        if(selectDate !=null && selectDate.size()==2){
+            if(!selectDate.get(0).isEmpty()){
+                startDate = selectDate.get(0);
+            }
+            if(!selectDate.get(1).isEmpty()){
+                endDate = selectDate.get(1);
+            }
+        }
         Map<String, Object> map = new HashMap<>();
-        map.put("data", flowCardMapper.selectFlowCard(offset, pageSize, selectTime1, selectTime2, flowCard));
-        map.put("total", flowCardMapper.getPageTotal(offset, pageSize, selectTime1, selectTime2, flowCard));
+        map.put("data", flowCardMapper.selectFlowCard(offset, pageSize, startDate, endDate, flowCard));
+        map.put("total", flowCardMapper.getPageTotal(offset, pageSize, startDate, endDate, flowCard));
+        List<String> list = new ArrayList<>();
+        list.add(startDate);
+        list.add(endDate);
+        map.put("selectDate",list);
         return map;
     }
 
@@ -216,6 +232,7 @@
     public Object flowCardDetailSv(String processId, FlowCard flowCard) {
         Map<String, Object> map = new HashMap<>();
         map.put("data", flowCardMapper.flowCardDetailMp(processId, flowCard));
+        map.put("merge", flowCardMapper.flowCardDetailMergeMp(processId));
         return map;
     }
 
@@ -797,16 +814,17 @@
         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();//鏈�缁堢粨鏋�
         List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class);
         if (!flowCardList.isEmpty()) {
-            Set<String> processedProcessIds = new HashSet<>();  // 鐢ㄦ潵瀛樻斁宸插鐞嗚繃鐨� processId
+            Set<String> processedKeys = new HashSet<>();
 
             if (lableType != 2) {//鎴愬搧鏍囩
                 for (FlowCard flowCard : flowCardList) {
                     String orderId = flowCard.getOrderId();
                     String processId = flowCard.getProcessId();
                     String orderNumber = flowCard.getOrderNumber().toString();
+                    String uniqueKey = processId + "|" + orderNumber;  // 鐢ㄧ壒娈婂瓧绗﹁繛鎺ラ槻姝㈠啿绐�
                        if (processId!=null){
                            // 妫�鏌ユ槸鍚﹀凡缁忓鐞嗚繃璇� processId锛屽鏋滃鐞嗚繃鍒欒烦杩�
-                           if (processedProcessIds.contains(processId) && processedProcessIds.contains(orderNumber)) {
+                           if (processedKeys.contains(uniqueKey)) {
                                continue;
                            }
                            Map<String, Object> itemmap = new HashMap<>();
@@ -814,8 +832,7 @@
                            list.add(itemmap);
 
                            // 灏嗚 processId 鍔犲叆宸插鐞嗛泦鍚�
-                           processedProcessIds.add(processId);
-                           processedProcessIds.add(orderNumber);
+                           processedKeys.add(uniqueKey);
                        } else{
 
                            Map<String, Object> itemmap = new HashMap<>();
@@ -863,23 +880,27 @@
 
     }
 
-    public String mergeFlowCard(Map<String, Object> object) {
+    public String mergeFlowCard(Map<String, Object> object, Integer merge) {
         String returns = "false";
         List<FlowCard> flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class);
         if (!flowCardList.isEmpty()) {
             List<Map<String, Object>> flowCardList1 = flowCardMapper.selectFlowCardMerge(flowCardList.get(0).getProcessId());
-            int index = 1;
-            for (int i = 0; i < flowCardList1.size(); i++) {
-                if (Integer.valueOf(flowCardList1.get(i).get("count2").toString()) > 1) {
-                    List<Integer> technologyNumber = Arrays.stream(flowCardList1.get(i).get("count1").toString().split(","))
-                            .map(Integer::parseInt)
-                            .collect(Collectors.toList());
-                    flowCardMapper.updateFlowCardMerge(flowCardList.get(0).getProcessId(), technologyNumber, index);
-                    index += 1;
-                    returns = "true";
+            if (merge == 0){
+                int index = 1;
+                for (int i = 0; i < flowCardList1.size(); i++) {
+                    if (Integer.valueOf(flowCardList1.get(i).get("count2").toString()) > 1) {
+                        List<Integer> technologyNumber = Arrays.stream(flowCardList1.get(i).get("count1").toString().split(","))
+                                .map(Integer::parseInt)
+                                .collect(Collectors.toList());
+                        flowCardMapper.updateFlowCardMerge(flowCardList.get(0).getProcessId(), technologyNumber, index);
+                        index += 1;
+                        returns = "true";
+                    }
                 }
+            }else {//鍙栨秷鍚堝苟
+                flowCardMapper.updateFlowCardIsMerge(flowCardList.get(0).getProcessId());
+                returns = "true";
             }
-
 
         }
 
@@ -895,11 +916,14 @@
         }
 
         String[] processCardList = processCard.split("/");
+        List<String> result = IntStream.range(0, processCardList[1].length())
+                .mapToObj(i -> String.valueOf(processCardList[1].charAt(i)))
+                .collect(Collectors.toList());
 
         List<FlowCard> flowCardList = flowCardMapper.selectList(
                 new QueryWrapper<FlowCard>()
                         .eq("process_id", processCardList[0])
-                        .eq("technology_number", processCardList[1])
+                        .in("technology_number", result)
         );
         for (FlowCard flowCard : flowCardList) {
             flowCard.setOrderGlassDetail(
@@ -1062,20 +1086,27 @@
     }
 
     public Object processCardAutoRack(Map<String, Object> object) {
-        String orderId = "NG25000004";
-        String productionId = "NG25000004B";
-        /*String orderId = object.get("orderId").toString();
+        String orderId = object.get("orderId").toString();
         String productionId = object.get("productionId").toString();
         Integer inMaxQuantity = Integer.parseInt(object.get("inMaxQuantity").toString());
         Float inWeight =  Float.parseFloat(object.get("inWeight").toString());
-        Float shelfThickness =  Float.parseFloat(object.get("shelfThickness").toString())*1000;
+        Float shelfThickness =  Float.parseFloat(object.get("shelfThickness").toString());
         Float spacerThickness =  Float.parseFloat(object.get("spacerThickness").toString());
-        */
-        //Integer inMaxQuantity = 1;
-        Float inWeight = 100.0f;
+        Float inLenMax = Float.parseFloat(object.get("inLenMax").toString());
+        Float inLenMin = Float.parseFloat(object.get("inLenMin").toString());
+        Float inShortMax = Float.parseFloat(object.get("inShortMax").toString());
+        Float inShortMin = Float.parseFloat(object.get("inShortMin").toString());
+
+        /*String orderId = "NG25000004";
+        String productionId = "NG25000004A";
+        Integer inMaxQuantity = 1;
+        Float inWeight = 4000.0f;
         Float shelfThickness = 2000.0f;
-        /*鍨墖鍘氬害*/
-        Float spacerThickness = 0.0f;
+        Float maxHeight = 1520.0f;
+        Float maxWid = 400.0f;
+        Float spacerThickness = 0.0f;//鍨墖鍘氬害*/
+
+
         Map<String, Object> thickness = flowCardMapper.getGlassThicknessByProdutionId(orderId, productionId);
 
         //鎴愬搧鐜荤拑鎬诲帤搴�
@@ -1084,7 +1115,8 @@
         Float glassThickness = Float.parseFloat(thickness.get("thickness").toString());
 
         //鑾峰彇姝ゅ伐绋嬪彿璁㈠崟鏄庣粏淇℃伅
-        List<OrderDetail> orderDetails = flowCardMapper.getOrderDetailByProductionId(orderId, productionId);
+        List<OrderDetail> orderDetails = flowCardMapper.getOrderDetailByProductionId(orderId, productionId,"scope",inLenMax,inLenMin,inShortMax,inShortMin,glassThickness);
+        List<OrderDetail> orderDetailsNotScope = flowCardMapper.getOrderDetailByProductionId(orderId, productionId,"notScope",inLenMax,inLenMin,inShortMax,inShortMin,glassThickness);
 
         //鏍规嵁鐜荤拑鍘氬害鍜屽灚鐗囧帤搴﹀綋鍓嶆灦瀛愭渶澶у彲鏀炬暟閲�
         Integer shelfMaxQuantityByThickness = (int) (shelfThickness / (glassTotalThickness + spacerThickness));
@@ -1106,59 +1138,74 @@
             );
             //褰撳墠璁㈠崟鏄庣粏鍓╀綑鏁伴噺
             if (shelfQuantity == 0) {
-                shelfQuantity = shelfQuantityByWeight;
+                shelfQuantity =Math.min( Math.min(shelfMaxQuantityByThickness,inMaxQuantity),shelfQuantityByWeight);
             }else if(shelfQuantity>0){//鏋跺瓙鍓╀綑鏁伴噺澶т簬0鏃讹紝鍒ゆ柇褰撳墠鏋跺瓙鍓╀綑閲嶉噺锛屾槸鍚︽敮鎸佹渶鏂板簭鍙风殑鐨勬垚鍝侀噸閲�
-                String FlowCardId = orderDetailList.get(orderDetailList.size() - 1).getFlowCardId();
+                String FlowCardId = orderDetailList.get(orderDetailList.size() - 1).getProcessId();
                 double flowCardWeight = 0.0;
                 for (OrderDetail orderDetail1 : orderDetailList) {
-                    if (orderDetail1.getFlowCardId().equals(FlowCardId)) {
+                    if (orderDetail1.getProcessId().equals(FlowCardId)) {
                         flowCardWeight += orderDetail1.getHeight()*orderDetail1.getQuantity()* orderDetail1.getWidth()* glassThickness* 2.5 / 1000000;
                     }
                 }
                 if(flowCardWeight>0){
                     flowCardWeight = inWeight - flowCardWeight;
-                    shelfQuantity = (int) (flowCardWeight /
+                    //鎸夌収褰撳墠娴佺▼鍗″墿浣欓噸閲忥紝璁$畻褰撳墠娴佺▼鍗″墿浣欐暟閲�
+                    int remainingQuantity = (int) (flowCardWeight /
                             (orderDetail.getHeight()
                                     * orderDetail.getWidth()
                                     * glassThickness
                                     * 2.5 / 1000000));
+                    shelfQuantity =Math.min(Math.min(Math.min(shelfQuantityByWeight, Math.min(inMaxQuantity, shelfMaxQuantityByThickness)),shelfQuantity),remainingQuantity);
                     if (shelfQuantity == 0) {
-                        shelfQuantity = shelfQuantityByWeight;
+                        shelfQuantity = Math.min(shelfQuantityByWeight, Math.min(inMaxQuantity, shelfMaxQuantityByThickness));
                         flowCardNo += 1;
                     }
                 }
 
             }
             //鍙栨渶灏忓��
-            Integer maxQuantity = 0;
+            //Integer maxQuantity = 0;
             while (orderDetail.getQuantity() > 0) {
                 OrderDetail newOrderDetail = new OrderDetail();
                 //褰撴寰幆涓紝褰撳墠鏋跺瓙鍓╀綑鏁伴噺涓�0鏃讹紝閲嶆柊璁$畻鏋跺瓙鍓╀綑鏁伴噺
                 if (shelfQuantity == 0) {
-                    shelfQuantity = shelfQuantityByWeight;
+                    shelfQuantity = Math.min(Math.min(shelfMaxQuantityByThickness,inMaxQuantity),shelfQuantityByWeight);
                 }
-                String processId = productionId + String.format("%05d", flowCardNo);
+                String processId = productionId + String.format("%03d", flowCardNo);
                 //鍙栨渶灏忓��
-               // maxQuantity = Math.min(shelfQuantity, Math.min(inMaxQuantity, shelfMaxQuantityByThickness));
-                maxQuantity = Math.min(shelfQuantity,  shelfMaxQuantityByThickness);
+                //maxQuantity = Math.min(shelfQuantity, Math.min(inMaxQuantity, shelfMaxQuantityByThickness));
+                //maxQuantity = Math.min(shelfQuantity,  shelfMaxQuantityByThickness);
 
-                /*System.out.println(shelfQuantity + "," + inMaxQuantity + "," + shelfMaxQuantityByThickness);
+                /*System.out.println("璁㈠崟搴忓彿锛�"+orderDetail.getOrderNumber());
+                System.out.println(shelfQuantity + ","  + "," + shelfMaxQuantityByThickness);
                 System.out.println(flowCardNo + "," + maxQuantity);
                 System.out.println("------");*/
+                if(shelfQuantity<=0){
+                    return false;
+                }
 
-                if (orderDetail.getQuantity() > maxQuantity) {
-                    newOrderDetail.setFlowCardId(processId);
-                    newOrderDetail.setQuantity(Long.valueOf(maxQuantity));
+                if (orderDetail.getQuantity() > shelfQuantity) {
+                    newOrderDetail.setProcessId(processId);
+                    newOrderDetail.setQuantity(Long.valueOf(shelfQuantity));
                     newOrderDetail.setHeight(orderDetail.getHeight());
                     newOrderDetail.setWidth(orderDetail.getWidth());
+                    newOrderDetail.setOrderNumber(orderDetail.getOrderNumber());
+                    newOrderDetail.setShape(orderDetail.getShape());
+                    newOrderDetail.setLandingSequence(flowCardNo);
                     orderDetailList.add(newOrderDetail);
-                    orderDetail.setQuantity(orderDetail.getQuantity() - maxQuantity);
+                    orderDetail.setQuantity(orderDetail.getQuantity() - shelfQuantity);
+                    orderDetail.setBaiscQuantity(String.valueOf(Integer.valueOf(orderDetail.getBaiscQuantity())-shelfQuantity));
                     flowCardNo += 1;
+                    shelfQuantity = shelfQuantity - shelfQuantity;
                 } else {
-                    newOrderDetail.setFlowCardId(processId);
+                    newOrderDetail.setProcessId(processId);
                     newOrderDetail.setQuantity(orderDetail.getQuantity());
                     newOrderDetail.setHeight(orderDetail.getHeight());
                     newOrderDetail.setWidth(orderDetail.getWidth());
+                    newOrderDetail.setOrderNumber(orderDetail.getOrderNumber());
+                    newOrderDetail.setShape(orderDetail.getShape());
+                    newOrderDetail.setLandingSequence(flowCardNo);
+                    newOrderDetail.setBaiscQuantity(String.valueOf(orderDetail.getBaiscQuantity()));
                     orderDetailList.add(newOrderDetail);
                     //褰撳墠鏋跺瓙鍓╀綑鏁伴噺
                     shelfQuantity = shelfQuantity - Math.toIntExact(orderDetail.getQuantity());
@@ -1170,9 +1217,11 @@
             }
 
         }
-
-
-        return orderDetailList;
+        Map<String, Object> map = new HashMap<>();
+        Collections.reverse(orderDetailList);
+        map.put("orderDetailList", orderDetailList);
+        map.put("orderDetailsNotScope", orderDetailsNotScope);
+        return map;
     }
 
 

--
Gitblit v1.8.0