BoxData.java 13.6 KB
package com.neotel.webbox.capacitynew.bean;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.util.NumberUtils;
import com.neotel.webbox.util.NumberUtil;
import lombok.Getter;
import lombok.Setter;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Setter
@Getter
public class BoxData {

    /**
     * 料仓名称
     */
    @ExcelProperty("料仓名称")
    private String boxName;

    /**
     * 料仓高度
     */
    @ExcelProperty("料仓高度")
    private int boxHeight;

    /**
     * 料仓不可用高度
     */
    @ExcelProperty("不可用高度")
    private int boxInvalidHeight;


    /**
     * 列数
     */
    @ExcelProperty("标准列数")
    private int columnCount;


    /**
     * 料仓特殊列
     */
    @ExcelIgnore
    private Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap;


    /**
     * 是否有效
     *
     * @return
     */
    public boolean isValid() {
        return !boxName.isEmpty()
                && boxHeight >= 1000
                && boxInvalidHeight >= 100
                && columnCount >= 1;
    }

    public int getBoxPureSizeCapacity(ReelData reelData) {
        //每一列可放料盘数量
        int columnPureSizeCapacity = getColumnPureSizeCapacity(reelData.getPressHeight(), reelData);
        //特殊列上部可放料盘数量
        int boxSpecialColumnUpCapacityTotal = getBoxSpecialColumnUpCapacityTotal(getBoxSpecialColumnMap(), reelData.getPressHeight(), reelData);
        //特殊列下部可放料盘数量
        int boxSpecialColumnCapacityTotal = getBoxSpecialColumnCapacityTotal(getBoxSpecialColumnMap(), reelData);
        int total = getColumnCount() * columnPureSizeCapacity + boxSpecialColumnUpCapacityTotal + boxSpecialColumnCapacityTotal;
        return total;
    }


    /**
     * 获取特殊列上部可放入料盘大小
     *
     * @param pressHeight
     * @param reelData
     * @return
     */
    public int getBoxSpecialColumnUpCapacityTotal(Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap, int pressHeight, ReelData reelData) {
        int boxSpecialColumnUpCapacity = 0;
        if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
            boxFillSpecialColumnHeight(boxSpecialColumnMap, reelData);
            for (Map.Entry<String, List<BoxSpecialColumnContent>> entry : boxSpecialColumnMap.entrySet()) {
                List<BoxSpecialColumnContent> boxSpecialColumnContentList = entry.getValue();
                if (boxSpecialColumnContentList != null && boxSpecialColumnContentList.size() > 0) {
                    //减去(可用+不可用的),得到可用高度,取放入的数量
                    int boxSpecialColumnHeightTotal = boxSpecialColumnContentList.stream().mapToInt(BoxSpecialColumnContent::getHeight).sum();
                    int boxSpecialColumnUpHeight = getBoxSpecialColumnUpHeightTotal(boxSpecialColumnHeightTotal, pressHeight);
                    boxSpecialColumnUpCapacity += getColumnPureSizeCapacity(boxSpecialColumnUpHeight, reelData.getReelSize(), reelData.getReelSlotHeight());
                }
            }
        }
        return boxSpecialColumnUpCapacity;
    }


    /**
     * 特殊列上方可用空间(总高度 - 特殊列可用不可用高度 - 下方高度 - 压紧高度)
     */
    public int getBoxSpecialColumnUpHeightTotal(int boxSpecialColumnHeightTotal, int pressHeight) {
        int columnValidHeight = getBoxHeight() - boxSpecialColumnHeightTotal - getBoxInvalidHeight() - pressHeight;
        return columnValidHeight;
    }

    /**
     * 获取特殊列可用高度,所能放的数量
     *
     * @param boxSpecialColumnMap
     * @param reelData
     * @return
     */
    public int getBoxSpecialColumnCapacityTotal(Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap, ReelData reelData) {
        int boxSpecialColumnCapacity = 0;
        if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
            //加载料仓与料盘之间的数据
            boxSpecialColumnMap = boxFillSpecialColumnHeight(boxSpecialColumnMap, reelData);
            //循环每列可以放下的高度
            for (Map.Entry<String, List<BoxSpecialColumnContent>> entry : boxSpecialColumnMap.entrySet()) {
                List<BoxSpecialColumnContent> boxSpecialColumnContentList = entry.getValue();
                if (boxSpecialColumnContentList != null && boxSpecialColumnContentList.size() > 0) {
                    for (BoxSpecialColumnContent boxSpecialColumnContent : boxSpecialColumnContentList) {
                        if ("可用".equals(boxSpecialColumnContent.getTitle())) {
                            boxSpecialColumnCapacity += getColumnPureSizeCapacity(boxSpecialColumnContent.getHeight(), reelData.getReelSize(), reelData.getReelSlotHeight());
                        }
                    }
                }
            }
        }
        return boxSpecialColumnCapacity;
    }


    /**
     * 获取特殊列可用高度,所能放的数量(单个)
     *
     * @param boxSpecialColumnContentList
     * @param reelData
     * @return
     */
    public int getBoxSingleSpecialColumnCapacity(List<BoxSpecialColumnContent> boxSpecialColumnContentList, ReelData reelData) {
        int boxSingleSpecialColumnCapacity = 0;
        //循环每列可以放下的高度
        if (boxSpecialColumnContentList != null && boxSpecialColumnContentList.size() > 0) {
            for (BoxSpecialColumnContent boxSpecialColumnContent : boxSpecialColumnContentList) {
                if ("可用".equals(boxSpecialColumnContent.getTitle())) {
                    boxSingleSpecialColumnCapacity += getColumnPureSizeCapacity(boxSpecialColumnContent.getHeight(), reelData.getReelSize(), reelData.getReelSlotHeight());
                }
            }

        }
        return boxSingleSpecialColumnCapacity;
    }


    /**
     * 获取到特殊列(单列)可用的总高度
     *
     * @param boxSpecialColumnContentList
     * @return
     */
    public int getBoxSingleSpecialColumnHeight(List<BoxSpecialColumnContent> boxSpecialColumnContentList) {
        return boxSpecialColumnContentList.stream().filter(boxSpecialColumnContent -> boxSpecialColumnContent.getTitle().equals("可用")).mapToInt(BoxSpecialColumnContent::getHeight).sum();
    }


    /**
     * 料仓特殊列取值 与 料盘关联
     *
     * @param boxSpecialColumnMap
     * @param reelData
     * @return
     */
    public static Map<String, List<BoxSpecialColumnContent>> boxFillSpecialColumnHeight(Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap, ReelData reelData) {
        if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
            for (Map.Entry<String, List<BoxSpecialColumnContent>> entry : boxSpecialColumnMap.entrySet()) {
                String boxSpecialColumnTitle = entry.getKey();
                //获取到特殊列的值
                List<BoxSpecialColumnContent> boxSpecialColumnContentList = entry.getValue();
                if (boxSpecialColumnContentList != null && boxSpecialColumnContentList.size() > 0) {
                    for (BoxSpecialColumnContent boxSpecialColumnContent : boxSpecialColumnContentList) {
                        getBoxSpecialColumnHeight(boxSpecialColumnContent, reelData);
                    }
                }
            }
        }
        return boxSpecialColumnMap;
    }

    /**
     * 特殊列进行转换,文本的转成数值
     *
     * @param boxSpecialColumnContent
     * @return
     */
    public static BoxSpecialColumnContent getBoxSpecialColumnHeight(BoxSpecialColumnContent boxSpecialColumnContent, ReelData reelData) {
        //先看料仓里是否配置,如果没有配置的话  就取料盘数据
        int height = 0;
        if (NumberUtil.isInteger(boxSpecialColumnContent.getValue())) {
            height = (int) Double.parseDouble(boxSpecialColumnContent.getValue());
        } else {
            Map<String, Integer> boxSpecialColumn = reelData.getBoxSpecialColumn();
            Integer boxSpecialColumnHeight = boxSpecialColumn.get(boxSpecialColumnContent.getValue());
            if (boxSpecialColumnHeight != null) {
                height = boxSpecialColumnHeight;
            }
        }
        boxSpecialColumnContent.setHeight(height);
        return boxSpecialColumnContent;
    }


    /**
     * 获取标准列可放入料盘数量
     *
     * @param pressHeight
     * @param reelData
     * @return
     */
    public int getColumnPureSizeCapacity(int pressHeight, ReelData reelData) {
        //标准列可用高度
        int columnValidHeight = getColumnValidHeight(pressHeight);
        return getColumnPureSizeCapacity(columnValidHeight, reelData.getReelSize(), reelData.getReelSlotHeight()/*, false*/);
    }


    /**
     * 根据可用空间和料盘尺寸计算料盘容量
     *
     * @param reelSize        料盘尺寸
     * @param validHeight     可用高度
     * @param reelSpaceHeight 单个格子占用高度
     * @return 容量
     */
    public int getColumnPureSizeCapacity(int validHeight, int reelSize, int reelSpaceHeight/*, boolean isDoorDown*/) {
        int countPerColumn = validHeight / reelSpaceHeight;
        //如果不是入料口下方,每一列上部可多放一盘
        //if (!isDoorDown) {
            if (reelSize == 7 || validHeight % reelSpaceHeight != 0) {
                //如果有空余可以再放一盘,7寸盘可以多放一盘
                countPerColumn = countPerColumn + 1;
            }
       // }
        //每个格子可放料盘数,7寸盘为2盘,其他为1
        int countPerUnit = 1;
        if (reelSize == 7) {
            countPerUnit = 2;
        }
        int capacity = countPerColumn * countPerUnit;
        return capacity;
    }


    /**
     * 料仓列可用高度,总高-不可用高度(下方电气板) - 压紧轴占用高度
     */
    public int getColumnValidHeight(int pressHeight) {
        return getBoxHeight() - getBoxInvalidHeight() - pressHeight;
    }

    /**
     * 获取到料仓总可用高度
     *
     * @param maxPressHeight
     * @param requestList
     * @return
     */
    public int getTotalValidHeight(int maxPressHeight, List<RequestItem> requestList) {
        return this.getColumnCount() * getColumnValidHeight(maxPressHeight) + getBoxSpecialColumnValidHeightTotal(getBoxSpecialColumnMap(),requestList) + getBoxSpecialColumnUpValidHeightTotal(getBoxSpecialColumnMap(), requestList, maxPressHeight);
    }


    /**
     * 获取特殊列上部有效高度
     *
     * @param boxSpecialColumnMap
     * @return
     */
    public int getBoxSpecialColumnUpValidHeightTotal(Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap, List<RequestItem> requestList, int maxPressHeight) {
        int boxSpecialColumnUpHeightTotal = 0;
        if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
            //循环特殊列
            for (Map.Entry<String, List<BoxSpecialColumnContent>> map : boxSpecialColumnMap.entrySet()) {
                int singleBoxSpecialColumnUpValidHeight = getBoxHeight();
                List<BoxSpecialColumnContent> boxSpecialColumnContentList = map.getValue();
                int tempValidHeight = 0;
                for (RequestItem requestItem : requestList) {
                    for (BoxSpecialColumnContent boxSpecialColumnContent : boxSpecialColumnContentList) {
                        getBoxSpecialColumnHeight(boxSpecialColumnContent, requestItem.getReelData());
                    }
                    int specialColumnValidHeight = boxSpecialColumnContentList.stream().mapToInt(BoxSpecialColumnContent::getHeight).sum();
                    tempValidHeight = getBoxSpecialColumnUpHeightTotal(specialColumnValidHeight, maxPressHeight);
                    if (tempValidHeight < singleBoxSpecialColumnUpValidHeight) {
                        singleBoxSpecialColumnUpValidHeight = tempValidHeight;
                    }
                }
                boxSpecialColumnUpHeightTotal += singleBoxSpecialColumnUpValidHeight;
            }
        }
        return boxSpecialColumnUpHeightTotal;
    }


    /**
     * 获取特殊列上部有效高度(单列)
     *
     * @param boxSpecialColumnContentList
     * @param maxPressHeight
     * @return
     */
    public int getBoxSingleSpecialColumnUpValidHeight(List<BoxSpecialColumnContent> boxSpecialColumnContentList, int maxPressHeight) {
        int specialColumnHeight = boxSpecialColumnContentList.stream().mapToInt(BoxSpecialColumnContent::getHeight).sum();
        return getBoxSpecialColumnUpHeightTotal(specialColumnHeight, maxPressHeight);
    }


    /**
     * 获取特殊列可用总高度
     *
     * @param boxSpecialColumnMap
     * @return
     */
    public int getBoxSpecialColumnValidHeightTotal(Map<String, List<BoxSpecialColumnContent>> boxSpecialColumnMap,List<RequestItem> requestList) {
        //获取到可用高度
        int specialColumnValidHeight = 0;
        if (boxSpecialColumnMap != null && boxSpecialColumnMap.size() > 0) {
            //每个料仓可用高度是一样的,在这里只取第一个
            boxSpecialColumnMap = boxFillSpecialColumnHeight(boxSpecialColumnMap,requestList.get(0).getReelData());
            for (Map.Entry<String, List<BoxSpecialColumnContent>> entry : boxSpecialColumnMap.entrySet()) {
                List<BoxSpecialColumnContent> specialColumnContentList = entry.getValue();
                specialColumnValidHeight += specialColumnContentList.stream().filter(boxSpecialColumnContent -> boxSpecialColumnContent.getTitle().equals("可用")).mapToInt(BoxSpecialColumnContent::getHeight).sum();
            }
        }
        return specialColumnValidHeight;
    }
}