class BestResult {
    CutConfigEx configEx
    int bestCount = 0
    double PaperUtilizationE = 0

    static Map calcEx(List<CutConfigEx> cutConfigExList, String size, int calcType) {

        int inputLength = Integer.valueOf(size.split("\\*")[0])
        int inputWidth = Integer.valueOf(size.split("\\*")[1])
        //当 opType = 0 ,  只用 0 和1 去找， 当他 = 1， 用全部
        //传入一个尺寸，然后用传入的尺寸 使用上面的 cutConfigExList 里的 X 和Y  计算出来一个开数（长 宽相除 向下取整，）每一个都计算一边，然后
        // 然后把使用率最高的那个 cutConfigExList 中 cutTypex 和 cutCountx 的值返回给我。，
        BestResult bestResult = new BestResult()
        cutConfigExList.each {
            if (calcType == 0 || calcType == 1) {
                if (calcType != it.cutTypex) return
            }

            int xCount1 = (int) Math.floor(it.cutSizeX / inputLength)
            int yCount1 = (int) Math.floor(it.cutSizeY / inputWidth)
            int total1 = xCount1 * yCount1
            int xCount2 = (int) Math.floor(it.cutSizeY / inputLength)
            int yCount2 = (int) Math.floor(it.cutSizeX / inputWidth)
            int total2 = xCount2 * yCount2
            int currentTotal = total1 > total2 ? total1 : total2
            //计算拼版面积
            double CountS = currentTotal * inputLength * inputWidth
            //计算纸张利用率
            double PaperUtilization = CountS / (it.cutSizeX * it.cutSizeY)
            //以上循环计算出来纸张利用率，然后取 纸张利用率最大的那一次的 Cut.cutTypex ConfigEx和CutConfigEx.cutCountx * currentTotal 的结果返回给我
            if (bestResult.PaperUtilizationE < PaperUtilization) {
                bestResult.PaperUtilizationE = PaperUtilization
                bestResult.bestCount = currentTotal
                bestResult.configEx = it
            }
        }
        Map<String, Integer> map1 = new HashMap<>()
        int cutTypeS = 0;
        int cutCountS = 0;
        int cutSizeX = 0
        int cutSizeY = 0
        if(bestResult.configEx) {
             cutTypeS = bestResult.configEx.cutTypex
             cutCountS = bestResult.configEx.cutCountx * bestResult.bestCount
             cutSizeX = bestResult.configEx.cutSizeX
             cutSizeY = bestResult.configEx.cutSizeY
        }
        int bestCountS = bestResult.bestCount
        map1.put("cutTypeS", cutTypeS)
        map1.put("cutCountS", cutCountS)
        map1.put("bestCountS", bestCountS)
        map1.put("cutSizeX",cutSizeX)
        map1.put("cutSizeY",cutSizeY)
        return map1
    }
}
