guoyujie
2025-04-27 6dbea727a1fcaa0de63578ac90183bfd0a1417b3
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 "";
    }
}