From 6dbea727a1fcaa0de63578ac90183bfd0a1417b3 Mon Sep 17 00:00:00 2001 From: guoyujie <guoyujie@ng.com> Date: 星期日, 27 四月 2025 09:51:48 +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/GlassOptimizeService.java | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 151 insertions(+), 0 deletions(-) diff --git a/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java b/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java index 81ffb3e..52a2b9e 100644 --- a/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java +++ b/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java @@ -24,6 +24,7 @@ import java.text.DecimalFormat; import java.util.*; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -459,4 +460,154 @@ return true; } + + + + public String simulatedTypesetting(Map<String, Object> object) { + + String optionVal = ""; + Integer quantity = 0; + Double area = 0.0; + if (object.get("optionVal") != null) { + optionVal = object.get("optionVal").toString(); + } + if (object.get("quantity") != null) { + quantity = Integer.valueOf(object.get("quantity").toString()); + } + if (object.get("area") != null) { + area = Double.valueOf(object.get("area").toString()); + } + List<Map<String, Object>> flowCardListNormal = glassOptimizeMapper.getFlowCardListNormal(optionVal); + + + int currentQuantity = 0; + double currentArea = 0; + List<List<Map<String, Object>>> result = new ArrayList<>(); + List<Map<String, Object>> currentGroup = new ArrayList<>(); + + if(area==0 && quantity>0){ + for(Map<String, Object> flowCardNormal: flowCardListNormal){ + if (Integer.valueOf(flowCardNormal.get("quantity").toString()) > quantity ) { + continue; + } + int newQuantity = currentQuantity + Integer.valueOf(flowCardNormal.get("quantity").toString()); + double newArea = currentArea + Double.valueOf(flowCardNormal.get("area").toString()); + if(newQuantity>quantity){ + result.add(currentGroup); + currentGroup = new ArrayList<>(); + currentQuantity = 0; + currentArea = 0; + newQuantity = Integer.valueOf(flowCardNormal.get("quantity").toString()); + newArea = Double.valueOf(flowCardNormal.get("area").toString()); + + } + currentGroup.add(flowCardNormal); + currentQuantity = newQuantity; + currentArea = newArea; + + } + + if (!currentGroup.isEmpty()) { + result.add(currentGroup); + } + } + System.out.println(result); + + return ""; + + } + + public String simulatedTypesetting1(Map<String, Object> object) { + + String optionVal = ""; + int quantity; + Double area; + if (object.get("optionVal") != null) { + optionVal = object.get("optionVal").toString(); + } + if (object.get("quantity") != null) { + quantity = Integer.valueOf(object.get("quantity").toString()); + } else { + quantity = 0; + } + if (object.get("area") != null) { + area = Double.valueOf(object.get("area").toString()); + } else { + area = 0.0; + } + List<Map<String, Object>> flowCardListNormal = glassOptimizeMapper.getFlowCardListNormal(optionVal); + + + Queue<Map<String, Object>> queue = flowCardListNormal.stream() + .filter(item -> { + if ((quantity>0 ? (Integer.valueOf(item.get("quantity").toString()) > quantity):false) || (area>0 ? (Double.valueOf(item.get("area").toString()) > area):false)) { + return false; + } + return true; + }) + .collect(Collectors.toCollection(LinkedList::new)); + + List<Map<String, Object>> result = new ArrayList<>(); + + while (!queue.isEmpty()) { + List<Map<String, Object>> currentGroup = new ArrayList<>(); + Map<String, Object> currentGroupMap = new HashMap<>(); + int currentCount = 0; + double currentArea = 0; + + // 澶勭悊褰撳墠杞闃熷垪涓殑鎵�鏈夊厓绱� + int queueSize = queue.size(); + boolean addedAny = false; + + String processId=""; + for (int i = 0; i < queueSize; i++) { + Map<String, Object> item = queue.poll(); + if ((quantity>0?currentCount + Integer.valueOf(item.get("quantity").toString()) <= quantity:true) + && (area>0?currentArea + Double.valueOf(item.get("area").toString()) <= area:true)) { + if(i+1==queueSize){ + processId=processId+item.get("process_id").toString()+"/"+item.get("technology_number").toString(); + }else{ + processId=processId+item.get("process_id").toString()+"/"+item.get("technology_number").toString()+";"; + } + currentGroup.add(item); + currentCount += Integer.valueOf(item.get("quantity").toString()); + currentArea += Double.valueOf(item.get("area").toString()); + addedAny = true; + } else { + queue.offer(item); // 鏀惧洖闃熷垪绛夊緟涓嬫澶勭悊 + } + } + + if (currentGroup.isEmpty()) { + throw new RuntimeException("鏃犳硶缁х画鍒嗙粍锛屽墿浣欐暟鎹棤娉曟斁鍏ヤ换浣曞垎缁�"); + } + currentGroupMap.put("processId",processId); + currentGroupMap.put("count",currentCount); + currentGroupMap.put("area",Math.round(currentArea * 100) / 100.0); + result.add(currentGroupMap); + //System.out.println("娴佺▼鍗�:"+processId+"鏁伴噺:"+currentCount+"闈㈢Н:"+Math.round(currentArea * 100) / 100.0); + } + + for (Map<String, Object> objectMap:result){ + Map<String,Object> map = new HashMap<>(); + String[] substrings = objectMap.get("processId").toString().split(";"); + List<Map<String, Object>> flowCardMap = new ArrayList<>(); + List<String> processIdList=new ArrayList<>(); + List<Integer> technologyNumberList=new ArrayList<>(); + for(String substring : substrings) { + String processId = substring.substring(0, 14); + Integer technologyNumber = Integer.valueOf(substring.substring(15)); + processIdList.add(processId); + technologyNumberList.add(technologyNumber); + } + map.put("data",glassOptimizeMapper.simulatedTypesettingUsingOpt(processIdList,technologyNumberList)); + objectMap.put("cuttingRate",90); + } + System.out.println(result); + + return ""; + + } + + } -- Gitblit v1.8.0